示例#1
0
 internal SectionGroupCollection(FileContext core, SectionGroup parent)
 {
     Parent = parent;
     _core  = core;
 }
示例#2
0
        internal ConfigurationElement(ConfigurationElement element, string name, ConfigurationElementSchema schema, ConfigurationElement parent, XElement entity, FileContext core)
        {
            Methods     = new ConfigurationMethodCollection();
            FileContext = parent?.FileContext ?? element?.FileContext ?? core;
            Section     = parent?.Section;
            InnerEntity = entity ?? element?.InnerEntity;
            if (element == null)
            {
                ElementTagName = name ?? throw new ArgumentException("empty name");
                Attributes     = new ConfigurationAttributeCollection(this);
                ChildElements  = new ConfigurationChildElementCollection(this);
                Collections    = new List <ConfigurationElementCollection>();
                RawAttributes  = new Dictionary <string, string>();
                ParentElement  = parent;
                if (parent == null)
                {
                    Schema          = schema ?? throw new ArgumentException();
                    IsLocallyStored = true;
                }
                else
                {
                    IsLocallyStored = !parent.Section.IsLocked;
                    var collection = parent.Schema.CollectionSchema;
                    if (collection == null)
                    {
                        Schema = parent.Schema.ChildElementSchemas[name];
                    }
                    else
                    {
                        Schema = parent.Schema.CollectionSchema.GetElementSchema(name) ?? parent.Schema.ChildElementSchemas[name];
                    }

                    if (Schema == null)
                    {
                        throw new ArgumentException("empty schema");
                    }
                }

                ParseAttributes();
            }
            else
            {
                IsLocallyStored = element.IsLocallyStored;
                ElementTagName  = element.ElementTagName;
                Attributes      = element.Attributes;
                ChildElements   = element.ChildElements;
                Collections     = element.Collections;
                RawAttributes   = element.RawAttributes;
                Schema          = element.Schema;
                ParentElement   = parent ?? element.ParentElement;
                if (schema != null)
                {
                    // TODO: here we ignore second schema
                    //throw new ArgumentException();
                }
            }
        }
 internal ConfigurationElementCollectionBase(ConfigurationElement element, string name, ConfigurationElementSchema schema, ConfigurationElement parent, XElement entity, FileContext core)
     : base(element, name, schema, parent, entity, core)
 {
     AllowsAdd    = Schema.CollectionSchema.AddSchemas.Count > 0;
     AllowsClear  = Schema.CollectionSchema.ClearSchema != null;
     AllowsRemove = Schema.CollectionSchema.RemoveSchema != null;
 }
        public T AddAt(int index, T element)
        {
            if (!SkipCheck)
            {
                FileContext.SetDirty();
            }

            element.Validate(false);
            element.ForceCreateEntity();
            CheckMatched(element);

            if (HasParent)
            {
                if (Count > 0)
                {
                    var left  = index == 0 ? Exposed[0].IsLocallyStored : Exposed[index - 1].IsLocallyStored;
                    var right = index == Count
                                    ? Schema.Path != "system.webServer/defaultDocument/files"
                                    : Exposed[index].IsLocallyStored;
                    if (!left && !right)
                    {
                        foreach (var item in Real.ToList())
                        {
                            if (Schema.CollectionSchema.RemoveElementName == item.ElementTagName)
                            {
                                Real.Remove(item);
                                item.Entity.Remove();
                            }
                        }

                        var clear1 = CreateElement(Schema.CollectionSchema.ClearElementName);
                        Real.Insert(0, clear1);
                        clear1.ForceCreateEntity();
                        clear1.AppendToParentElement(clear1.Entity, true);
                        foreach (var item in Exposed)
                        {
                            if (item.IsLocallyStored)
                            {
                                continue;
                            }

                            item.IsLocallyStored = true;
                            item.AppendToParentElement(item.Entity, false);
                            Real.Add(item);
                        }
                    }
                }

                element.IsLocallyStored = true;
            }

            if (Count == index)
            {
                Real.Add(element);
                Exposed.Add(element);
                element.AppendToParentElement(element.Entity, false);
                return(element);
            }

            Real.Insert(index, element);
            var previous = Exposed[index];

            Exposed.Insert(index, element);

            if (previous.IsLocallyStored)
            {
                previous.InnerEntity.AddBeforeSelf(element.InnerEntity);
            }

            element.AppendToParentElement(element.Entity, false);
            return(element);
        }
示例#5
0
 internal SectionDefinitionCollection(FileContext core)
 {
     _core = core;
 }
示例#6
0
 internal Configuration(FileContext fileContext)
 {
     FileContext = fileContext;
 }
示例#7
0
        private ConfigurationSection DetectSection(string sectionPath, string locationPath, FileContext core)
        {
            var index = sectionPath.IndexOf(Path, StringComparison.Ordinal);

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

            if (Path.Length != 0)
            {
                if (sectionPath.Length != Path.Length && sectionPath[Path.Length] != '/')
                {
                    return(null);
                }
            }

            foreach (ConfigurationSection section in ConfigurationSections)
            {
                if (section.ElementTagName == sectionPath && section.Location == locationPath && !section.IsLocked)
                {
                    return(section);
                }
            }

            foreach (SectionGroup group in SectionGroups)
            {
                var found = group.DetectSection(sectionPath, locationPath, core);
                if (found != null)
                {
                    return(found);
                }
            }

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

            if (definition?.Schema == null)
            {
                var sectionInParent = core.Parent?.RootSectionGroup.DetectSection(sectionPath, locationPath, core.Parent);
                return(sectionInParent);
            }

            return(null);
        }
示例#8
0
        private ConfigurationSection CreateSection(string sectionPath, string locationPath, FileContext core, FileContext top)
        {
            var index = sectionPath.IndexOf(Path, StringComparison.Ordinal);

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

            if (Path.Length != 0)
            {
                if (sectionPath.Length != Path.Length && sectionPath[Path.Length] != '/')
                {
                    return(null);
                }
            }

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

            if (definition?.Schema != null)
            {
                var section = new ConfigurationSection(sectionPath, definition.Schema.Root, locationPath,
                                                       top, null);
                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(section);
            }

            foreach (SectionGroup group in SectionGroups)
            {
                var created = group.CreateSection(sectionPath, locationPath, core, top);
                if (created != null)
                {
                    return(created);
                }
            }

            var sectionBasedOnParent = core.Parent?.RootSectionGroup.CreateSection(sectionPath, locationPath, core.Parent, top);

            return(sectionBasedOnParent);
        }
示例#9
0
        internal ConfigurationSection FindSection(string sectionPath, string locationPath, FileContext core)
        {
            var temp = DetectSection(sectionPath, locationPath, core);

            if (temp != null)
            {
                return(temp);
            }

            // IMPORTANT: force system.web to go to root web.config.
            var top = locationPath == null && sectionPath.StartsWith("system.web/") && core.AppHost ? core.Parent : core;

            return(CreateSection(sectionPath, locationPath, top, top));
        }
 internal ConfigurationElementCollection(string name, ConfigurationElementSchema schema, ConfigurationElement parent, XElement entity, FileContext core)
     : base(null, name, schema, parent, entity, core)
 {
 }