Raba - Defend your code RSS 2.0
# Monday, February 11, 2008

There are time you would like to load your configuration data from a specific config file or maybe even from the config file but not from the main one, I'll explain it using an example from the real world (last week refactoring).
We have many client which run the ArcGis Explorer (AGX) client (Geographic application like Google Earth), this client can be installed on each and every client, and it has its own configuration files. Within our team we write tasks that running on that AGX. while opening the application it will download to your profile directory the relevant DLL's for running those tasks. but hey those DLL's will be in a separate directory, neither in the GAC nor in the AGX executable directory. You can find many examples for such scenarios.

Here you can see the two different directories: one for the E2.exe and its config file, and the specific task DLL's and its config file (Sample.dll.config)

All we wanted to make is a Task specific configuration. so we would like it to work on every other task we will create.
First you might know this bunch of code, this will help you load the Sample.dll.config file from the wanted directory (The Task directory).

   1:  // Get the application configuration file path.
   2:  string exeFilePath = @"C:\ShaniData\Projects2008\ConfigHandlerDemo\Sample.dll.config"; 
   4:  // Map to the application configuration file.
   5:  ExeConfigurationFileMap configFile = new ExeConfigurationFileMap();
   6:  configFile.ExeConfigFilename = exeFilePath;
   7:  System.Configuration.Configuration config =
   8:  ConfigurationManager.OpenMappedExeConfiguration(configFile,
   9:  ConfigurationUserLevel.None);
  11:  ConfigurationSection sec = config.GetSection("MailManagerConfiguration");

In this situation we should use the .Net default ConfigurationSection implementations (for example: the ApplicationSettingsSection). Those of you who think of using the DictionarySectionHandler or NameValueSectionHandler will found it returning the DefaultSection instead.

Pay also attention that your code is running from the AGX installation directory so if you'll write your own section it won't work unless it was installed on the given computer (in GAC or in the AGX installation directory).

Monday, February 11, 2008 3:38:38 PM (GMT Standard Time, UTC+00:00)  #    Comments [0] - Trackback
.Net 2.0 | GIS | AGX

Comments are closed.
<July 2015>

The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2015
Shani Raba
Sign In
Total Posts: 146
This Year: 0
This Month: 0
This Week: 0
Comments: 97
Cool Stuff
Add to Technorati Favorites
Pick a theme:
All Content © 2015, Shani Raba
DasBlog theme 'Business' created by Christoph De Baene (delarou)