internal ConfigurationLockCollection(ConfigurationElement thisElement, ConfigurationLockCollectionType lockType, string ignoreName, ConfigurationLockCollection parentCollection) { _thisElement = thisElement; LockType = lockType; _internalDictionary = new HybridDictionary(); _internalArraylist = new ArrayList(); IsModified = false; ExceptionList = (LockType == ConfigurationLockCollectionType.LockedExceptionList) || (LockType == ConfigurationLockCollectionType.LockedElementsExceptionList); _ignoreName = ignoreName; if (parentCollection == null) { return; } foreach (string key in parentCollection) // seed the new collection { Add(key, ConfigurationValueFlags.Inherited); // add the local copy if (!ExceptionList) { continue; } if (_seedList.Length != 0) { _seedList += ","; } _seedList += key; } }
internal ConfigurationLockCollection(ConfigurationElement thisElement, ConfigurationLockCollectionType lockType, string ignoreName, ConfigurationLockCollection parentCollection) { this._ignoreName = string.Empty; this.SeedList = string.Empty; this._thisElement = thisElement; this._lockType = lockType; this.internalDictionary = new HybridDictionary(); this.internalArraylist = new ArrayList(); this._bModified = false; this._bExceptionList = (this._lockType == ConfigurationLockCollectionType.LockedExceptionList) || (this._lockType == ConfigurationLockCollectionType.LockedElementsExceptionList); this._ignoreName = ignoreName; if (parentCollection != null) { foreach (string str in parentCollection) { this.Add(str, ConfigurationValueFlags.Inherited); if (this._bExceptionList) { if (this.SeedList.Length != 0) { this.SeedList = this.SeedList + ","; } this.SeedList = this.SeedList + str; } } } }
internal ConfigurationLockCollection(ConfigurationElement thisElement, ConfigurationLockCollectionType lockType, string ignoreName, ConfigurationLockCollection parentCollection) { _thisElement = thisElement; _lockType = lockType; internalDictionary = new HybridDictionary(); internalArraylist = new ArrayList(); _bModified = false; _bExceptionList = _lockType == ConfigurationLockCollectionType.LockedExceptionList || _lockType == ConfigurationLockCollectionType.LockedElementsExceptionList; _ignoreName = ignoreName; if (parentCollection != null) { foreach (string key in parentCollection) // seed the new collection { Add(key, ConfigurationValueFlags.Inherited); // add the local copy if (_bExceptionList) { if (SeedList.Length != 0) { SeedList += ","; } SeedList += key; } } } }
internal ConfigurationLockCollection(ConfigurationElement thisElement, ConfigurationLockCollectionType lockType, string ignoreName, ConfigurationLockCollection parentCollection) { _thisElement = thisElement; _lockType = lockType; internalDictionary = new HybridDictionary(); internalArraylist = new ArrayList(); _bModified = false; _bExceptionList = _lockType == ConfigurationLockCollectionType.LockedExceptionList || _lockType == ConfigurationLockCollectionType.LockedElementsExceptionList; _ignoreName = ignoreName; if (parentCollection != null) { foreach (string key in parentCollection) // seed the new collection { Add(key, ConfigurationValueFlags.Inherited); // add the local copy if (_bExceptionList) { if (SeedList.Length != 0) SeedList += ","; SeedList += key; } } } }
internal ConfigurationLockCollection(ConfigurationElement thisElement, ConfigurationLockCollectionType lockType, string ignoreName, ConfigurationLockCollection parentCollection) { _thisElement = thisElement; LockType = lockType; _internalDictionary = new HybridDictionary(); _internalArraylist = new ArrayList(); IsModified = false; ExceptionList = (LockType == ConfigurationLockCollectionType.LockedExceptionList) || (LockType == ConfigurationLockCollectionType.LockedElementsExceptionList); _ignoreName = ignoreName; if (parentCollection == null) return; foreach (string key in parentCollection) // seed the new collection { Add(key, ConfigurationValueFlags.Inherited); // add the local copy if (!ExceptionList) continue; if (_seedList.Length != 0) _seedList += ","; _seedList += key; } }
protected internal virtual void DeserializeElement(XmlReader reader, bool serializeCollectionKey) { ConfigurationPropertyCollection props = Properties; ConfigurationValue LockedAttributesList = null; ConfigurationValue LockedAllExceptList = null; ConfigurationValue LockedElementList = null; ConfigurationValue LockedAllElementsExceptList = null; bool ItemLockedLocally = false; _bElementPresent = true; ConfigurationElement defaultCollection = null; ConfigurationProperty defaultCollectionProperty = props != null ? props.DefaultCollectionProperty : null; if (defaultCollectionProperty != null) { defaultCollection = (ConfigurationElement)this[defaultCollectionProperty]; } // Process attributes _elementTagName = reader.Name; PropertySourceInfo rootInfo = new PropertySourceInfo(reader); _values.SetValue(reader.Name, null, ConfigurationValueFlags.Modified, rootInfo); _values.SetValue(DefaultCollectionPropertyName, defaultCollection, ConfigurationValueFlags.Modified, rootInfo); if ((_lockedElementsList != null && (_lockedElementsList.Contains(reader.Name) || (_lockedElementsList.Contains(LockAll) && reader.Name != ElementTagName))) || (_lockedAllExceptElementsList != null && _lockedAllExceptElementsList.Count != 0 && !_lockedAllExceptElementsList.Contains(reader.Name)) || ((_fItemLocked & ConfigurationValueFlags.Locked) != 0 && (_fItemLocked & ConfigurationValueFlags.Inherited) != 0) ) { throw new ConfigurationErrorsException(SR.GetString(SR.Config_base_element_locked, reader.Name), reader); } if (reader.AttributeCount > 0) { while (reader.MoveToNextAttribute()) { String propertyName = reader.Name; if ((_lockedAttributesList != null && (_lockedAttributesList.Contains(propertyName) || _lockedAttributesList.Contains(LockAll))) || (_lockedAllExceptAttributesList != null && !_lockedAllExceptAttributesList.Contains(propertyName)) ) { if (propertyName != LockAttributesKey && propertyName != LockAllAttributesExceptKey) throw new ConfigurationErrorsException(SR.GetString(SR.Config_base_attribute_locked, propertyName), reader); } ConfigurationProperty prop = props != null ? props[propertyName] : null; if (prop != null) { if (serializeCollectionKey && !prop.IsKey) { throw new ConfigurationErrorsException(SR.GetString(SR.Config_base_unrecognized_attribute, propertyName), reader); } _values.SetValue(propertyName, DeserializePropertyValue(prop, reader), ConfigurationValueFlags.Modified, new PropertySourceInfo(reader)); } // if (deserializing a remove OR an add that does not handle optional attributes) else if (propertyName == LockItemKey) { try { ItemLockedLocally = bool.Parse(reader.Value); } catch { throw new ConfigurationErrorsException(SR.GetString(SR.Config_invalid_boolean_attribute, propertyName), reader); } } else if (propertyName == LockAttributesKey) { LockedAttributesList = new ConfigurationValue(reader.Value, ConfigurationValueFlags.Default, new PropertySourceInfo(reader)); } else if (propertyName == LockAllAttributesExceptKey) { LockedAllExceptList = new ConfigurationValue(reader.Value, ConfigurationValueFlags.Default, new PropertySourceInfo(reader)); } else if (propertyName == LockElementsKey) { LockedElementList = new ConfigurationValue(reader.Value, ConfigurationValueFlags.Default, new PropertySourceInfo(reader)); } else if (propertyName == LockAllElementsExceptKey) { LockedAllElementsExceptList = new ConfigurationValue(reader.Value, ConfigurationValueFlags.Default, new PropertySourceInfo(reader)); } else if (serializeCollectionKey || !OnDeserializeUnrecognizedAttribute(propertyName, reader.Value)) { throw new ConfigurationErrorsException(SR.GetString(SR.Config_base_unrecognized_attribute, propertyName), reader); } } } reader.MoveToElement(); // Check for nested elements. try { HybridDictionary nodeFound = new HybridDictionary(); if (!reader.IsEmptyElement) { while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element) { String propertyName = reader.Name; CheckLockedElement(propertyName, null); ConfigurationProperty prop = props != null ? props[propertyName] : null; if (prop != null) { if (typeof(ConfigurationElement).IsAssignableFrom(prop.Type)) { if (nodeFound.Contains(propertyName)) throw new ConfigurationErrorsException(SR.GetString(SR.Config_base_element_cannot_have_multiple_child_elements, propertyName), reader); nodeFound.Add(propertyName, propertyName); ConfigurationElement childElement = (ConfigurationElement)this[prop]; childElement.DeserializeElement(reader, serializeCollectionKey); // Validate the new element with the per-property Validator // Note that the per-type validator for childElement has been already executed as part of Deserialize ValidateElement(childElement, prop.Validator, false); } else { throw new ConfigurationErrorsException(SR.GetString(SR.Config_base_property_is_not_a_configuration_element, propertyName), reader); } } else if (!OnDeserializeUnrecognizedElement(propertyName, reader)) { // Let the default collection, if there is one, handle this node. if (defaultCollection == null || !defaultCollection.OnDeserializeUnrecognizedElement(propertyName, reader)) { throw new ConfigurationErrorsException(SR.GetString(SR.Config_base_unrecognized_element_name, propertyName), reader); } } } else if (reader.NodeType == XmlNodeType.EndElement) { break; } else if ((reader.NodeType == XmlNodeType.CDATA) || (reader.NodeType == XmlNodeType.Text)) { throw new ConfigurationErrorsException(SR.GetString(SR.Config_base_section_invalid_content), reader); } } } EnsureRequiredProperties(serializeCollectionKey); // Call the per-type validator for this object ValidateElement(this, null, false); } catch (ConfigurationException e) { // Catch the generic message from deserialization and include line info if necessary if (e.Filename == null || e.Filename.Length == 0) throw new ConfigurationErrorsException(e.Message, reader); // give it some info else throw e; } if (ItemLockedLocally) { SetLocked(); _fItemLocked = ConfigurationValueFlags.Locked; } if (LockedAttributesList != null) { if (_lockedAttributesList == null) _lockedAttributesList = new ConfigurationLockCollection(this, ConfigurationLockCollectionType.LockedAttributes); foreach (string key in ParseLockedAttributes(LockedAttributesList, ConfigurationLockCollectionType.LockedAttributes)) { if (!_lockedAttributesList.Contains(key)) _lockedAttributesList.Add(key, ConfigurationValueFlags.Default); // add the local copy else _lockedAttributesList.Add(key, ConfigurationValueFlags.Modified | ConfigurationValueFlags.Inherited); // add the local copy } } if (LockedAllExceptList != null) { ConfigurationLockCollection newCollection = ParseLockedAttributes(LockedAllExceptList, ConfigurationLockCollectionType.LockedExceptionList); if (_lockedAllExceptAttributesList == null) { _lockedAllExceptAttributesList = new ConfigurationLockCollection(this, ConfigurationLockCollectionType.LockedExceptionList, String.Empty, newCollection); _lockedAllExceptAttributesList.ClearSeedList(); // Prevent the list from thinking this was set by a parent. } StringCollection intersectionCollection = IntersectLockCollections(_lockedAllExceptAttributesList, newCollection); /* if (intersectionCollection.Count == 0) { throw new ConfigurationErrorsException(SR.GetString(SR.Config_empty_lock_attributes_except_effective, LockAllAttributesExceptKey, LockedAllExceptList.Value, LockAttributesKey), LockedAllExceptList.SourceInfo.FileName, LockedAllExceptList.SourceInfo.LineNumber); } */ _lockedAllExceptAttributesList.ClearInternal(false); foreach (string key in intersectionCollection) { _lockedAllExceptAttributesList.Add(key, ConfigurationValueFlags.Default); } } if (LockedElementList != null) { if (_lockedElementsList == null) _lockedElementsList = new ConfigurationLockCollection(this, ConfigurationLockCollectionType.LockedElements); ConfigurationLockCollection localLockedElementList = ParseLockedAttributes(LockedElementList, ConfigurationLockCollectionType.LockedElements); ConfigurationElementCollection collection = null; if (props.DefaultCollectionProperty != null) // this is not a collection but it may contain a default collection { collection = this[props.DefaultCollectionProperty] as ConfigurationElementCollection; if (collection != null && collection._lockedElementsList == null) collection._lockedElementsList = _lockedElementsList; } foreach (string key in localLockedElementList) { if (!_lockedElementsList.Contains(key)) { _lockedElementsList.Add(key, ConfigurationValueFlags.Default); // add the local copy ConfigurationProperty propToLock = Properties[key]; if (propToLock != null && typeof(ConfigurationElement).IsAssignableFrom(propToLock.Type)) { ((ConfigurationElement)this[key]).SetLocked(); } if (key == LockAll) { foreach (ConfigurationProperty prop in Properties) { if (!string.IsNullOrEmpty(prop.Name) && typeof(ConfigurationElement).IsAssignableFrom(prop.Type)) { ((ConfigurationElement)this[prop]).SetLocked(); } } } } } } if (LockedAllElementsExceptList != null) { ConfigurationLockCollection newCollection = ParseLockedAttributes(LockedAllElementsExceptList, ConfigurationLockCollectionType.LockedElementsExceptionList); if (_lockedAllExceptElementsList == null) { _lockedAllExceptElementsList = new ConfigurationLockCollection(this, ConfigurationLockCollectionType.LockedElementsExceptionList, _elementTagName, newCollection); _lockedAllExceptElementsList.ClearSeedList(); } StringCollection intersectionCollection = IntersectLockCollections(_lockedAllExceptElementsList, newCollection); ConfigurationElementCollection collection = null; if (props.DefaultCollectionProperty != null) // this is not a collection but it may contain a default collection { collection = this[props.DefaultCollectionProperty] as ConfigurationElementCollection; if (collection != null && collection._lockedAllExceptElementsList == null) collection._lockedAllExceptElementsList = _lockedAllExceptElementsList; } _lockedAllExceptElementsList.ClearInternal(false); foreach (string key in intersectionCollection) { if (!_lockedAllExceptElementsList.Contains(key) || key == ElementTagName) _lockedAllExceptElementsList.Add(key, ConfigurationValueFlags.Default); // add the local copy } foreach (ConfigurationProperty prop in Properties) { if (!(string.IsNullOrEmpty(prop.Name) || _lockedAllExceptElementsList.Contains(prop.Name)) && typeof(ConfigurationElement).IsAssignableFrom(prop.Type)) { ((ConfigurationElement)this[prop]).SetLocked(); } } } // Make sure default collections use the same lock element lists if (defaultCollectionProperty != null) { defaultCollection = (ConfigurationElement)this[defaultCollectionProperty]; if (_lockedElementsList == null) { _lockedElementsList = new ConfigurationLockCollection(this, ConfigurationLockCollectionType.LockedElements); } defaultCollection._lockedElementsList = _lockedElementsList; if (_lockedAllExceptElementsList == null) { _lockedAllExceptElementsList = new ConfigurationLockCollection(this, ConfigurationLockCollectionType.LockedElementsExceptionList, reader.Name); _lockedAllExceptElementsList.ClearSeedList(); } defaultCollection._lockedAllExceptElementsList = _lockedAllExceptElementsList; } // This has to be the last thing to execute PostDeserialize(); }
private StringCollection IntersectLockCollections(ConfigurationLockCollection Collection1, ConfigurationLockCollection Collection2) { ConfigurationLockCollection smallCollection = Collection1.Count < Collection2.Count ? Collection1 : Collection2; ConfigurationLockCollection largeCollection = Collection1.Count >= Collection2.Count ? Collection1 : Collection2; StringCollection intersectionCollection = new StringCollection(); foreach (string key in smallCollection) { if (largeCollection.Contains(key) || key == ElementTagName) intersectionCollection.Add(key); // add the local copy } return intersectionCollection; }
private ConfigurationLockCollection ParseLockedAttributes(ConfigurationValue value, ConfigurationLockCollectionType lockType) { // check that only actual properties are in the lock attribute ConfigurationLockCollection localLockedAttributesList = new ConfigurationLockCollection(this, lockType); string attributeList = (string)(value.Value); if (string.IsNullOrEmpty(attributeList)) { if (lockType == ConfigurationLockCollectionType.LockedAttributes) throw new ConfigurationErrorsException(SR.GetString(SR.Empty_attribute, LockAttributesKey), value.SourceInfo.FileName, value.SourceInfo.LineNumber); if (lockType == ConfigurationLockCollectionType.LockedElements) throw new ConfigurationErrorsException(SR.GetString(SR.Empty_attribute, LockElementsKey), value.SourceInfo.FileName, value.SourceInfo.LineNumber); if (lockType == ConfigurationLockCollectionType.LockedExceptionList) throw new ConfigurationErrorsException(SR.GetString(SR.Config_empty_lock_attributes_except, LockAllAttributesExceptKey, LockAttributesKey), value.SourceInfo.FileName, value.SourceInfo.LineNumber); if (lockType == ConfigurationLockCollectionType.LockedElementsExceptionList) throw new ConfigurationErrorsException(SR.GetString(SR.Config_empty_lock_element_except, LockAllElementsExceptKey, LockElementsKey), value.SourceInfo.FileName, value.SourceInfo.LineNumber); } string[] attribsToLock = attributeList.Split(new char[] { ',', ':', ';' }); foreach (string attribToLock in attribsToLock) { string attribToLockTrim = attribToLock.Trim(); if (!String.IsNullOrEmpty(attribToLockTrim)) { // validate that the locks are good if (!((lockType == ConfigurationLockCollectionType.LockedElements || lockType == ConfigurationLockCollectionType.LockedAttributes) && attribToLockTrim == LockAll)) { ConfigurationProperty propToLock = Properties[attribToLockTrim]; if (propToLock == null || // if the prop does not exist attribToLockTrim == LockAttributesKey || // or it is the lockattributes keyword attribToLockTrim == LockAllAttributesExceptKey || // or it is the lockattributes keyword attribToLockTrim == LockElementsKey || // or it is the lockelements keyword (lockType != ConfigurationLockCollectionType.LockedElements && lockType != ConfigurationLockCollectionType.LockedElementsExceptionList && typeof(ConfigurationElement).IsAssignableFrom(propToLock.Type)) || // or if not locking elements but the property is a element ((lockType == ConfigurationLockCollectionType.LockedElements || lockType == ConfigurationLockCollectionType.LockedElementsExceptionList) && !typeof(ConfigurationElement).IsAssignableFrom(propToLock.Type)) // or if locking elements but the property is not an element ) { // check to see if this is a collection and we are locking a collection element ConfigurationElementCollection collection = this as ConfigurationElementCollection; if (collection == null && Properties.DefaultCollectionProperty != null) // this is not a collection but it may contain a default collection { collection = this[Properties.DefaultCollectionProperty] as ConfigurationElementCollection; } if (collection == null || lockType == ConfigurationLockCollectionType.LockedAttributes || // If the collection type is not element then the lock is bogus lockType == ConfigurationLockCollectionType.LockedExceptionList) { ReportInvalidLock(attribToLockTrim, lockType, value, null); } else if (!collection.IsLockableElement(attribToLockTrim)) { ReportInvalidLock(attribToLockTrim, lockType, value, collection.LockableElements); } } if (propToLock != null && propToLock.IsRequired == true) throw new ConfigurationErrorsException(SR.GetString(SR.Config_base_required_attribute_lock_attempt, propToLock.Name)); } // concatenate the new attribute. localLockedAttributesList.Add(attribToLockTrim, ConfigurationValueFlags.Default); // Mark as local } } return localLockedAttributesList; }
/// <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); } } }
private StringCollection IntersectLockCollections(ConfigurationLockCollection Collection1, ConfigurationLockCollection Collection2) { ConfigurationLockCollection configurationLockCollection1 = Collection1.Count < Collection2.Count ? Collection1 : Collection2; ConfigurationLockCollection configurationLockCollection2 = Collection1.Count >= Collection2.Count ? Collection1 : Collection2; StringCollection stringCollection = new StringCollection(); foreach (string name in configurationLockCollection1) { if (configurationLockCollection2.Contains(name) || name == this.ElementTagName) stringCollection.Add(name); } return stringCollection; }
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 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) 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(); } } }
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(); } }
/// <summary> /// Reads XML from the configuration file. /// </summary> /// <param name="reader">The <see cref="T:System.Xml.XmlReader"/> that reads from the configuration file.</param><param name="serializeCollectionKey">true to serialize only the collection key properties; otherwise, false.</param><exception cref="T:System.Configuration.ConfigurationErrorsException">The element to read is locked.- or -An attribute of the current node is not recognized.- or -The lock status of the current node cannot be determined. </exception> protected internal virtual void DeserializeElement(XmlReader reader, bool serializeCollectionKey) { ConfigurationPropertyCollection properties = this.Properties; ConfigurationValue configurationValue1 = (ConfigurationValue) null; ConfigurationValue configurationValue2 = (ConfigurationValue) null; ConfigurationValue configurationValue3 = (ConfigurationValue) null; ConfigurationValue configurationValue4 = (ConfigurationValue) null; bool flag = false; this._bElementPresent = true; ConfigurationElement configurationElement1 = (ConfigurationElement) null; ConfigurationProperty index1 = properties != null ? properties.DefaultCollectionProperty : (ConfigurationProperty) null; if (index1 != null) configurationElement1 = (ConfigurationElement) this[index1]; this._elementTagName = reader.Name; PropertySourceInfo sourceInfo = new PropertySourceInfo(reader); this._values.SetValue(reader.Name, (object) null, ConfigurationValueFlags.Modified, sourceInfo); this._values.SetValue("", (object) configurationElement1, ConfigurationValueFlags.Modified, sourceInfo); if (this._lockedElementsList != null && (this._lockedElementsList.Contains(reader.Name) || this._lockedElementsList.Contains("*") && reader.Name != this.ElementTagName) || (this._lockedAllExceptElementsList != null && this._lockedAllExceptElementsList.Count != 0 && !this._lockedAllExceptElementsList.Contains(reader.Name) || (this._fItemLocked & ConfigurationValueFlags.Locked) != ConfigurationValueFlags.Default && (this._fItemLocked & ConfigurationValueFlags.Inherited) != ConfigurationValueFlags.Default)) { throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_base_element_locked", new object[1] { (object) reader.Name }), reader); } else { if (reader.AttributeCount > 0) { while (reader.MoveToNextAttribute()) { string name = reader.Name; if ((this._lockedAttributesList != null && (this._lockedAttributesList.Contains(name) || this._lockedAttributesList.Contains("*")) || this._lockedAllExceptAttributesList != null && !this._lockedAllExceptAttributesList.Contains(name)) && (name != "lockAttributes" && name != "lockAllAttributesExcept")) { throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_base_attribute_locked", new object[1] { (object) name }), reader); } else { ConfigurationProperty prop = properties != null ? properties[name] : (ConfigurationProperty) null; if (prop != null) { if (serializeCollectionKey && !prop.IsKey) throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_base_unrecognized_attribute", new object[1] { (object) name }), reader); else this._values.SetValue(name, this.DeserializePropertyValue(prop, reader), ConfigurationValueFlags.Modified, new PropertySourceInfo(reader)); } else if (name == "lockItem") { try { flag = bool.Parse(reader.Value); } catch { throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_invalid_boolean_attribute", new object[1] { (object) name }), reader); } } else if (name == "lockAttributes") configurationValue1 = new ConfigurationValue((object) reader.Value, ConfigurationValueFlags.Default, new PropertySourceInfo(reader)); else if (name == "lockAllAttributesExcept") configurationValue2 = new ConfigurationValue((object) reader.Value, ConfigurationValueFlags.Default, new PropertySourceInfo(reader)); else if (name == "lockElements") configurationValue3 = new ConfigurationValue((object) reader.Value, ConfigurationValueFlags.Default, new PropertySourceInfo(reader)); else if (name == "lockAllElementsExcept") configurationValue4 = new ConfigurationValue((object) reader.Value, ConfigurationValueFlags.Default, new PropertySourceInfo(reader)); else if (serializeCollectionKey || !this.OnDeserializeUnrecognizedAttribute(name, reader.Value)) throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_base_unrecognized_attribute", new object[1] { (object) name }), reader); } } } reader.MoveToElement(); try { HybridDictionary hybridDictionary = new HybridDictionary(); if (!reader.IsEmptyElement) { while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element) { string name = reader.Name; this.CheckLockedElement(name, (XmlReader) null); ConfigurationProperty index2 = properties != null ? properties[name] : (ConfigurationProperty) null; if (index2 != null) { if (index2.IsConfigurationElementType) { if (hybridDictionary.Contains((object) name)) { throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_base_element_cannot_have_multiple_child_elements", new object[1] { (object) name }), reader); } else { hybridDictionary.Add((object) name, (object) name); ConfigurationElement elem = (ConfigurationElement) this[index2]; elem.DeserializeElement(reader, serializeCollectionKey); ConfigurationElement.ValidateElement(elem, index2.Validator, false); } } else throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_base_property_is_not_a_configuration_element", new object[1] { (object) name }), reader); } else if (!this.OnDeserializeUnrecognizedElement(name, reader) && (configurationElement1 == null || !configurationElement1.OnDeserializeUnrecognizedElement(name, reader))) throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_base_unrecognized_element_name", new object[1] { (object) name }), reader); } else if (reader.NodeType != XmlNodeType.EndElement) { if (reader.NodeType == XmlNodeType.CDATA || reader.NodeType == XmlNodeType.Text) throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_base_section_invalid_content"), reader); } else break; } } this.EnsureRequiredProperties(serializeCollectionKey); ConfigurationElement.ValidateElement(this, (ConfigurationValidatorBase) null, false); } catch (ConfigurationException ex) { if (ex.Filename == null || ex.Filename.Length == 0) throw new ConfigurationErrorsException(ex.Message, reader); else throw ex; } if (flag) { this.SetLocked(); this._fItemLocked = ConfigurationValueFlags.Locked; } if (configurationValue1 != null) { if (this._lockedAttributesList == null) this._lockedAttributesList = new ConfigurationLockCollection(this, ConfigurationLockCollectionType.LockedAttributes); foreach (string name in this.ParseLockedAttributes(configurationValue1, ConfigurationLockCollectionType.LockedAttributes)) { if (!this._lockedAttributesList.Contains(name)) this._lockedAttributesList.Add(name, ConfigurationValueFlags.Default); else this._lockedAttributesList.Add(name, ConfigurationValueFlags.Inherited | ConfigurationValueFlags.Modified); } } if (configurationValue2 != null) { ConfigurationLockCollection configurationLockCollection = this.ParseLockedAttributes(configurationValue2, ConfigurationLockCollectionType.LockedExceptionList); if (this._lockedAllExceptAttributesList == null) { this._lockedAllExceptAttributesList = new ConfigurationLockCollection(this, ConfigurationLockCollectionType.LockedExceptionList, string.Empty, configurationLockCollection); this._lockedAllExceptAttributesList.ClearSeedList(); } StringCollection stringCollection = this.IntersectLockCollections(this._lockedAllExceptAttributesList, configurationLockCollection); this._lockedAllExceptAttributesList.ClearInternal(false); foreach (string name in stringCollection) this._lockedAllExceptAttributesList.Add(name, ConfigurationValueFlags.Default); } if (configurationValue3 != null) { if (this._lockedElementsList == null) this._lockedElementsList = new ConfigurationLockCollection(this, ConfigurationLockCollectionType.LockedElements); ConfigurationLockCollection configurationLockCollection = this.ParseLockedAttributes(configurationValue3, ConfigurationLockCollectionType.LockedElements); if (properties.DefaultCollectionProperty != null) { ConfigurationElementCollection elementCollection = this[properties.DefaultCollectionProperty] as ConfigurationElementCollection; if (elementCollection != null && elementCollection._lockedElementsList == null) elementCollection._lockedElementsList = this._lockedElementsList; } foreach (string name in configurationLockCollection) { if (!this._lockedElementsList.Contains(name)) { this._lockedElementsList.Add(name, ConfigurationValueFlags.Default); ConfigurationProperty configurationProperty = this.Properties[name]; if (configurationProperty != null && typeof (ConfigurationElement).IsAssignableFrom(configurationProperty.Type)) ((ConfigurationElement) this[name]).SetLocked(); if (name == "*") { foreach (ConfigurationProperty index2 in this.Properties) { if (!string.IsNullOrEmpty(index2.Name) && index2.IsConfigurationElementType) ((ConfigurationElement) this[index2]).SetLocked(); } } } } } if (configurationValue4 != null) { ConfigurationLockCollection configurationLockCollection = this.ParseLockedAttributes(configurationValue4, ConfigurationLockCollectionType.LockedElementsExceptionList); if (this._lockedAllExceptElementsList == null) { this._lockedAllExceptElementsList = new ConfigurationLockCollection(this, ConfigurationLockCollectionType.LockedElementsExceptionList, this._elementTagName, configurationLockCollection); this._lockedAllExceptElementsList.ClearSeedList(); } StringCollection stringCollection = this.IntersectLockCollections(this._lockedAllExceptElementsList, configurationLockCollection); if (properties.DefaultCollectionProperty != null) { ConfigurationElementCollection elementCollection = this[properties.DefaultCollectionProperty] as ConfigurationElementCollection; if (elementCollection != null && elementCollection._lockedAllExceptElementsList == null) elementCollection._lockedAllExceptElementsList = this._lockedAllExceptElementsList; } this._lockedAllExceptElementsList.ClearInternal(false); foreach (string name in stringCollection) { if (!this._lockedAllExceptElementsList.Contains(name) || name == this.ElementTagName) this._lockedAllExceptElementsList.Add(name, ConfigurationValueFlags.Default); } foreach (ConfigurationProperty index2 in this.Properties) { if (!string.IsNullOrEmpty(index2.Name) && !this._lockedAllExceptElementsList.Contains(index2.Name) && index2.IsConfigurationElementType) ((ConfigurationElement) this[index2]).SetLocked(); } } if (index1 != null) { ConfigurationElement configurationElement2 = (ConfigurationElement) this[index1]; if (this._lockedElementsList == null) this._lockedElementsList = new ConfigurationLockCollection(this, ConfigurationLockCollectionType.LockedElements); configurationElement2._lockedElementsList = this._lockedElementsList; if (this._lockedAllExceptElementsList == null) { this._lockedAllExceptElementsList = new ConfigurationLockCollection(this, ConfigurationLockCollectionType.LockedElementsExceptionList, reader.Name); this._lockedAllExceptElementsList.ClearSeedList(); } configurationElement2._lockedAllExceptElementsList = this._lockedAllExceptElementsList; } this.PostDeserialize(); } }
private bool SerializeLockList(ConfigurationLockCollection list, string elementKey, XmlWriter writer) { StringBuilder stringBuilder = new StringBuilder(); if (list != null) { foreach (string name in list) { if (!list.DefinedInParent(name)) { if (stringBuilder.Length != 0) stringBuilder.Append(','); stringBuilder.Append(name); } } } if (writer != null && stringBuilder.Length != 0) writer.WriteAttributeString(elementKey, ((object) stringBuilder).ToString()); return stringBuilder.Length != 0; }
private ConfigurationLockCollection ParseLockedAttributes(ConfigurationValue value, ConfigurationLockCollectionType lockType) { ConfigurationLockCollection configurationLockCollection = new ConfigurationLockCollection(this, lockType); string str1 = (string) value.Value; if (string.IsNullOrEmpty(str1)) { if (lockType == ConfigurationLockCollectionType.LockedAttributes) throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Empty_attribute", new object[1] { (object) "lockAttributes" }), value.SourceInfo.FileName, value.SourceInfo.LineNumber); else if (lockType == ConfigurationLockCollectionType.LockedElements) throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Empty_attribute", new object[1] { (object) "lockElements" }), value.SourceInfo.FileName, value.SourceInfo.LineNumber); else if (lockType == ConfigurationLockCollectionType.LockedExceptionList) throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_empty_lock_attributes_except", (object) "lockAllAttributesExcept", (object) "lockAttributes"), value.SourceInfo.FileName, value.SourceInfo.LineNumber); else if (lockType == ConfigurationLockCollectionType.LockedElementsExceptionList) throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_empty_lock_element_except", (object) "lockAllElementsExcept", (object) "lockElements"), value.SourceInfo.FileName, value.SourceInfo.LineNumber); } string str2 = str1; char[] chArray = new char[3] { ',', ':', ';' }; foreach (string str3 in str2.Split(chArray)) { string index = str3.Trim(); if (!string.IsNullOrEmpty(index)) { if (lockType != ConfigurationLockCollectionType.LockedElements && lockType != ConfigurationLockCollectionType.LockedAttributes || !(index == "*")) { ConfigurationProperty configurationProperty = this.Properties[index]; if (configurationProperty == null || index == "lockAttributes" || (index == "lockAllAttributesExcept" || index == "lockElements") || lockType != ConfigurationLockCollectionType.LockedElements && lockType != ConfigurationLockCollectionType.LockedElementsExceptionList && typeof (ConfigurationElement).IsAssignableFrom(configurationProperty.Type) || (lockType == ConfigurationLockCollectionType.LockedElements || lockType == ConfigurationLockCollectionType.LockedElementsExceptionList) && !typeof (ConfigurationElement).IsAssignableFrom(configurationProperty.Type)) { ConfigurationElementCollection elementCollection = this as ConfigurationElementCollection; if (elementCollection == null && this.Properties.DefaultCollectionProperty != null) elementCollection = this[this.Properties.DefaultCollectionProperty] as ConfigurationElementCollection; if (elementCollection == null || lockType == ConfigurationLockCollectionType.LockedAttributes || lockType == ConfigurationLockCollectionType.LockedExceptionList) this.ReportInvalidLock(index, lockType, value, (string) null); else if (!elementCollection.IsLockableElement(index)) this.ReportInvalidLock(index, lockType, value, elementCollection.LockableElements); } if (configurationProperty != null && configurationProperty.IsRequired) throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_base_required_attribute_lock_attempt", new object[1] { (object) configurationProperty.Name })); } configurationLockCollection.Add(index, ConfigurationValueFlags.Default); } } return configurationLockCollection; }
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(); } } } } } }
internal ConfigurationLockCollection UnMergeLockList( ConfigurationLockCollection sourceLockList, ConfigurationLockCollection parentLockList, ConfigurationSaveMode saveMode) { if (sourceLockList.ExceptionList == false) { switch (saveMode) { case ConfigurationSaveMode.Modified: { ConfigurationLockCollection tempLockList = new ConfigurationLockCollection(this, sourceLockList.LockType); foreach (string lockedAttributeName in sourceLockList) if (!parentLockList.Contains(lockedAttributeName) || sourceLockList.IsValueModified(lockedAttributeName)) { tempLockList.Add(lockedAttributeName, ConfigurationValueFlags.Default); } return tempLockList; } case ConfigurationSaveMode.Minimal: { ConfigurationLockCollection tempLockList = new ConfigurationLockCollection(this, sourceLockList.LockType); foreach (string lockedAttributeName in sourceLockList) if (!parentLockList.Contains(lockedAttributeName)) { tempLockList.Add(lockedAttributeName, ConfigurationValueFlags.Default); } return tempLockList; } } } else { // exception list write out the entire collection unless the entire collection // came from the parent. if (saveMode == ConfigurationSaveMode.Modified || saveMode == ConfigurationSaveMode.Minimal) { bool sameAsParent = false; if (sourceLockList.Count == parentLockList.Count) { sameAsParent = true; foreach (string lockedAttributeName in sourceLockList) { if (!parentLockList.Contains(lockedAttributeName) || (sourceLockList.IsValueModified(lockedAttributeName) && saveMode == ConfigurationSaveMode.Modified)) { sameAsParent = false; } } } if (sameAsParent == true) { return null; } } } return sourceLockList; }
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); } } } } } }
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); } } } } }
protected internal virtual void DeserializeElement(XmlReader reader, bool serializeCollectionKey) { ConfigurationPropertyCollection properties = this.Properties; ConfigurationValue value2 = null; ConfigurationValue value3 = null; ConfigurationValue value4 = null; ConfigurationValue value5 = null; bool flag = false; this._bElementPresent = true; ConfigurationElement element = null; ConfigurationProperty property = (properties != null) ? properties.DefaultCollectionProperty : null; if (property != null) { element = (ConfigurationElement) this[property]; } this._elementTagName = reader.Name; PropertySourceInfo sourceInfo = new PropertySourceInfo(reader); this._values.SetValue(reader.Name, null, ConfigurationValueFlags.Modified, sourceInfo); this._values.SetValue("", element, ConfigurationValueFlags.Modified, sourceInfo); if (((this._lockedElementsList != null) && (this._lockedElementsList.Contains(reader.Name) || (this._lockedElementsList.Contains("*") && (reader.Name != this.ElementTagName)))) || ((((this._lockedAllExceptElementsList != null) && (this._lockedAllExceptElementsList.Count != 0)) && !this._lockedAllExceptElementsList.Contains(reader.Name)) || (((this._fItemLocked & ConfigurationValueFlags.Locked) != ConfigurationValueFlags.Default) && ((this._fItemLocked & ConfigurationValueFlags.Inherited) != ConfigurationValueFlags.Default)))) { throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_base_element_locked", new object[] { reader.Name }), reader); } if (reader.AttributeCount > 0) { while (reader.MoveToNextAttribute()) { string name = reader.Name; if ((((this._lockedAttributesList != null) && (this._lockedAttributesList.Contains(name) || this._lockedAttributesList.Contains("*"))) || ((this._lockedAllExceptAttributesList != null) && !this._lockedAllExceptAttributesList.Contains(name))) && ((name != "lockAttributes") && (name != "lockAllAttributesExcept"))) { throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_base_attribute_locked", new object[] { name }), reader); } ConfigurationProperty prop = (properties != null) ? properties[name] : null; if (prop != null) { if (serializeCollectionKey && !prop.IsKey) { throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_base_unrecognized_attribute", new object[] { name }), reader); } this._values.SetValue(name, this.DeserializePropertyValue(prop, reader), ConfigurationValueFlags.Modified, new PropertySourceInfo(reader)); } else { if (name == "lockItem") { try { flag = bool.Parse(reader.Value); continue; } catch { throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_invalid_boolean_attribute", new object[] { name }), reader); } } if (name == "lockAttributes") { value2 = new ConfigurationValue(reader.Value, ConfigurationValueFlags.Default, new PropertySourceInfo(reader)); } else { if (name == "lockAllAttributesExcept") { value3 = new ConfigurationValue(reader.Value, ConfigurationValueFlags.Default, new PropertySourceInfo(reader)); continue; } if (name == "lockElements") { value4 = new ConfigurationValue(reader.Value, ConfigurationValueFlags.Default, new PropertySourceInfo(reader)); continue; } if (name == "lockAllElementsExcept") { value5 = new ConfigurationValue(reader.Value, ConfigurationValueFlags.Default, new PropertySourceInfo(reader)); continue; } if (serializeCollectionKey || !this.OnDeserializeUnrecognizedAttribute(name, reader.Value)) { throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_base_unrecognized_attribute", new object[] { name }), reader); } } } } } reader.MoveToElement(); try { HybridDictionary dictionary = new HybridDictionary(); if (!reader.IsEmptyElement) { while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element) { string elementName = reader.Name; this.CheckLockedElement(elementName, null); ConfigurationProperty property3 = (properties != null) ? properties[elementName] : null; if (property3 == null) { if (!this.OnDeserializeUnrecognizedElement(elementName, reader) && ((element == null) || !element.OnDeserializeUnrecognizedElement(elementName, reader))) { throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_base_unrecognized_element_name", new object[] { elementName }), reader); } } else { if (!property3.IsConfigurationElementType) { throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_base_property_is_not_a_configuration_element", new object[] { elementName }), reader); } if (dictionary.Contains(elementName)) { throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_base_element_cannot_have_multiple_child_elements", new object[] { elementName }), reader); } dictionary.Add(elementName, elementName); ConfigurationElement elem = (ConfigurationElement) this[property3]; elem.DeserializeElement(reader, serializeCollectionKey); ValidateElement(elem, property3.Validator, false); } } else { if (reader.NodeType == XmlNodeType.EndElement) { break; } if ((reader.NodeType == XmlNodeType.CDATA) || (reader.NodeType == XmlNodeType.Text)) { throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_base_section_invalid_content"), reader); } } } } this.EnsureRequiredProperties(serializeCollectionKey); ValidateElement(this, null, false); } catch (ConfigurationException exception) { if ((exception.Filename != null) && (exception.Filename.Length != 0)) { throw exception; } throw new ConfigurationErrorsException(exception.Message, reader); } if (flag) { this.SetLocked(); this._fItemLocked = ConfigurationValueFlags.Locked; } if (value2 != null) { if (this._lockedAttributesList == null) { this._lockedAttributesList = new ConfigurationLockCollection(this, ConfigurationLockCollectionType.LockedAttributes); } foreach (string str3 in this.ParseLockedAttributes(value2, ConfigurationLockCollectionType.LockedAttributes)) { if (!this._lockedAttributesList.Contains(str3)) { this._lockedAttributesList.Add(str3, ConfigurationValueFlags.Default); } else { this._lockedAttributesList.Add(str3, ConfigurationValueFlags.Modified | ConfigurationValueFlags.Inherited); } } } if (value3 != null) { ConfigurationLockCollection parentCollection = this.ParseLockedAttributes(value3, ConfigurationLockCollectionType.LockedExceptionList); if (this._lockedAllExceptAttributesList == null) { this._lockedAllExceptAttributesList = new ConfigurationLockCollection(this, ConfigurationLockCollectionType.LockedExceptionList, string.Empty, parentCollection); this._lockedAllExceptAttributesList.ClearSeedList(); } StringCollection strings = this.IntersectLockCollections(this._lockedAllExceptAttributesList, parentCollection); this._lockedAllExceptAttributesList.ClearInternal(false); foreach (string str4 in strings) { this._lockedAllExceptAttributesList.Add(str4, ConfigurationValueFlags.Default); } } if (value4 != null) { if (this._lockedElementsList == null) { this._lockedElementsList = new ConfigurationLockCollection(this, ConfigurationLockCollectionType.LockedElements); } ConfigurationLockCollection locks2 = this.ParseLockedAttributes(value4, ConfigurationLockCollectionType.LockedElements); ConfigurationElementCollection elements = null; if (properties.DefaultCollectionProperty != null) { elements = this[properties.DefaultCollectionProperty] as ConfigurationElementCollection; if ((elements != null) && (elements._lockedElementsList == null)) { elements._lockedElementsList = this._lockedElementsList; } } foreach (string str5 in locks2) { if (!this._lockedElementsList.Contains(str5)) { this._lockedElementsList.Add(str5, ConfigurationValueFlags.Default); ConfigurationProperty property4 = this.Properties[str5]; if ((property4 != null) && typeof(ConfigurationElement).IsAssignableFrom(property4.Type)) { ((ConfigurationElement) this[str5]).SetLocked(); } if (str5 == "*") { foreach (ConfigurationProperty property5 in this.Properties) { if (!string.IsNullOrEmpty(property5.Name) && property5.IsConfigurationElementType) { ((ConfigurationElement) this[property5]).SetLocked(); } } } } } } if (value5 != null) { ConfigurationLockCollection locks3 = this.ParseLockedAttributes(value5, ConfigurationLockCollectionType.LockedElementsExceptionList); if (this._lockedAllExceptElementsList == null) { this._lockedAllExceptElementsList = new ConfigurationLockCollection(this, ConfigurationLockCollectionType.LockedElementsExceptionList, this._elementTagName, locks3); this._lockedAllExceptElementsList.ClearSeedList(); } StringCollection strings2 = this.IntersectLockCollections(this._lockedAllExceptElementsList, locks3); ConfigurationElementCollection elements2 = null; if (properties.DefaultCollectionProperty != null) { elements2 = this[properties.DefaultCollectionProperty] as ConfigurationElementCollection; if ((elements2 != null) && (elements2._lockedAllExceptElementsList == null)) { elements2._lockedAllExceptElementsList = this._lockedAllExceptElementsList; } } this._lockedAllExceptElementsList.ClearInternal(false); foreach (string str6 in strings2) { if (!this._lockedAllExceptElementsList.Contains(str6) || (str6 == this.ElementTagName)) { this._lockedAllExceptElementsList.Add(str6, ConfigurationValueFlags.Default); } } foreach (ConfigurationProperty property6 in this.Properties) { if ((!string.IsNullOrEmpty(property6.Name) && !this._lockedAllExceptElementsList.Contains(property6.Name)) && property6.IsConfigurationElementType) { ((ConfigurationElement) this[property6]).SetLocked(); } } } if (property != null) { element = (ConfigurationElement) this[property]; if (this._lockedElementsList == null) { this._lockedElementsList = new ConfigurationLockCollection(this, ConfigurationLockCollectionType.LockedElements); } element._lockedElementsList = this._lockedElementsList; if (this._lockedAllExceptElementsList == null) { this._lockedAllExceptElementsList = new ConfigurationLockCollection(this, ConfigurationLockCollectionType.LockedElementsExceptionList, reader.Name); this._lockedAllExceptElementsList.ClearSeedList(); } element._lockedAllExceptElementsList = this._lockedAllExceptElementsList; } this.PostDeserialize(); }
private bool SerializeLockList(ConfigurationLockCollection list, string elementKey, XmlWriter writer) { StringBuilder builder = new StringBuilder(); if (list != null) { foreach (string str in list) { if (!list.DefinedInParent(str)) { if (builder.Length != 0) { builder.Append(','); } builder.Append(str); } } } if ((writer != null) && (builder.Length != 0)) { writer.WriteAttributeString(elementKey, builder.ToString()); } return (builder.Length != 0); }
internal ConfigurationLockCollection UnMergeLockList(ConfigurationLockCollection sourceLockList, ConfigurationLockCollection parentLockList, ConfigurationSaveMode saveMode) { if (!sourceLockList.ExceptionList) { switch (saveMode) { case ConfigurationSaveMode.Modified: ConfigurationLockCollection configurationLockCollection1 = new ConfigurationLockCollection(this, sourceLockList.LockType); foreach (string name in sourceLockList) { if (!parentLockList.Contains(name) || sourceLockList.IsValueModified(name)) configurationLockCollection1.Add(name, ConfigurationValueFlags.Default); } return configurationLockCollection1; case ConfigurationSaveMode.Minimal: ConfigurationLockCollection configurationLockCollection2 = new ConfigurationLockCollection(this, sourceLockList.LockType); foreach (string name in sourceLockList) { if (!parentLockList.Contains(name)) configurationLockCollection2.Add(name, ConfigurationValueFlags.Default); } return configurationLockCollection2; } } else if (saveMode == ConfigurationSaveMode.Modified || saveMode == ConfigurationSaveMode.Minimal) { bool flag = false; if (sourceLockList.Count == parentLockList.Count) { flag = true; foreach (string name in sourceLockList) { if (!parentLockList.Contains(name) || sourceLockList.IsValueModified(name) && saveMode == ConfigurationSaveMode.Modified) flag = false; } } if (flag) return (ConfigurationLockCollection) null; } return sourceLockList; }
internal ConfigurationLockCollection UnMergeLockList(ConfigurationLockCollection sourceLockList, ConfigurationLockCollection parentLockList, ConfigurationSaveMode saveMode) { if (!sourceLockList.ExceptionList) { switch (saveMode) { case ConfigurationSaveMode.Modified: { ConfigurationLockCollection locks = new ConfigurationLockCollection(this, sourceLockList.LockType); foreach (string str in sourceLockList) { if (!parentLockList.Contains(str) || sourceLockList.IsValueModified(str)) { locks.Add(str, ConfigurationValueFlags.Default); } } return locks; } case ConfigurationSaveMode.Minimal: { ConfigurationLockCollection locks2 = new ConfigurationLockCollection(this, sourceLockList.LockType); foreach (string str2 in sourceLockList) { if (!parentLockList.Contains(str2)) { locks2.Add(str2, ConfigurationValueFlags.Default); } } return locks2; } } return sourceLockList; } if ((saveMode == ConfigurationSaveMode.Modified) || (saveMode == ConfigurationSaveMode.Minimal)) { bool flag = false; if (sourceLockList.Count == parentLockList.Count) { flag = true; foreach (string str3 in sourceLockList) { if (!parentLockList.Contains(str3) || (sourceLockList.IsValueModified(str3) && (saveMode == ConfigurationSaveMode.Modified))) { flag = false; } } } if (flag) { return null; } } return sourceLockList; }
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(); } } } } } }
private StringCollection IntersectLockCollections(ConfigurationLockCollection Collection1, ConfigurationLockCollection Collection2) { ConfigurationLockCollection locks = (Collection1.Count < Collection2.Count) ? Collection1 : Collection2; ConfigurationLockCollection locks2 = (Collection1.Count >= Collection2.Count) ? Collection1 : Collection2; StringCollection strings = new StringCollection(); foreach (string str in locks) { if (locks2.Contains(str) || (str == this.ElementTagName)) { strings.Add(str); } } return strings; }
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; }
private ConfigurationLockCollection ParseLockedAttributes(ConfigurationValue value, ConfigurationLockCollectionType lockType) { ConfigurationLockCollection locks = new ConfigurationLockCollection(this, lockType); string str = (string) value.Value; if (string.IsNullOrEmpty(str)) { if (lockType == ConfigurationLockCollectionType.LockedAttributes) { throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Empty_attribute", new object[] { "lockAttributes" }), value.SourceInfo.FileName, value.SourceInfo.LineNumber); } if (lockType == ConfigurationLockCollectionType.LockedElements) { throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Empty_attribute", new object[] { "lockElements" }), value.SourceInfo.FileName, value.SourceInfo.LineNumber); } if (lockType == ConfigurationLockCollectionType.LockedExceptionList) { throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_empty_lock_attributes_except", new object[] { "lockAllAttributesExcept", "lockAttributes" }), value.SourceInfo.FileName, value.SourceInfo.LineNumber); } if (lockType == ConfigurationLockCollectionType.LockedElementsExceptionList) { throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_empty_lock_element_except", new object[] { "lockAllElementsExcept", "lockElements" }), value.SourceInfo.FileName, value.SourceInfo.LineNumber); } } foreach (string str2 in str.Split(new char[] { ',', ':', ';' })) { string str3 = str2.Trim(); if (!string.IsNullOrEmpty(str3)) { if (((lockType != ConfigurationLockCollectionType.LockedElements) && (lockType != ConfigurationLockCollectionType.LockedAttributes)) || (str3 != "*")) { ConfigurationProperty property = this.Properties[str3]; if (((((property == null) || (str3 == "lockAttributes")) || ((str3 == "lockAllAttributesExcept") || (str3 == "lockElements"))) || (((lockType != ConfigurationLockCollectionType.LockedElements) && (lockType != ConfigurationLockCollectionType.LockedElementsExceptionList)) && typeof(ConfigurationElement).IsAssignableFrom(property.Type))) || (((lockType == ConfigurationLockCollectionType.LockedElements) || (lockType == ConfigurationLockCollectionType.LockedElementsExceptionList)) && !typeof(ConfigurationElement).IsAssignableFrom(property.Type))) { ConfigurationElementCollection elements = this as ConfigurationElementCollection; if ((elements == null) && (this.Properties.DefaultCollectionProperty != null)) { elements = this[this.Properties.DefaultCollectionProperty] as ConfigurationElementCollection; } if (((elements == null) || (lockType == ConfigurationLockCollectionType.LockedAttributes)) || (lockType == ConfigurationLockCollectionType.LockedExceptionList)) { this.ReportInvalidLock(str3, lockType, value, null); } else if (!elements.IsLockableElement(str3)) { this.ReportInvalidLock(str3, lockType, value, elements.LockableElements); } } if ((property != null) && property.IsRequired) { throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_base_required_attribute_lock_attempt", new object[] { property.Name })); } } locks.Add(str3, ConfigurationValueFlags.Default); } } return locks; }
private bool SerializeLockList(ConfigurationLockCollection list, String elementKey, XmlWriter writer) { StringBuilder sb; sb = new StringBuilder(); if (list != null) { foreach (string key in list) { if (!list.DefinedInParent(key)) { if (sb.Length != 0) sb.Append(','); sb.Append((string)key); } } } if (writer != null && sb.Length != 0) writer.WriteAttributeString(elementKey, sb.ToString()); return (sb.Length != 0); }