From: <tps...@us...> - 2004-02-07 11:29:08
|
Update of /cvsroot/easystock/EasyStock/DAL/EasyStock.Dal.Configuration In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26885/DAL/EasyStock.Dal.Configuration Modified Files: ConfigSettingsReader.cs Log Message: - Added a new public Constructor without parameters It takes the name of the calling assembly, adds ".config" to it and uses that file as the configuration file for this instance. Index: ConfigSettingsReader.cs =================================================================== RCS file: /cvsroot/easystock/EasyStock/DAL/EasyStock.Dal.Configuration/ConfigSettingsReader.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ConfigSettingsReader.cs 4 Feb 2004 18:26:19 -0000 1.1 --- ConfigSettingsReader.cs 7 Feb 2004 10:55:18 -0000 1.2 *************** *** 28,31 **** --- 28,32 ---- using System.IO; using System.Collections; + using System.Reflection; namespace EasyStock.Dal.Configuration *************** *** 42,73 **** ///<summary> ! ///Creates a new instance of the ConfigSettingsReader ///</summary> public ConfigSettingsReader(string ConfigFile) { ! //Create a new XmlDocument ! XmlDocument configDocument = new XmlDocument(); ! ! try ! { ! //Try loading the ConfigFile ! configDocument.Load(ConfigFile); ! } ! catch (Exception e) ! { ! //Throw an exception ! throw new ApplicationException("The ConfigFile could not be opened.\nPlease check if you specified a valid file",e); ! } ! ! //Get the <add> nodes ! XmlNodeList addNodes = configDocument.GetElementsByTagName("add"); ! //Loop trough the nodes in the nodelist ! foreach(XmlNode addNode in addNodes) ! { ! //Add the values to the HashTable ! configurationValues.Add(addNode.Attributes["key"].Value,addNode.Attributes["value"].Value); ! } ! } ///<summary> --- 43,66 ---- ///<summary> ! ///Creates a new instance of the ConfigSettingsReader for a specific configuration file ///</summary> + ///<param name="ConfigFile">A valid path to the configuration file you want to load</param> public ConfigSettingsReader(string ConfigFile) { ! //Read the configuration file ! this.ReadConfigurationFile(ConfigFile); ! } ! ! ///<summary> ! ///Creates a new instance of the ConfigSettingsReader using the name of the calling assembly ! ///</summary> ! public ConfigSettingsReader() ! { ! //Get a reference to the Assembly who called this constructor ! Assembly callingAssembly = Assembly.GetCallingAssembly(); ! //Now get the filename of that assembly, add .config to it and read it ! this.ReadConfigurationFile(String.Concat(callingAssembly.CodeBase,".config")); ! } ///<summary> *************** *** 102,105 **** --- 95,129 ---- return returnValue; } + + ///<summary> + ///Reads all the key/value pairs from the specified configuration file + ///</summary> + ///<param name="ConfigFile">A valid path to the configuration file you want to load</param> + private void ReadConfigurationFile(string ConfigFile) + { + //Create a new XmlDocument + XmlDocument configDocument = new XmlDocument(); + + try + { + //Try loading the ConfigFile + configDocument.Load(ConfigFile); + } + catch (Exception e) + { + //Throw an exception + throw new ApplicationException("The ConfigFile could not be opened.\nPlease check if you specified a valid file",e); + } + + //Get the <add> nodes + XmlNodeList addNodes = configDocument.GetElementsByTagName("add"); + + //Loop trough the nodes in the nodelist + foreach(XmlNode addNode in addNodes) + { + //Add the values to the HashTable + configurationValues.Add(addNode.Attributes["key"].Value,addNode.Attributes["value"].Value); + } + } } } |