Reading a custom section from app.config

Nov 24, 2012 at 4:30 PM

Hi,

Can't seem to find a simple answer or there must not be one for reading section attributes from the application config file.  All I want to do is read a Section that has assembly element properties.

App.Config:

<?xml version="1.0"?>
<configuration>
  <configSections>
    <section name="modules"
             type="Microsoft.Practices.Prism.Modularity.ModulesConfigurationSection, Microsoft.Practices.Prism"/>
  </configSections>
  <modules>
    <module
      assemblyFile="ServiceCommon.dll"
      moduleType="ServiceCommon.CommonServiceModule, ServiceCommon, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
      moduleName="ServiceCommon"
      startupLoaded="true">
    </module>
    <module
      assemblyFile="ExcelService.dll"
      moduleType="ExcelService.ExcelServiceModule, ExcelService, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
      moduleName="ExcelService"
      startupLoaded="false">
    </module>
    <module
      assemblyFile="RegionTurahList.dll"
      moduleType="RegionTurahList.TurahListRegionModule, RegionTurahList, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
      moduleName="RegionTurahList"
      startupLoaded="false">
      <dependencies>
        <dependency moduleName="ExcelService"/>
      </dependencies>
    </module>
    <module
      assemblyFile="RegionTurahBooks.dll"
      moduleType="RegionTurahBooks.TurahBooksRegionModule, RegionTurahBooks, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
      moduleName="RegionTurahBooks"
      startupLoaded="false">
      <dependencies>
        <dependency moduleName="ExcelService"/>
      </dependencies>
    </module>
    <module
      assemblyFile="RegionTurahHebrew.dll"
      moduleType="RegionTurahHebrew.TurahHebrewRegionModule, RegionTurahHebrew, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
      moduleName="RegionTurahHebrew"
      startupLoaded="false">
      <dependencies>
        <dependency moduleName="ExcelService"/>
      </dependencies>
    </module>
    <module
      assemblyFile="RegionTurahAleppo.dll"
      moduleType="RegionTurahAleppo.TurahAleppoRegionModule, RegionTurahAleppo, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
      moduleName="RegionTurahAleppo"
      startupLoaded="false">
      <dependencies>
        <dependency moduleName="ExcelService"/>
      </dependencies>
    </module>
    <module
      assemblyFile="RegionTurahNames.dll"
      moduleType="RegionTurahNames.TurahNamesRegionModule, RegionTurahNames, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
      moduleName="RegionTurahNames"
      startupLoaded="false">
      <dependencies>
        <dependency moduleName="ExcelService"/>
      </dependencies>
    </module>
  </modules>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
  </startup>
</configuration>

I want to read and get the properties of all the elements <module> in the Section <modules> and put them in a Dictionary when I load a module (assembly):

    public class CommonService : ICommonService, IRegionTracker
    {
        private readonly IEventAggregator eventAggregator;
        private readonly IUnityContainer container;
        private IModuleManager moduleManager;
        private Dictionary<string, RegionTrackingState> _regionCollection = new Dictionary<string, RegionTrackingState>();

        public CommonService(IEventAggregator eventAggregator, IUnityContainer container, IModuleManager moduleManager)
        {
            this.eventAggregator = eventAggregator;
            this.moduleManager = moduleManager;
            this.container = container;
        }

...
..
.
        public void loadModule(string parameter)
        {
            if (!container.IsRegistered<ExcelService>())
                this.moduleManager.LoadModule(RegionNames.ExcelService);

            if (!_regionCollection.ContainsKey(parameter))
            {
                Configuration appConfig = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None) as Configuration;
                ConfigurationSection section = appConfig.GetSection("modules");
                SectionInformation sInfo = section.SectionInformation;

                RegionTrackingState region = new RegionTrackingState(
                    parameter,
                    DiscoveryMethod.ConfigurationManifest,
                    InitializationMode.OnDemand,
                    DownloadTiming.WithApplication,
                    RegionNames.ExcelService);

                _regionCollection.Add(parameter, region);
                this.moduleManager.LoadModule(parameter);
            }
        }

...
..
.
}

I can only get as far as getting the Section and don't know where to go from there.  I've read a lot of posts that have not giving me a solution to this.