Cinchoo – Configuration framework, part 19

Using ChoFireBirdConfigStorage

UPDATE:

This article is outdated. Please visit the below codeproject article for more updated information on this storage plug-ins

Cinchoo – Using FireBird database as configuration source

 

In this section, I’ll go over the details of using ChoFireBirdConfigStorage in your application. It provides name/value-pair configuration information from FireBird Database.  ChoFireBirdConfigurationSectionAttribute is the corresponding attribute used to decorate the configuration object class.

1. Define the configuration section object decorated with ChoFireBirdConfigurationSectionAttribute 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.

[ChoFireBirdConfigurationSection("sample", @"User=SYSDBA;Password=masterkey;Database=C:\Sample.fdb;DataSource=localhost; Port=3050;Dialect=3; Charset=NONE;",
    "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>
  <configSections>
    <section name="sample" type="Cinchoo.Core.Configuration.ChoNameValueSectionHandler, Cinchoo.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b7dacd80ff3e33de" />
  </configSections>
  <sample cinchoo:connectionString="User=SYSDBA;Password=masterkey;Database=C:\Sample.fdb;DataSource=localhost; Port=3050;Dialect=3; Charset=NONE;" cinchoo:tableName="APP_SETTINGS" cinchoo:configDataColumnSize="250" xmlns:cinchoo="http://schemas.cinchoo.com/cinchoo/01/framework" />
</configuration>
The corresponding meta-data looks as below
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <sample bindingMode="TwoWay" defaultable="true" silent="true">
    <configStorage>Cinchoo.Core.Configuration.ChoFireBirdConfigStorage, Cinchoo.Core.Configuration.Storage.FireBirdConfigStorage, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null</configStorage>
    <logInfo condition="true" directory="Settings" fileName="Cinchoo.Core.Configuration.ChoFireBirdClientSectionHandler.Test.SampleConfigSection.log" />
  </sample>
</configuration>
About these ads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: