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; } }
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); }
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; } }
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; } }
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); }
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); }
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]); } } }
public void Add(string name, ConfigInfo config) { BaseAdd(name, config); }
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(); }
internal void RemoveConfigInfo(ConfigInfo config) { elementData.Remove(config); }
internal abstract void Merge(ConfigInfo data);
internal abstract void Merge (ConfigInfo data);
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]); } }
internal override void Merge(ConfigInfo data) { }
internal void RemoveConfigInfo (ConfigInfo config) { elementData.Remove (config); }
internal override void Merge (ConfigInfo data) {}