public void AddChild (ConfigInfo data)
		{
			data.Parent = this;
			if (data is SectionInfo) {
				if (sections == null) sections = new ConfigInfoCollection ();
				sections [data.Name] = data;
			}
			else {
				if (groups == null) groups = new ConfigInfoCollection ();
				groups [data.Name] = data;
			}
		}
Exemplo n.º 2
0
 public override bool HasConfigContent(Configuration cfg)
 {
     if (StreamName == cfg.FileName)
     {
         return(true);
     }
     foreach (ConfigInfoCollection col in new object[] { Sections, Groups })
     {
         foreach (string key in col)
         {
             ConfigInfo cinfo = col [key];
             if (cinfo.HasConfigContent(cfg))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Exemplo n.º 3
0
 public void AddChild(ConfigInfo data)
 {
     data.Parent = this;
     if (data is SectionInfo)
     {
         if (_sections == null)
         {
             _sections = new ConfigInfoCollection();
         }
         _sections[data.Name] = data;
     }
     else
     {
         if (_groups == null)
         {
             _groups = new ConfigInfoCollection();
         }
         _groups[data.Name] = data;
     }
 }
Exemplo n.º 4
0
 public void AddChild(ConfigInfo data)
 {
     modified    = true;
     data.Parent = this;
     if (data is SectionInfo)
     {
         if (sections == null)
         {
             sections = new ConfigInfoCollection();
         }
         sections [data.Name] = data;
     }
     else
     {
         if (groups == null)
         {
             groups = new ConfigInfoCollection();
         }
         groups [data.Name] = data;
     }
 }
Exemplo n.º 5
0
        internal override bool HasValues(Configuration config, ConfigurationSaveMode mode)
        {
            if (modified && (mode == ConfigurationSaveMode.Modified))
            {
                return(true);
            }

            foreach (ConfigInfoCollection col in new object[] { Sections, Groups })
            {
                foreach (string key in col)
                {
                    ConfigInfo cinfo = col [key];
                    if (cinfo.HasValues(config, mode))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Exemplo n.º 6
0
        private static ConfigInfo GetConfigInfo(XmlReader reader, SectionGroupInfo current)
        {
            ConfigInfo data = null;

            if (current._sections != null)
            {
                data = current._sections[reader.LocalName];
            }
            if (data != null)
            {
                return(data);
            }
            if (current._groups != null)
            {
                data = current._groups[reader.LocalName];
            }
            if (data != null)
            {
                return(data);
            }
            if (current._groups == null)
            {
                return(null);
            }
            // It might be a section in descendant sectionGroups
            foreach (string key in current._groups.AllKeys)
            {
                data = GetConfigInfo(reader, (SectionGroupInfo)current._groups[key]);
                if (data != null)
                {
                    return(data);
                }
            }

            // It might be in the root section group
            return(null);
        }
Exemplo n.º 7
0
        internal override void Merge(ConfigInfo newData)
        {
            var data = newData as SectionGroupInfo;

            if (data == null)
            {
                return;
            }
            ConfigInfo actInfo;

            if (data._sections != null && data._sections.Count > 0)
            {
                foreach (string key in data._sections.AllKeys)
                {
                    actInfo = _sections[key];
                    if (actInfo != null)
                    {
                        continue;
                    }
                    _sections.Add(key, data._sections[key]);
                }
            }

            if (data._groups != null && data._sections != null && data._sections.Count > 0)
            {
                foreach (string key in data._groups.AllKeys)
                {
                    actInfo = _groups[key];
                    if (actInfo != null)
                    {
                        continue;
                    }
                    _groups.Add(key, data._groups[key]);
                }
            }
        }
Exemplo n.º 8
0
 public void Add(string name, ConfigInfo config)
 {
     BaseAdd(name, config);
 }
Exemplo n.º 9
0
        public override void ReadConfig(Configuration cfg, string streamName, XmlReader reader)
        {
            StreamName = streamName;
            ConfigHost = cfg.ConfigHost;

            if (reader.LocalName != "configSections")
            {
                while (reader.MoveToNextAttribute())
                {
                    if (reader.Name == "name")
                    {
                        Name = reader.Value;
                    }
                    else if (reader.Name == "type")
                    {
                        TypeName = reader.Value;
                        Type     = null;
                    }
                    else
                    {
                        ThrowException("Unrecognized attribute", reader);
                    }
                }

                if (Name == null)
                {
                    ThrowException("sectionGroup must have a 'name' attribute", reader);
                }

                if (Name == "location")
                {
                    ThrowException("location is a reserved section name", reader);
                }
            }

            if (TypeName == null)
            {
                TypeName = "System.Configuration.ConfigurationSectionGroup";
            }

            if (reader.IsEmptyElement)
            {
                reader.Skip();
                return;
            }

            reader.ReadStartElement();
            reader.MoveToContent();

            while (reader.NodeType != XmlNodeType.EndElement)
            {
                if (reader.NodeType != XmlNodeType.Element)
                {
                    reader.Skip();
                    continue;
                }

                string     name  = reader.LocalName;
                ConfigInfo cinfo = null;

                if (name == "remove")
                {
                    ReadRemoveSection(reader);
                    continue;
                }

                if (name == "clear")
                {
                    if (reader.HasAttributes)
                    {
                        ThrowException("Unrecognized attribute.", reader);
                    }

                    Clear();
                    reader.Skip();
                    continue;
                }

                if (name == "section")
                {
                    cinfo = new SectionInfo();
                }
                else if (name == "sectionGroup")
                {
                    cinfo = new SectionGroupInfo();
                }
                else
                {
                    ThrowException("Unrecognized element: " + reader.Name, reader);
                }

                cinfo.ReadConfig(cfg, streamName, reader);
                var actInfo = Groups[cinfo.Name];
                if (actInfo == null)
                {
                    actInfo = Sections[cinfo.Name];
                }

                if (actInfo != null)
                {
                    if (actInfo.GetType() != cinfo.GetType())
                    {
                        ThrowException("A section or section group named '" + cinfo.Name + "' already exists", reader);
                    }
                    // Merge all the new data
                    actInfo.Merge(cinfo);

                    // Make sure that this section is saved in this configuration file:
                    actInfo.StreamName = streamName;
                }
                else
                {
                    AddChild(cinfo);
                }
            }

            reader.ReadEndElement();
        }
Exemplo n.º 10
0
 internal void RemoveConfigInfo(ConfigInfo config)
 {
     elementData.Remove(config);
 }
Exemplo n.º 11
0
 internal abstract void Merge(ConfigInfo data);
Exemplo n.º 12
0
		internal abstract void Merge (ConfigInfo data);
Exemplo n.º 13
0
        void ReadContent(XmlReader reader, Configuration config, bool overrideAllowed, bool root)
        {
            while (reader.NodeType != XmlNodeType.EndElement && reader.NodeType != XmlNodeType.None)
            {
                if (reader.NodeType != XmlNodeType.Element)
                {
                    reader.Skip();
                    continue;
                }

                if (reader.LocalName == "dllmap")
                {
                    reader.Skip();
                    continue;
                }

                if (reader.LocalName == "location")
                {
                    if (!root)
                    {
                        ThrowException("<location> elements are only allowed in <configuration> elements.", reader);
                    }

                    string allowOverrideAttr = reader.GetAttribute("allowOverride");
                    bool   allowOverride     = allowOverrideAttr == null || allowOverrideAttr.Length == 0 || bool.Parse(allowOverrideAttr);
                    string path = reader.GetAttribute("path");
                    if (path != null && path.Length > 0)
                    {
                        string   xml      = reader.ReadOuterXml();
                        string[] pathList = path.Split(',');
                        string   tpath;
                        foreach (string p in pathList)
                        {
                            tpath = p.Trim();
                            if (config.Locations.Find(tpath) != null)
                            {
                                ThrowException("Sections must only appear once per config file.", reader);
                            }

                            ConfigurationLocation loc = new ConfigurationLocation(tpath, xml, config, allowOverride);
                            config.Locations.Add(loc);
                        }
                    }
                    else
                    {
                        ReadData(config, reader, allowOverride);
                    }
                    continue;
                }

                ConfigInfo data = GetConfigInfo(reader, this);
                if (data != null)
                {
                    data.ReadData(config, reader, overrideAllowed);
                }
                else
                {
                    ThrowException("Unrecognized configuration section <" + reader.LocalName + ">", reader);
                }
            }
        }
		public void Add (string name, ConfigInfo config)
		{
			BaseAdd (name, config);
		}
		internal override void Merge (ConfigInfo newData)
		{
			SectionGroupInfo data = newData as SectionGroupInfo;
			if (data == null)
				return;
			ConfigInfo actInfo;
			if (data.sections != null && data.sections.Count > 0)
				foreach (string key in data.sections.AllKeys) {
					actInfo = sections[key];
					if (actInfo != null)
						continue;
					sections.Add (key, data.sections[key]);
				}
			
			if (data.groups != null && data.sections != null && data.sections.Count > 0)
				foreach (string key in data.groups.AllKeys) {
					actInfo = groups[key];
					if (actInfo != null)
						continue;
					groups.Add (key, data.groups[key]);
				}
		}
Exemplo n.º 16
0
 internal override void Merge(ConfigInfo data)
 {
 }
Exemplo n.º 17
0
		internal void RemoveConfigInfo (ConfigInfo config)
		{
			elementData.Remove (config);
		}
Exemplo n.º 18
0
		internal override void Merge (ConfigInfo data)
		{}