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) { _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) { _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) { 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) { 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 void ReportInvalidLock(string attribToLockTrim, ConfigurationLockCollectionType lockedType, ConfigurationValue value, string collectionProperties) { StringBuilder builder = new StringBuilder(); if (!string.IsNullOrEmpty(collectionProperties) && ((lockedType == ConfigurationLockCollectionType.LockedElements) || (lockedType == ConfigurationLockCollectionType.LockedElementsExceptionList))) { if (builder.Length != 0) { builder.Append(','); } builder.Append(collectionProperties); } foreach (object obj2 in this.Properties) { ConfigurationProperty property = (ConfigurationProperty) obj2; if (((property.Name != "lockAttributes") && (property.Name != "lockAllAttributesExcept")) && ((property.Name != "lockElements") && (property.Name != "lockAllElementsExcept"))) { if ((lockedType == ConfigurationLockCollectionType.LockedElements) || (lockedType == ConfigurationLockCollectionType.LockedElementsExceptionList)) { if (typeof(ConfigurationElement).IsAssignableFrom(property.Type)) { if (builder.Length != 0) { builder.Append(", "); } builder.Append("'"); builder.Append(property.Name); builder.Append("'"); } } else if (!typeof(ConfigurationElement).IsAssignableFrom(property.Type)) { if (builder.Length != 0) { builder.Append(", "); } builder.Append("'"); builder.Append(property.Name); builder.Append("'"); } } } string format = null; if ((lockedType == ConfigurationLockCollectionType.LockedElements) || (lockedType == ConfigurationLockCollectionType.LockedElementsExceptionList)) { if (value != null) { format = System.Configuration.SR.GetString("Config_base_invalid_element_to_lock"); } else { format = System.Configuration.SR.GetString("Config_base_invalid_element_to_lock_by_add"); } } else if (value != null) { format = System.Configuration.SR.GetString("Config_base_invalid_attribute_to_lock"); } else { format = System.Configuration.SR.GetString("Config_base_invalid_attribute_to_lock_by_add"); } if (value != null) { throw new ConfigurationErrorsException(string.Format(CultureInfo.CurrentCulture, format, new object[] { attribToLockTrim, builder.ToString() }), value.SourceInfo.FileName, value.SourceInfo.LineNumber); } throw new ConfigurationErrorsException(string.Format(CultureInfo.CurrentCulture, format, new object[] { attribToLockTrim, builder.ToString() })); }
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 ConfigurationLockCollection ParseLockedAttributes(ConfigurationValue value, ConfigurationLockCollectionType lockType) { // check that only actual properties are in the lock attribute ConfigurationLockCollection localLockedAttributesList = new ConfigurationLockCollection(this, lockType); string attributeList = (string)(value.Value); if (string.IsNullOrEmpty(attributeList)) { if (lockType == ConfigurationLockCollectionType.LockedAttributes) throw new ConfigurationErrorsException(SR.GetString(SR.Empty_attribute, LockAttributesKey), value.SourceInfo.FileName, value.SourceInfo.LineNumber); if (lockType == ConfigurationLockCollectionType.LockedElements) throw new ConfigurationErrorsException(SR.GetString(SR.Empty_attribute, LockElementsKey), value.SourceInfo.FileName, value.SourceInfo.LineNumber); if (lockType == ConfigurationLockCollectionType.LockedExceptionList) throw new ConfigurationErrorsException(SR.GetString(SR.Config_empty_lock_attributes_except, LockAllAttributesExceptKey, LockAttributesKey), value.SourceInfo.FileName, value.SourceInfo.LineNumber); if (lockType == ConfigurationLockCollectionType.LockedElementsExceptionList) throw new ConfigurationErrorsException(SR.GetString(SR.Config_empty_lock_element_except, LockAllElementsExceptKey, LockElementsKey), value.SourceInfo.FileName, value.SourceInfo.LineNumber); } string[] attribsToLock = attributeList.Split(new char[] { ',', ':', ';' }); foreach (string attribToLock in attribsToLock) { string attribToLockTrim = attribToLock.Trim(); if (!String.IsNullOrEmpty(attribToLockTrim)) { // validate that the locks are good if (!((lockType == ConfigurationLockCollectionType.LockedElements || lockType == ConfigurationLockCollectionType.LockedAttributes) && attribToLockTrim == LockAll)) { ConfigurationProperty propToLock = Properties[attribToLockTrim]; if (propToLock == null || // if the prop does not exist attribToLockTrim == LockAttributesKey || // or it is the lockattributes keyword attribToLockTrim == LockAllAttributesExceptKey || // or it is the lockattributes keyword attribToLockTrim == LockElementsKey || // or it is the lockelements keyword (lockType != ConfigurationLockCollectionType.LockedElements && lockType != ConfigurationLockCollectionType.LockedElementsExceptionList && typeof(ConfigurationElement).IsAssignableFrom(propToLock.Type)) || // or if not locking elements but the property is a element ((lockType == ConfigurationLockCollectionType.LockedElements || lockType == ConfigurationLockCollectionType.LockedElementsExceptionList) && !typeof(ConfigurationElement).IsAssignableFrom(propToLock.Type)) // or if locking elements but the property is not an element ) { // check to see if this is a collection and we are locking a collection element ConfigurationElementCollection collection = this as ConfigurationElementCollection; if (collection == null && Properties.DefaultCollectionProperty != null) // this is not a collection but it may contain a default collection { collection = this[Properties.DefaultCollectionProperty] as ConfigurationElementCollection; } if (collection == null || lockType == ConfigurationLockCollectionType.LockedAttributes || // If the collection type is not element then the lock is bogus lockType == ConfigurationLockCollectionType.LockedExceptionList) { ReportInvalidLock(attribToLockTrim, lockType, value, null); } else if (!collection.IsLockableElement(attribToLockTrim)) { ReportInvalidLock(attribToLockTrim, lockType, value, collection.LockableElements); } } if (propToLock != null && propToLock.IsRequired == true) throw new ConfigurationErrorsException(SR.GetString(SR.Config_base_required_attribute_lock_attempt, propToLock.Name)); } // concatenate the new attribute. localLockedAttributesList.Add(attribToLockTrim, ConfigurationValueFlags.Default); // Mark as local } } return localLockedAttributesList; }
internal void ReportInvalidLock(string attribToLockTrim, ConfigurationLockCollectionType lockedType, ConfigurationValue value, String collectionProperties) { StringBuilder sb; sb = new StringBuilder(); // Add the collection properties when locking elements if (!String.IsNullOrEmpty(collectionProperties) && ((lockedType == ConfigurationLockCollectionType.LockedElements) || (lockedType == ConfigurationLockCollectionType.LockedElementsExceptionList))) { if (sb.Length != 0) sb.Append(','); sb.Append(collectionProperties); } // construct a list of valid lockable properties foreach (object _prop in Properties) { ConfigurationProperty validProp = (ConfigurationProperty)_prop; if (validProp.Name != LockAttributesKey && validProp.Name != LockAllAttributesExceptKey && validProp.Name != LockElementsKey && validProp.Name != LockAllElementsExceptKey ) { if ((lockedType == ConfigurationLockCollectionType.LockedElements) || (lockedType == ConfigurationLockCollectionType.LockedElementsExceptionList)) { if (typeof(ConfigurationElement).IsAssignableFrom(validProp.Type)) { if (sb.Length != 0) sb.Append(", "); sb.Append("'"); sb.Append(validProp.Name); sb.Append("'"); } } else { if (!typeof(ConfigurationElement).IsAssignableFrom(validProp.Type)) { if (sb.Length != 0) sb.Append(", "); sb.Append("'"); sb.Append(validProp.Name); sb.Append("'"); } } } } string format = null; if ((lockedType == ConfigurationLockCollectionType.LockedElements) || (lockedType == ConfigurationLockCollectionType.LockedElementsExceptionList)) { if (value != null) format = SR.GetString(SR.Config_base_invalid_element_to_lock); else format = SR.GetString(SR.Config_base_invalid_element_to_lock_by_add); } else { if (value != null) format = SR.GetString(SR.Config_base_invalid_attribute_to_lock); else format = SR.GetString(SR.Config_base_invalid_attribute_to_lock_by_add); } if (value != null) throw new ConfigurationErrorsException(string.Format(CultureInfo.CurrentCulture, format, attribToLockTrim, sb.ToString()), value.SourceInfo.FileName, value.SourceInfo.LineNumber); else throw new ConfigurationErrorsException(string.Format(CultureInfo.CurrentCulture, format, attribToLockTrim, sb.ToString())); }
internal ConfigurationLockCollection(ConfigurationElement thisElement, ConfigurationLockCollectionType lockType, string ignoreName) : this(thisElement, lockType, ignoreName, null) { }
internal ConfigurationLockCollection(ConfigurationElement thisElement, ConfigurationLockCollectionType lockType) : this(thisElement, lockType, string.Empty) { }
internal ConfigurationLockCollection(ConfigurationElement thisElement, ConfigurationLockCollectionType lockType, string ignoreName) : this(thisElement, lockType, ignoreName, null) { }
internal ConfigurationLockCollection(ConfigurationElement thisElement, ConfigurationLockCollectionType lockType) : this(thisElement, lockType, string.Empty) { }
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 ReportInvalidLock(string attribToLockTrim, ConfigurationLockCollectionType lockedType, ConfigurationValue value, string collectionProperties) { StringBuilder stringBuilder = new StringBuilder(); if (!string.IsNullOrEmpty(collectionProperties) && (lockedType == ConfigurationLockCollectionType.LockedElements || lockedType == ConfigurationLockCollectionType.LockedElementsExceptionList)) { if (stringBuilder.Length != 0) stringBuilder.Append(','); stringBuilder.Append(collectionProperties); } foreach (ConfigurationProperty configurationProperty in this.Properties) { if (configurationProperty.Name != "lockAttributes" && configurationProperty.Name != "lockAllAttributesExcept" && (configurationProperty.Name != "lockElements" && configurationProperty.Name != "lockAllElementsExcept")) { if (lockedType == ConfigurationLockCollectionType.LockedElements || lockedType == ConfigurationLockCollectionType.LockedElementsExceptionList) { if (typeof (ConfigurationElement).IsAssignableFrom(configurationProperty.Type)) { if (stringBuilder.Length != 0) stringBuilder.Append(", "); stringBuilder.Append("'"); stringBuilder.Append(configurationProperty.Name); stringBuilder.Append("'"); } } else if (!typeof (ConfigurationElement).IsAssignableFrom(configurationProperty.Type)) { if (stringBuilder.Length != 0) stringBuilder.Append(", "); stringBuilder.Append("'"); stringBuilder.Append(configurationProperty.Name); stringBuilder.Append("'"); } } } string format = lockedType == ConfigurationLockCollectionType.LockedElements || lockedType == ConfigurationLockCollectionType.LockedElementsExceptionList ? (value == null ? System.Configuration.SR.GetString("Config_base_invalid_element_to_lock_by_add") : System.Configuration.SR.GetString("Config_base_invalid_element_to_lock")) : (value == null ? System.Configuration.SR.GetString("Config_base_invalid_attribute_to_lock_by_add") : System.Configuration.SR.GetString("Config_base_invalid_attribute_to_lock")); if (value != null) throw new ConfigurationErrorsException(string.Format((IFormatProvider) CultureInfo.CurrentCulture, format, new object[2] { (object) attribToLockTrim, (object) ((object) stringBuilder).ToString() }), value.SourceInfo.FileName, value.SourceInfo.LineNumber); else throw new ConfigurationErrorsException(string.Format((IFormatProvider) CultureInfo.CurrentCulture, format, new object[2] { (object) attribToLockTrim, (object) ((object) stringBuilder).ToString() })); }