Skip to main content

Configuring custom paths

This article explains how to configure custom paths and other parameters in a .NET application using the Aurigma.DesignAtoms library.

Configuration in .NET Framework​

In classic .NET Framework applications, configurations are typically managed using the App.config or Web.config files. These configurations can be accessed using the System.Configuration namespace.

Config sections​

To define custom configuration sections, use the <configSections> element. This allows you to specify custom handlers for different configuration sections.

<configSections>
<section name="Aurigma.DesignAtoms" type="System.Configuration.NameValueSectionHandler" />
</configSections>

Custom configuration section​

You can define a custom configuration section like this:

<Aurigma.DesignAtoms>
<add key="FontDirectory" value="C:\inetpub\aurigma\data\assets\fonts" />
<add key="ColorProfilesDirectory" value="C:\inetpub\aurigma\data\assets\ColorProfiles" />
<add key="CmykColorProfileFileName" value="USWebCoatedSWOP.icc" />
<add key="PdfRenderDeviceProfileEnabled" value="False" />
<add key="PdfRenderKeepOriginalColors" value="False" />
<add key="PdfTextOutputMode" value="Text" />
<add key="PsdTextBoxWorkaroundEnabled" value="False" />
<add key="PdfHiResRasterizeVectorLayers" value="False" />
<add key="GetDefaultRichTextStyleFromLastChar" value="False" />
<add key="IgnoreInDesignMissingLinks" value="False" />
<add key="LegacyIdmlBleedParsingEnabled" value="False" />
<add key="FlattenGroups" value="False" />
<add key="UseAnisotropic9ResizeMode" value="false" />
<add key="NotFoundGlyphRemovalEnabled" value="false" />
<add key="LegacyTextEngineEnabled" value="False" />
</Aurigma.DesignAtoms>

Accessing configuration values​

To access these configuration values in your code, you can use the ConfigurationManager class:

public string GetParameter(string name)
{
var collection = ConfigurationManager.GetSection("Aurigma.DesignAtoms") as NameValueCollection;
return collection?[name];
}

Local paths configuration​

Let's look at how you can configure asset paths correctly to understand where to fetch design. This can be done by registering the necessary services with the correct parameters.

Registering Services​

Here is an example of how to register a custom ITemplateStorage service with specific paths:

var builder = new ContainerBuilder();
DefaultInjectorFactory.Setup(builder);
builder.RegisterType<LocalTemplateStorage>()
.WithParameters(new[]
{
new NamedParameter("designFolderPath", @"C:\inetpub\aurigma\data\assets\designs"),
new NamedParameter("mockupFolderPath", @"C:\inetpub\aurigma\data\assets\mockups"),
new NamedParameter("sourceFolderPath", @"C:\inetpub\aurigma\data\assets\templates"),
})
.As<ITemplateStorage>()
.SingleInstance();

Example application​

Let's consider a complete example of a console application that uses the Aurigma.DesignAtoms library to load a PSD template and render it to PDF image:

using Aurigma.DesignAtoms.Configuration;
using Aurigma.DesignAtoms.Convert;
using Aurigma.DesignAtoms.Convert.TemplateStorage;
using Aurigma.DesignAtoms.Rendering;
using Autofac;
using System.Configuration;
using System.IO;

namespace DesignAtomsConsole
{
class Program
{
static void Main(string[] args)
{
Injector.CurrentFactory = () =>
{
var builder = new ContainerBuilder();
DefaultInjectorFactory.Setup(builder);
builder.RegisterType<LocalTemplateStorage>()
.WithParameters(new[]
{
new NamedParameter("designFolderPath", @"C:\inetpub\aurigma\data\assets\designs"),
new NamedParameter("mockupFolderPath", @"C:\inetpub\aurigma\data\assets\mockups"),
new NamedParameter("sourceFolderPath", @"C:\inetpub\aurigma\data\assets\templates"),
})
.As<ITemplateStorage>()
.SingleInstance();
return builder.Build();
};

var instance = Injector.Instance;
var parser = instance.Resolve<ITemplateParser>();
var product = parser.FromFile("samples/test-page.psd");
var renderer = instance.Resolve<IProductRenderer>();

using (var fileStream = File.Create("card.pdf"))
{
renderer.RenderHiRes(fileStream, product.Product);
}
}
}
}
Was this page helpful?