views:

203

answers:

3

I would like to download a file, parse it and put it somewhere. So I have a few sections outlined below and I would like to use the directives below to guide what the program should be doing. I like this form of config and I would like to figure out how to get this to work somehow but I know it won't work exactly like this because I can't use the same section more than once. I am just hoping someone could throw some ideas my way on how to get this idea to work.

 <configSections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
    <sectionGroup name="processor">
      <sectionGroup name="process">
        <!-- AVAILABLE TRANSPORTS -->
        <section name="ftp_transport" type="someFTPClass1, someAssembly"/>
        <section name="web_transport" type="someHTTPClass2, someAssembly"/>

        <!-- AVAILABLE PARSERS -->
        <section name="fixed_line_parser" type="someParserClass3, someAssembly" />
        <section name="regular_expression_parser" type="someParserClass4, someAssembly" />

        <!-- AVAILABLE LOADERS -->
        <section name="database_loader" type="someDbLoaderClass5, someAssembly" />
      </sectionGroup>
    </sectionGroup>
  </configSections>

and then something like this to drive the program:

<processor>
   <process name="File1">
    <ftp_transport>...</ftp_transport>
    <fixed_line_parser>...</fixed_line_parser>
    <database_loader>...</database_loader>
   </process>

   <process name="File2">
    <web_transport>...</web_transport>
    <fixed_line_parser>...</fixed_line_parser>
    <database_loader>...</database_loader>
   </process>
</processing>
A: 

Is the problem that you have a SectionGroup nested within SectionGroup? Change the outer SectionGroup tags to SectionGroups instead of SectionGroup.

<!-- SECTION DECLARATION -->
 <configSections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
    <sectionGroups name="processor">
      <sectionGroup name="process">
        <!-- AVAILABLE TRANSPORTS -->
        <section name="ftp_transport" type="someFTPClass1, someAssembly"/>
        <section name="web_transport" type="someHTTPClass2, someAssembly"/>

        <!-- AVAILABLE PARSERS -->
        <section name="fixed_line_parser" type="someParserClass3, someAssembly" />
        <section name="regular_expression_parser" type="someParserClass4, someAssembly" />

        <!-- AVAILABLE LOADERS -->
        <section name="database_loader" type="someDbLoaderClass5, someAssembly" />
      </sectionGroup>
    </sectionGroups>
  </configSections>
Robert Harvey
A: 

I wanted to do something similar. After hours of searching, I found this example:

http://www.dotneat.net/2007/10/16/StoringACollectionOnYourAppconfigUsingSectionHandlers.aspx

Works well.

sirdan
+1  A: 

Seems like you're basically building an Inversion of Control (IoC) container. Take a look at some of them for .Net here

Brian Frantz