internal ConfigurationElement(ConfigurationElement element, string name, ConfigurationElementSchema schema, ConfigurationElement parent, XElement entity, FileContext core, string fileName = null)
        {
            Methods             = new ConfigurationMethodCollection();
            FileContext         = parent?.FileContext ?? element?.FileContext ?? core;
            Section             = parent?.Section;
            InnerEntity         = entity ?? element?.InnerEntity;
            _overriddenFileName = fileName;
            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(_overriddenFileName ?? FileContext.FileName);
            }
            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();
                }
            }
        }
 public SectionSchema(string name, XElement element, string fileName)
 {
     Name = name;
     Root = new ConfigurationElementSchema(fileName)
     {
         Path = name,
         AllowUnrecognizedAttributes =
             element.Attribute("allowUnrecognizedAttributes")
             .LoadBoolean(false)
     };
 }
 public SectionSchema(string name, XElement element)
 {
     Name = name;
     Root = new ConfigurationElementSchema
     {
         Path = name,
         AllowUnrecognizedAttributes =
                        element.Attribute("allowUnrecognizedAttributes")
                        .LoadBoolean(false)
     };
 }
Exemple #4
0
 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;
 }
 internal ConfigurationSection(string path, ConfigurationElementSchema schema, string location, FileContext core, XElement entity)
     : base(null, path, schema, null, entity, core)
 {
     Location = location;
     Section  = this;
 }
        //static ConfigurationProperty providersProp;
        //static ConfigurationPropertyCollection properties;

        //protected internal override ConfigurationPropertyCollection Properties {
        //	get { return properties; }
        //}

        //[ConfigurationProperty ("", Options = ConfigurationPropertyOptions.IsDefaultCollection)]
        //public ProviderSettingsCollection Providers {
        //	get { return (ProviderSettingsCollection) base[providersProp]; }
        //}
        internal ProtectedProviderSettings(ConfigurationElement element, string name, ConfigurationElementSchema schema, ConfigurationElement parent, XElement entity)
            : base(element, name, schema, parent, entity, null)
        {
        }
        internal void ParseSectionSchema(XElement element, ConfigurationElementSchema schema, string fileName)
        {
            foreach (var node in element.Nodes())
            {
                var item = node as XElement;
                if (item == null)
                {
                    continue;
                }

                if (item.Name.LocalName == "attribute")
                {
                    var attribute = new ConfigurationAttributeSchema
                    {
                        Name                = item.Attribute("name").Value,
                        Type                = item.Attribute("type").Value,
                        IsRequired          = item.Attribute("required").LoadBoolean(false),
                        IsUniqueKey         = item.Attribute("isUniqueKey").LoadBoolean(false),
                        IsCombinedKey       = item.Attribute("isCombinedKey").LoadBoolean(false),
                        IsCaseSensitive     = item.Attribute("caseSensitive").LoadBoolean(false),
                        IsEncrypted         = item.Attribute("encrypted").LoadBoolean(false),
                        AllowInfinite       = item.Attribute("allowInfinite").LoadBoolean(false),
                        TimeSpanFormat      = item.Attribute("timeSpanFormat").LoadString("string"),
                        IsExpanded          = item.Attribute("expanded").LoadBoolean(false),
                        ValidationType      = item.Attribute("validationType").LoadString(null),
                        ValidationParameter = item.Attribute("validationParameter").LoadString(null)
                    };

                    if (attribute.Type == "enum" || attribute.Type == "flags")
                    {
                        attribute.LoadEnums(item);
                    }

                    attribute.CreateValidator();

                    var defaultValue = item.Attribute("defaultValue");
                    if (defaultValue != null)
                    {
                        attribute.SetDefaultValue(defaultValue.Value);
                    }

                    if (schema == null)
                    {
                        Root.AttributeSchemas.Add(attribute);
                    }
                    else
                    {
                        schema.AttributeSchemas.Add(attribute);
                    }

                    continue;
                }

                if (item.Name.LocalName == "element")
                {
                    var name = item.Attribute("name").Value;
                    var top  = schema ?? Root;
                    ConfigurationElementSchema child = top.ChildElementSchemas[name];
                    if (child == null)
                    {
                        child = new ConfigurationElementSchema(fileName)
                        {
                            Name = name,
                            IsCollectionDefault         = item.Attribute("isCollectionDefault").LoadBoolean(false),
                            AllowUnrecognizedAttributes = top.AllowUnrecognizedAttributes
                        };
                        top.ChildElementSchemas.Add(child);
                        child.Path = string.Format("{0}/{1}", schema == null ? Name : schema.Path, child.Name);
                    }
                    else
                    {
                        // TODO: validation
                        if (item.Attribute("isCollectionDefault").LoadBoolean(false) != child.IsCollectionDefault)
                        {
                            throw new ArgumentException($"isCollectionDefault not equals: item {fileName} child {child.IsCollectionDefault} {child.FileName}");
                        }

                        if (top.AllowUnrecognizedAttributes != child.AllowUnrecognizedAttributes)
                        {
                            throw new ArgumentException($"allowUnrecognizedAttributes not equals: {fileName} child {child.AllowUnrecognizedAttributes} {child.FileName}");
                        }
                    }

                    ParseSectionSchema(item, child, fileName);
                }
                else if (item.Name.LocalName == "collection")
                {
                    var path                        = (schema == null) ? Name : schema.Path;
                    var addElementNames             = item.Attribute("addElement").LoadString(string.Empty);
                    var removeElementName           = item.Attribute("removeElement").LoadString(string.Empty);
                    var clearElementName            = item.Attribute("clearElement").LoadString(string.Empty);
                    var isMergeAppend               = item.Attribute("mergeAppend").LoadBoolean(true);
                    var allowDuplicates             = item.Attribute("allowDuplicates").LoadBoolean(false);
                    var allowUnrecognizedAttributes = item.Attribute("allowUnrecognizedAttributes").LoadBoolean(false);
                    var child                       = new ConfigurationCollectionSchema(path, addElementNames, removeElementName,
                                                                                        clearElementName, isMergeAppend, allowDuplicates, allowUnrecognizedAttributes, fileName);

                    var top = schema ?? Root;
                    if (top.CollectionSchema == null)
                    {
                        top.CollectionSchema = child;
                    }
                    else
                    {
                        top.CollectionSchema.Merge(child);
                    }

                    ParseSectionSchema(item, top.CollectionSchema.AddSchemas[0], fileName);
                    top.CollectionSchema.ReplicateAddSchema();
                }
            }
        }
Exemple #8
0
        private static bool Match(ConfigurationElement existing, ConfigurationElement remove, ConfigurationElementSchema removeSchema)
        {
            foreach (ConfigurationAttributeSchema attribute in removeSchema.AttributeSchemas)
            {
                if (attribute.IsUniqueKey || attribute.IsCombinedKey)
                {
                    if (existing.Attributes[attribute.Name].Value.ToString() != remove.Attributes[attribute.Name].Value.ToString())
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
Exemple #9
0
 internal ConfigurationElementCollection(string name, ConfigurationElementSchema schema, ConfigurationElement parent, XElement entity, FileContext core)
     : base(null, name, schema, parent, entity, core)
 {
 }
 internal ConfigurationSection(string path, ConfigurationElementSchema schema, string location, FileContext core, XElement entity)
     : base(null, path, schema, null, entity, core, null, true, location)
 {
 }
 internal ConfigurationSection(string path, ConfigurationElementSchema schema, string location, FileContext core, XElement entity)
     : base(null, path, schema, null, entity, core)
 {
     Location = location;
     Section = this;
 }
        internal ConfigurationElement(ConfigurationElement element, string name, ConfigurationElementSchema schema, ConfigurationElement parent, XElement entity, FileContext core)
        {
            Methods = new ConfigurationMethodCollection();
            this.FileContext = parent?.FileContext ?? element?.FileContext ?? core;
            Section = parent?.Section;
            this.InnerEntity = entity ?? element?.InnerEntity;
            if (element == null)
            {
                if (name == null)
                {
                    throw new ArgumentException("empty name");
                }

                ElementTagName = name;
                Attributes = new ConfigurationAttributeCollection(this);
                ChildElements = new ConfigurationChildElementCollection(this);
                Collections = new List<ConfigurationElementCollection>();
                RawAttributes = new Dictionary<string, string>();
                ParentElement = parent;
                if (parent == null)
                {
                    if (schema == null)
                    {
                        throw new ArgumentException();
                    }

                    Schema = schema;
                    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();
                }
            }
        }
        //ConfigNameValueCollection parameters;

        //static ConfigurationProperty nameProp;
        //static ConfigurationProperty typeProp;
        //static ConfigurationPropertyCollection properties;

        //public ProviderSettings ()
        //{
        //}

        //public ProviderSettings (string name, string type)
        //{
        //	Name = name;
        //	Type = type;
        //}

        internal ProviderSettings(ConfigurationElement element, string name, ConfigurationElementSchema schema, ConfigurationElement parent, XElement entity)
    : base(element, name, schema, parent, entity, null)
        {
        }
        internal void ParseSectionSchema(XElement element, ConfigurationElementSchema schema)
        {
            foreach (var node in element.Nodes())
            {
                var item = node as XElement;
                if (item == null)
                {
                    continue;
                }

                if (item.Name.LocalName == "attribute")
                {
                    var attribute = new ConfigurationAttributeSchema
                    {
                        Name = item.Attribute("name").Value,
                        Type = item.Attribute("type").Value,
                        IsRequired = item.Attribute("required").LoadBoolean(false),
                        IsUniqueKey = item.Attribute("isUniqueKey").LoadBoolean(false),
                        IsCombinedKey = item.Attribute("isCombinedKey").LoadBoolean(false),
                        IsCaseSensitive = item.Attribute("caseSensitive").LoadBoolean(false),
                        IsEncrypted = item.Attribute("encrypted").LoadBoolean(false),
                        AllowInfinite = item.Attribute("allowInfinite").LoadBoolean(false),
                        TimeSpanFormat = item.Attribute("timeSpanFormat").LoadString("string"),
                        IsExpanded = item.Attribute("expanded").LoadBoolean(false),
                        ValidationType = item.Attribute("validationType").LoadString(null),
                        ValidationParameter = item.Attribute("validationParameter").LoadString(null)
                    };

                    if (attribute.Type == "enum" || attribute.Type == "flags")
                    {
                        attribute.LoadEnums(item);
                    }

                    attribute.CreateValidator();

                    var defaultValue = item.Attribute("defaultValue");
                    if (defaultValue != null)
                    {
                        attribute.SetDefaultValue(defaultValue.Value);
                    }

                    if (schema == null)
                    {
                        Root.AttributeSchemas.Add(attribute);
                    }
                    else
                    {
                        schema.AttributeSchemas.Add(attribute);
                    }

                    continue;
                }

                if (item.Name.LocalName == "element")
                {
                    var name = item.Attribute("name").Value;
                    var top = schema ?? Root;
                    ConfigurationElementSchema child = top.ChildElementSchemas[name];
                    if (child == null)
                    {
                        child = new ConfigurationElementSchema
                        {
                            Name = name,
                            IsCollectionDefault = item.Attribute("isCollectionDefault").LoadBoolean(false),
                            AllowUnrecognizedAttributes = top.AllowUnrecognizedAttributes
                        };
                        top.ChildElementSchemas.Add(child);
                        child.Path = string.Format("{0}/{1}", (schema == null ? Name : schema.Path), child.Name);
                    }
                    else
                    {
                        // TODO: validation
                        if (item.Attribute("isCollectionDefault").LoadBoolean(false) != child.IsCollectionDefault)
                        {
                            throw new ArgumentException("isCollectionDefault not equals");
                        }

                        if (top.AllowUnrecognizedAttributes != child.AllowUnrecognizedAttributes)
                        {
                            throw new ArgumentException("allowUnrecognizedAttributes not equals");
                        }
                    }

                    ParseSectionSchema(item, child);
                }
                else if (item.Name.LocalName == "collection")
                {
                    var path = (schema == null) ? Name : schema.Path;
                    var addElementNames = item.Attribute("addElement").LoadString(string.Empty);
                    var removeElementName = item.Attribute("removeElement").LoadString(string.Empty);
                    var clearElementName = item.Attribute("clearElement").LoadString(string.Empty);
                    var isMergeAppend = item.Attribute("mergeAppend").LoadBoolean(true);
                    var allowDuplicates = item.Attribute("allowDuplicates").LoadBoolean(false);
                    var allowUnrecognizedAttributes = item.Attribute("allowUnrecognizedAttributes").LoadBoolean(false);
                    var child = new ConfigurationCollectionSchema(path, addElementNames, removeElementName,
                        clearElementName, isMergeAppend, allowDuplicates, allowUnrecognizedAttributes);

                    var top = schema ?? Root;
                    if (top.CollectionSchema == null)
                    {
                        top.CollectionSchema = child;
                    }
                    else
                    {
                        top.CollectionSchema.Merge(child);
                    }

                    ParseSectionSchema(item, top.CollectionSchema.AddSchemas[0]);
                    top.CollectionSchema.ReplicateAddSchema();
                }
            }
        }