Esempio n. 1
0
        internal void ParseSectionDefinitions(XElement root, Dictionary <string, SectionSchema> sectionSchemas)
        {
            foreach (var node in root.Nodes())
            {
                var element = node as XElement;
                if (element == null)
                {
                    continue;
                }

                if (element.Name.LocalName == KEYWORD_SECTIONGROUP)
                {
                    var group = SectionGroups.Add(element.Attribute(KEYWORD_SECTIONGROUP_NAME).Value);
                    group.Path = Name == string.Empty ? group.Name : string.Format("{0}/{1}", Path, @group.Name);
                    group.ParseSectionDefinitions(element, sectionSchemas);
                    continue;
                }

                if (element.Name.LocalName == KEYWORD_SECTION)
                {
                    var sectionDefinition = Sections.Add(element.Attribute(KEYWORD_SECTION_NAME).Value);
                    sectionDefinition.OverrideModeDefault = element.Attribute(KEYWORD_SECTION_OVERRIDEMODEDEFAULT).LoadString(KEYWORD_OVERRIDEMODE_ALLOW);
                    sectionDefinition.AllowLocation       = element.Attribute(KEYWORD_SECTION_ALLOWLOCATION).LoadString(KEYWORD_TRUE);
                    sectionDefinition.AllowDefinition     = element.Attribute(KEYWORD_SECTION_ALLOWDEFINITION).LoadString(KEYWORD_SECTION_ALLOWDEFINITION_EVERYWHERE);
                    sectionDefinition.Path = Name == string.Empty ? sectionDefinition.Name : $"{Path}/{sectionDefinition.Name}";
                    sectionDefinition.Type = element.Attribute(KEYWORD_SECTION_TYPE).LoadString(string.Empty);

                    SectionSchema schema;
                    sectionSchemas.TryGetValue(sectionDefinition.Path, out schema);
                    sectionDefinition.Schema = schema;
                }
            }
        }
Esempio n. 2
0
        internal bool Add(ConfigurationSection section, Location location)
        {
            var index = section.ElementTagName.IndexOf(Path, StringComparison.Ordinal);

            if (index != 0)
            {
                return(false);
            }

            if (Path.Length != 0)
            {
                if (section.ElementTagName.Length != Path.Length && section.ElementTagName[Path.Length] != '/')
                {
                    return(false);
                }
            }

            var definition = Sections.FirstOrDefault(item => item.Path == section.ElementTagName);

            if (definition != null)
            {
                if (definition.AllowLocation == KEYWORD_FALSE && location != null && location.FromTag)
                {
                    throw new ServerManagerException("Section is not allowed in location tag");
                }

                section.OverrideMode          = OverrideMode.Inherit;
                section.OverrideModeEffective =
                    (OverrideMode)Enum.Parse(typeof(OverrideMode), definition.OverrideModeDefault);

                section.IsLocked = section.FileContext.FileName != definition.FileContext.FileName &&
                                   section.OverrideModeEffective != OverrideMode.Allow;
                section.IsLocallyStored = section.FileContext.FileName == definition.FileContext.FileName;
                ConfigurationSections.Add(section);
                return(true);
            }

            if (SectionGroups.Select(@group => @group.Add(section, location)).Any(result => result))
            {
                return(true);
            }

            if (section.SectionPath == "configProtectedData")
            {
                ConfigurationSections.Add(section);
                return(true);
            }

            throw new FileLoadException(string.Format(
                                            "Filename: \\\\?\\{0}\r\nLine number: {1}\r\nError: This configuration section cannot be used at this path. This happens when the section is locked at a parent level. Locking is either by default (overrideModeDefault=\"Deny\"), or set explicitly by a location tag with overrideMode=\"Deny\" or the legacy allowOverride=\"false\".\r\n\r\n",
                                            section.FileContext.FileName,
                                            (section.Entity as IXmlLineInfo).LineNumber));
        }
Esempio n. 3
0
        internal void ParseSectionDefinitions(XElement root, Dictionary <string, SectionSchema> sectionSchemas)
        {
            foreach (var node in root.Nodes())
            {
                if (!(node is XElement element))
                {
                    continue;
                }

                if (element.Name.LocalName == KEYWORD_SECTIONGROUP)
                {
                    XAttribute groupName = element.Attribute(KEYWORD_SECTIONGROUP_NAME);
                    Debug.Assert(groupName != null, nameof(groupName) + " != null");
                    var group = SectionGroups.Add(groupName.Value);
                    group.Path = Name == string.Empty ? group.Name : $"{Path}/{@group.Name}";
                    group.ParseSectionDefinitions(element, sectionSchemas);
                    continue;
                }

                if (element.Name.LocalName == KEYWORD_SECTION)
                {
                    XAttribute sectionName = element.Attribute(KEYWORD_SECTION_NAME);
                    Debug.Assert(sectionName != null, nameof(sectionName) + " != null");
                    var sectionDefinition = Sections.Add(sectionName.Value);
                    sectionDefinition.OverrideModeDefault = element.Attribute(KEYWORD_SECTION_OVERRIDEMODEDEFAULT).LoadString(KEYWORD_OVERRIDEMODE_ALLOW);
                    sectionDefinition.AllowLocation       = element.Attribute(KEYWORD_SECTION_ALLOWLOCATION).LoadString(KEYWORD_TRUE);
                    sectionDefinition.AllowDefinition     = element.Attribute(KEYWORD_SECTION_ALLOWDEFINITION).LoadString(KEYWORD_SECTION_ALLOWDEFINITION_EVERYWHERE);
                    sectionDefinition.Path = Name == string.Empty ? sectionDefinition.Name : $"{Path}/{sectionDefinition.Name}";
                    sectionDefinition.Type = element.Attribute(KEYWORD_SECTION_TYPE).LoadString(string.Empty);

                    sectionSchemas.TryGetValue(sectionDefinition.Path, out SectionSchema schema);
                    sectionDefinition.Schema = schema;
                    sectionDefinition.Entity = element;
                }
            }
        }