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 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) { _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 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; }