Inheritance: ConfigurationElement, ICollection, IEnumerable
Exemple #1
0
        internal override void Execute(ConfigurationElementCollection collection)
        {
            if (!(collection is OracleSettingsCollection))
            {
                throw new ArgumentException("setting must be a OracleSettingsCollection");
            }

            foreach (var settings in collection.Cast<OracleSettings>())
            {
                using (var connection = GetConnection(ConnectionStringTemplate, settings.TnsData, settings.UserID, settings.Password))
                {
                    connection.Open();

                    Console.WriteLine("Executing commands on " + settings);

                    int count = ExecuteCommandsFromTemplate(connection, CreateDropTableCommandString);
                    count += ExecuteCommandsFromTemplate(connection, CreateDropIndexCommandString);
                    count += ExecuteCommandsFromTemplate(connection, CreateDropSequenceCommandString);
                    count += ExecuteCommandsFromTemplate(connection, CreateDropTriggerString);

                    Console.WriteLine("Finished executing commands. There were {0} operations.", count);

                    if (count > 0)
                    {
                        Console.WriteLine("Purging recycle bin");
                        ExecuteNonQuery(connection, PurgeRecycleBin);
                    }

                    connection.Close();
                }
            }

            Console.Write("Press any key to continue . . . ");
            Console.ReadKey(true);
        }
Exemple #2
0
        internal override void Execute(ConfigurationElementCollection collection)
        {
            if (!(collection is MsSqlSettingsCollection))
            {
                throw new ArgumentException("collection must be a MsSqlSettingsCollection");
            }

            foreach (var settings in collection.Cast<MsSqlSettings>())
            {
                using (var connection = GetConnection(ConnectionStringTemplate, settings.DataSource, settings.Catalog, settings.UserID, settings.Password))
                {
                    connection.Open();

                    Console.WriteLine("Executing commands on " + settings);

                    int count = ExecuteCommandsFromTemplate(connection, CreateDropTableCommandString);

                    Console.WriteLine("Finished executing commands. There were {0} operations.", count);

                    connection.Close();
                }
            }

            Console.Write("Press any key to continue . . . ");
            Console.ReadKey(true);
        }
			internal ConfigurationRemoveElement (ConfigurationElement origElement, ConfigurationElementCollection origCollection)
			{
				_origElement = origElement;
				_origCollection = origCollection;

				foreach (ConfigurationProperty p in origElement.Properties)
					if (p.IsKey) {
						properties.Add (p);
					}
			}
        void CheckName(string name)
        {
            bool isAttribute = (lockType & ConfigurationLockType.Attribute) == ConfigurationLockType.Attribute;

            if (valid_name_hash == null)
            {
                valid_name_hash = new Hashtable();
                foreach (ConfigurationProperty prop in element.Properties)
                {
                    if (isAttribute == prop.IsElement)
                    {
                        continue;
                    }
                    valid_name_hash.Add(prop.Name, true);
                }

                /* add the add/remove/clear names of the
                 * default collection if there is one */
                if (!isAttribute)
                {
                    ConfigurationElementCollection c = element.GetDefaultCollection();
                    valid_name_hash.Add(c.AddElementName, true);
                    valid_name_hash.Add(c.ClearElementName, true);
                    valid_name_hash.Add(c.RemoveElementName, true);
                }

                string[] valid_name_array = new string[valid_name_hash.Keys.Count];
                valid_name_hash.Keys.CopyTo(valid_name_array, 0);

                valid_names = String.Join(",", valid_name_array);
            }

            if (valid_name_hash [name] == null)
            {
                throw new ConfigurationErrorsException(
                          String.Format("The {2} '{0}' is not valid in the locked list for this section.  The following {3} can be locked: '{1}'",
                                        name, valid_names, isAttribute ? "attribute" : "element", isAttribute ? "attributes" : "elements"));
            }
        }
        ///<summary>
        /// Creates a <see cref="IMergeableConfigurationElementCollection"/> based on a ConfigurationElementCollection type.
        ///</summary>
        ///<param name="collection"></param>
        ///<returns></returns>
        public static IMergeableConfigurationElementCollection GetCreateMergeableCollection(ConfigurationElementCollection collection)
        {
            if (collection is IMergeableConfigurationElementCollection)
            {
                return (IMergeableConfigurationElementCollection)collection;
            }
            else if (collection is ConnectionStringSettingsCollection)
            {
                return new MergeableConnectionStringSettingsCollection((ConnectionStringSettingsCollection)collection);
            }
            else if (collection is KeyValueConfigurationCollection)
            {
                return new MergeableKeyValueConfigurationCollection((KeyValueConfigurationCollection)collection);
            }

            var mergeableConfigurationCollectionAttribute = TypeDescriptor.GetAttributes(collection).OfType<MergeableConfigurationCollectionTypeAttribute>().FirstOrDefault();
            if (mergeableConfigurationCollectionAttribute != null)
            {
                return Activator.CreateInstance(mergeableConfigurationCollectionAttribute.MergeableConfigurationCollectionType, collection) as IMergeableConfigurationElementCollection;
            }

            return null;
        }
            static internal ConfigurationElement FindElement(ConfigurationElementCollection collection, string attributeName, string value)
            {
                foreach (ConfigurationElement element in collection)
                {
                    if (String.Equals((string)element[attributeName], value, StringComparison.OrdinalIgnoreCase))
                    {
                        return element;
                    }
                }

                return null;
            }
Exemple #7
0
        protected internal virtual void DeserializeElement(XmlReader reader, bool serializeCollectionKey)
        {
            Hashtable readProps = new Hashtable();

            reader.MoveToContent();
            elementPresent = true;

            while (reader.MoveToNextAttribute())
            {
                PropertyInformation prop = ElementInformation.Properties [reader.LocalName];
                if (prop == null || (serializeCollectionKey && !prop.IsKey))
                {
                    /* handle the built in ConfigurationElement attributes here */
                    if (reader.LocalName == "lockAllAttributesExcept")
                    {
                        LockAllAttributesExcept.SetFromList(reader.Value);
                    }
                    else if (reader.LocalName == "lockAllElementsExcept")
                    {
                        LockAllElementsExcept.SetFromList(reader.Value);
                    }
                    else if (reader.LocalName == "lockAttributes")
                    {
                        LockAttributes.SetFromList(reader.Value);
                    }
                    else if (reader.LocalName == "lockElements")
                    {
                        LockElements.SetFromList(reader.Value);
                    }
                    else if (reader.LocalName == "lockItem")
                    {
                        LockItem = (reader.Value.ToLowerInvariant() == "true");
                    }
                    else if (reader.LocalName == "xmlns")
                    {
                        /* ignore */
                    }
                    else if (this is ConfigurationSection && reader.LocalName == "configSource")
                    {
                        /* ignore */
                    }
                    else if (!OnDeserializeUnrecognizedAttribute(reader.LocalName, reader.Value))
                    {
                        throw new ConfigurationErrorsException("Unrecognized attribute '" + reader.LocalName + "'.", reader);
                    }

                    continue;
                }

                if (readProps.ContainsKey(prop))
                {
                    throw new ConfigurationErrorsException("The attribute '" + prop.Name + "' may only appear once in this element.", reader);
                }

                string value = null;
                try {
                    value = reader.Value;
                    ValidateValue(prop.Property, value);
                    prop.SetStringValue(value);
                } catch (ConfigurationErrorsException) {
                    throw;
                } catch (ConfigurationException) {
                    throw;
                } catch (Exception ex) {
                    string msg = String.Format("The value for the property '{0}' is not valid. The error is: {1}", prop.Name, ex.Message);
                    throw new ConfigurationErrorsException(msg, reader);
                }
                readProps [prop] = prop.Name;

                ConfigXmlTextReader _reader = reader as ConfigXmlTextReader;
                if (_reader != null)
                {
                    prop.Source     = _reader.Filename;
                    prop.LineNumber = _reader.LineNumber;
                }
            }

            reader.MoveToElement();
            if (reader.IsEmptyElement)
            {
                reader.Skip();
            }
            else
            {
                int depth = reader.Depth;

                reader.ReadStartElement();
                reader.MoveToContent();

                do
                {
                    if (reader.NodeType != XmlNodeType.Element)
                    {
                        reader.Skip();
                        continue;
                    }

                    PropertyInformation prop = ElementInformation.Properties [reader.LocalName];
                    if (prop == null || (serializeCollectionKey && !prop.IsKey))
                    {
                        if (!OnDeserializeUnrecognizedElement(reader.LocalName, reader))
                        {
                            if (prop == null)
                            {
                                ConfigurationElementCollection c = GetDefaultCollection();
                                if (c != null && c.OnDeserializeUnrecognizedElement(reader.LocalName, reader))
                                {
                                    continue;
                                }
                            }
                            throw new ConfigurationErrorsException("Unrecognized element '" + reader.LocalName + "'.", reader);
                        }
                        continue;
                    }

                    if (!prop.IsElement)
                    {
                        throw new ConfigurationErrorsException("Property '" + prop.Name + "' is not a ConfigurationElement.");
                    }

                    if (readProps.Contains(prop))
                    {
                        throw new ConfigurationErrorsException("The element <" + prop.Name + "> may only appear once in this section.", reader);
                    }

                    ConfigurationElement val = (ConfigurationElement)prop.Value;
                    val.DeserializeElement(reader, serializeCollectionKey);
                    readProps [prop] = prop.Name;

                    if (depth == reader.Depth)
                    {
                        reader.Read();
                    }
                } while (depth < reader.Depth);
            }

            modified = false;

            foreach (PropertyInformation prop in ElementInformation.Properties)
            {
                if (!String.IsNullOrEmpty(prop.Name) && prop.IsRequired && !readProps.ContainsKey(prop))
                {
                    PropertyInformation p = ElementInformation.Properties [prop.Name];
                    if (p == null)
                    {
                        object val = OnRequiredPropertyNotFound(prop.Name);
                        if (!object.Equals(val, prop.DefaultValue))
                        {
                            prop.Value      = val;
                            prop.IsModified = false;
                        }
                    }
                }
            }

            PostDeserialize();
        }
            public ConfigurationElementCollectionMerge(ConfigurationElementCollection parentCollection, ConfigurationElementCollection localCollection)
            {
                this.parentCollection = parentCollection;
                
                ConfigurationElementMerge elementMerge = new ConfigurationElementMerge(parentCollection, localCollection);
                this.localCollection = (ConfigurationElementCollection) elementMerge.GetMergedElement();

                this.mergeableLocalElement = MergeableConfigurationCollectionFactory.GetCreateMergeableCollection(localCollection);

                //TODO : what to do around: localCollection.CollectionType
            }
 /// <summary>
 ///   Looks up a source element given the parent element collection and expected name and, assuming it's enabled,
 ///   identifies the source value.
 /// </summary>
 /// <param name="parent">The parent <see cref="ConfigurationElementCollection"/>.</param>
 /// <param name="key">The string key (expected name).</param>
 /// <returns>The target value, or null if one is not found.</returns>
 public static string GetValue(ConfigurationElementCollection parent, string key)
 {
     return GetValue(GetElement(parent, key));
 }
Exemple #10
0
 /// <summary>
 ///   Determines whether the specified element is trusted, using the parent element collection and expected element name to
 ///   find the element.
 /// </summary>
 /// <param name="parent">The parent <see cref="ConfigurationElementCollection"/>.</param>
 /// <param name="key">The string key (expected name).</param>
 /// <returns>
 ///   Boolean value representing whether the specified element is available.
 /// </returns>
 public static bool IsTrusted(ConfigurationElementCollection parent, string key)
 {
     return IsTrusted(GetElement(parent, key));
 }
Exemple #11
0
 /// <summary>
 ///   Gets the source element given the parent element collection and expected name.
 /// </summary>
 /// <param name="parent">The parent <see cref="ConfigurationElementCollection"/>.</param>
 /// <param name="key">The string key (expected name).</param>
 /// <returns>The matching source configuration element, or null if not found.</returns>
 public static SourceElement GetElement(ConfigurationElementCollection parent, string key)
 {
     if (parent == null) return null;
       foreach (SourceElement source in parent) {
     if (source.Source.Equals(key)) {
       return source;
     }
       }
       return null;
 }
 internal Enumerator(ArrayList items, ConfigurationElementCollection collection)
 {
     this._itemsEnumerator = items.GetEnumerator();
     this.ThisCollection = collection;
 }
Exemple #13
0
        public void Add(string name)
        {
            if (((_thisElement.ItemLocked & ConfigurationValueFlags.Locked) != 0) &&
                ((_thisElement.ItemLocked & ConfigurationValueFlags.Inherited) != 0))
            {
                throw new ConfigurationErrorsException(SR.Format(SR.Config_base_attribute_locked, name));
            }

            ConfigurationValueFlags flags = ConfigurationValueFlags.Modified;

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

            if ((propToLock == null) && (attribToLockTrim != LockAll))
            {
                ConfigurationElementCollection collection = _thisElement as ConfigurationElementCollection;
                if ((collection == null) && (_thisElement.Properties.DefaultCollectionProperty != null))
                {
                    // this is not a collection but it may contain a default collection
                    collection =
                        _thisElement[_thisElement.Properties.DefaultCollectionProperty] as
                        ConfigurationElementCollection;
                }

                if ((collection == null) ||
                    (LockType == ConfigurationLockCollectionType.LockedAttributes) ||
                    // If the collection type is not element then the lock is bogus
                    (LockType == ConfigurationLockCollectionType.LockedExceptionList))
                {
                    _thisElement.ReportInvalidLock(attribToLockTrim, LockType, null, null);
                }
                else
                {
                    if (!collection.IsLockableElement(attribToLockTrim))
                    {
                        _thisElement.ReportInvalidLock(attribToLockTrim, LockType, null, collection.LockableElements);
                    }
                }
            }
            else
            {
                // the lock is in the property bag but is it the correct type?
                if ((propToLock != null) && propToLock.IsRequired)
                {
                    throw new ConfigurationErrorsException(SR.Format(SR.Config_base_required_attribute_lock_attempt,
                                                                     propToLock.Name));
                }

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

            if (_internalDictionary.Contains(name))
            {
                flags = ConfigurationValueFlags.Modified | (ConfigurationValueFlags)_internalDictionary[name];
                _internalDictionary.Remove(name); // not from parent
                _internalArraylist.Remove(name);
            }
            _internalDictionary.Add(name, flags); // not from parent
            _internalArraylist.Add(name);
            IsModified = true;
        }
        /// <summary> 讀取 ConfigurationElementCollection </summary>
        private void ReadConfigCollection(StringBuilder sb, ConfigurationElementCollection collection)
        {
            foreach (Argument item in collection)
            {
                if (item.Option)
                    continue;

                sb.Append(item.Key);
                if (!String.IsNullOrEmpty(item.Value))
                    sb.Append(" " + item.Value);
                sb.Append(" ");
            }
        }
Exemple #15
0
		internal ConfigurationElementCollection GetDefaultCollection ()
		{
			if (defaultCollection != null) return defaultCollection;

			ConfigurationProperty defaultCollectionProp = null;

			foreach (ConfigurationProperty prop in Properties) {
				if (prop.IsDefaultCollection) {
					defaultCollectionProp = prop;
					break;
				}
			}

			if (defaultCollectionProp != null) {
				defaultCollection = this [defaultCollectionProp] as ConfigurationElementCollection;
			}

			return defaultCollection;
		}
 static void AddQueryCollection(Collection<TrackingQuery> queries, ConfigurationElementCollection elements)
 {
     foreach (TrackingQueryElement queryElement in elements)
     {
         queries.Add(queryElement.CreateTrackingQuery());
     }
 }
        /// <summary>
        /// Get a list of YouTube providerConfig configurations from Web.config.
        /// </summary>
        private List<YouTubeProvider> GetYouTubeProvidersFromConfig(ConfigurationElementCollection youTubeProviderConfigs)
        {
            if (youTubeProviderConfigs.Count > 0)
            {
                var youTubeProviders = new List<YouTubeProvider>();
                foreach (YouTubeProviderConfig entry in youTubeProviderConfigs)
                {
                    youTubeProviders.Add(new YouTubeProvider(entry));
                }

                return youTubeProviders;
            }

            return new List<YouTubeProvider>();
            //{
            //    new YouTubeProvider("ITV1", 5),
            //    new YouTubeProvider("paulsoaresjr", 5)
            //};
        }
        /// <summary>
        /// Get a list of Twitter providerConfig configurations from Web.config.
        /// </summary>
        private List<TwitterProvider> GetTwitterProvidersFromConfig(ConfigurationElementCollection twitterProviderConfigs)
        {
            if (twitterProviderConfigs.Count > 0)
            {
                var twitterProviders = new List<TwitterProvider>();
                foreach (TwitterProviderConfig entry in twitterProviderConfigs)
                {
                    twitterProviders.Add(new TwitterProvider(entry));
                }

                return twitterProviders;
            }

            return new List<TwitterProvider>();
            //{
            //    new TwitterProvider("ITV", 20, true, true),
            //    new TwitterProvider("BigReunionITV", 20, true, true),
            //    new TwitterProvider("ITV2", 20, true, true)
            //};
        }
 internal Entry(ConfigurationElementCollection.EntryType type, object key, ConfigurationElement value)
 {
     this._entryType = type;
     this._key = key;
     this._value = value;
 }
Exemple #20
0
 /// <summary>
 ///   Looks up a source element at a given location and based on a specified parent configuration elemnt collection and 
 ///   the target element's key, identifies the source value, and verifies whether the element is available, enabled, or
 ///   set to true.
 /// </summary>
 /// <param name="parent">The parent <see cref="ConfigurationElementCollection"/>.</param>
 /// <param name="key">The string key (expected name).</param>
 /// <returns>
 ///   A boolean value representing whether or not the source is available, enabled or set to true.
 /// </returns>
 public static bool IsEnabled(ConfigurationElementCollection parent, string key)
 {
     return IsEnabled(parent, key, false);
 }
 internal object GetKey(ConfigurationElementCollection ThisCollection)
 {
     if (this._value != null)
     {
         return ThisCollection.GetElementKeyInternal(this._value);
     }
     return this._key;
 }
Exemple #22
0
 /// <summary>
 ///   Looks up a source element at a given location and based on a specified parent configuration elemnt collection and 
 ///   the target element's key, identifies the source value, and verifies whether the element is available, enabled, or
 ///   set to true.
 /// </summary>
 /// <param name="parent">The parent <see cref="ConfigurationElementCollection"/>.</param>
 /// <param name="key">The string key (expected name).</param>
 /// <param name="evaluateValue">Boolean indicator noting whether to use the Value to determine enabled status.</param>
 /// <returns>
 ///   Boolean value representing whether or not the source is available, enabled or set to true.
 /// </returns>
 public static bool IsEnabled(ConfigurationElementCollection parent, string key, bool evaluateValue)
 {
     return IsEnabled(GetElement(parent, key), evaluateValue);
 }
 internal Object GetKey(ConfigurationElementCollection ThisCollection)
 {
     // For items that have been really inserted...
     if (_value != null)
     {
         return ThisCollection.GetElementKeyInternal(_value);
     }
     else
     {
         return _key; // These are items that only have been removed
     }
 }
 /// <summary>
 /// Gets the list of filters that are defined per action
 /// </summary>
 public ConfigurationElementCollection<FilterElement> GetActionFilters(string controllerName, string actionName)
 {
     lock (_actionFiltersLock)
     {
         if (_actionFilters == null)
         {
             _actionFilters = new Dictionary<string, ConfigurationElementCollection<FilterElement>>();
             var filters = Filters.Where(f => (!String.IsNullOrEmpty(f.Controller)) && (!String.IsNullOrEmpty(f.Action)));
             foreach (var f in filters)
             {
                 var collection = new ConfigurationElementCollection<FilterElement>();
                 var key = GetActionFilterKey(f.Controller, f.Action);
                 if (_actionFilters.ContainsKey(key))
                 {
                     collection = _actionFilters[key];
                 }
                 else
                 {
                     _actionFilters.Add(key, collection);
                 }
                 collection.Add(f);
             }
         }
     }
     ConfigurationElementCollection<FilterElement> result  = null;
     if (_actionFilters.ContainsKey(GetActionFilterKey(controllerName, actionName)))
     {
         result = _actionFilters[GetActionFilterKey(controllerName, actionName)];
     }
     return result;
 }
 public void SetConfigurationElementCollectionReadOnlyBit(ConfigurationElementCollection target, bool value)
 {
     CommonReflectionUtil.WriteField(this._fi_ConfigurationElementCollection_bReadOnly, target, value);
 }
        private static ConfigurationElementCollection CloneCollection(ConfigurationElementCollection sourceCollection, ConfigurationElementCollection targetCollection)
        {
            targetCollection = (ConfigurationElementCollection)CloneElement(sourceCollection, targetCollection);
            
            IMergeableConfigurationElementCollection mergeableSource = MergeableConfigurationCollectionFactory.GetCreateMergeableCollection(sourceCollection);
            IMergeableConfigurationElementCollection mergeableTarget = MergeableConfigurationCollectionFactory.GetCreateMergeableCollection(targetCollection);

            if (mergeableSource == null) return targetCollection;

            List<ConfigurationElement> targetCollectionContents = new List<ConfigurationElement>();

            foreach (ConfigurationElement sourceElement in sourceCollection)
            {
                ConfigurationElement targetElement;
                targetElement = CreateCopyOfCollectionElement(mergeableSource, sourceElement);
                targetElement = CloneElement(sourceElement, targetElement);

                targetCollectionContents.Add(targetElement);
            }

            mergeableTarget.ResetCollection(targetCollectionContents);

            targetCollection.EmitClear = sourceCollection.EmitClear;
            return targetCollection;
        }
Exemple #27
0
 internal abstract void Execute(ConfigurationElementCollection settings);
 internal object GetKey(ConfigurationElementCollection thisCollection)
 {
     // For items that have been really inserted...
     return Value != null ? thisCollection.GetElementKeyInternal(Value) : _key;
 }