Click here to Skip to main content
15,890,947 members
Home / Discussions / C#
   

C#

 
GeneralRe: Ensure a parameter is not null Pin
S. Senthil Kumar13-May-08 17:36
S. Senthil Kumar13-May-08 17:36 
GeneralRe: Ensure a parameter is not null Pin
Vikram A Punathambekar13-May-08 19:08
Vikram A Punathambekar13-May-08 19:08 
GeneralRe: Ensure a parameter is not null Pin
Malcolm Smart13-May-08 21:24
Malcolm Smart13-May-08 21:24 
GeneralRe: Ensure a parameter is not null Pin
S. Senthil Kumar13-May-08 22:38
S. Senthil Kumar13-May-08 22:38 
GeneralRe: Ensure a parameter is not null Pin
Vikram A Punathambekar13-May-08 19:12
Vikram A Punathambekar13-May-08 19:12 
AnswerRe: Ensure a parameter is not null Pin
PIEBALDconsult13-May-08 13:23
mvePIEBALDconsult13-May-08 13:23 
QuestionApp.Config Sharing (sort of) Pin
#realJSOP13-May-08 5:17
mve#realJSOP13-May-08 5:17 
AnswerRe: App.Config Sharing (sort of) Pin
Miszou13-May-08 7:12
Miszou13-May-08 7:12 
I'm actually doing something similar at the moment, so I know where you're coming from. I have a service that hosts four different tasks, and each one has its own config section.

I have organized the app.config file like this (Only showing 2 services for brevity and with names changed to protect the innocent):
<configuration>
	<configSections>
		<section name="ClassMap" type="System.Configuration.SingleTagSectionHandler" />
		<section name="service1" type="System.Configuration.NameValueSectionHandler" />
		<section name="service2" type="System.Configuration.NameValueSectionHandler" />
	</configSections>
 
	<ClassMap
		service1="Service.Service1"
		service2="Service.Service2" />
 
	<!-- Service 1 -->
	<Service1>
		<!-- settings -->
	</Service1>
 
	<!-- Service 2 -->
	<Service2>
		<!-- settings -->
	</Service2>
 
	<!-- Global Application Settings -->
	<appSettings>
		<!-- settings -->
	</appSettings>
 
</configuration>
The classmap section is basically just a list of internal class names that get constructed by a class factory. Each service class derives from the same base class, which contains a few useful methods/properties.

The most useful of these is a private aggregated NameValueCollection class that reads from the given configuration section and exposes the settings to the correct service, where processorName is the name of the configuration section and is passed to the service by the class factory during construction from the ClassMap section:

Base class property
protected NameValueCollection config;

Base class constuctor
public BaseProcessor( string serviceName )<br />
{<br />
	config = (NameValueCollection)ConfigurationManager.GetSection(serviceName);<br />
}


Derived classes can then read their own settings by simply doing something like this:

string userName = config["UserName"]

To construct each service, I do something like this:

Hashtable ClassMap = (Hashtable)ConfigurationManager.GetSection("ClassMap");<br />
foreach (string key in ClassMap.Keys)<br />
{<br />
BaseProcessor proc = (BaseProcessor)ClassFactory.Create(ClassMap[key].ToString(), key);<br />
}<br />
<br />
I hope this helps and isn't too confusing. It really is much easier to use than it is to describe!


GeneralRe: App.Config Sharing (sort of) Pin
#realJSOP13-May-08 8:31
mve#realJSOP13-May-08 8:31 
GeneralRe: App.Config Sharing (sort of) Pin
Miszou13-May-08 9:04
Miszou13-May-08 9:04 
GeneralRe: App.Config Sharing (sort of) Pin
#realJSOP13-May-08 10:57
mve#realJSOP13-May-08 10:57 
GeneralRe: App.Config Sharing (sort of) Pin
Miszou14-May-08 6:45
Miszou14-May-08 6:45 
QuestionException Handling Pin
jchigg200013-May-08 5:13
jchigg200013-May-08 5:13 
AnswerRe: Exception Handling Pin
jchigg200013-May-08 5:43
jchigg200013-May-08 5:43 
QuestionMenuStrip -&gt; Open new child form Pin
benjamin yap13-May-08 4:31
benjamin yap13-May-08 4:31 
AnswerRe: MenuStrip -&gt; Open new child form Pin
Gareth H13-May-08 4:38
Gareth H13-May-08 4:38 
GeneralRe: MenuStrip -&gt; Open new child form Pin
benjamin yap13-May-08 4:48
benjamin yap13-May-08 4:48 
GeneralRe: MenuStrip -&gt; Open new child form Pin
Gareth H13-May-08 4:52
Gareth H13-May-08 4:52 
GeneralRe: MenuStrip -&gt; Open new child form Pin
benjamin yap13-May-08 5:00
benjamin yap13-May-08 5:00 
AnswerRe: MenuStrip -&gt; Open new child form Pin
darkelv13-May-08 5:13
darkelv13-May-08 5:13 
GeneralRe: MenuStrip -&gt; Open new child form Pin
benjamin yap13-May-08 5:24
benjamin yap13-May-08 5:24 
GeneralRe: MenuStrip -&gt; Open new child form Pin
darkelv13-May-08 17:33
darkelv13-May-08 17:33 
QuestionResizing form nad positioning controls Pin
benjamin yap13-May-08 4:16
benjamin yap13-May-08 4:16 
QuestionXMLSerializer Pin
George_George13-May-08 4:12
George_George13-May-08 4:12 
AnswerRe: XMLSerializer Pin
led mike13-May-08 4:29
led mike13-May-08 4:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.