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"; 
   3:   
   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);
  10:              
  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.
Archive
<July 2014>
SunMonTueWedThuFriSat
293012345
6789101112
13141516171819
20212223242526
272829303112
3456789
Disclaimer

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

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