public void AlreadyExistsException()
 {
     ConfigBase config = new ConfigBase ("Test", null);
     ConfigCollection collection = new ConfigCollection (null);
     collection.Add (config);
     collection.Add (config); // exception
 }
		public void NameAlreadyExists ()
		{
			ConfigBase config1 = new ConfigBase ("Test", null);
			ConfigBase config2 = new ConfigBase ("Test", null);
			ConfigCollection collection = new ConfigCollection (null);
			collection.Add (config1);
			collection.Add (config2); // merges, no exception
		}
        /// <include file='IConfigSource.xml' path='//Method[@name="AddConfig"]/docs/*' />
        public IConfig AddConfig(string name)
        {
            ConfigBase result = null;

            if (configList[name] == null) {
                result = new ConfigBase (name, (IConfigSource)this);
                configList.Add (result);
            } else {
                throw new Exception ("An IConfig of that name already exists");
            }

            return result;
        }
        public void AddAndRemove()
        {
            ConfigBase config1 = new ConfigBase ("Test", null);
            ConfigBase config2 = new ConfigBase ("Another", null);
            ConfigCollection collection = new ConfigCollection (null);
            collection.Add (config1);
            collection.Add (config2);

            Assert.AreEqual (2, collection.Count);
            Assert.IsNotNull (collection["Test"]);
            Assert.IsNotNull (collection["Another"]);

            collection.Remove (config2);
            Assert.AreEqual (1, collection.Count);
            Assert.IsNotNull (collection["Test"]);
            Assert.IsNull (collection["Another"]);
        }
		public void GetConfig ()
		{
			ConfigBase config1 = new ConfigBase ("Test1", null);
			ConfigBase config2 = new ConfigBase ("Test2", null);
			ConfigBase config3 = new ConfigBase ("Test3", null);
			ConfigCollection collection = new ConfigCollection (null);
			
			collection.Add (config1);
			Assert.AreEqual (1, collection.Count);
			Assert.AreEqual (config1, collection[0]);
			
			collection.Add (config2);
			collection.Add (config3);
			Assert.AreEqual (3, collection.Count);
			
			Assert.AreEqual (config2, collection["Test2"]);
			Assert.AreEqual (config3, collection["Test3"]);
			Assert.AreEqual (config3, collection[2]);
		}
		/// <summary>
		/// Merges the IniDocument into the Configs when the document is 
		/// reloaded.  
		/// </summary>
		private void MergeDocumentIntoConfigs ()
		{
			// Remove all missing configs first
			RemoveConfigs ();

			IniSection section = null;
			for (int i = 0; i < iniDocument.Sections.Count; i++)
			{
				section = iniDocument.Sections[i];

				IConfig config = this.Configs[section.Name];
				if (config == null) {
					// The section is new so add it
					config = new ConfigBase (section.Name, this);
					this.Configs.Add (config);
				}				
				RemoveConfigKeys (config);
			}
		}
        /// <summary>
        /// Merges the XmlDocument into the Configs when the document is 
        /// reloaded.  
        /// </summary>
        private void MergeDocumentIntoConfigs()
        {
            // Remove all missing configs first
            RemoveConfigs ();

            foreach (XmlNode node in configDoc.DocumentElement.ChildNodes)
            {
                // If node is a section node
                if (node.NodeType == XmlNodeType.Element
                    && node.Name == "Section") {

                    string sectionName = node.Attributes["Name"].Value;
                    IConfig config = this.Configs[sectionName];
                    if (config == null) {
                        // The section is new so add it
                        config = new ConfigBase (sectionName, this);
                        this.Configs.Add (config);
                    }
                    RemoveConfigKeys (config);
                }
            }
        }
        /// <summary>
        /// Loads all configuration sections.
        /// </summary>
        private void LoadSections(XmlNode rootNode)
        {
            LoadOtherSection (rootNode, "appSettings");

            XmlNode sections = GetChildElement (rootNode, "configSections");

            if (sections == null) {
                // There is no configSections node so exit
                return;
            }

            ConfigBase config = null;
            foreach (XmlNode node in sections.ChildNodes)
            {
                if (node.NodeType == XmlNodeType.Element
                    && node.Name == "section") {
                    config = new ConfigBase
                            (node.Attributes["name"].Value, this);

                    this.Configs.Add (config);
                    LoadKeys (rootNode, config);
                }
            }
        }
        /// <summary>
        /// Loads all keys for a config.
        /// </summary>
        private void LoadKeys(XmlNode rootNode, ConfigBase config)
        {
            XmlNode section = GetChildElement (rootNode, config.Name);

            foreach (XmlNode node in section.ChildNodes)
            {
                if (node.NodeType == XmlNodeType.Element
                    && node.Name == "add") {
                    config.Add (node.Attributes["key"].Value,
                                node.Attributes["value"].Value);
                }
            }
        }
        /// <summary>
        /// Returns an IConfig.  If it does not exist then it is added.
        /// </summary>
        private IConfig GetConfig(string name)
        {
            IConfig result = null;

            if (this.Configs[name] == null) {
                result = new ConfigBase (name, this);
                this.Configs.Add (result);
            } else {
                result = this.Configs[name];
            }

            return result;
        }
        /// <summary>
        /// Loads all keys for a config.
        /// </summary>
        private void LoadKeys(XmlNode node, ConfigBase config)
        {
            XmlNodeList nodeList = node.SelectNodes ("Key");

            for (int i = 0; i < nodeList.Count; i++)
            {
                config.Add (nodeList[i].Attributes["Name"].Value,
                            nodeList[i].Attributes["Value"].Value);
            }
        }
        /// <summary>
        /// Loads all configuration sections.
        /// </summary>
        private void LoadSections(XmlNode rootNode)
        {
            XmlNodeList nodeList = rootNode.SelectNodes ("Section");
            ConfigBase config = null;

            for (int i = 0; i < nodeList.Count; i++)
            {
                config = new ConfigBase (nodeList[i].Attributes["Name"].Value, this);

                this.Configs.Add (config);
                LoadKeys (nodeList[i], config);
            }
        }
        /// <summary>
        /// Loads all configuration sections.
        /// </summary>
        private void LoadSections(XmlNode rootNode)
        {
            XmlNodeList nodeList = rootNode.SelectNodes ("configSections/section");
            ConfigBase config = null;

            for (int i = 0; i < nodeList.Count; i++)
            {
                config = new ConfigBase (nodeList[i].Attributes["name"].Value, this);

                this.Configs.Add (config);
                LoadKeys (rootNode, config);
            }
            LoadOtherSection (rootNode, "appSettings");
        }
        /// <summary>
        /// Loads special sections that are not loaded in the configSections
        /// node.  This includes such sections such as appSettings.
        /// </summary>
        private void LoadOtherSection(XmlNode rootNode, string nodeName)
        {
            XmlNode node = rootNode.SelectSingleNode (nodeName);
            ConfigBase config = null;

            if (node != null) {
                config = new ConfigBase (nodeName, this);

                this.Configs.Add (config);
                LoadKeys (rootNode, config);
            }
        }
        /// <summary>
        /// Loads all keys for a config.
        /// </summary>
        private void LoadKeys(XmlNode rootNode, ConfigBase config)
        {
            XmlNodeList nodeList = rootNode.SelectNodes (config.Name + "/add");

            for (int i = 0; i < nodeList.Count; i++)
            {
                config.Add (nodeList[i].Attributes["key"].Value,
                            nodeList[i].Attributes["value"].Value);
            }
        }
Exemple #16
0
		/// <include file='ConfigCollection.xml' path='//Method[@name="AddName"]/docs/*' />
		public IConfig Add (string name)
		{
			ConfigBase result = null;

			if (this[name] == null) {
				result = new ConfigBase (name, owner);
				configList.Add (result);
				OnConfigAdded (new ConfigEventArgs (result));
			} else {
				throw new ArgumentException ("An IConfig of that name already exists");
			}
			
			return result;
		}
Exemple #17
0
        /// <summary>
        /// Loads a collection class.
        /// </summary>
        private void LoadCollection(string name, NameValueCollection collection)
        {
            ConfigBase config = new ConfigBase (name, this);

            if (collection == null) {
                throw new ArgumentException ("Section was not found");
            }

            if (collection != null) {
                for (int i = 0; i < collection.Count; i++)
                {
                    config.Add (collection.Keys[i], collection[i]);
                }

                this.Configs.Add (config);
            }
        }
        /// <summary>
        /// Loads the configuration file.
        /// </summary>
        private void Load()
        {
            ConfigBase config = null;
            IniSection section = null;
            IniItem item = null;

            for (int j = 0; j < iniDocument.Sections.Count; j++)
            {
                section = iniDocument.Sections[j];
                config = new ConfigBase (section.Name, this);

                for (int i = 0; i < section.ItemCount; i++)
                {
                    item = section.GetItem (i);

                    if  (item.Type == IniType.Key) {
                        config.Add (item.Name, item.Value);
                    }
                }

                this.Configs.Add (config);
            }
            base.ReplaceTextAll ();
        }
Exemple #19
0
        /// <summary>
        /// Loads special sections that are not loaded in the configSections
        /// node.  This includes such sections such as appSettings.
        /// </summary>
        private void LoadOtherSection(XmlNode rootNode, string nodeName)
        {
            XmlNode section = GetChildElement (rootNode, nodeName);
            ConfigBase config = null;

            if (section != null) {
                config = new ConfigBase (section.Name, this);

                this.Configs.Add (config);
                LoadKeys (rootNode, config);
            }
        }
 /// <summary>
 /// Loads all keys for a config.
 /// </summary>
 private void LoadKeys(XmlNode node, ConfigBase config)
 {
     foreach (XmlNode child in node.ChildNodes)
     {
         if (child.NodeType == XmlNodeType.Element
             && child.Name == "Key") {
             config.Add (child.Attributes["Name"].Value,
                         child.Attributes["Value"].Value);
         }
     }
 }
Exemple #21
0
        /// <summary>
        /// Merges the XmlDocument into the Configs when the document is 
        /// reloaded.  
        /// </summary>
        private void MergeDocumentIntoConfigs()
        {
            // Remove all missing configs first
            RemoveConfigs ();

            XmlNode sections = GetChildElement ("configSections");

            if (sections == null) {
                // There is no configSections node so exit
                return;
            }

            foreach (XmlNode node in sections.ChildNodes)
            {
                // Find all section nodes
                if (node.NodeType == XmlNodeType.Element
                    && node.Name == "section") {

                    string sectionName = node.Attributes["name"].Value;
                    IConfig config = this.Configs[sectionName];
                    if (config == null) {
                        // The section is new so add it
                        config = new ConfigBase (sectionName, this);
                        this.Configs.Add (config);
                    }
                    RemoveConfigKeys (config);
                }
            }
        }
        /// <summary>
        /// Loads all configuration sections.
        /// </summary>
        private void LoadSections(XmlNode rootNode)
        {
            ConfigBase config = null;

            foreach (XmlNode child in rootNode.ChildNodes)
            {
                if (child.NodeType == XmlNodeType.Element
                    && child.Name == "Section") {
                    config = new ConfigBase (child.Attributes["Name"].Value, this);
                    this.Configs.Add (config);
                    LoadKeys (child, config);
                }
            }
        }