internal void SetValue(string key, object value, ConfigurationValueFlags valueFlags,
                               PropertySourceInfo sourceInfo)
        {
            ConfigurationValue configValue = CreateConfigValue(value, valueFlags, sourceInfo);

            BaseSet(key, configValue);
        }
Beispiel #2
0
        public void Remove(string name)
        {
            if (!_internalDictionary.Contains(name))
            {
                throw new ConfigurationErrorsException(SR.Format(SR.Config_base_collection_entry_not_found, name));
            }

            // in a locked list you cannot remove items that were locked in the parent
            // in an exception list this is legal because it makes the list more restrictive
            if ((ExceptionList == false) &&
                (((ConfigurationValueFlags)_internalDictionary[name] & ConfigurationValueFlags.Inherited) != 0))
            {
                if (((ConfigurationValueFlags)_internalDictionary[name] & ConfigurationValueFlags.Modified) == 0)
                {
                    throw new ConfigurationErrorsException(SR.Format(SR.Config_base_attribute_locked, name));
                }

                // allow the local one to be "removed" so it won't write out but throw if they try and remove
                // one that is only inherited
                ConfigurationValueFlags flags = (ConfigurationValueFlags)_internalDictionary[name];
                flags &= ~ConfigurationValueFlags.Modified;
                _internalDictionary[name] = flags;
                IsModified = true;
                return;
            }

            _internalDictionary.Remove(name);
            _internalArraylist.Remove(name);
            IsModified = true;
        }
Beispiel #3
0
        public void Add(string name)
        {
            if (((this._thisElement.ItemLocked & ConfigurationValueFlags.Locked) != ConfigurationValueFlags.Default) && ((this._thisElement.ItemLocked & ConfigurationValueFlags.Inherited) != ConfigurationValueFlags.Default))
            {
                throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_base_attribute_locked", new object[] { name }));
            }
            ConfigurationValueFlags modified = ConfigurationValueFlags.Modified;
            string attribToLockTrim          = name.Trim();
            ConfigurationProperty property   = this._thisElement.Properties[attribToLockTrim];

            if ((property == null) && (attribToLockTrim != "*"))
            {
                ConfigurationElementCollection elements = this._thisElement as ConfigurationElementCollection;
                if ((elements == null) && (this._thisElement.Properties.DefaultCollectionProperty != null))
                {
                    elements = this._thisElement[this._thisElement.Properties.DefaultCollectionProperty] as ConfigurationElementCollection;
                }
                if (((elements == null) || (this._lockType == ConfigurationLockCollectionType.LockedAttributes)) || (this._lockType == ConfigurationLockCollectionType.LockedExceptionList))
                {
                    this._thisElement.ReportInvalidLock(attribToLockTrim, this._lockType, null, null);
                }
                else if (!elements.IsLockableElement(attribToLockTrim))
                {
                    this._thisElement.ReportInvalidLock(attribToLockTrim, this._lockType, null, elements.LockableElements);
                }
            }
            else
            {
                if ((property != null) && property.IsRequired)
                {
                    throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_base_required_attribute_lock_attempt", new object[] { property.Name }));
                }
                if (attribToLockTrim != "*")
                {
                    if ((this._lockType == ConfigurationLockCollectionType.LockedElements) || (this._lockType == ConfigurationLockCollectionType.LockedElementsExceptionList))
                    {
                        if (!typeof(ConfigurationElement).IsAssignableFrom(property.Type))
                        {
                            this._thisElement.ReportInvalidLock(attribToLockTrim, this._lockType, null, null);
                        }
                    }
                    else if (typeof(ConfigurationElement).IsAssignableFrom(property.Type))
                    {
                        this._thisElement.ReportInvalidLock(attribToLockTrim, this._lockType, null, null);
                    }
                }
            }
            if (this.internalDictionary.Contains(name))
            {
                modified = ConfigurationValueFlags.Modified | ((ConfigurationValueFlags)this.internalDictionary[name]);
                this.internalDictionary.Remove(name);
                this.internalArraylist.Remove(name);
            }
            this.internalDictionary.Add(name, modified);
            this.internalArraylist.Add(name);
            this._bModified = true;
        }
Beispiel #4
0
 internal void Add(string name, ConfigurationValueFlags flags)
 {
     if ((flags != ConfigurationValueFlags.Inherited) && this.internalDictionary.Contains(name))
     {
         flags = ConfigurationValueFlags.Modified | ((ConfigurationValueFlags)this.internalDictionary[name]);
         this.internalDictionary.Remove(name);
         this.internalArraylist.Remove(name);
     }
     this.internalDictionary.Add(name, flags);
     this.internalArraylist.Add(name);
 }
Beispiel #5
0
        internal void Add(string name, ConfigurationValueFlags flags)
        {
            if ((flags != ConfigurationValueFlags.Inherited) && _internalDictionary.Contains(name))
            {
                // the user has an item declared as locked below a level where it is already locked
                // keep enough info so we can write out the lock if they save in modified mode
                flags = ConfigurationValueFlags.Modified | (ConfigurationValueFlags)_internalDictionary[name];
                _internalDictionary.Remove(name);
                _internalArraylist.Remove(name);
            }

            _internalDictionary.Add(name, flags); // not from parent
            _internalArraylist.Add(name);
        }
        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;
        }
Beispiel #7
0
 private ConfigurationValue CreateConfigValue(object value, ConfigurationValueFlags valueFlags, PropertySourceInfo sourceInfo)
 {
     if (value != null)
     {
         if (value is ConfigurationElement)
         {
             this._containsElement = true;
             ((ConfigurationElement)value).AssociateContext(this._configRecord);
         }
         else if (value is InvalidPropValue)
         {
             this._containsInvalidValue = true;
         }
     }
     return(new ConfigurationValue(value, valueFlags, sourceInfo));
 }
Beispiel #8
0
 public void Remove(string name)
 {
     if (!this.internalDictionary.Contains(name))
     {
         throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_base_collection_entry_not_found", new object[] { name }));
     }
     if (!this._bExceptionList && ((((ConfigurationValueFlags)this.internalDictionary[name]) & ConfigurationValueFlags.Inherited) != ConfigurationValueFlags.Default))
     {
         if ((((ConfigurationValueFlags)this.internalDictionary[name]) & ConfigurationValueFlags.Modified) == ConfigurationValueFlags.Default)
         {
             throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_base_attribute_locked", new object[] { name }));
         }
         ConfigurationValueFlags flags = (ConfigurationValueFlags)this.internalDictionary[name];
         flags &= ~ConfigurationValueFlags.Modified;
         this.internalDictionary[name] = flags;
         this._bModified = true;
     }
     else
     {
         this.internalDictionary.Remove(name);
         this.internalArraylist.Remove(name);
         this._bModified = true;
     }
 }
Beispiel #9
0
 internal void SetLocked()
 {
     this._fItemLocked = ConfigurationValueFlags.Locked | ConfigurationValueFlags.XMLParentInherited;
       foreach (ConfigurationProperty index in this.Properties)
       {
     ConfigurationElement configurationElement1 = this[index] as ConfigurationElement;
     if (configurationElement1 != null)
     {
       if (configurationElement1.GetType() != this.GetType())
     configurationElement1.SetLocked();
       ConfigurationElementCollection elementCollection = this[index] as ConfigurationElementCollection;
       if (elementCollection != null)
       {
     foreach (object obj in elementCollection)
     {
       ConfigurationElement configurationElement2 = obj as ConfigurationElement;
       if (configurationElement2 != null)
         configurationElement2.SetLocked();
     }
       }
     }
       }
 }
Beispiel #10
0
        public void Add(string name)
        {
            if (((_thisElement.ItemLocked & ConfigurationValueFlags.Locked) != 0) &&
                ((_thisElement.ItemLocked & ConfigurationValueFlags.Inherited) != 0))
            {
                throw new ConfigurationErrorsException(SR.Format(SR.Config_base_attribute_locked, name));
            }

            ConfigurationValueFlags flags = ConfigurationValueFlags.Modified;

            string attribToLockTrim          = name.Trim();
            ConfigurationProperty propToLock = _thisElement.Properties[attribToLockTrim];

            if ((propToLock == null) && (attribToLockTrim != LockAll))
            {
                ConfigurationElementCollection collection = _thisElement as ConfigurationElementCollection;
                if ((collection == null) && (_thisElement.Properties.DefaultCollectionProperty != null))
                {
                    // this is not a collection but it may contain a default collection
                    collection =
                        _thisElement[_thisElement.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))
                {
                    _thisElement.ReportInvalidLock(attribToLockTrim, LockType, null, null);
                }
                else
                {
                    if (!collection.IsLockableElement(attribToLockTrim))
                    {
                        _thisElement.ReportInvalidLock(attribToLockTrim, LockType, null, collection.LockableElements);
                    }
                }
            }
            else
            {
                // the lock is in the property bag but is it the correct type?
                if ((propToLock != null) && propToLock.IsRequired)
                {
                    throw new ConfigurationErrorsException(SR.Format(SR.Config_base_required_attribute_lock_attempt,
                                                                     propToLock.Name));
                }

                if (attribToLockTrim != LockAll)
                {
                    if ((LockType == ConfigurationLockCollectionType.LockedElements) ||
                        (LockType == ConfigurationLockCollectionType.LockedElementsExceptionList))
                    {
                        // If it is an element then it must be derived from ConfigurationElement
                        if (!typeof(ConfigurationElement).IsAssignableFrom(propToLock?.Type))
                        {
                            _thisElement.ReportInvalidLock(attribToLockTrim, LockType, null, null);
                        }
                    }
                    else
                    {
                        // if it is a property then it cannot be derived from ConfigurationElement
                        if (typeof(ConfigurationElement).IsAssignableFrom(propToLock?.Type))
                        {
                            _thisElement.ReportInvalidLock(attribToLockTrim, LockType, null, null);
                        }
                    }
                }
            }

            if (_internalDictionary.Contains(name))
            {
                flags = ConfigurationValueFlags.Modified | (ConfigurationValueFlags)_internalDictionary[name];
                _internalDictionary.Remove(name); // not from parent
                _internalArraylist.Remove(name);
            }
            _internalDictionary.Add(name, flags); // not from parent
            _internalArraylist.Add(name);
            IsModified = true;
        }
Beispiel #11
0
 internal ConfigurationValue(object value, ConfigurationValueFlags valueFlags, PropertySourceInfo sourceInfo)
 {
     Value      = value;
     ValueFlags = valueFlags;
     SourceInfo = sourceInfo;
 }
 internal ConfigurationValue(object value, ConfigurationValueFlags valueFlags, PropertySourceInfo sourceInfo) {
     Value = value;
     ValueFlags = valueFlags;
     SourceInfo = sourceInfo;
 }
Beispiel #13
0
        private void SetValue(int index, object value, ConfigurationValueFlags valueFlags, PropertySourceInfo sourceInfo)
        {
            ConfigurationValue configValue = CreateConfigValue(value, valueFlags, sourceInfo);

            BaseSet(index, configValue);
        }
 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();
 }
Beispiel #15
0
 internal void MergeLocks(ConfigurationElement source)
 {
     if (source == null)
     return;
       this._fItemLocked = (source._fItemLocked & ConfigurationValueFlags.Locked) != ConfigurationValueFlags.Default ? ConfigurationValueFlags.Inherited | source._fItemLocked : this._fItemLocked;
       if (source._lockedAttributesList != null)
       {
     if (this._lockedAttributesList == null)
       this._lockedAttributesList = new ConfigurationLockCollection(this, ConfigurationLockCollectionType.LockedAttributes);
     foreach (string name in source._lockedAttributesList)
       this._lockedAttributesList.Add(name, ConfigurationValueFlags.Inherited);
       }
       if (source._lockedAllExceptAttributesList != null)
       {
     if (this._lockedAllExceptAttributesList == null)
       this._lockedAllExceptAttributesList = new ConfigurationLockCollection(this, ConfigurationLockCollectionType.LockedExceptionList, string.Empty, source._lockedAllExceptAttributesList);
     StringCollection stringCollection = this.IntersectLockCollections(this._lockedAllExceptAttributesList, source._lockedAllExceptAttributesList);
     this._lockedAllExceptAttributesList.ClearInternal(false);
     foreach (string name in stringCollection)
       this._lockedAllExceptAttributesList.Add(name, ConfigurationValueFlags.Default);
       }
       if (source._lockedElementsList != null)
       {
     if (this._lockedElementsList == null)
       this._lockedElementsList = new ConfigurationLockCollection(this, ConfigurationLockCollectionType.LockedElements);
     ConfigurationElementCollection elementCollection = (ConfigurationElementCollection) null;
     if (this.Properties.DefaultCollectionProperty != null)
     {
       elementCollection = this[this.Properties.DefaultCollectionProperty] as ConfigurationElementCollection;
       if (elementCollection != null)
       {
     elementCollection.internalElementTagName = source.ElementTagName;
     if (elementCollection._lockedElementsList == null)
       elementCollection._lockedElementsList = this._lockedElementsList;
       }
     }
     foreach (string name in source._lockedElementsList)
     {
       this._lockedElementsList.Add(name, ConfigurationValueFlags.Inherited);
       if (elementCollection != null)
     elementCollection._lockedElementsList.Add(name, ConfigurationValueFlags.Inherited);
     }
       }
       if (source._lockedAllExceptElementsList == null)
     return;
       if (this._lockedAllExceptElementsList == null || this._lockedAllExceptElementsList.Count == 0)
     this._lockedAllExceptElementsList = new ConfigurationLockCollection(this, ConfigurationLockCollectionType.LockedElementsExceptionList, source._elementTagName, source._lockedAllExceptElementsList);
       StringCollection stringCollection1 = this.IntersectLockCollections(this._lockedAllExceptElementsList, source._lockedAllExceptElementsList);
       if (this.Properties.DefaultCollectionProperty != null)
       {
     ConfigurationElementCollection elementCollection = this[this.Properties.DefaultCollectionProperty] as ConfigurationElementCollection;
     if (elementCollection != null && elementCollection._lockedAllExceptElementsList == null)
       elementCollection._lockedAllExceptElementsList = this._lockedAllExceptElementsList;
       }
       this._lockedAllExceptElementsList.ClearInternal(false);
       foreach (string name in stringCollection1)
       {
     if (!this._lockedAllExceptElementsList.Contains(name) || name == this.ElementTagName)
       this._lockedAllExceptElementsList.Add(name, ConfigurationValueFlags.Default);
       }
       if (!this._lockedAllExceptElementsList.HasParentElements)
     return;
       foreach (ConfigurationProperty index in this.Properties)
       {
     if (!this._lockedAllExceptElementsList.Contains(index.Name) && index.IsConfigurationElementType)
       ((ConfigurationElement) this[index]).SetLocked();
       }
 }
Beispiel #16
0
 /// <summary>
 /// Modifies the <see cref="T:System.Configuration.ConfigurationElement"/> object to remove all values that should not be saved.
 /// </summary>
 /// <param name="sourceElement">A <see cref="T:System.Configuration.ConfigurationElement"/> at the current level containing a merged view of the properties.</param><param name="parentElement">The parent <see cref="T:System.Configuration.ConfigurationElement"/>, or null if this is the top level.</param><param name="saveMode">A <see cref="T:System.Configuration.ConfigurationSaveMode"/> that determines which property values to include.</param>
 protected internal virtual void Unmerge(ConfigurationElement sourceElement, ConfigurationElement parentElement, ConfigurationSaveMode saveMode)
 {
     if (sourceElement == null)
     return;
       bool flag1 = false;
       this._lockedAllExceptAttributesList = sourceElement._lockedAllExceptAttributesList;
       this._lockedAllExceptElementsList = sourceElement._lockedAllExceptElementsList;
       this._fItemLocked = sourceElement._fItemLocked;
       this._lockedAttributesList = sourceElement._lockedAttributesList;
       this._lockedElementsList = sourceElement._lockedElementsList;
       this.AssociateContext(sourceElement._configRecord);
       if (parentElement != null)
       {
     if (parentElement._lockedAttributesList != null)
       this._lockedAttributesList = this.UnMergeLockList(sourceElement._lockedAttributesList, parentElement._lockedAttributesList, saveMode);
     if (parentElement._lockedElementsList != null)
       this._lockedElementsList = this.UnMergeLockList(sourceElement._lockedElementsList, parentElement._lockedElementsList, saveMode);
     if (parentElement._lockedAllExceptAttributesList != null)
       this._lockedAllExceptAttributesList = this.UnMergeLockList(sourceElement._lockedAllExceptAttributesList, parentElement._lockedAllExceptAttributesList, saveMode);
     if (parentElement._lockedAllExceptElementsList != null)
       this._lockedAllExceptElementsList = this.UnMergeLockList(sourceElement._lockedAllExceptElementsList, parentElement._lockedAllExceptElementsList, saveMode);
       }
       ConfigurationPropertyCollection properties = this.Properties;
       ConfigurationPropertyCollection propertyCollection = (ConfigurationPropertyCollection) null;
       for (int index = 0; index < sourceElement.Values.Count; ++index)
       {
     string key = sourceElement.Values.GetKey(index);
     object obj = sourceElement.Values[index];
     ConfigurationProperty property = sourceElement.Properties[key];
     if (property != null && (propertyCollection == null || propertyCollection.Contains(property.Name)))
     {
       if (property.IsConfigurationElementType)
     flag1 = true;
       else if (obj != ConfigurationElement.s_nullPropertyValue && !properties.Contains(key))
       {
     ConfigurationValueFlags valueFlags = sourceElement.Values.RetrieveFlags(key);
     this._values.SetValue(key, obj, valueFlags, (PropertySourceInfo) null);
     properties.Add(property);
       }
     }
       }
       foreach (ConfigurationProperty configurationProperty in this.Properties)
       {
     if (configurationProperty != null && (propertyCollection == null || propertyCollection.Contains(configurationProperty.Name)))
     {
       if (configurationProperty.IsConfigurationElementType)
       {
     flag1 = true;
       }
       else
       {
     object objA = sourceElement.Values[configurationProperty.Name];
     if ((configurationProperty.IsRequired || saveMode == ConfigurationSaveMode.Full) && (objA == null || objA == ConfigurationElement.s_nullPropertyValue) && configurationProperty.DefaultValue != null)
       objA = configurationProperty.DefaultValue;
     if (objA != null && objA != ConfigurationElement.s_nullPropertyValue)
     {
       object objB = (object) null;
       if (parentElement != null)
         objB = parentElement.Values[configurationProperty.Name];
       if (objB == null)
         objB = configurationProperty.DefaultValue;
       switch (saveMode)
       {
         case ConfigurationSaveMode.Modified:
           bool flag2 = sourceElement.Values.IsModified(configurationProperty.Name);
           bool flag3 = sourceElement.Values.IsInherited(configurationProperty.Name);
           if (configurationProperty.IsRequired || flag2 || !flag3 || parentElement == null && flag3 && !object.Equals(objA, objB))
           {
             this._values[configurationProperty.Name] = objA;
             continue;
           }
           else
             continue;
         case ConfigurationSaveMode.Minimal:
           if (!object.Equals(objA, objB) || configurationProperty.IsRequired)
           {
             this._values[configurationProperty.Name] = objA;
             continue;
           }
           else
             continue;
         case ConfigurationSaveMode.Full:
           this._values[configurationProperty.Name] = objA == null || objA == ConfigurationElement.s_nullPropertyValue ? objB : objA;
           continue;
         default:
           continue;
       }
     }
       }
     }
       }
       if (!flag1)
     return;
       foreach (ConfigurationProperty index in this.Properties)
       {
     if (index.IsConfigurationElementType)
     {
       ConfigurationElement parentElement1 = parentElement != null ? (ConfigurationElement) parentElement[index] : (ConfigurationElement) (object) null;
       ConfigurationElement configurationElement = (ConfigurationElement) this[index];
       if ((ConfigurationElement) sourceElement[index] != null)
     configurationElement.Unmerge((ConfigurationElement) sourceElement[index], parentElement1, saveMode);
     }
       }
 }
        internal void ResetLockLists(ConfigurationElement parentElement) {
            _lockedAttributesList = null;
            _lockedAllExceptAttributesList = null;
            _lockedElementsList = null;
            _lockedAllExceptElementsList = null;

            if (parentElement != null) {
                _fItemLocked = ((parentElement._fItemLocked & ConfigurationValueFlags.Locked) != 0) ?
                    (ConfigurationValueFlags.Inherited | parentElement._fItemLocked) :
                    ConfigurationValueFlags.Default;

                if (parentElement._lockedAttributesList != null) {
                    _lockedAttributesList = new ConfigurationLockCollection(this, ConfigurationLockCollectionType.LockedAttributes);
                    foreach (string key in parentElement._lockedAttributesList)
                        _lockedAttributesList.Add(key, ConfigurationValueFlags.Inherited);  // Mark entry as from the parent - read only
                }
                if (parentElement._lockedAllExceptAttributesList != null) {
                    _lockedAllExceptAttributesList = new ConfigurationLockCollection(this, ConfigurationLockCollectionType.LockedExceptionList, String.Empty, parentElement._lockedAllExceptAttributesList);
                }
                if (parentElement._lockedElementsList != null) {
                    _lockedElementsList = new ConfigurationLockCollection(this, ConfigurationLockCollectionType.LockedElements);

                    ConfigurationElementCollection collection = null;
                    if (Properties.DefaultCollectionProperty != null) // this is not a collection but it may contain a default collection
                    {
                        collection = this[Properties.DefaultCollectionProperty] as ConfigurationElementCollection;
                        if (collection != null) {
                            collection.internalElementTagName = parentElement.ElementTagName; // Default collections don't know there tag name
                            if (collection._lockedElementsList == null) {
                                collection._lockedElementsList = _lockedElementsList;
                            }
                        }
                    }

                    foreach (string key in parentElement._lockedElementsList) {
                        _lockedElementsList.Add(key, ConfigurationValueFlags.Inherited);  // Mark entry as from the parent - read only
                    }
                }

                if (parentElement._lockedAllExceptElementsList != null) {
                    _lockedAllExceptElementsList = new ConfigurationLockCollection(this, ConfigurationLockCollectionType.LockedElementsExceptionList, parentElement._elementTagName, parentElement._lockedAllExceptElementsList);

                    ConfigurationElementCollection collection = null;
                    if (Properties.DefaultCollectionProperty != null) // this is not a collection but it may contain a default collection
                    {
                        collection = this[Properties.DefaultCollectionProperty] as ConfigurationElementCollection;
                        if (collection != null && collection._lockedAllExceptElementsList == null) {
                            collection._lockedAllExceptElementsList = _lockedAllExceptElementsList;
                        }
                    }
                }
            }
        }
        internal void MergeLocks(ConfigurationElement source) {
            if (source != null) {
                _fItemLocked = ((source._fItemLocked & ConfigurationValueFlags.Locked) != 0) ?
                    (ConfigurationValueFlags.Inherited | source._fItemLocked) : _fItemLocked;

                if (source._lockedAttributesList != null) {
                    if (_lockedAttributesList == null) {
                        _lockedAttributesList = new ConfigurationLockCollection(this, ConfigurationLockCollectionType.LockedAttributes);
                    }
                    foreach (string key in source._lockedAttributesList)
                        _lockedAttributesList.Add(key, ConfigurationValueFlags.Inherited);  // Mark entry as from the parent - read only
                }
                if (source._lockedAllExceptAttributesList != null) {
                    if (_lockedAllExceptAttributesList == null) {
                        _lockedAllExceptAttributesList = new ConfigurationLockCollection(this, ConfigurationLockCollectionType.LockedExceptionList, String.Empty, source._lockedAllExceptAttributesList);
                    }

                    StringCollection intersectionCollection = IntersectLockCollections(_lockedAllExceptAttributesList, source._lockedAllExceptAttributesList);

                    _lockedAllExceptAttributesList.ClearInternal(false);
                    foreach (string key in intersectionCollection) {
                        _lockedAllExceptAttributesList.Add(key, ConfigurationValueFlags.Default);
                    }

                }
                if (source._lockedElementsList != null) {
                    if (_lockedElementsList == null) {
                        _lockedElementsList = new ConfigurationLockCollection(this, ConfigurationLockCollectionType.LockedElements);
                    }

                    ConfigurationElementCollection collection = null;
                    if (Properties.DefaultCollectionProperty != null) // this is not a collection but it may contain a default collection
                {
                        collection = this[Properties.DefaultCollectionProperty] as ConfigurationElementCollection;
                        if (collection != null) {
                            collection.internalElementTagName = source.ElementTagName; // Default collections don't know there tag name
                            if (collection._lockedElementsList == null) {
                                collection._lockedElementsList = _lockedElementsList; //point to the same instance of the collection from parent
                            }
                        }
                    }

                    foreach (string key in source._lockedElementsList) {
                        _lockedElementsList.Add(key, ConfigurationValueFlags.Inherited);  // Mark entry as from the parent - read only
                        if (collection != null) {
                            collection._lockedElementsList.Add(key, ConfigurationValueFlags.Inherited);  // add the local copy
                        }
                    }
                }

                if (source._lockedAllExceptElementsList != null) {
                    if (_lockedAllExceptElementsList == null || _lockedAllExceptElementsList.Count == 0) {
                        _lockedAllExceptElementsList = new ConfigurationLockCollection(this, ConfigurationLockCollectionType.LockedElementsExceptionList, source._elementTagName, source._lockedAllExceptElementsList);
                    }
                    StringCollection intersectionCollection = IntersectLockCollections(_lockedAllExceptElementsList, source._lockedAllExceptElementsList);

                    ConfigurationElementCollection collection = null;
                    if (Properties.DefaultCollectionProperty != null) { // this is not a collection but it may contain a default collection
                        collection = this[Properties.DefaultCollectionProperty] as ConfigurationElementCollection;
                        if (collection != null && collection._lockedAllExceptElementsList == null) {
                            // point default collection to the parent collection
                            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
                    }
                    if (_lockedAllExceptElementsList.HasParentElements) {
                        foreach (ConfigurationProperty prop in Properties) {
                            if ((!_lockedAllExceptElementsList.Contains(prop.Name)) &&
                                typeof(ConfigurationElement).IsAssignableFrom(prop.Type)) {
                                ((ConfigurationElement)this[prop]).SetLocked();
                            }
                        }
                    }
                }
            }
        }
Beispiel #19
0
        internal void SetValue(string key, object value, ConfigurationValueFlags valueFlags, PropertySourceInfo sourceInfo)
        {
            ConfigurationValue value2 = this.CreateConfigValue(value, valueFlags, sourceInfo);

            base.BaseSet(key, value2);
        }
Beispiel #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();
       }
 }
Beispiel #21
0
 internal void ResetLockLists(ConfigurationElement parentElement)
 {
     this._lockedAttributesList = (ConfigurationLockCollection) null;
       this._lockedAllExceptAttributesList = (ConfigurationLockCollection) null;
       this._lockedElementsList = (ConfigurationLockCollection) null;
       this._lockedAllExceptElementsList = (ConfigurationLockCollection) null;
       if (parentElement == null)
     return;
       this._fItemLocked = (parentElement._fItemLocked & ConfigurationValueFlags.Locked) != ConfigurationValueFlags.Default ? ConfigurationValueFlags.Inherited | parentElement._fItemLocked : ConfigurationValueFlags.Default;
       if (parentElement._lockedAttributesList != null)
       {
     this._lockedAttributesList = new ConfigurationLockCollection(this, ConfigurationLockCollectionType.LockedAttributes);
     foreach (string name in parentElement._lockedAttributesList)
       this._lockedAttributesList.Add(name, ConfigurationValueFlags.Inherited);
       }
       if (parentElement._lockedAllExceptAttributesList != null)
     this._lockedAllExceptAttributesList = new ConfigurationLockCollection(this, ConfigurationLockCollectionType.LockedExceptionList, string.Empty, parentElement._lockedAllExceptAttributesList);
       if (parentElement._lockedElementsList != null)
       {
     this._lockedElementsList = new ConfigurationLockCollection(this, ConfigurationLockCollectionType.LockedElements);
     if (this.Properties.DefaultCollectionProperty != null)
     {
       ConfigurationElementCollection elementCollection = this[this.Properties.DefaultCollectionProperty] as ConfigurationElementCollection;
       if (elementCollection != null)
       {
     elementCollection.internalElementTagName = parentElement.ElementTagName;
     if (elementCollection._lockedElementsList == null)
       elementCollection._lockedElementsList = this._lockedElementsList;
       }
     }
     foreach (string name in parentElement._lockedElementsList)
       this._lockedElementsList.Add(name, ConfigurationValueFlags.Inherited);
       }
       if (parentElement._lockedAllExceptElementsList == null)
     return;
       this._lockedAllExceptElementsList = new ConfigurationLockCollection(this, ConfigurationLockCollectionType.LockedElementsExceptionList, parentElement._elementTagName, parentElement._lockedAllExceptElementsList);
       if (this.Properties.DefaultCollectionProperty == null)
     return;
       ConfigurationElementCollection elementCollection1 = this[this.Properties.DefaultCollectionProperty] as ConfigurationElementCollection;
       if (elementCollection1 == null || elementCollection1._lockedAllExceptElementsList != null)
     return;
       elementCollection1._lockedAllExceptElementsList = this._lockedAllExceptElementsList;
 }
 internal void SetLocked()
 {
     this._fItemLocked = ConfigurationValueFlags.XMLParentInherited | ConfigurationValueFlags.Locked;
     foreach (ConfigurationProperty property in this.Properties)
     {
         ConfigurationElement element = this[property] as ConfigurationElement;
         if (element != null)
         {
             if (element.GetType() != base.GetType())
             {
                 element.SetLocked();
             }
             ConfigurationElementCollection elements = this[property] as ConfigurationElementCollection;
             if (elements != null)
             {
                 foreach (object obj2 in elements)
                 {
                     ConfigurationElement element2 = obj2 as ConfigurationElement;
                     if (element2 != null)
                     {
                         element2.SetLocked();
                     }
                 }
             }
         }
     }
 }
        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();
        }
 internal void SetValue(string key, object value, ConfigurationValueFlags valueFlags, PropertySourceInfo sourceInfo)
 {
     ConfigurationValue value2 = this.CreateConfigValue(value, valueFlags, sourceInfo);
     base.BaseSet(key, value2);
 }
        internal void SetLocked() {
            _fItemLocked = ConfigurationValueFlags.Locked | ConfigurationValueFlags.XMLParentInherited;

            foreach (ConfigurationProperty prop in Properties) {
                ConfigurationElement elem = this[prop] as ConfigurationElement;
                if (elem != null) {
                    if (elem.GetType() != this.GetType()) {
                        elem.SetLocked();
                    }

                    ConfigurationElementCollection collection = this[prop] as ConfigurationElementCollection;
                    if (collection != null) {
                        foreach (object obj in collection) {
                            ConfigurationElement element = obj as ConfigurationElement;
                            if (element != null) {
                                element.SetLocked();
                            }
                        }
                    }
                }
            }
        }
Beispiel #26
0
        internal void MergeLocks(ConfigurationElement source)
        {
            if (source == null) return;

            _fItemLocked = (source._fItemLocked & ConfigurationValueFlags.Locked) != 0
                ? ConfigurationValueFlags.Inherited | source._fItemLocked
                : _fItemLocked;

            if (source._lockedAttributesList != null)
            {
                // Mark entry as from the parent - read only
                if (_lockedAttributesList == null)
                {
                    _lockedAttributesList = new ConfigurationLockCollection(this,
                        ConfigurationLockCollectionType.LockedAttributes);
                }

                foreach (string key in source._lockedAttributesList)
                    _lockedAttributesList.Add(key, ConfigurationValueFlags.Inherited);
            }

            if (source._lockedAllExceptAttributesList != null)
            {
                if (_lockedAllExceptAttributesList == null)
                {
                    _lockedAllExceptAttributesList = new ConfigurationLockCollection(this,
                        ConfigurationLockCollectionType.LockedExceptionList, string.Empty,
                        source._lockedAllExceptAttributesList);
                }

                StringCollection intersectionCollection = IntersectLockCollections(_lockedAllExceptAttributesList,
                    source._lockedAllExceptAttributesList);

                _lockedAllExceptAttributesList.ClearInternal(false);
                foreach (string key in intersectionCollection)
                    _lockedAllExceptAttributesList.Add(key, ConfigurationValueFlags.Default);
            }

            if (source._lockedElementsList != null)
            {
                if (_lockedElementsList == null)
                {
                    _lockedElementsList = new ConfigurationLockCollection(this,
                        ConfigurationLockCollectionType.LockedElements);
                }

                ConfigurationElementCollection collection = null;
                if (Properties.DefaultCollectionProperty != null)
                {
                    // this is not a collection but it may contain a default collection
                    collection = this[Properties.DefaultCollectionProperty] as ConfigurationElementCollection;
                    if (collection != null)
                    {
                        // Default collections don't know their tag name
                        collection.InternalElementTagName = source.ElementTagName;
                        //point to the same instance of the collection from parent
                        if (collection._lockedElementsList == null)
                            collection._lockedElementsList = _lockedElementsList;
                    }
                }

                foreach (string key in source._lockedElementsList)
                {
                    // Mark entry as from the parent - read only
                    _lockedElementsList.Add(key, ConfigurationValueFlags.Inherited);
                    // add the local copy
                    collection?._lockedElementsList.Add(key, ConfigurationValueFlags.Inherited);
                }
            }

            if (source._lockedAllExceptElementsList != null)
            {
                if ((_lockedAllExceptElementsList == null) || (_lockedAllExceptElementsList.Count == 0))
                {
                    _lockedAllExceptElementsList = new ConfigurationLockCollection(this,
                        ConfigurationLockCollectionType.LockedElementsExceptionList, source.ElementTagName,
                        source._lockedAllExceptElementsList);
                }

                StringCollection intersectionCollection = IntersectLockCollections(_lockedAllExceptElementsList,
                    source._lockedAllExceptElementsList);

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

                _lockedAllExceptElementsList.ClearInternal(false);
                foreach (string key in intersectionCollection)
                    if (!_lockedAllExceptElementsList.Contains(key) || (key == ElementTagName))
                        _lockedAllExceptElementsList.Add(key, ConfigurationValueFlags.Default);

                if (_lockedAllExceptElementsList.HasParentElements)
                {
                    // add the local copy
                    foreach (ConfigurationProperty prop in Properties)
                        if (!_lockedAllExceptElementsList.Contains(prop.Name) &&
                                prop.IsConfigurationElementType)
                            ((ConfigurationElement)this[prop]).SetLocked();
                }
            }
        }
        protected internal virtual void Unmerge(ConfigurationElement sourceElement,
                                                ConfigurationElement parentElement,
                                                ConfigurationSaveMode saveMode) {
            if (sourceElement != null) {
                bool hasAnyChildElements = false;


                _lockedAllExceptAttributesList = sourceElement._lockedAllExceptAttributesList;
                _lockedAllExceptElementsList = sourceElement._lockedAllExceptElementsList;
                _fItemLocked = sourceElement._fItemLocked;
                _lockedAttributesList = sourceElement._lockedAttributesList;
                _lockedElementsList = sourceElement._lockedElementsList;
                AssociateContext(sourceElement._configRecord);

                if (parentElement != null) {
                    if (parentElement._lockedAttributesList != null)
                        _lockedAttributesList = UnMergeLockList(sourceElement._lockedAttributesList,
                            parentElement._lockedAttributesList, saveMode);
                    if (parentElement._lockedElementsList != null)
                        _lockedElementsList = UnMergeLockList(sourceElement._lockedElementsList,
                            parentElement._lockedElementsList, saveMode);
                    if (parentElement._lockedAllExceptAttributesList != null)
                        _lockedAllExceptAttributesList = UnMergeLockList(sourceElement._lockedAllExceptAttributesList,
                            parentElement._lockedAllExceptAttributesList, saveMode);
                    if (parentElement._lockedAllExceptElementsList != null)
                        _lockedAllExceptElementsList = UnMergeLockList(sourceElement._lockedAllExceptElementsList,
                            parentElement._lockedAllExceptElementsList, saveMode);
                }

                ConfigurationPropertyCollection props = Properties;
                ConfigurationPropertyCollection collectionKeys = null;

                // check for props not in bag from source
                for (int index = 0; index < sourceElement.Values.Count; index++) {
                    string key = sourceElement.Values.GetKey(index);
                    object value = sourceElement.Values[index];
                    ConfigurationProperty prop = (ConfigurationProperty)sourceElement.Properties[key];
                    if (prop == null || (collectionKeys != null && !collectionKeys.Contains(prop.Name)))
                        continue;
                    if (typeof(ConfigurationElement).IsAssignableFrom(prop.Type)) {
                        hasAnyChildElements = true;
                    }
                    else {
                        if (value != s_nullPropertyValue) {
                            if (!props.Contains(key)) // this is for optional provider models keys
                            {
                                // _values[key] = value;
                                ConfigurationValueFlags valueFlags = sourceElement.Values.RetrieveFlags(key);
                                _values.SetValue(key, value, valueFlags, null);

                                props.Add(prop);
                            }
                        }
                    }
                }

                foreach (ConfigurationProperty prop in Properties) {
                    if (prop == null || (collectionKeys != null && !collectionKeys.Contains(prop.Name))) {
                        continue;
                    }
                    if (typeof(ConfigurationElement).IsAssignableFrom(prop.Type)) {
                        hasAnyChildElements = true;
                    }
                    else {
                        object value = sourceElement.Values[prop.Name];

                        // if the property is required or we are writing a full config make sure we have defaults
                        if ((prop.IsRequired == true || saveMode == ConfigurationSaveMode.Full) && (value == null || value == s_nullPropertyValue)) {
                            // If the default value is null, this means there wasnt a reasonable default for the value
                            // and there is nothing more we can do. Otherwise reset the value to the default

                            // Note: 'null' should be used as default for non-empty strings instead
                            // of the current practice to use String.Epmty

                            if (prop.DefaultValue != null) {
                                value = prop.DefaultValue; // need to make sure required properties are persisted
                            }
                        }

                        if (value != null && value != s_nullPropertyValue) {
                            object value2 = null;
                            if (parentElement != null)                      // Is there a parent
                                value2 = parentElement.Values[prop.Name];   // if so get it's value

                            if (value2 == null)                             // no parent use default
                                value2 = prop.DefaultValue;
                            // If changed and not same as parent write or required

                            switch (saveMode) {
                                case ConfigurationSaveMode.Minimal: {
                                        if (!Object.Equals(value, value2) || prop.IsRequired == true)
                                            _values[prop.Name] = value;
                                    }
                                    break;
                                // (value != null && value != s_nullPropertyValue) ||
                                case ConfigurationSaveMode.Modified: {
                                        bool modified = sourceElement.Values.IsModified(prop.Name);
                                        bool inherited = sourceElement.Values.IsInherited(prop.Name);

                                        // update the value if the property is required, modified or it was not inherited
                                        // Also update properties that ARE inherited when we are resetting the object
                                        // as long as the property is not the same as the default value for the property
                                        if ((prop.IsRequired || modified || !inherited) ||
                                            (parentElement == null && inherited && !Object.Equals(value, value2))) {
                                            _values[prop.Name] = value;
                                        }
                                    }
                                    break;
                                case ConfigurationSaveMode.Full: {
                                        if (value != null && value != s_nullPropertyValue)
                                            _values[prop.Name] = value;
                                        else
                                            _values[prop.Name] = value2;

                                    }
                                    break;
                            }
                        }
                    }
                }

                if (hasAnyChildElements) {
                    foreach (ConfigurationProperty prop in Properties) {
                        if (typeof(ConfigurationElement).IsAssignableFrom(prop.Type)) {
                            ConfigurationElement pElem = (ConfigurationElement)((parentElement != null) ? parentElement[prop] : null);
                            ConfigurationElement childElement = (ConfigurationElement)this[prop];
                            if ((ConfigurationElement)sourceElement[prop] != null)
                                childElement.Unmerge((ConfigurationElement)sourceElement[prop],
                                    pElem, saveMode);
                        }

                    }
                }
            }
        }
 private void SetValue(int index, object value, ConfigurationValueFlags valueFlags, PropertySourceInfo sourceInfo) {
     ConfigurationValue configValue = CreateConfigValue(value, valueFlags, sourceInfo);
     BaseSet(index, configValue);
 }
 internal void ResetLockLists(ConfigurationElement parentElement)
 {
     this._lockedAttributesList = null;
     this._lockedAllExceptAttributesList = null;
     this._lockedElementsList = null;
     this._lockedAllExceptElementsList = null;
     if (parentElement != null)
     {
         this._fItemLocked = ((parentElement._fItemLocked & ConfigurationValueFlags.Locked) != ConfigurationValueFlags.Default) ? (ConfigurationValueFlags.Inherited | parentElement._fItemLocked) : ConfigurationValueFlags.Default;
         if (parentElement._lockedAttributesList != null)
         {
             this._lockedAttributesList = new ConfigurationLockCollection(this, ConfigurationLockCollectionType.LockedAttributes);
             foreach (string str in parentElement._lockedAttributesList)
             {
                 this._lockedAttributesList.Add(str, ConfigurationValueFlags.Inherited);
             }
         }
         if (parentElement._lockedAllExceptAttributesList != null)
         {
             this._lockedAllExceptAttributesList = new ConfigurationLockCollection(this, ConfigurationLockCollectionType.LockedExceptionList, string.Empty, parentElement._lockedAllExceptAttributesList);
         }
         if (parentElement._lockedElementsList != null)
         {
             this._lockedElementsList = new ConfigurationLockCollection(this, ConfigurationLockCollectionType.LockedElements);
             ConfigurationElementCollection elements = null;
             if (this.Properties.DefaultCollectionProperty != null)
             {
                 elements = this[this.Properties.DefaultCollectionProperty] as ConfigurationElementCollection;
                 if (elements != null)
                 {
                     elements.internalElementTagName = parentElement.ElementTagName;
                     if (elements._lockedElementsList == null)
                     {
                         elements._lockedElementsList = this._lockedElementsList;
                     }
                 }
             }
             foreach (string str2 in parentElement._lockedElementsList)
             {
                 this._lockedElementsList.Add(str2, ConfigurationValueFlags.Inherited);
             }
         }
         if (parentElement._lockedAllExceptElementsList != null)
         {
             this._lockedAllExceptElementsList = new ConfigurationLockCollection(this, ConfigurationLockCollectionType.LockedElementsExceptionList, parentElement._elementTagName, parentElement._lockedAllExceptElementsList);
             ConfigurationElementCollection elements2 = null;
             if (this.Properties.DefaultCollectionProperty != null)
             {
                 elements2 = this[this.Properties.DefaultCollectionProperty] as ConfigurationElementCollection;
                 if ((elements2 != null) && (elements2._lockedAllExceptElementsList == null))
                 {
                     elements2._lockedAllExceptElementsList = this._lockedAllExceptElementsList;
                 }
             }
         }
     }
 }
 internal void SetValue(string key, object value, ConfigurationValueFlags valueFlags, PropertySourceInfo sourceInfo) {
     ConfigurationValue configValue = CreateConfigValue(value, valueFlags, sourceInfo);
     BaseSet(key, configValue);
 }
        protected internal virtual void Unmerge(ConfigurationElement sourceElement, ConfigurationElement parentElement, ConfigurationSaveMode saveMode)
        {
            if (sourceElement != null)
            {
                bool flag = false;
                this._lockedAllExceptAttributesList = sourceElement._lockedAllExceptAttributesList;
                this._lockedAllExceptElementsList = sourceElement._lockedAllExceptElementsList;
                this._fItemLocked = sourceElement._fItemLocked;
                this._lockedAttributesList = sourceElement._lockedAttributesList;
                this._lockedElementsList = sourceElement._lockedElementsList;
                this.AssociateContext(sourceElement._configRecord);
                if (parentElement != null)
                {
                    if (parentElement._lockedAttributesList != null)
                    {
                        this._lockedAttributesList = this.UnMergeLockList(sourceElement._lockedAttributesList, parentElement._lockedAttributesList, saveMode);
                    }
                    if (parentElement._lockedElementsList != null)
                    {
                        this._lockedElementsList = this.UnMergeLockList(sourceElement._lockedElementsList, parentElement._lockedElementsList, saveMode);
                    }
                    if (parentElement._lockedAllExceptAttributesList != null)
                    {
                        this._lockedAllExceptAttributesList = this.UnMergeLockList(sourceElement._lockedAllExceptAttributesList, parentElement._lockedAllExceptAttributesList, saveMode);
                    }
                    if (parentElement._lockedAllExceptElementsList != null)
                    {
                        this._lockedAllExceptElementsList = this.UnMergeLockList(sourceElement._lockedAllExceptElementsList, parentElement._lockedAllExceptElementsList, saveMode);
                    }
                }
                ConfigurationPropertyCollection properties = this.Properties;
                ConfigurationPropertyCollection propertys2 = null;
                for (int i = 0; i < sourceElement.Values.Count; i++)
                {
                    string key = sourceElement.Values.GetKey(i);
                    object obj2 = sourceElement.Values[i];
                    ConfigurationProperty property = sourceElement.Properties[key];
                    if ((property != null) && ((propertys2 == null) || propertys2.Contains(property.Name)))
                    {
                        if (property.IsConfigurationElementType)
                        {
                            flag = true;
                        }
                        else if ((obj2 != s_nullPropertyValue) && !properties.Contains(key))
                        {
                            ConfigurationValueFlags valueFlags = sourceElement.Values.RetrieveFlags(key);
                            this._values.SetValue(key, obj2, valueFlags, null);
                            properties.Add(property);
                        }
                    }
                }
                foreach (ConfigurationProperty property2 in this.Properties)
                {
                    object defaultValue;
                    if ((property2 != null) && ((propertys2 == null) || propertys2.Contains(property2.Name)))
                    {
                        if (property2.IsConfigurationElementType)
                        {
                            flag = true;
                        }
                        else
                        {
                            object objA = sourceElement.Values[property2.Name];
                            if (((property2.IsRequired || (saveMode == ConfigurationSaveMode.Full)) && ((objA == null) || (objA == s_nullPropertyValue))) && (property2.DefaultValue != null))
                            {
                                objA = property2.DefaultValue;
                            }
                            if ((objA != null) && (objA != s_nullPropertyValue))
                            {
                                defaultValue = null;
                                if (parentElement != null)
                                {
                                    defaultValue = parentElement.Values[property2.Name];
                                }
                                if (defaultValue == null)
                                {
                                    defaultValue = property2.DefaultValue;
                                }
                                switch (saveMode)
                                {
                                    case ConfigurationSaveMode.Modified:
                                    {
                                        bool flag2 = sourceElement.Values.IsModified(property2.Name);
                                        bool flag3 = sourceElement.Values.IsInherited(property2.Name);
                                        if (((property2.IsRequired || flag2) || !flag3) || (((parentElement == null) && flag3) && !object.Equals(objA, defaultValue)))
                                        {
                                            this._values[property2.Name] = objA;
                                        }
                                        break;
                                    }
                                    case ConfigurationSaveMode.Minimal:
                                        if (!object.Equals(objA, defaultValue) || property2.IsRequired)
                                        {
                                            this._values[property2.Name] = objA;
                                        }
                                        break;

                                    case ConfigurationSaveMode.Full:
                                        if ((objA == null) || (objA == s_nullPropertyValue))
                                        {
                                            goto Label_031E;
                                        }
                                        this._values[property2.Name] = objA;
                                        break;
                                }
                            }
                        }
                    }
                    continue;
                Label_031E:
                    this._values[property2.Name] = defaultValue;
                }
                if (flag)
                {
                    foreach (ConfigurationProperty property3 in this.Properties)
                    {
                        if (property3.IsConfigurationElementType)
                        {
                            ConfigurationElement element = (parentElement != null) ? ((ConfigurationElement) parentElement[property3]) : null;
                            ConfigurationElement element2 = (ConfigurationElement) this[property3];
                            if (((ConfigurationElement) sourceElement[property3]) != null)
                            {
                                element2.Unmerge((ConfigurationElement) sourceElement[property3], element, saveMode);
                            }
                        }
                    }
                }
            }
        }
        internal void Add(string name, ConfigurationValueFlags flags)
        {
            if ((flags != ConfigurationValueFlags.Inherited) && _internalDictionary.Contains(name))
            {
                // the user has an item declared as locked below a level where it is already locked
                // keep enough info so we can write out the lock if they save in modified mode
                flags = ConfigurationValueFlags.Modified | (ConfigurationValueFlags)_internalDictionary[name];
                _internalDictionary.Remove(name);
                _internalArraylist.Remove(name);
            }

            _internalDictionary.Add(name, flags); // not from parent
            _internalArraylist.Add(name);
        }
 internal void MergeLocks(ConfigurationElement source)
 {
     if (source != null)
     {
         this._fItemLocked = ((source._fItemLocked & ConfigurationValueFlags.Locked) != ConfigurationValueFlags.Default) ? (ConfigurationValueFlags.Inherited | source._fItemLocked) : this._fItemLocked;
         if (source._lockedAttributesList != null)
         {
             if (this._lockedAttributesList == null)
             {
                 this._lockedAttributesList = new ConfigurationLockCollection(this, ConfigurationLockCollectionType.LockedAttributes);
             }
             foreach (string str in source._lockedAttributesList)
             {
                 this._lockedAttributesList.Add(str, ConfigurationValueFlags.Inherited);
             }
         }
         if (source._lockedAllExceptAttributesList != null)
         {
             if (this._lockedAllExceptAttributesList == null)
             {
                 this._lockedAllExceptAttributesList = new ConfigurationLockCollection(this, ConfigurationLockCollectionType.LockedExceptionList, string.Empty, source._lockedAllExceptAttributesList);
             }
             StringCollection strings = this.IntersectLockCollections(this._lockedAllExceptAttributesList, source._lockedAllExceptAttributesList);
             this._lockedAllExceptAttributesList.ClearInternal(false);
             foreach (string str2 in strings)
             {
                 this._lockedAllExceptAttributesList.Add(str2, ConfigurationValueFlags.Default);
             }
         }
         if (source._lockedElementsList != null)
         {
             if (this._lockedElementsList == null)
             {
                 this._lockedElementsList = new ConfigurationLockCollection(this, ConfigurationLockCollectionType.LockedElements);
             }
             ConfigurationElementCollection elements = null;
             if (this.Properties.DefaultCollectionProperty != null)
             {
                 elements = this[this.Properties.DefaultCollectionProperty] as ConfigurationElementCollection;
                 if (elements != null)
                 {
                     elements.internalElementTagName = source.ElementTagName;
                     if (elements._lockedElementsList == null)
                     {
                         elements._lockedElementsList = this._lockedElementsList;
                     }
                 }
             }
             foreach (string str3 in source._lockedElementsList)
             {
                 this._lockedElementsList.Add(str3, ConfigurationValueFlags.Inherited);
                 if (elements != null)
                 {
                     elements._lockedElementsList.Add(str3, ConfigurationValueFlags.Inherited);
                 }
             }
         }
         if (source._lockedAllExceptElementsList != null)
         {
             if ((this._lockedAllExceptElementsList == null) || (this._lockedAllExceptElementsList.Count == 0))
             {
                 this._lockedAllExceptElementsList = new ConfigurationLockCollection(this, ConfigurationLockCollectionType.LockedElementsExceptionList, source._elementTagName, source._lockedAllExceptElementsList);
             }
             StringCollection strings2 = this.IntersectLockCollections(this._lockedAllExceptElementsList, source._lockedAllExceptElementsList);
             ConfigurationElementCollection elements2 = null;
             if (this.Properties.DefaultCollectionProperty != null)
             {
                 elements2 = this[this.Properties.DefaultCollectionProperty] as ConfigurationElementCollection;
                 if ((elements2 != null) && (elements2._lockedAllExceptElementsList == null))
                 {
                     elements2._lockedAllExceptElementsList = this._lockedAllExceptElementsList;
                 }
             }
             this._lockedAllExceptElementsList.ClearInternal(false);
             foreach (string str4 in strings2)
             {
                 if (!this._lockedAllExceptElementsList.Contains(str4) || (str4 == this.ElementTagName))
                 {
                     this._lockedAllExceptElementsList.Add(str4, ConfigurationValueFlags.Default);
                 }
             }
             if (this._lockedAllExceptElementsList.HasParentElements)
             {
                 foreach (ConfigurationProperty property in this.Properties)
                 {
                     if (!this._lockedAllExceptElementsList.Contains(property.Name) && property.IsConfigurationElementType)
                     {
                         ((ConfigurationElement) this[property]).SetLocked();
                     }
                 }
             }
         }
     }
 }
 internal void Add(string name, ConfigurationValueFlags flags)
 {
     if ((flags != ConfigurationValueFlags.Inherited) && this.internalDictionary.Contains(name))
     {
         flags = ConfigurationValueFlags.Modified | ((ConfigurationValueFlags) this.internalDictionary[name]);
         this.internalDictionary.Remove(name);
         this.internalArraylist.Remove(name);
     }
     this.internalDictionary.Add(name, flags);
     this.internalArraylist.Add(name);
 }