A while ago, I wrote Advanced Configuration Section Manipulation and posted a similar article on my blog. I got a surprising amount of feedback but I think this comment typifies the majority of responses:
| "You'll probably want to slap me for this, but I've never seen the big deal with config files. I mean sure, they're basically like an INI file that handles .NET properties and tells .NET how to run your code, but besides that I don't see any point.... If there was a way to simply convert a config file into binary, I'd probably use them more often. My luck there probably is one, but because I don't like the text based crap to begin with I haven't tried to do homework to see if there is. Even so that could mean that someone could make a decryptor program that could easily decrypt your config file into text. The goal is to make it so that no one can enter the text equivalent because that would lead to a lot of potential problems and tests that I'm just not interested in making any more. I decided back in '97 when I was still in college that text based configurations are the work of the devil and I'm not about to bow to it's wishes even if the .NET god tells me I must obey." |
| <?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> <section name="messageQueues" type="KDN.QueueInfoCollection, KDNMessageConfigGlobal"/> <messageQueues> <messageQueue Description="InfoConfig" queueName=".\\MessageQueues\\InfoQuePrimary"/> <messageQueue Name="InfoConfigBackup" queueName=".\\MessageQueues\\InfoQueBackup"/> <system.runtime.remoting> <application name="KDNApplicationMessaging"> <channels> <channel ref="http" useDefaultCredentials="false"> <clientProviders> <serverProviders> <client url="http://localhost:80/KDNMessagingServer"> <wellknown <BR> url="http://localhost:80/KDNApplicationMessagingServer/MessageTransmitter.rem" type="KDN.Business.IMessageTransmitter, KDNMessageTransmissionAPIInterfaces"/> |
| using System; namespace KDN.Messaging.Global { public class QueueInfo { private System.String mDescription; private System.String mName; /// <summary> /// Default Constructor /// public QueueInfo(){} public System.String Description{ get{return mDescription;} set{mDescription = value;} } public System.String Name{ get{return mName;} set{mName = value;} } } } |
| using System; using System.Collections; using System.Xml; using System.Configuration; namespace SCBOS.Core.Messaging.Global { /// <summary> /// Summary description for QueueCollection. /// public class QueueInfoCollection : CollectionBase, System.Configuration.IConfigurationSectionHandler { /// <summary> /// Default contructor - nothing needs to be done /// because the List property is already initialized /// by the base class. /// static QueueInfoCollection(){} /// <summary> /// Overridden from CollectionBase - Adds a QueueInfo /// object to the collection /// /// QueueInfo /// <returns>System.Int32 public System.Int32 Add(QueueInfo value){ return this.List.Add(value); } /// <summary> /// Overridden form CollectionBase - removes a Queue /// Info object from the List Collection /// /// QueueInfo public void Remove(QueueInfo value){ this.List.Remove(value); } /// <summary> /// Overridden from CollectionBase - serves as the /// default property/indexer for the collection /// public QueueInfo this [System.Int32 index]{ get{return this.List[index] as QueueInfo;} set{this.List[index] = value;} } /// <summary> /// Overridden from CollectionBase - returns /// true or false depending on whether or not the /// specified queue exists in the collection or not /// /// QueueInfo /// <returns>bool public bool Contains(QueueInfo value){ return this.List.Contains(value); } /// <summary> /// Overridden from CollectionBase - Inserts a /// given QueueInfo object into the collection at the /// position specified by the index (which is 0 based). /// /// System.Int32 /// QueueInfo public void Insert(System.Int32 index, QueueInfo value){ this.List.Insert(index, value); } /// <summary> /// /// /// /// /// /// <returns> public object Create(object parent, object configContext, XmlNode section){ foreach(XmlNode node in section.ChildNodes){ QueueInfo queInfo = new QueueInfo(); queInfo.Agency = node.Attributes["Description"].Value; queInfo.Name = node.Attributes["queueName"].Value; this.Add(queInfo); } return this; } } } |