Geeks With Blogs

News
Paul's Petrov Whiteboard [BizTalk, Enterprise Application Integration, Business Process Automation, SOA, .NET]

Choice of configuration settings storage is an important topic when it comes to enterprise BizTalk application planning. One of the many options is to use regular .Net configuration files. Some prefer this way over the Enterprise SSO database option for reasons of simplicity and familiarity. I wanted to show how it can be done with Microsoft Enterprise Library configuration application block.

In this case Enterprise Library configuration section is placed in the BTNTSvc.exe.config file while application settings are stored in a separate configuration file. The problem here is how do we make EntLib to load required settings file at runtime.  Its done by simple helper class CustomSettings that looks up registry entry for the location and name of the application configuration file and creates FileConfigurationSource with it. The registry entry can be created  by MSI installation package.

The initialization method of this static helper class looks like this (thread synchronization code omited for brevity):

          RegistryKey regKey = null;

          try
          {
             regKey = Registry.LocalMachine.OpenSubKey(@"Software\MyCompany\MyApplication");
             configurationFile = Path.Combine(
             (string)regKey.GetValue("ConfigDir"),
             (string)regKey.GetValue("ConfigFile"));

              ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap();
              fileMap.ExeConfigFilename = configurationFile;
              configuration = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
              configurationSource = new FileConfigurationSource(configurationFile);

              //- store configPath in the settings
              configuration.AppSettings.Settings.Add(
              new KeyValueConfigurationElement("configDir", (string)regKey.GetValue("ConfigDir")));
           }
           catch (Exception ex)
           {
              Debug.WriteLine("Exception while initializing Settings:" + ex.ToString());
              throw ex;
           }
           finally
           {
              if (regKey != null) regKey.Close();
           }

 Then it has method to access properties by name:

        public static string GetValue(string name)
        {
            KeyValueConfigurationElement entry = Configuration.AppSettings.Settings[name];

            if (entry == null)
                throw new ConfigurationErrorsException("Key '" + name + "' is not found in the configuration file.");

            return Configuration.AppSettings.Settings[name].Value;
        }

 Which is used as in:

string propertyValue = CustomSettings.GetValue("propertyName");

 

Posted on Wednesday, June 11, 2008 3:12 PM .Net , BizTalk | Back to top


Comments on this post: Storing BizTalk settings in custom configuration file using Enterprise Library

# re: Storing BizTalk settings in custom configuration file using Enterprise Library
Requesting Gravatar...
Thanks for new idea. I've never used BizTalk. We've always used Enterprise 2.0 . There are some shortages but it is impossible without them. But not long ago I read a book by Goldratt (found it at the rapidshare http://pdf.rapid4me.com ) and I got a strong desire to make the best of the enterprise. I'm very thankful for you. I think the information at your site will be very helpful in my fullfilling the goal.
Left by Violet on Oct 19, 2009 3:45 AM

# re: Storing BizTalk settings in custom configuration file using Enterprise Library
Requesting Gravatar...
Thanks for new idea. I've never used BizTalk. We've always used Enterprise 2.0 . There are some shortages but it is impossible without them. But not long ago I read a book by Goldratt (found it at the rapidshare http://pdf.rapid4me.com ) and I got a strong desire to make the best of the enterprise. I'm very thankful for you. I think the information at your site will be very helpful in my fullfilling the goal.
Left by Violet on Oct 19, 2009 3:46 AM

# re: Storing BizTalk settings in custom configuration file using Enterprise Library
Requesting Gravatar...
This is a great idea! Why I did not guess it before!
BizTalk found on the website http://atrapidshare.com
Left by Frenki on Dec 19, 2009 11:08 AM

# re:Storing BizTalk settings in custom configuration file using Enterprise Library
Requesting Gravatar...
design of the layout perfect and i must commite this article one of the best i ever read
Left by mortgage calculatorl on Jun 08, 2010 11:31 PM

# re: Storing BizTalk settings in custom configuration file using Enterprise Library
Requesting Gravatar...
very intelligent, from yesterday I am looking for this article,thanks for sharing with us
Left by komputer on Jun 16, 2010 10:55 PM

# re: Storing BizTalk settings in custom configuration file using Enterprise Library
Requesting Gravatar...
Nice java program
Left by my blogspot on Oct 17, 2010 12:39 PM

Your comment:
 (will show your gravatar)


Copyright © Paul Petrov | Powered by: GeeksWithBlogs.net