internal void CreateSectionGroup(SectionGroupInfo parentGroup, string name, ConfigurationSectionGroup sec) { if (parentGroup.HasChild(name)) { throw new ConfigurationErrorsException( "Cannot add a ConfigurationSectionGroup. A section or section group already exists with the name '" + name + "'"); } if (sec.Type == null) { sec.Type = _system.Host.GetConfigTypeName(sec.GetType()); } sec.SetName(name); var section = new SectionGroupInfo(name, sec.Type) { StreamName = FileName, ConfigHost = _system.Host }; parentGroup.AddChild(section); _elementData[section] = sec; sec.Initialize(this, section); }
internal Configuration(Configuration parent, string locationSubPath) { this.parent = parent; this.system = parent.system; this.rootGroup = parent.rootGroup; this.locationSubPath = locationSubPath; }
internal void CreateSection(SectionGroupInfo group, string name, ConfigurationSection sec) { if (group.HasChild(name)) { throw new ConfigurationErrorsException("Cannot add a ConfigurationSection. A section or section group already exists with the name '" + name + "'"); } if (!HasFile && !sec.SectionInformation.AllowLocation) { throw new ConfigurationErrorsException("The configuration section <" + name + "> cannot be defined inside a <location> element."); } if (!system.Host.IsDefinitionAllowed(configPath, sec.SectionInformation.AllowDefinition, sec.SectionInformation.AllowExeDefinition)) { object ctx = sec.SectionInformation.AllowExeDefinition != ConfigurationAllowExeDefinition.MachineToApplication ? (object)sec.SectionInformation.AllowExeDefinition : (object)sec.SectionInformation.AllowDefinition; throw new ConfigurationErrorsException("The section <" + name + "> can't be defined in this configuration file (the allowed definition context is '" + ctx + "')."); } if (sec.SectionInformation.Type == null) { sec.SectionInformation.Type = system.Host.GetConfigTypeName(sec.GetType()); } SectionInfo section = new SectionInfo(name, sec.SectionInformation); section.StreamName = streamName; section.ConfigHost = system.Host; group.AddChild(section); elementData [section] = sec; sec.Configuration = this; }
internal void Init(IConfigSystem system, string configPath, Configuration parent) { this.system = system; this.configPath = configPath; streamName = system.Host.GetStreamName(configPath); this.parent = parent; if (parent != null) { rootGroup = parent.rootGroup; } else { rootGroup = new SectionGroupInfo(); rootGroup.StreamName = streamName; } try { if (streamName != null) { Load(); } } catch (XmlException ex) { throw new ConfigurationErrorsException(ex.Message, ex, streamName, 0); } }
internal void Initialize (Configuration config, SectionGroupInfo group) { if (initialized) throw new SystemException ("INTERNAL ERROR: this configuration section is being initialized twice: " + GetType ()); initialized = true; this.config = config; this.group = group; }
internal Configuration(Configuration parent, string locationSubPath) { Parent = parent; _system = parent._system; _rootGroup = parent._rootGroup; _locationSubPath = locationSubPath; _configPath = parent.ConfigPath; }
internal Configuration (Configuration parent, string locationSubPath) { this.parent = parent; this.system = parent.system; this.rootGroup = parent.rootGroup; this.locationSubPath = locationSubPath; this.configPath = parent.ConfigPath; }
public void Remove(string name) { SectionGroupInfo secData = group.Groups [name] as SectionGroupInfo; if (secData != null) { config.RemoveConfigInfo(secData); } }
internal ConfigurationSectionGroup GetSectionGroupInstance(SectionGroupInfo group) { ConfigurationSectionGroup gr = group.CreateInstance() as ConfigurationSectionGroup; if (gr != null) { gr.Initialize(this, group); } return(gr); }
internal void Initialize(Configuration config, SectionGroupInfo group) { if (initialized) { throw new SystemException("INTERNAL ERROR: this configuration section is being initialized twice: " + GetType()); } initialized = true; this.config = config; this.group = group; }
public ConfigurationSectionGroup this [string name] { get { ConfigurationSectionGroup sec = BaseGet(name) as ConfigurationSectionGroup; if (sec == null) { SectionGroupInfo secData = group.Groups [name] as SectionGroupInfo; if (secData == null) { return(null); } sec = config.GetSectionGroupInstance(secData); BaseSet(name, sec); } return(sec); } }
internal void Init(IConfigSystem system, string configPath, Configuration parent) { this.system = system; this.configPath = configPath; streamName = system.Host.GetStreamName(configPath); this.parent = parent; if (parent != null) { rootGroup = parent.rootGroup; } else { rootGroup = new SectionGroupInfo(); rootGroup.StreamName = streamName; } if (streamName != null) { Load(); } }
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) { 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 void Init(IConfigSystem system, string configPath, Configuration parent) { _system = system; _configPath = configPath; FileName = system.Host.GetStreamName(configPath); Parent = parent; if (parent != null) { _rootGroup = parent._rootGroup; } else { _rootGroup = new SectionGroupInfo { StreamName = FileName }; // Addd Machine.config sections foreach (var keyValuePair in MachineConfig.ConfigSections) { var sectionInfo = CreateSectionInfo(system, configPath, keyValuePair.Key, keyValuePair.Value); _rootGroup.AddChild(sectionInfo); } } try { if (FileName != null) { Load(); } } catch (XmlException ex) { throw new ConfigurationErrorsException(ex.Message, ex, FileName, 0); } }
internal void CreateSectionGroup (SectionGroupInfo parentGroup, string name, ConfigurationSectionGroup sec) { if (parentGroup.HasChild (name)) throw new ConfigurationErrorsException ("Cannot add a ConfigurationSectionGroup. A section or section group already exists with the name '" + name + "'"); if (sec.Type == null) sec.Type = system.Host.GetConfigTypeName (sec.GetType ()); sec.SetName (name); SectionGroupInfo section = new SectionGroupInfo (name, sec.Type); section.StreamName = streamName; section.ConfigHost = system.Host; parentGroup.AddChild (section); elementData [section] = sec; sec.Initialize (this, section); }
internal ConfigurationSectionGroupCollection(Configuration config, SectionGroupInfo group) : base(StringComparer.Ordinal) { this.config = config; this.group = group; }
internal ConfigurationSectionGroup GetSectionGroupInstance (SectionGroupInfo group) { ConfigurationSectionGroup gr = group.CreateInstance () as ConfigurationSectionGroup; if (gr != null) gr.Initialize (this, group); return gr; }
internal void CreateSection (SectionGroupInfo group, string name, ConfigurationSection sec) { if (group.HasChild (name)) throw new ConfigurationErrorsException ("Cannot add a ConfigurationSection. A section or section group already exists with the name '" + name + "'"); if (!HasFile && !sec.SectionInformation.AllowLocation) throw new ConfigurationErrorsException ("The configuration section <" + name + "> cannot be defined inside a <location> element."); if (!system.Host.IsDefinitionAllowed (configPath, sec.SectionInformation.AllowDefinition, sec.SectionInformation.AllowExeDefinition)) { object ctx = sec.SectionInformation.AllowExeDefinition != ConfigurationAllowExeDefinition.MachineToApplication ? (object) sec.SectionInformation.AllowExeDefinition : (object) sec.SectionInformation.AllowDefinition; throw new ConfigurationErrorsException ("The section <" + name + "> can't be defined in this configuration file (the allowed definition context is '" + ctx + "')."); } if (sec.SectionInformation.Type == null) sec.SectionInformation.Type = system.Host.GetConfigTypeName (sec.GetType ()); SectionInfo section = new SectionInfo (name, sec.SectionInformation); section.StreamName = streamName; section.ConfigHost = system.Host; group.AddChild (section); elementData [section] = sec; sec.Configuration = this; }
internal void Init (IConfigSystem system, string configPath, Configuration parent) { this.system = system; this.configPath = configPath; streamName = system.Host.GetStreamName (configPath); this.parent = parent; if (parent != null) rootGroup = parent.rootGroup; else { rootGroup = new SectionGroupInfo (); rootGroup.StreamName = streamName; } try { if (streamName != null) Load (); } catch (XmlException ex) { throw new ConfigurationErrorsException (ex.Message, ex, streamName, 0); } }
internal void Init (IConfigSystem system, string configPath, Configuration parent) { this.system = system; this.configPath = configPath; streamName = system.Host.GetStreamName (configPath); this.parent = parent; if (parent != null) rootGroup = parent.rootGroup; else { rootGroup = new SectionGroupInfo (); rootGroup.StreamName = streamName; } if (streamName != null) Load (); }
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); ConfigInfo 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 (); }
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(); }
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 ConfigurationSectionCollection (Configuration config, SectionGroupInfo group) : base (StringComparer.Ordinal) { this.config = config; this.group = group; }
public void RemoveAt(int index) { SectionGroupInfo secData = group.Groups [index] as SectionGroupInfo; config.RemoveConfigInfo(secData); }