Click or drag to resize

Centralized modules configuration

Configuration file

To make it works correctly, AskiaPortalCmn require a configuration file.
This configuration file must at least contains the connection string to the AskiaPortal database.

Location

In your ProgramData folder (C:\ProgramData\), create a file AskiaPortal.config under a sub-folder named AskiaPortal\.

The full path should look like that C:\ProgramData\AskiaPortal\AskiaPortal.config

This file centralize the configuration of AskiaPortal for the entire machine.
So once the configuration is done, it's done for all modules!

File content

The content of the configuration file have the following format:

XML
<configuration version="1.0">
  <askiaportalcmn>
    <settings key="mainDatabase" value="Data Source=(local);Initial Catalog=AskiaPortal;Persist Security Info=True;Trusted_Connection=yes;" />
  </askiaportalcmn>
</configuration>

Where Key is:

mainDatabase

Provide the SQL connection string to the AskiaPortal database

Extra keys for developers:

masterDatabase

Provide the SQL connection string to the SQL Server master database (use to create/drop database within integration tests)

testDatabase

Provide the SQL connection string to an AskiaPortalTest database

testLicensesKey

Provide the key to obtain licenses for the unit tests

XML
<configuration version="1.0">
<askiaportalcmn>
  <settings key="mainDatabase" value="Data Source=(local);Initial Catalog=AskiaPortal;Persist Security Info=True;Trusted_Connection=yes;" />
  <settings key="masterDatabase" value="Data Source=(local);Initial Catalog=master;Persist Security Info=True;Trusted_Connection=yes;" />
  <settings key="testDatabase" value="Data Source=(local);Initial Catalog=AskiaPortalTest;Persist Security Info=True;Trusted_Connection=yes;" />
  <settings key="testLicensesKey"><![CDATA[SECRET]]></settings>
</askiaportalcmn>
</configuration>
Configuration class

Except for the connection string in the configuration file, the entire AskiaPortal configuration is stored into the database Config table.

Using the API, the configuration is accessible via a singleton instance of the Config.

The first call of ConfigGetInstance will read the configuration file and open the database according to the ConfigEnvironmentMode.

Configuration of modules

The Config class loads and contains all IConfigItem of all modules. This is very useful when a given module depends or uses the configuration of another module.

As AskiaPortal is itself consider as a module, you can therefore access all his configuration.
As it's built-in there is a convenient accessors that uses the ConfigKey enumerator.

Test environment

Most of the developers need to connect alternatively on a test database or on the production/development database.

To provide a quick switch between both databases, you first need to reference the test database connection string in the configuration file.

Secondly, the first call of the API must set the environment using the following line of code:

Config.SetEnvironment(Config.EnvMode.Test);
See Also