Пример #1
0
        internal void SetValue(string key, object value, ConfigurationValueFlags valueFlags,
                               PropertySourceInfo sourceInfo)
        {
            ConfigurationValue configValue = CreateConfigValue(value, valueFlags, sourceInfo);

            BaseSet(key, configValue);
        }
Пример #2
0
 internal object this[int index]
 {
     get
     {
         ConfigurationValue configValue = GetConfigValue(index);
         return(configValue?.Value);
     }
 }
Пример #3
0
        internal void ChangeSourceInfo(string key, PropertySourceInfo sourceInfo)
        {
            ConfigurationValue configurationValue = GetConfigValue(key);

            if (configurationValue != null)
            {
                configurationValue.SourceInfo = sourceInfo;
            }
        }
Пример #4
0
 internal object this[string key]
 {
     get
     {
         ConfigurationValue configValue = GetConfigValue(key);
         return(configValue?.Value);
     }
     set { SetValue(key, value, ConfigurationValueFlags.Modified, null); }
 }
Пример #5
0
        internal PropertySourceInfo GetSourceInfo(string key)
        {
            ConfigurationValue configValue = this.GetConfigValue(key);

            if (configValue != null)
            {
                return(configValue.SourceInfo);
            }
            return(null);
        }
Пример #6
0
        internal ConfigurationValueFlags RetrieveFlags(string key)
        {
            ConfigurationValue value2 = (ConfigurationValue)base.BaseGet(key);

            if (value2 != null)
            {
                return(value2.ValueFlags);
            }
            return(ConfigurationValueFlags.Default);
        }
Пример #7
0
        internal bool IsInherited(string key)
        {
            ConfigurationValue configurationValue = (ConfigurationValue)BaseGet(key);

            if (configurationValue != null)
            {
                return((configurationValue.ValueFlags & ConfigurationValueFlags.Inherited) != 0);
            }
            return(false);
        }
Пример #8
0
 internal object this[int index]
 {
     get
     {
         ConfigurationValue configValue = this.GetConfigValue(index);
         if (configValue != null)
         {
             return(configValue.Value);
         }
         return(null);
     }
 }
Пример #9
0
        internal ConfigurationValueFlags RetrieveFlags(string key)
        {
            ConfigurationValue configurationValue = (ConfigurationValue)BaseGet(key);

            if (configurationValue != null)
            {
                return(configurationValue.ValueFlags);
            }
            else
            {
                return(ConfigurationValueFlags.Default);
            }
        }
Пример #10
0
        internal bool IsModified(string key)
        {
            ConfigurationValue configurationValue = (ConfigurationValue)BaseGet(key);

            if (configurationValue != null)
            {
                return((configurationValue.ValueFlags & ConfigurationValueFlags.Modified) != 0);
            }
            else
            {
                return(false);
            }
        }
Пример #11
0
 internal object this[string key]
 {
     get
     {
         ConfigurationValue configValue = this.GetConfigValue(key);
         if (configValue != null)
         {
             return(configValue.Value);
         }
         return(null);
     }
     set
     {
         this.SetValue(key, value, ConfigurationValueFlags.Modified, null);
     }
 }
Пример #12
0
        private ConfigurationValue CreateConfigValue(object value, ConfigurationValueFlags valueFlags, PropertySourceInfo sourceInfo)
        {
            if (value != null)
            {
                if (value is ConfigurationElement)
                {
                    _containsElement = true;
                    ((ConfigurationElement)value).AssociateContext(_configRecord);
                }
                else if (value is InvalidPropValue)
                {
                    _containsInvalidValue = true;
                }
            }

            ConfigurationValue configValue = new ConfigurationValue(value, valueFlags, sourceInfo);

            return(configValue);
        }
Пример #13
0
        internal object this[int index] {
            get {
                ConfigurationValue configValue = GetConfigValue(index);
                if (configValue != null)
                {
                    return(configValue.Value);
                }
                else
                {
                    return(null);
                }
            }

#if UNUSED_CODE
            set {
                SetValue(index, value, ConfigurationValueFlags.Modified, null);
            }
#endif
        }
Пример #14
0
        internal ConfigurationValueFlags RetrieveFlags(string key)
        {
            ConfigurationValue configurationValue = (ConfigurationValue)BaseGet(key);

            return(configurationValue?.ValueFlags ?? ConfigurationValueFlags.Default);
        }
        protected internal virtual void DeserializeElement(XmlReader reader, bool serializeCollectionKey) {
            ConfigurationPropertyCollection props = Properties;
            ConfigurationValue LockedAttributesList = null;
            ConfigurationValue LockedAllExceptList = null;
            ConfigurationValue LockedElementList = null;
            ConfigurationValue LockedAllElementsExceptList = null;
            bool ItemLockedLocally = false;

            _bElementPresent = true;

            ConfigurationElement defaultCollection = null;
            ConfigurationProperty defaultCollectionProperty = props != null ? props.DefaultCollectionProperty : null;
            if (defaultCollectionProperty != null) {
                defaultCollection = (ConfigurationElement)this[defaultCollectionProperty];
            }

            // Process attributes
            _elementTagName = reader.Name;
            PropertySourceInfo rootInfo = new PropertySourceInfo(reader);
            _values.SetValue(reader.Name, null, ConfigurationValueFlags.Modified, rootInfo);
            _values.SetValue(DefaultCollectionPropertyName, defaultCollection, ConfigurationValueFlags.Modified, rootInfo);

            if ((_lockedElementsList != null && (_lockedElementsList.Contains(reader.Name) || 
                    (_lockedElementsList.Contains(LockAll) && reader.Name != ElementTagName))) ||
                (_lockedAllExceptElementsList != null && _lockedAllExceptElementsList.Count != 0 && !_lockedAllExceptElementsList.Contains(reader.Name)) ||
                ((_fItemLocked & ConfigurationValueFlags.Locked) != 0 && (_fItemLocked & ConfigurationValueFlags.Inherited) != 0)
               ) {
                throw new ConfigurationErrorsException(SR.GetString(SR.Config_base_element_locked, reader.Name), reader);
            }


            if (reader.AttributeCount > 0) {
                while (reader.MoveToNextAttribute()) {

                    String propertyName = reader.Name;
                    if ((_lockedAttributesList != null && (_lockedAttributesList.Contains(propertyName) || _lockedAttributesList.Contains(LockAll))) ||
                        (_lockedAllExceptAttributesList != null && !_lockedAllExceptAttributesList.Contains(propertyName))
                       ) {
                        if (propertyName != LockAttributesKey && propertyName != LockAllAttributesExceptKey)
                            throw new ConfigurationErrorsException(SR.GetString(SR.Config_base_attribute_locked, propertyName), reader);
                    }

                    ConfigurationProperty prop = props != null ? props[propertyName] : null;
                    if (prop != null) {
                        if (serializeCollectionKey && !prop.IsKey) {
                            throw new ConfigurationErrorsException(SR.GetString(SR.Config_base_unrecognized_attribute, propertyName), reader);
                        }

                        _values.SetValue(propertyName,
                                            DeserializePropertyValue(prop, reader),
                                            ConfigurationValueFlags.Modified,
                                            new PropertySourceInfo(reader));

                    }   // if (deserializing a remove OR an add that does not handle optional attributes)
                    else if (propertyName == LockItemKey) {
                        try {
                                ItemLockedLocally = bool.Parse(reader.Value);
                        }
                        catch {
                            throw new ConfigurationErrorsException(SR.GetString(SR.Config_invalid_boolean_attribute, propertyName), reader);
                        }
                    }
                    else if (propertyName == LockAttributesKey) {
                        LockedAttributesList = new ConfigurationValue(reader.Value, ConfigurationValueFlags.Default, new PropertySourceInfo(reader));
                    }
                    else if (propertyName == LockAllAttributesExceptKey) {
                        LockedAllExceptList = new ConfigurationValue(reader.Value, ConfigurationValueFlags.Default, new PropertySourceInfo(reader));
                    }
                    else if (propertyName == LockElementsKey) {
                        LockedElementList = new ConfigurationValue(reader.Value, ConfigurationValueFlags.Default, new PropertySourceInfo(reader));
                    }
                    else if (propertyName == LockAllElementsExceptKey) {
                        LockedAllElementsExceptList = new ConfigurationValue(reader.Value, ConfigurationValueFlags.Default, new PropertySourceInfo(reader));
                    }
                    else if (serializeCollectionKey || !OnDeserializeUnrecognizedAttribute(propertyName, reader.Value)) {
                        throw new ConfigurationErrorsException(SR.GetString(SR.Config_base_unrecognized_attribute, propertyName), reader);
                    }
                }
            }

            reader.MoveToElement();

            // Check for nested elements.
            try {

                HybridDictionary nodeFound = new HybridDictionary();
                if (!reader.IsEmptyElement) {
                    while (reader.Read()) {
                        if (reader.NodeType == XmlNodeType.Element) {
                            String propertyName = reader.Name;

                            CheckLockedElement(propertyName, null);

                            ConfigurationProperty prop = props != null ? props[propertyName] : null;
                            if (prop != null) {
                                if (typeof(ConfigurationElement).IsAssignableFrom(prop.Type)) {
                                    if (nodeFound.Contains(propertyName))
                                        throw new ConfigurationErrorsException(SR.GetString(SR.Config_base_element_cannot_have_multiple_child_elements, propertyName), reader);
                                    nodeFound.Add(propertyName, propertyName);
                                    ConfigurationElement childElement = (ConfigurationElement)this[prop];
                                    childElement.DeserializeElement(reader, serializeCollectionKey);

                                    // Validate the new element with the per-property Validator
                                    // Note that the per-type validator for childElement has been already executed as part of Deserialize
                                    ValidateElement(childElement, prop.Validator, false);
                                }
                                else {
                                    throw new ConfigurationErrorsException(SR.GetString(SR.Config_base_property_is_not_a_configuration_element, propertyName), reader);
                                }
                            }
                            else if (!OnDeserializeUnrecognizedElement(propertyName, reader)) {
                                // Let the default collection, if there is one, handle this node.
                                if (defaultCollection == null ||
                                        !defaultCollection.OnDeserializeUnrecognizedElement(propertyName, reader)) {
                                    throw new ConfigurationErrorsException(SR.GetString(SR.Config_base_unrecognized_element_name, propertyName), reader);
                                }
                            }
                        }
                        else if (reader.NodeType == XmlNodeType.EndElement) {
                            break;
                        }
                        else if ((reader.NodeType == XmlNodeType.CDATA) || (reader.NodeType == XmlNodeType.Text)) {
                            throw new ConfigurationErrorsException(SR.GetString(SR.Config_base_section_invalid_content), reader);
                        }
                    }
                }

                EnsureRequiredProperties(serializeCollectionKey);

                // Call the per-type validator for this object
                ValidateElement(this, null, false);
            }
            catch (ConfigurationException e) {
                // Catch the generic message from deserialization and include line info if necessary
                if (e.Filename == null || e.Filename.Length == 0)
                    throw new ConfigurationErrorsException(e.Message, reader); // give it some info
                else
                    throw e;
            }

            if (ItemLockedLocally) {
                SetLocked();
                _fItemLocked = ConfigurationValueFlags.Locked;
            }

            if (LockedAttributesList != null) {
                if (_lockedAttributesList == null)
                    _lockedAttributesList = new ConfigurationLockCollection(this, ConfigurationLockCollectionType.LockedAttributes);
                foreach (string key in ParseLockedAttributes(LockedAttributesList, ConfigurationLockCollectionType.LockedAttributes)) {
                    if (!_lockedAttributesList.Contains(key))
                        _lockedAttributesList.Add(key, ConfigurationValueFlags.Default);  // add the local copy
                    else
                        _lockedAttributesList.Add(key, ConfigurationValueFlags.Modified | ConfigurationValueFlags.Inherited);  // add the local copy
                }
            }
            if (LockedAllExceptList != null) {
                ConfigurationLockCollection newCollection = ParseLockedAttributes(LockedAllExceptList, ConfigurationLockCollectionType.LockedExceptionList);
                if (_lockedAllExceptAttributesList == null) {
                    _lockedAllExceptAttributesList = new ConfigurationLockCollection(this, ConfigurationLockCollectionType.LockedExceptionList, String.Empty, newCollection);
                    _lockedAllExceptAttributesList.ClearSeedList(); // Prevent the list from thinking this was set by a parent.
                }
                StringCollection intersectionCollection = IntersectLockCollections(_lockedAllExceptAttributesList, newCollection);
                /*
                if (intersectionCollection.Count == 0) {
                    throw new ConfigurationErrorsException(SR.GetString(SR.Config_empty_lock_attributes_except_effective,
                                                                        LockAllAttributesExceptKey,
                                                                        LockedAllExceptList.Value,
                                                                        LockAttributesKey),
                                                                        LockedAllExceptList.SourceInfo.FileName,
                                                                        LockedAllExceptList.SourceInfo.LineNumber);

                }
                */
                _lockedAllExceptAttributesList.ClearInternal(false);
                foreach (string key in intersectionCollection) {
                    _lockedAllExceptAttributesList.Add(key, ConfigurationValueFlags.Default);
                }
            }
            if (LockedElementList != null) {
                if (_lockedElementsList == null)
                    _lockedElementsList = new ConfigurationLockCollection(this, ConfigurationLockCollectionType.LockedElements);

                ConfigurationLockCollection localLockedElementList = ParseLockedAttributes(LockedElementList, ConfigurationLockCollectionType.LockedElements);

                ConfigurationElementCollection collection = null;
                if (props.DefaultCollectionProperty != null) // this is not a collection but it may contain a default collection
                {
                    collection = this[props.DefaultCollectionProperty] as ConfigurationElementCollection;
                    if (collection != null && collection._lockedElementsList == null)
                        collection._lockedElementsList = _lockedElementsList;
                }

                foreach (string key in localLockedElementList) {
                    if (!_lockedElementsList.Contains(key)) {
                        _lockedElementsList.Add(key, ConfigurationValueFlags.Default);  // add the local copy

                        ConfigurationProperty propToLock = Properties[key];
                        if (propToLock != null && typeof(ConfigurationElement).IsAssignableFrom(propToLock.Type)) {
                            ((ConfigurationElement)this[key]).SetLocked();
                        }
                        if (key == LockAll) {
                            foreach (ConfigurationProperty prop in Properties) {
                                if (!string.IsNullOrEmpty(prop.Name) &&
                                    typeof(ConfigurationElement).IsAssignableFrom(prop.Type)) {
                                    ((ConfigurationElement)this[prop]).SetLocked();
                                }
                            }
                        }

                    }
                }
            }

            if (LockedAllElementsExceptList != null) {
                ConfigurationLockCollection newCollection = ParseLockedAttributes(LockedAllElementsExceptList, ConfigurationLockCollectionType.LockedElementsExceptionList);
                if (_lockedAllExceptElementsList == null) {
                    _lockedAllExceptElementsList = new ConfigurationLockCollection(this, ConfigurationLockCollectionType.LockedElementsExceptionList, _elementTagName, newCollection);
                    _lockedAllExceptElementsList.ClearSeedList();
                }

                StringCollection intersectionCollection = IntersectLockCollections(_lockedAllExceptElementsList, newCollection);

                ConfigurationElementCollection collection = null;
                if (props.DefaultCollectionProperty != null) // this is not a collection but it may contain a default collection
                {
                    collection = this[props.DefaultCollectionProperty] as ConfigurationElementCollection;
                    if (collection != null && collection._lockedAllExceptElementsList == null)
                        collection._lockedAllExceptElementsList = _lockedAllExceptElementsList;
                }

                _lockedAllExceptElementsList.ClearInternal(false);
                foreach (string key in intersectionCollection) {
                    if (!_lockedAllExceptElementsList.Contains(key) || key == ElementTagName)
                        _lockedAllExceptElementsList.Add(key, ConfigurationValueFlags.Default);  // add the local copy
                }

                foreach (ConfigurationProperty prop in Properties) {
                    if (!(string.IsNullOrEmpty(prop.Name) || _lockedAllExceptElementsList.Contains(prop.Name)) &&
                        typeof(ConfigurationElement).IsAssignableFrom(prop.Type)) {
                        ((ConfigurationElement)this[prop]).SetLocked();
                    }
                }

            }

            // Make sure default collections use the same lock element lists
            if (defaultCollectionProperty != null) {
                defaultCollection = (ConfigurationElement)this[defaultCollectionProperty];
                if (_lockedElementsList == null) {
                    _lockedElementsList = new ConfigurationLockCollection(this, ConfigurationLockCollectionType.LockedElements);
                }
                defaultCollection._lockedElementsList = _lockedElementsList; 
                if (_lockedAllExceptElementsList == null) {
                    _lockedAllExceptElementsList = new ConfigurationLockCollection(this, ConfigurationLockCollectionType.LockedElementsExceptionList, reader.Name);
                    _lockedAllExceptElementsList.ClearSeedList();
                }
                defaultCollection._lockedAllExceptElementsList = _lockedAllExceptElementsList;
            }

            // This has to be the last thing to execute
            PostDeserialize();
        }
        private ConfigurationLockCollection ParseLockedAttributes(ConfigurationValue value, ConfigurationLockCollectionType lockType) {
            // check that only actual properties are in the lock attribute
            ConfigurationLockCollection localLockedAttributesList = new ConfigurationLockCollection(this, lockType);
            string attributeList = (string)(value.Value);

            if (string.IsNullOrEmpty(attributeList)) {
                if (lockType == ConfigurationLockCollectionType.LockedAttributes)
                    throw new ConfigurationErrorsException(SR.GetString(SR.Empty_attribute, LockAttributesKey), value.SourceInfo.FileName, value.SourceInfo.LineNumber);
                if (lockType == ConfigurationLockCollectionType.LockedElements)
                    throw new ConfigurationErrorsException(SR.GetString(SR.Empty_attribute, LockElementsKey), value.SourceInfo.FileName, value.SourceInfo.LineNumber);
                if (lockType == ConfigurationLockCollectionType.LockedExceptionList)
                    throw new ConfigurationErrorsException(SR.GetString(SR.Config_empty_lock_attributes_except, LockAllAttributesExceptKey, LockAttributesKey), value.SourceInfo.FileName, value.SourceInfo.LineNumber);
                if (lockType == ConfigurationLockCollectionType.LockedElementsExceptionList)
                    throw new ConfigurationErrorsException(SR.GetString(SR.Config_empty_lock_element_except, LockAllElementsExceptKey, LockElementsKey), value.SourceInfo.FileName, value.SourceInfo.LineNumber);
            }

            string[] attribsToLock = attributeList.Split(new char[] { ',', ':', ';' });
            foreach (string attribToLock in attribsToLock) {
                string attribToLockTrim = attribToLock.Trim();
                if (!String.IsNullOrEmpty(attribToLockTrim)) {
                    // validate that the locks are good
                    if (!((lockType == ConfigurationLockCollectionType.LockedElements ||
                         lockType == ConfigurationLockCollectionType.LockedAttributes) &&
                         attribToLockTrim == LockAll)) {
                        ConfigurationProperty propToLock = Properties[attribToLockTrim];

                        if (propToLock == null ||                                   // if the prop does not exist 
                            attribToLockTrim == LockAttributesKey ||                // or it is the lockattributes keyword
                            attribToLockTrim == LockAllAttributesExceptKey ||       // or it is the lockattributes keyword
                            attribToLockTrim == LockElementsKey ||                  // or it is the lockelements keyword
                            (lockType != ConfigurationLockCollectionType.LockedElements && lockType != ConfigurationLockCollectionType.LockedElementsExceptionList &&
                                typeof(ConfigurationElement).IsAssignableFrom(propToLock.Type)) ||  // or if not locking elements but the property is a element
                            ((lockType == ConfigurationLockCollectionType.LockedElements || lockType == ConfigurationLockCollectionType.LockedElementsExceptionList) &&
                             !typeof(ConfigurationElement).IsAssignableFrom(propToLock.Type)) // or if locking elements but the property is not an element
                        ) {
                        // check to see if this is a collection and we are locking a collection element

                            ConfigurationElementCollection collection = this as ConfigurationElementCollection;
                            if (collection == null && Properties.DefaultCollectionProperty != null) // this is not a collection but it may contain a default collection
                            {
                                collection = this[Properties.DefaultCollectionProperty] as ConfigurationElementCollection;
                            }
                            if (collection == null ||
                                lockType == ConfigurationLockCollectionType.LockedAttributes || // If the collection type is not element then the lock is bogus
                                lockType == ConfigurationLockCollectionType.LockedExceptionList) {
                                ReportInvalidLock(attribToLockTrim, lockType, value, null);
                            }
                            else if (!collection.IsLockableElement(attribToLockTrim)) {
                                ReportInvalidLock(attribToLockTrim, lockType, value, collection.LockableElements);
                            }
                        }
                        if (propToLock != null && propToLock.IsRequired == true)
                            throw new ConfigurationErrorsException(SR.GetString(SR.Config_base_required_attribute_lock_attempt, propToLock.Name));
                    }


                    // concatenate the new attribute.
                    localLockedAttributesList.Add(attribToLockTrim, ConfigurationValueFlags.Default); // Mark as local
                }
            }
            return localLockedAttributesList;
        }
        internal void ReportInvalidLock(string attribToLockTrim, ConfigurationLockCollectionType lockedType, ConfigurationValue value, String collectionProperties) {
            StringBuilder sb;
            sb = new StringBuilder();

            // Add the collection properties when locking elements
            if (!String.IsNullOrEmpty(collectionProperties) &&
                    ((lockedType == ConfigurationLockCollectionType.LockedElements) || (lockedType == ConfigurationLockCollectionType.LockedElementsExceptionList))) {
                if (sb.Length != 0)
                    sb.Append(',');
                sb.Append(collectionProperties);
            }

            // construct a list of valid lockable properties
            foreach (object _prop in Properties) {
                ConfigurationProperty validProp = (ConfigurationProperty)_prop;
                if (validProp.Name != LockAttributesKey &&
                    validProp.Name != LockAllAttributesExceptKey &&
                    validProp.Name != LockElementsKey &&
                    validProp.Name != LockAllElementsExceptKey
                ) {
                    if ((lockedType == ConfigurationLockCollectionType.LockedElements) ||
                            (lockedType == ConfigurationLockCollectionType.LockedElementsExceptionList)) {
                        if (typeof(ConfigurationElement).IsAssignableFrom(validProp.Type)) {
                            if (sb.Length != 0)
                                sb.Append(", ");
                            sb.Append("'");
                            sb.Append(validProp.Name);
                            sb.Append("'");
                        }
                    }
                    else {
                        if (!typeof(ConfigurationElement).IsAssignableFrom(validProp.Type)) {
                            if (sb.Length != 0)
                                sb.Append(", ");
                            sb.Append("'");
                            sb.Append(validProp.Name);
                            sb.Append("'");
                        }
                    }
                }
            }

            string format = null;

            if ((lockedType == ConfigurationLockCollectionType.LockedElements) ||
                    (lockedType == ConfigurationLockCollectionType.LockedElementsExceptionList)) {
                if (value != null)
                    format = SR.GetString(SR.Config_base_invalid_element_to_lock);
                else
                    format = SR.GetString(SR.Config_base_invalid_element_to_lock_by_add);

            }
            else {
                if (value != null)
                    format = SR.GetString(SR.Config_base_invalid_attribute_to_lock);
                else
                    format = SR.GetString(SR.Config_base_invalid_attribute_to_lock_by_add);
            }
            if (value != null)
                throw new ConfigurationErrorsException(string.Format(CultureInfo.CurrentCulture, format, attribToLockTrim, sb.ToString()), value.SourceInfo.FileName, value.SourceInfo.LineNumber);
            else
                throw new ConfigurationErrorsException(string.Format(CultureInfo.CurrentCulture, format, attribToLockTrim, sb.ToString()));
        }
Пример #18
0
 private ConfigurationLockCollection ParseLockedAttributes(ConfigurationValue value, ConfigurationLockCollectionType lockType)
 {
     ConfigurationLockCollection configurationLockCollection = new ConfigurationLockCollection(this, lockType);
       string str1 = (string) value.Value;
       if (string.IsNullOrEmpty(str1))
       {
     if (lockType == ConfigurationLockCollectionType.LockedAttributes)
       throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Empty_attribute", new object[1]
       {
     (object) "lockAttributes"
       }), value.SourceInfo.FileName, value.SourceInfo.LineNumber);
     else if (lockType == ConfigurationLockCollectionType.LockedElements)
       throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Empty_attribute", new object[1]
       {
     (object) "lockElements"
       }), value.SourceInfo.FileName, value.SourceInfo.LineNumber);
     else if (lockType == ConfigurationLockCollectionType.LockedExceptionList)
       throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_empty_lock_attributes_except", (object) "lockAllAttributesExcept", (object) "lockAttributes"), value.SourceInfo.FileName, value.SourceInfo.LineNumber);
     else if (lockType == ConfigurationLockCollectionType.LockedElementsExceptionList)
       throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_empty_lock_element_except", (object) "lockAllElementsExcept", (object) "lockElements"), value.SourceInfo.FileName, value.SourceInfo.LineNumber);
       }
       string str2 = str1;
       char[] chArray = new char[3]
       {
     ',',
     ':',
     ';'
       };
       foreach (string str3 in str2.Split(chArray))
       {
     string index = str3.Trim();
     if (!string.IsNullOrEmpty(index))
     {
       if (lockType != ConfigurationLockCollectionType.LockedElements && lockType != ConfigurationLockCollectionType.LockedAttributes || !(index == "*"))
       {
     ConfigurationProperty configurationProperty = this.Properties[index];
     if (configurationProperty == null || index == "lockAttributes" || (index == "lockAllAttributesExcept" || index == "lockElements") || lockType != ConfigurationLockCollectionType.LockedElements && lockType != ConfigurationLockCollectionType.LockedElementsExceptionList && typeof (ConfigurationElement).IsAssignableFrom(configurationProperty.Type) || (lockType == ConfigurationLockCollectionType.LockedElements || lockType == ConfigurationLockCollectionType.LockedElementsExceptionList) && !typeof (ConfigurationElement).IsAssignableFrom(configurationProperty.Type))
     {
       ConfigurationElementCollection elementCollection = this as ConfigurationElementCollection;
       if (elementCollection == null && this.Properties.DefaultCollectionProperty != null)
         elementCollection = this[this.Properties.DefaultCollectionProperty] as ConfigurationElementCollection;
       if (elementCollection == null || lockType == ConfigurationLockCollectionType.LockedAttributes || lockType == ConfigurationLockCollectionType.LockedExceptionList)
         this.ReportInvalidLock(index, lockType, value, (string) null);
       else if (!elementCollection.IsLockableElement(index))
         this.ReportInvalidLock(index, lockType, value, elementCollection.LockableElements);
     }
     if (configurationProperty != null && configurationProperty.IsRequired)
       throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_base_required_attribute_lock_attempt", new object[1]
       {
         (object) configurationProperty.Name
       }));
       }
       configurationLockCollection.Add(index, ConfigurationValueFlags.Default);
     }
       }
       return configurationLockCollection;
 }
Пример #19
0
        internal void SetValue(string key, object value, ConfigurationValueFlags valueFlags, PropertySourceInfo sourceInfo)
        {
            ConfigurationValue value2 = this.CreateConfigValue(value, valueFlags, sourceInfo);

            base.BaseSet(key, value2);
        }
Пример #20
0
 /// <summary>
 /// Reads XML from the configuration file.
 /// </summary>
 /// <param name="reader">The <see cref="T:System.Xml.XmlReader"/> that reads from the configuration file.</param><param name="serializeCollectionKey">true to serialize only the collection key properties; otherwise, false.</param><exception cref="T:System.Configuration.ConfigurationErrorsException">The element to read is locked.- or -An attribute of the current node is not recognized.- or -The lock status of the current node cannot be determined.  </exception>
 protected internal virtual void DeserializeElement(XmlReader reader, bool serializeCollectionKey)
 {
     ConfigurationPropertyCollection properties = this.Properties;
       ConfigurationValue configurationValue1 = (ConfigurationValue) null;
       ConfigurationValue configurationValue2 = (ConfigurationValue) null;
       ConfigurationValue configurationValue3 = (ConfigurationValue) null;
       ConfigurationValue configurationValue4 = (ConfigurationValue) null;
       bool flag = false;
       this._bElementPresent = true;
       ConfigurationElement configurationElement1 = (ConfigurationElement) null;
       ConfigurationProperty index1 = properties != null ? properties.DefaultCollectionProperty : (ConfigurationProperty) null;
       if (index1 != null)
     configurationElement1 = (ConfigurationElement) this[index1];
       this._elementTagName = reader.Name;
       PropertySourceInfo sourceInfo = new PropertySourceInfo(reader);
       this._values.SetValue(reader.Name, (object) null, ConfigurationValueFlags.Modified, sourceInfo);
       this._values.SetValue("", (object) configurationElement1, ConfigurationValueFlags.Modified, sourceInfo);
       if (this._lockedElementsList != null && (this._lockedElementsList.Contains(reader.Name) || this._lockedElementsList.Contains("*") && reader.Name != this.ElementTagName) || (this._lockedAllExceptElementsList != null && this._lockedAllExceptElementsList.Count != 0 && !this._lockedAllExceptElementsList.Contains(reader.Name) || (this._fItemLocked & ConfigurationValueFlags.Locked) != ConfigurationValueFlags.Default && (this._fItemLocked & ConfigurationValueFlags.Inherited) != ConfigurationValueFlags.Default))
       {
     throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_base_element_locked", new object[1]
     {
       (object) reader.Name
     }), reader);
       }
       else
       {
     if (reader.AttributeCount > 0)
     {
       while (reader.MoveToNextAttribute())
       {
     string name = reader.Name;
     if ((this._lockedAttributesList != null && (this._lockedAttributesList.Contains(name) || this._lockedAttributesList.Contains("*")) || this._lockedAllExceptAttributesList != null && !this._lockedAllExceptAttributesList.Contains(name)) && (name != "lockAttributes" && name != "lockAllAttributesExcept"))
     {
       throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_base_attribute_locked", new object[1]
       {
         (object) name
       }), reader);
     }
     else
     {
       ConfigurationProperty prop = properties != null ? properties[name] : (ConfigurationProperty) null;
       if (prop != null)
       {
         if (serializeCollectionKey && !prop.IsKey)
           throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_base_unrecognized_attribute", new object[1]
           {
             (object) name
           }), reader);
         else
           this._values.SetValue(name, this.DeserializePropertyValue(prop, reader), ConfigurationValueFlags.Modified, new PropertySourceInfo(reader));
       }
       else if (name == "lockItem")
       {
         try
         {
           flag = bool.Parse(reader.Value);
         }
         catch
         {
           throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_invalid_boolean_attribute", new object[1]
           {
             (object) name
           }), reader);
         }
       }
       else if (name == "lockAttributes")
         configurationValue1 = new ConfigurationValue((object) reader.Value, ConfigurationValueFlags.Default, new PropertySourceInfo(reader));
       else if (name == "lockAllAttributesExcept")
         configurationValue2 = new ConfigurationValue((object) reader.Value, ConfigurationValueFlags.Default, new PropertySourceInfo(reader));
       else if (name == "lockElements")
         configurationValue3 = new ConfigurationValue((object) reader.Value, ConfigurationValueFlags.Default, new PropertySourceInfo(reader));
       else if (name == "lockAllElementsExcept")
         configurationValue4 = new ConfigurationValue((object) reader.Value, ConfigurationValueFlags.Default, new PropertySourceInfo(reader));
       else if (serializeCollectionKey || !this.OnDeserializeUnrecognizedAttribute(name, reader.Value))
         throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_base_unrecognized_attribute", new object[1]
         {
           (object) name
         }), reader);
     }
       }
     }
     reader.MoveToElement();
     try
     {
       HybridDictionary hybridDictionary = new HybridDictionary();
       if (!reader.IsEmptyElement)
       {
     while (reader.Read())
     {
       if (reader.NodeType == XmlNodeType.Element)
       {
         string name = reader.Name;
         this.CheckLockedElement(name, (XmlReader) null);
         ConfigurationProperty index2 = properties != null ? properties[name] : (ConfigurationProperty) null;
         if (index2 != null)
         {
           if (index2.IsConfigurationElementType)
           {
             if (hybridDictionary.Contains((object) name))
             {
               throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_base_element_cannot_have_multiple_child_elements", new object[1]
               {
                 (object) name
               }), reader);
             }
             else
             {
               hybridDictionary.Add((object) name, (object) name);
               ConfigurationElement elem = (ConfigurationElement) this[index2];
               elem.DeserializeElement(reader, serializeCollectionKey);
               ConfigurationElement.ValidateElement(elem, index2.Validator, false);
             }
           }
           else
             throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_base_property_is_not_a_configuration_element", new object[1]
             {
               (object) name
             }), reader);
         }
         else if (!this.OnDeserializeUnrecognizedElement(name, reader) && (configurationElement1 == null || !configurationElement1.OnDeserializeUnrecognizedElement(name, reader)))
           throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_base_unrecognized_element_name", new object[1]
           {
             (object) name
           }), reader);
       }
       else if (reader.NodeType != XmlNodeType.EndElement)
       {
         if (reader.NodeType == XmlNodeType.CDATA || reader.NodeType == XmlNodeType.Text)
           throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_base_section_invalid_content"), reader);
       }
       else
         break;
     }
       }
       this.EnsureRequiredProperties(serializeCollectionKey);
       ConfigurationElement.ValidateElement(this, (ConfigurationValidatorBase) null, false);
     }
     catch (ConfigurationException ex)
     {
       if (ex.Filename == null || ex.Filename.Length == 0)
     throw new ConfigurationErrorsException(ex.Message, reader);
       else
     throw ex;
     }
     if (flag)
     {
       this.SetLocked();
       this._fItemLocked = ConfigurationValueFlags.Locked;
     }
     if (configurationValue1 != null)
     {
       if (this._lockedAttributesList == null)
     this._lockedAttributesList = new ConfigurationLockCollection(this, ConfigurationLockCollectionType.LockedAttributes);
       foreach (string name in this.ParseLockedAttributes(configurationValue1, ConfigurationLockCollectionType.LockedAttributes))
       {
     if (!this._lockedAttributesList.Contains(name))
       this._lockedAttributesList.Add(name, ConfigurationValueFlags.Default);
     else
       this._lockedAttributesList.Add(name, ConfigurationValueFlags.Inherited | ConfigurationValueFlags.Modified);
       }
     }
     if (configurationValue2 != null)
     {
       ConfigurationLockCollection configurationLockCollection = this.ParseLockedAttributes(configurationValue2, ConfigurationLockCollectionType.LockedExceptionList);
       if (this._lockedAllExceptAttributesList == null)
       {
     this._lockedAllExceptAttributesList = new ConfigurationLockCollection(this, ConfigurationLockCollectionType.LockedExceptionList, string.Empty, configurationLockCollection);
     this._lockedAllExceptAttributesList.ClearSeedList();
       }
       StringCollection stringCollection = this.IntersectLockCollections(this._lockedAllExceptAttributesList, configurationLockCollection);
       this._lockedAllExceptAttributesList.ClearInternal(false);
       foreach (string name in stringCollection)
     this._lockedAllExceptAttributesList.Add(name, ConfigurationValueFlags.Default);
     }
     if (configurationValue3 != null)
     {
       if (this._lockedElementsList == null)
     this._lockedElementsList = new ConfigurationLockCollection(this, ConfigurationLockCollectionType.LockedElements);
       ConfigurationLockCollection configurationLockCollection = this.ParseLockedAttributes(configurationValue3, ConfigurationLockCollectionType.LockedElements);
       if (properties.DefaultCollectionProperty != null)
       {
     ConfigurationElementCollection elementCollection = this[properties.DefaultCollectionProperty] as ConfigurationElementCollection;
     if (elementCollection != null && elementCollection._lockedElementsList == null)
       elementCollection._lockedElementsList = this._lockedElementsList;
       }
       foreach (string name in configurationLockCollection)
       {
     if (!this._lockedElementsList.Contains(name))
     {
       this._lockedElementsList.Add(name, ConfigurationValueFlags.Default);
       ConfigurationProperty configurationProperty = this.Properties[name];
       if (configurationProperty != null && typeof (ConfigurationElement).IsAssignableFrom(configurationProperty.Type))
         ((ConfigurationElement) this[name]).SetLocked();
       if (name == "*")
       {
         foreach (ConfigurationProperty index2 in this.Properties)
         {
           if (!string.IsNullOrEmpty(index2.Name) && index2.IsConfigurationElementType)
             ((ConfigurationElement) this[index2]).SetLocked();
         }
       }
     }
       }
     }
     if (configurationValue4 != null)
     {
       ConfigurationLockCollection configurationLockCollection = this.ParseLockedAttributes(configurationValue4, ConfigurationLockCollectionType.LockedElementsExceptionList);
       if (this._lockedAllExceptElementsList == null)
       {
     this._lockedAllExceptElementsList = new ConfigurationLockCollection(this, ConfigurationLockCollectionType.LockedElementsExceptionList, this._elementTagName, configurationLockCollection);
     this._lockedAllExceptElementsList.ClearSeedList();
       }
       StringCollection stringCollection = this.IntersectLockCollections(this._lockedAllExceptElementsList, configurationLockCollection);
       if (properties.DefaultCollectionProperty != null)
       {
     ConfigurationElementCollection elementCollection = this[properties.DefaultCollectionProperty] as ConfigurationElementCollection;
     if (elementCollection != null && elementCollection._lockedAllExceptElementsList == null)
       elementCollection._lockedAllExceptElementsList = this._lockedAllExceptElementsList;
       }
       this._lockedAllExceptElementsList.ClearInternal(false);
       foreach (string name in stringCollection)
       {
     if (!this._lockedAllExceptElementsList.Contains(name) || name == this.ElementTagName)
       this._lockedAllExceptElementsList.Add(name, ConfigurationValueFlags.Default);
       }
       foreach (ConfigurationProperty index2 in this.Properties)
       {
     if (!string.IsNullOrEmpty(index2.Name) && !this._lockedAllExceptElementsList.Contains(index2.Name) && index2.IsConfigurationElementType)
       ((ConfigurationElement) this[index2]).SetLocked();
       }
     }
     if (index1 != null)
     {
       ConfigurationElement configurationElement2 = (ConfigurationElement) this[index1];
       if (this._lockedElementsList == null)
     this._lockedElementsList = new ConfigurationLockCollection(this, ConfigurationLockCollectionType.LockedElements);
       configurationElement2._lockedElementsList = this._lockedElementsList;
       if (this._lockedAllExceptElementsList == null)
       {
     this._lockedAllExceptElementsList = new ConfigurationLockCollection(this, ConfigurationLockCollectionType.LockedElementsExceptionList, reader.Name);
     this._lockedAllExceptElementsList.ClearSeedList();
       }
       configurationElement2._lockedAllExceptElementsList = this._lockedAllExceptElementsList;
     }
     this.PostDeserialize();
       }
 }
 private ConfigurationLockCollection ParseLockedAttributes(ConfigurationValue value, ConfigurationLockCollectionType lockType)
 {
     ConfigurationLockCollection locks = new ConfigurationLockCollection(this, lockType);
     string str = (string) value.Value;
     if (string.IsNullOrEmpty(str))
     {
         if (lockType == ConfigurationLockCollectionType.LockedAttributes)
         {
             throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Empty_attribute", new object[] { "lockAttributes" }), value.SourceInfo.FileName, value.SourceInfo.LineNumber);
         }
         if (lockType == ConfigurationLockCollectionType.LockedElements)
         {
             throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Empty_attribute", new object[] { "lockElements" }), value.SourceInfo.FileName, value.SourceInfo.LineNumber);
         }
         if (lockType == ConfigurationLockCollectionType.LockedExceptionList)
         {
             throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_empty_lock_attributes_except", new object[] { "lockAllAttributesExcept", "lockAttributes" }), value.SourceInfo.FileName, value.SourceInfo.LineNumber);
         }
         if (lockType == ConfigurationLockCollectionType.LockedElementsExceptionList)
         {
             throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_empty_lock_element_except", new object[] { "lockAllElementsExcept", "lockElements" }), value.SourceInfo.FileName, value.SourceInfo.LineNumber);
         }
     }
     foreach (string str2 in str.Split(new char[] { ',', ':', ';' }))
     {
         string str3 = str2.Trim();
         if (!string.IsNullOrEmpty(str3))
         {
             if (((lockType != ConfigurationLockCollectionType.LockedElements) && (lockType != ConfigurationLockCollectionType.LockedAttributes)) || (str3 != "*"))
             {
                 ConfigurationProperty property = this.Properties[str3];
                 if (((((property == null) || (str3 == "lockAttributes")) || ((str3 == "lockAllAttributesExcept") || (str3 == "lockElements"))) || (((lockType != ConfigurationLockCollectionType.LockedElements) && (lockType != ConfigurationLockCollectionType.LockedElementsExceptionList)) && typeof(ConfigurationElement).IsAssignableFrom(property.Type))) || (((lockType == ConfigurationLockCollectionType.LockedElements) || (lockType == ConfigurationLockCollectionType.LockedElementsExceptionList)) && !typeof(ConfigurationElement).IsAssignableFrom(property.Type)))
                 {
                     ConfigurationElementCollection elements = this as ConfigurationElementCollection;
                     if ((elements == null) && (this.Properties.DefaultCollectionProperty != null))
                     {
                         elements = this[this.Properties.DefaultCollectionProperty] as ConfigurationElementCollection;
                     }
                     if (((elements == null) || (lockType == ConfigurationLockCollectionType.LockedAttributes)) || (lockType == ConfigurationLockCollectionType.LockedExceptionList))
                     {
                         this.ReportInvalidLock(str3, lockType, value, null);
                     }
                     else if (!elements.IsLockableElement(str3))
                     {
                         this.ReportInvalidLock(str3, lockType, value, elements.LockableElements);
                     }
                 }
                 if ((property != null) && property.IsRequired)
                 {
                     throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_base_required_attribute_lock_attempt", new object[] { property.Name }));
                 }
             }
             locks.Add(str3, ConfigurationValueFlags.Default);
         }
     }
     return locks;
 }
Пример #22
0
 internal void ReportInvalidLock(string attribToLockTrim, ConfigurationLockCollectionType lockedType, ConfigurationValue value, string collectionProperties)
 {
     StringBuilder stringBuilder = new StringBuilder();
       if (!string.IsNullOrEmpty(collectionProperties) && (lockedType == ConfigurationLockCollectionType.LockedElements || lockedType == ConfigurationLockCollectionType.LockedElementsExceptionList))
       {
     if (stringBuilder.Length != 0)
       stringBuilder.Append(',');
     stringBuilder.Append(collectionProperties);
       }
       foreach (ConfigurationProperty configurationProperty in this.Properties)
       {
     if (configurationProperty.Name != "lockAttributes" && configurationProperty.Name != "lockAllAttributesExcept" && (configurationProperty.Name != "lockElements" && configurationProperty.Name != "lockAllElementsExcept"))
     {
       if (lockedType == ConfigurationLockCollectionType.LockedElements || lockedType == ConfigurationLockCollectionType.LockedElementsExceptionList)
       {
     if (typeof (ConfigurationElement).IsAssignableFrom(configurationProperty.Type))
     {
       if (stringBuilder.Length != 0)
         stringBuilder.Append(", ");
       stringBuilder.Append("'");
       stringBuilder.Append(configurationProperty.Name);
       stringBuilder.Append("'");
     }
       }
       else if (!typeof (ConfigurationElement).IsAssignableFrom(configurationProperty.Type))
       {
     if (stringBuilder.Length != 0)
       stringBuilder.Append(", ");
     stringBuilder.Append("'");
     stringBuilder.Append(configurationProperty.Name);
     stringBuilder.Append("'");
       }
     }
       }
       string format = lockedType == ConfigurationLockCollectionType.LockedElements || lockedType == ConfigurationLockCollectionType.LockedElementsExceptionList ? (value == null ? System.Configuration.SR.GetString("Config_base_invalid_element_to_lock_by_add") : System.Configuration.SR.GetString("Config_base_invalid_element_to_lock")) : (value == null ? System.Configuration.SR.GetString("Config_base_invalid_attribute_to_lock_by_add") : System.Configuration.SR.GetString("Config_base_invalid_attribute_to_lock"));
       if (value != null)
     throw new ConfigurationErrorsException(string.Format((IFormatProvider) CultureInfo.CurrentCulture, format, new object[2]
     {
       (object) attribToLockTrim,
       (object) ((object) stringBuilder).ToString()
     }), value.SourceInfo.FileName, value.SourceInfo.LineNumber);
       else
     throw new ConfigurationErrorsException(string.Format((IFormatProvider) CultureInfo.CurrentCulture, format, new object[2]
     {
       (object) attribToLockTrim,
       (object) ((object) stringBuilder).ToString()
     }));
 }
Пример #23
0
        internal PropertySourceInfo GetSourceInfo(string key)
        {
            ConfigurationValue configurationValue = GetConfigValue(key);

            return(configurationValue?.SourceInfo);
        }
Пример #24
0
        internal bool IsInherited(string key)
        {
            ConfigurationValue value2 = (ConfigurationValue)base.BaseGet(key);

            return((value2 != null) && ((value2.ValueFlags & ConfigurationValueFlags.Inherited) != ConfigurationValueFlags.Default));
        }
 protected internal virtual void DeserializeElement(XmlReader reader, bool serializeCollectionKey)
 {
     ConfigurationPropertyCollection properties = this.Properties;
     ConfigurationValue value2 = null;
     ConfigurationValue value3 = null;
     ConfigurationValue value4 = null;
     ConfigurationValue value5 = null;
     bool flag = false;
     this._bElementPresent = true;
     ConfigurationElement element = null;
     ConfigurationProperty property = (properties != null) ? properties.DefaultCollectionProperty : null;
     if (property != null)
     {
         element = (ConfigurationElement) this[property];
     }
     this._elementTagName = reader.Name;
     PropertySourceInfo sourceInfo = new PropertySourceInfo(reader);
     this._values.SetValue(reader.Name, null, ConfigurationValueFlags.Modified, sourceInfo);
     this._values.SetValue("", element, ConfigurationValueFlags.Modified, sourceInfo);
     if (((this._lockedElementsList != null) && (this._lockedElementsList.Contains(reader.Name) || (this._lockedElementsList.Contains("*") && (reader.Name != this.ElementTagName)))) || ((((this._lockedAllExceptElementsList != null) && (this._lockedAllExceptElementsList.Count != 0)) && !this._lockedAllExceptElementsList.Contains(reader.Name)) || (((this._fItemLocked & ConfigurationValueFlags.Locked) != ConfigurationValueFlags.Default) && ((this._fItemLocked & ConfigurationValueFlags.Inherited) != ConfigurationValueFlags.Default))))
     {
         throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_base_element_locked", new object[] { reader.Name }), reader);
     }
     if (reader.AttributeCount > 0)
     {
         while (reader.MoveToNextAttribute())
         {
             string name = reader.Name;
             if ((((this._lockedAttributesList != null) && (this._lockedAttributesList.Contains(name) || this._lockedAttributesList.Contains("*"))) || ((this._lockedAllExceptAttributesList != null) && !this._lockedAllExceptAttributesList.Contains(name))) && ((name != "lockAttributes") && (name != "lockAllAttributesExcept")))
             {
                 throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_base_attribute_locked", new object[] { name }), reader);
             }
             ConfigurationProperty prop = (properties != null) ? properties[name] : null;
             if (prop != null)
             {
                 if (serializeCollectionKey && !prop.IsKey)
                 {
                     throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_base_unrecognized_attribute", new object[] { name }), reader);
                 }
                 this._values.SetValue(name, this.DeserializePropertyValue(prop, reader), ConfigurationValueFlags.Modified, new PropertySourceInfo(reader));
             }
             else
             {
                 if (name == "lockItem")
                 {
                     try
                     {
                         flag = bool.Parse(reader.Value);
                         continue;
                     }
                     catch
                     {
                         throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_invalid_boolean_attribute", new object[] { name }), reader);
                     }
                 }
                 if (name == "lockAttributes")
                 {
                     value2 = new ConfigurationValue(reader.Value, ConfigurationValueFlags.Default, new PropertySourceInfo(reader));
                 }
                 else
                 {
                     if (name == "lockAllAttributesExcept")
                     {
                         value3 = new ConfigurationValue(reader.Value, ConfigurationValueFlags.Default, new PropertySourceInfo(reader));
                         continue;
                     }
                     if (name == "lockElements")
                     {
                         value4 = new ConfigurationValue(reader.Value, ConfigurationValueFlags.Default, new PropertySourceInfo(reader));
                         continue;
                     }
                     if (name == "lockAllElementsExcept")
                     {
                         value5 = new ConfigurationValue(reader.Value, ConfigurationValueFlags.Default, new PropertySourceInfo(reader));
                         continue;
                     }
                     if (serializeCollectionKey || !this.OnDeserializeUnrecognizedAttribute(name, reader.Value))
                     {
                         throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_base_unrecognized_attribute", new object[] { name }), reader);
                     }
                 }
             }
         }
     }
     reader.MoveToElement();
     try
     {
         HybridDictionary dictionary = new HybridDictionary();
         if (!reader.IsEmptyElement)
         {
             while (reader.Read())
             {
                 if (reader.NodeType == XmlNodeType.Element)
                 {
                     string elementName = reader.Name;
                     this.CheckLockedElement(elementName, null);
                     ConfigurationProperty property3 = (properties != null) ? properties[elementName] : null;
                     if (property3 == null)
                     {
                         if (!this.OnDeserializeUnrecognizedElement(elementName, reader) && ((element == null) || !element.OnDeserializeUnrecognizedElement(elementName, reader)))
                         {
                             throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_base_unrecognized_element_name", new object[] { elementName }), reader);
                         }
                     }
                     else
                     {
                         if (!property3.IsConfigurationElementType)
                         {
                             throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_base_property_is_not_a_configuration_element", new object[] { elementName }), reader);
                         }
                         if (dictionary.Contains(elementName))
                         {
                             throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_base_element_cannot_have_multiple_child_elements", new object[] { elementName }), reader);
                         }
                         dictionary.Add(elementName, elementName);
                         ConfigurationElement elem = (ConfigurationElement) this[property3];
                         elem.DeserializeElement(reader, serializeCollectionKey);
                         ValidateElement(elem, property3.Validator, false);
                     }
                 }
                 else
                 {
                     if (reader.NodeType == XmlNodeType.EndElement)
                     {
                         break;
                     }
                     if ((reader.NodeType == XmlNodeType.CDATA) || (reader.NodeType == XmlNodeType.Text))
                     {
                         throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_base_section_invalid_content"), reader);
                     }
                 }
             }
         }
         this.EnsureRequiredProperties(serializeCollectionKey);
         ValidateElement(this, null, false);
     }
     catch (ConfigurationException exception)
     {
         if ((exception.Filename != null) && (exception.Filename.Length != 0))
         {
             throw exception;
         }
         throw new ConfigurationErrorsException(exception.Message, reader);
     }
     if (flag)
     {
         this.SetLocked();
         this._fItemLocked = ConfigurationValueFlags.Locked;
     }
     if (value2 != null)
     {
         if (this._lockedAttributesList == null)
         {
             this._lockedAttributesList = new ConfigurationLockCollection(this, ConfigurationLockCollectionType.LockedAttributes);
         }
         foreach (string str3 in this.ParseLockedAttributes(value2, ConfigurationLockCollectionType.LockedAttributes))
         {
             if (!this._lockedAttributesList.Contains(str3))
             {
                 this._lockedAttributesList.Add(str3, ConfigurationValueFlags.Default);
             }
             else
             {
                 this._lockedAttributesList.Add(str3, ConfigurationValueFlags.Modified | ConfigurationValueFlags.Inherited);
             }
         }
     }
     if (value3 != null)
     {
         ConfigurationLockCollection parentCollection = this.ParseLockedAttributes(value3, ConfigurationLockCollectionType.LockedExceptionList);
         if (this._lockedAllExceptAttributesList == null)
         {
             this._lockedAllExceptAttributesList = new ConfigurationLockCollection(this, ConfigurationLockCollectionType.LockedExceptionList, string.Empty, parentCollection);
             this._lockedAllExceptAttributesList.ClearSeedList();
         }
         StringCollection strings = this.IntersectLockCollections(this._lockedAllExceptAttributesList, parentCollection);
         this._lockedAllExceptAttributesList.ClearInternal(false);
         foreach (string str4 in strings)
         {
             this._lockedAllExceptAttributesList.Add(str4, ConfigurationValueFlags.Default);
         }
     }
     if (value4 != null)
     {
         if (this._lockedElementsList == null)
         {
             this._lockedElementsList = new ConfigurationLockCollection(this, ConfigurationLockCollectionType.LockedElements);
         }
         ConfigurationLockCollection locks2 = this.ParseLockedAttributes(value4, ConfigurationLockCollectionType.LockedElements);
         ConfigurationElementCollection elements = null;
         if (properties.DefaultCollectionProperty != null)
         {
             elements = this[properties.DefaultCollectionProperty] as ConfigurationElementCollection;
             if ((elements != null) && (elements._lockedElementsList == null))
             {
                 elements._lockedElementsList = this._lockedElementsList;
             }
         }
         foreach (string str5 in locks2)
         {
             if (!this._lockedElementsList.Contains(str5))
             {
                 this._lockedElementsList.Add(str5, ConfigurationValueFlags.Default);
                 ConfigurationProperty property4 = this.Properties[str5];
                 if ((property4 != null) && typeof(ConfigurationElement).IsAssignableFrom(property4.Type))
                 {
                     ((ConfigurationElement) this[str5]).SetLocked();
                 }
                 if (str5 == "*")
                 {
                     foreach (ConfigurationProperty property5 in this.Properties)
                     {
                         if (!string.IsNullOrEmpty(property5.Name) && property5.IsConfigurationElementType)
                         {
                             ((ConfigurationElement) this[property5]).SetLocked();
                         }
                     }
                 }
             }
         }
     }
     if (value5 != null)
     {
         ConfigurationLockCollection locks3 = this.ParseLockedAttributes(value5, ConfigurationLockCollectionType.LockedElementsExceptionList);
         if (this._lockedAllExceptElementsList == null)
         {
             this._lockedAllExceptElementsList = new ConfigurationLockCollection(this, ConfigurationLockCollectionType.LockedElementsExceptionList, this._elementTagName, locks3);
             this._lockedAllExceptElementsList.ClearSeedList();
         }
         StringCollection strings2 = this.IntersectLockCollections(this._lockedAllExceptElementsList, locks3);
         ConfigurationElementCollection elements2 = null;
         if (properties.DefaultCollectionProperty != null)
         {
             elements2 = this[properties.DefaultCollectionProperty] as ConfigurationElementCollection;
             if ((elements2 != null) && (elements2._lockedAllExceptElementsList == null))
             {
                 elements2._lockedAllExceptElementsList = this._lockedAllExceptElementsList;
             }
         }
         this._lockedAllExceptElementsList.ClearInternal(false);
         foreach (string str6 in strings2)
         {
             if (!this._lockedAllExceptElementsList.Contains(str6) || (str6 == this.ElementTagName))
             {
                 this._lockedAllExceptElementsList.Add(str6, ConfigurationValueFlags.Default);
             }
         }
         foreach (ConfigurationProperty property6 in this.Properties)
         {
             if ((!string.IsNullOrEmpty(property6.Name) && !this._lockedAllExceptElementsList.Contains(property6.Name)) && property6.IsConfigurationElementType)
             {
                 ((ConfigurationElement) this[property6]).SetLocked();
             }
         }
     }
     if (property != null)
     {
         element = (ConfigurationElement) this[property];
         if (this._lockedElementsList == null)
         {
             this._lockedElementsList = new ConfigurationLockCollection(this, ConfigurationLockCollectionType.LockedElements);
         }
         element._lockedElementsList = this._lockedElementsList;
         if (this._lockedAllExceptElementsList == null)
         {
             this._lockedAllExceptElementsList = new ConfigurationLockCollection(this, ConfigurationLockCollectionType.LockedElementsExceptionList, reader.Name);
             this._lockedAllExceptElementsList.ClearSeedList();
         }
         element._lockedAllExceptElementsList = this._lockedAllExceptElementsList;
     }
     this.PostDeserialize();
 }
        private ConfigurationValue CreateConfigValue(object value, ConfigurationValueFlags valueFlags, PropertySourceInfo sourceInfo) {
            if (value != null) {
                if (value is ConfigurationElement) {
                    _containsElement = true;
                    ((ConfigurationElement)value).AssociateContext(_configRecord);
                }
                else if (value is InvalidPropValue) {
                    _containsInvalidValue = true;
                }
            }

            ConfigurationValue configValue = new ConfigurationValue(value, valueFlags, sourceInfo);
            return configValue;
        }
 internal void ReportInvalidLock(string attribToLockTrim, ConfigurationLockCollectionType lockedType, ConfigurationValue value, string collectionProperties)
 {
     StringBuilder builder = new StringBuilder();
     if (!string.IsNullOrEmpty(collectionProperties) && ((lockedType == ConfigurationLockCollectionType.LockedElements) || (lockedType == ConfigurationLockCollectionType.LockedElementsExceptionList)))
     {
         if (builder.Length != 0)
         {
             builder.Append(',');
         }
         builder.Append(collectionProperties);
     }
     foreach (object obj2 in this.Properties)
     {
         ConfigurationProperty property = (ConfigurationProperty) obj2;
         if (((property.Name != "lockAttributes") && (property.Name != "lockAllAttributesExcept")) && ((property.Name != "lockElements") && (property.Name != "lockAllElementsExcept")))
         {
             if ((lockedType == ConfigurationLockCollectionType.LockedElements) || (lockedType == ConfigurationLockCollectionType.LockedElementsExceptionList))
             {
                 if (typeof(ConfigurationElement).IsAssignableFrom(property.Type))
                 {
                     if (builder.Length != 0)
                     {
                         builder.Append(", ");
                     }
                     builder.Append("'");
                     builder.Append(property.Name);
                     builder.Append("'");
                 }
             }
             else if (!typeof(ConfigurationElement).IsAssignableFrom(property.Type))
             {
                 if (builder.Length != 0)
                 {
                     builder.Append(", ");
                 }
                 builder.Append("'");
                 builder.Append(property.Name);
                 builder.Append("'");
             }
         }
     }
     string format = null;
     if ((lockedType == ConfigurationLockCollectionType.LockedElements) || (lockedType == ConfigurationLockCollectionType.LockedElementsExceptionList))
     {
         if (value != null)
         {
             format = System.Configuration.SR.GetString("Config_base_invalid_element_to_lock");
         }
         else
         {
             format = System.Configuration.SR.GetString("Config_base_invalid_element_to_lock_by_add");
         }
     }
     else if (value != null)
     {
         format = System.Configuration.SR.GetString("Config_base_invalid_attribute_to_lock");
     }
     else
     {
         format = System.Configuration.SR.GetString("Config_base_invalid_attribute_to_lock_by_add");
     }
     if (value != null)
     {
         throw new ConfigurationErrorsException(string.Format(CultureInfo.CurrentCulture, format, new object[] { attribToLockTrim, builder.ToString() }), value.SourceInfo.FileName, value.SourceInfo.LineNumber);
     }
     throw new ConfigurationErrorsException(string.Format(CultureInfo.CurrentCulture, format, new object[] { attribToLockTrim, builder.ToString() }));
 }
Пример #28
0
        private void SetValue(int index, object value, ConfigurationValueFlags valueFlags, PropertySourceInfo sourceInfo)
        {
            ConfigurationValue configValue = CreateConfigValue(value, valueFlags, sourceInfo);

            BaseSet(index, configValue);
        }