Click here to Skip to main content
15,886,026 members
Articles / Programming Languages / XML

Custom AppSettings

Rate me:
Please Sign up or sign in to vote.
4.12/5 (7 votes)
29 Nov 2005CPOL5 min read 84.7K   1.9K   21  
Another article on AppSettings.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>

	<configSections>
	<!-- 
		It's not necesary to remove the appSettings section in order to implement ours,
		if you want to rename your section, you can do it  (Look at Copy of App2.config)
	-->	
		<remove name="appSettings"/>
		<section name="appSettings" type="BellAppSetting.AppSettingHandler, BellAppSetting" />
	</configSections>
	
	<appSettings>
	<!-- You can use as many Config Nodes as you want, but you can only use one Other Node-->
	<!-- 
		The Config node is meant to be used for any application configuration you need, 
		like the main or the most important configuration in your program,
		The Other node is meant to expand the need for more and different configurations
	-->
	
	<!-- The RESULT: will be in a ArrayList, if you run this example you will get:
ArrayList0.Count = 1
ArrayList0[0] = Hashtable1.Count = 2
		Hashtable1[OtherValue1] => ArrayList1.Count = 2
				 				   ArrayList1[0] => ArrayList2.Count = 3
													ArrayList2[0] = DictionaryEntry
																	DictionaryEntry.Key = Address2Connect
																	DictionaryEntry.Value = 192.168.1.107
													ArrayList2[1] = DictionaryEntry
													.....................................................
		Hashtable1[ServerConfig] => ArrayList1.Count = 6
				 					ArrayList1[0] => ArrayList2.Count = 
													ArrayList2[0] = DictionaryEntry
																	DictionaryEntry.Key = PortListenerName
																	DictionaryEntry.Value = 2002
													ArrayList2[1] = DictionaryEntry
													.....................................................															
	-->
	<!-- You can put several Configs Nodes -->
	<!-- put true in the Other Node to if you want the program to process each child-->
		  <Configs use="true"> 
			<add key="ClientConfig" use="true" />
		<!-- This element will be skipped -->
			<add key="ServerConfig" use="false"/>
		<!-- This element will be parsed -->
			<add key="ServerConfig" use="true"/> 
		<!-- This element will be skipped, because there is already a ServerConfig child --> 
			<add key="ServerConfig" use="true"/> 
		<!-- if you put false in a child element it does not have to exist as a node-->
			<add key="OtherValue3" use="false"/> 
			<add key="OtherValue4" use="false"/> 
		  </Configs>

	<!-- put false if you want the program to skip all its childs and return an empty Hashtable-->		  
		  <Configs use="true"> 
			<add key="ClientConfig" use="true" />
			<add key="ServerConfig" use="true"/> 
		<!-- if you put true in a child element and it does not exist it will be ignored-->
			<add key="OtherValue3" use="true"/> 
			<add key="OtherValue4" use="true"/> 
		  </Configs>
		
		<!-- You can put as many nodes as you want-->  
		  <ClientConfig use="true">
			<add key="Address2Connect" value="192.168.1.107"/> 
			<add key="Port2Connect" value="2000"/> 
			<add key="Log2File" value="Logging.txt"/>		  
		  </ClientConfig>
		  
		  <ClientConfig use="true">
			<add key="Address2Connect" value="192.168.1.105"/> 
			<add key="Port2Connect" value="2000"/> 
			<add key="Log2File" value="Logging.txt"/>		  
		  </ClientConfig>
		  	
		  <ServerConfig use="true">
			<add key="PortListenerName" value="2002"/> 
			<add key="Port2Listen" value="2002"/> 
			<add key="PortLisFile2Log" value="Logging.txt"/>
			<add key="PortLisLogAll2File" value="false"/>
			<add key="GossipSockets" value ="false"/>
			<add key="SocketLogAll2IndependantFile" value="false"/>
		  </ServerConfig>
		  
		  <ServerConfig use="false"><!-- put false if you want the program to skip this element-->
		  	<add key="PortListenerName" value="2004"/> 
			<add key="Port2Listen" value="2004"/> 
			<add key="PortLisFile2Log" value="Logging.txt"/>
			<add key="PortLisLogAll2File" value="false"/>
			<add key="GossipSockets" value ="false"/>
			<add key="SocketLogAll2IndependantFile" value="false"/>
		 </ServerConfig>
		 
		 <ServerConfig use="true">
		  	<add key="PortListenerName" value="2006"/> 
			<add key="Port2Listen" value="2006"/> 
			<add key="PortLisFile2Log" value="Logging.txt"/>
			<add key="PortLisLogAll2File" value="false"/>
			<add key="GossipSockets" value ="false"/>
			<add key="SocketLogAll2IndependantFile" value="false"/>
		 </ServerConfig>
		 
		 <!-- Even though this node has the use="true" it will be skipped 
			  because it has use="false" in the first Config node-->
		  <OtherValue4 use="true"> 
			<add key="CheckConnections" value="false"/> 
			<add key="NotifyUserWhenDone" value="true"/> 
		  </OtherValue4>
		 
	</appSettings>
	
</configuration>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
Canada Canada
Althought i'm a Electronic Engineering, my stong side is IT.

I've developped code in different languages:
Assembly, C, Java, HTML, Javascript, Perl/CGI, VB6, and C#, in which i've been working latetly.

I'm also keen on Security and Cryptography topics, as well as on Multimedia Technologies.

Comments and Discussions