Exemplo n.º 1
0
        internal object SetAttributeValueInner(string name, object value)
        {
            if (Section.IsLocked)
            {
                throw new FileLoadException("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");
            }

            if (!this.SkipCheck)
            {
                this.FileContext.SetDirty();
            }

            var attribute = this.GetAttribute(name);
            var result    = attribute.TypeMatch(value);

            attribute.IsInheritedFromDefaultValue = (attribute.Schema == null || !attribute.Schema.IsRequired) &&
                                                    result.Equals(attribute.ExtractDefaultValue());
            // IMPORTANT: remove attribute if value is equal to default.
            this.Entity.SetAttributeValue(
                name, attribute.IsInheritedFromDefaultValue
                    ? null
                    : attribute.Format(result));

            // IMPORTANT: IIS seems to use the following
            // this.Entity.SetAttributeValue(name, attribute.Format(_value));

            this.CleanEntity();
            if (attribute.IsInheritedFromDefaultValue)
            {
                this.RawAttributes.Remove(name);
            }
            else
            {
                if (RawAttributes.ContainsKey(name))
                {
                    RawAttributes[name] = value.ToString();
                }
                else
                {
                    RawAttributes.Add(name, value.ToString());
                }
            }

            return(result);
        }
        private void ParseAttribute(XAttribute attribute)
        {
            if (attribute.Name.NamespaceName == "http://www.w3.org/2000/xmlns/")
            {
                return;
            }

            var name = attribute.Name.LocalName;

            switch (name)
            {
            case "lockAllAttributesExcept":
                LockAllAttributesExcept.SetFromList(attribute.Value);
                return;

            case "lockAllElementsExcept":
                LockAllElementsExcept.SetFromList(attribute.Value);
                return;

            case "lockAttributes":
                LockAttributes.SetFromList(attribute.Value);
                return;

            case "lockElements":
                LockElements.SetFromList(attribute.Value);
                return;

            case "lockItem":
                IsLocked = attribute.Value;
                return;
            }

            RawAttributes.Add(name, attribute.Value);
            var child = Schema.AttributeSchemas[name];

            if (child == null && !Schema.AllowUnrecognizedAttributes)
            {
                throw new ArgumentException(String.Format("Unrecognized attribute '{0}'", name));
            }

            var item = new ConfigurationAttribute(name, child, attribute.Value, this);

            Attributes.Add(item);
        }