Using ChoSqlServerConfigStorage
UPDATE:
This article is outdated. Please visit the below codeproject article for more updated information on this storage plug-ins
Cinchoo – Using SQLServer database as configuration source
In this section, I’ll go over the details of using ChoSqlServerConfigStorage in your application. It provides name/value-pair configuration information from SqlServer Database. ChoSqlServerConfigurationSectionAttribute is the corresponding attribute used to decorate the configuration object class.
1. Define the configuration section object decorated with ChoSqlServerConfigurationSectionAttribute as below. You must provide ConnectionString and TableName where the configuration data stored. The table will be created if not exists. The table will have two columns (CONFIG_DATA varchar(250), LAST_UPDATTED_TIME Timestamp). ConnectionString and TableName can be overridden through configuration file.
[ChoSqlServerConfigurationSection("sample", @"Data Source=shreeya-pc\SQLExpress;Initial Catalog=Cinchoo;Integrated Security=True", "APP_SETTINGS")]
public class SampleConfigSection : ChoConfigurableObject
{
#region Instance Data Members (Public)
[ChoPropertyInfo("name", DefaultValue = "Mark")]
public string Name;
[ChoPropertyInfo("message", DefaultValue = "Hello World!")]
public string Message;
#endregion
[ChoAfterConfigurationObjectLoadedHandler]
void OnAfterConfigurationObjectLoaded(object sender, ChoConfigurationObjectEventArgs e)
{
Console.WriteLine(sender.ToString());
}
}
2. Now instantiate and use it as below
class Program
{
static void Main(string[] args)
{
SampleConfigSection sampleConfigSection = new SampleConfigSection();
Console.WriteLine(sampleConfigSection.ToString());
//Shutdown the framework to stop the background services...otherwise the application will not terminate
ChoFramework.Shutdown();
}
}
The configuration section will be generated automatically for the first time in HelloWorld.exe.xml as below
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<sample cinchoo:connectionString="Data Source=your-pc\SQLExpress;Initial Catalog=Cinchoo;Integrated Security=True" cinchoo:tableName="APP_SETTINGS" cinchoo:configDataColumnSize="250" xmlns:cinchoo="http://schemas.cinchoo.com/cinchoo/01/framework" />
<configSections>
<section name="sample" type="Cinchoo.Core.Configuration.ChoNameValueSectionHandler, Cinchoo.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b7dacd80ff3e33de" />
</configSections>
</configuration>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<sample bindingMode="TwoWay" defaultable="true" silent="true">
<configStorage>Cinchoo.Core.Configuration.ChoSqlServerConfigStorage, Cinchoo.Core.Configuration.Storage.ChoSqlServerNameValueConfigStorage, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null</configStorage>
<logInfo condition="true" directory="Settings" fileName="ChoSqlServerConfigStorageDemo.SampleConfigSection.log" />
</sample>
</configuration>