internal AutoConfigurationHelper(ConfigurationElement element, Action<ConfigurationProperty, object> valueSetter, Func<ConfigurationProperty, object> valueGetter)
        {
            _ConfigElement = element;
            _ValueSetter = valueSetter;
            _ValueGetter = valueGetter;

            var type = element.GetType();
            Dictionary<ConfigurationProperty, PropertyInfo> properties;
            if (!_TypeProperties.TryGetValue(type, out properties))
            {
                properties = new Dictionary<ConfigurationProperty, PropertyInfo>();
                foreach (var member in type.GetProperties())
                {
                    var configField = member.GetCustomAttributes(typeof(ConfigurationPropertyAttribute), true).Cast<ConfigurationPropertyAttribute>().FirstOrDefault();
                    if (configField != null)
                    {
                        var property = new ConfigurationProperty(configField.Name, member.PropertyType, configField.DefaultValue, ConfigurationPropertyOptions.None);
                        properties[property] = member;
                    }
                }
                _TypeProperties.TryAdd(type, properties);
            }
            _Properties = properties;

            // Pre-initialize properties of type ConfigurationElement, or things go boom
            foreach (var property in _Properties)
            {
                if (typeof(ConfigurationElement).IsAssignableFrom(property.Value.PropertyType))
                    property.Value.SetValue(_ConfigElement, _ValueGetter(property.Key), null);
            }
        }
Example #2
0
		protected override object GetElementKey (ConfigurationElement element)
		{
			if (!(element is BypassElement))
				throw new ArgumentException ("element");

			return ((BypassElement)element).Address;
		}
 protected override object GetElementKey(ConfigurationElement element)
 {
     var configElement = element as CacheFactoryConfigurationElement;
     if (Equals(configElement, null))
         throw new Exception("Unable to cast System.Configuration.ConfigurationElement into Meek.Caching.Configuration.CacheFactoryConfigurationElement");
     return configElement.Name;
 }
 protected internal override void Reset(ConfigurationElement parentSection) {
     _KeyValueCollection = null;
     base.Reset(parentSection);
     if (!String.IsNullOrEmpty((string)base[s_propFile])) { // don't inherit from the parent
         SetPropertyValue(s_propFile,null,true); // ignore the lock to prevent inheritence
     }
 }
 public new void Configure(ConfigurationElement configuration)
 {
     //Store the .config configuration section for us to maybe created modified version later (if requested on the model).
     //Note, we had to implement IConfigurable as well (despite it being implemented on our base class) or this would not be called.
     _realConfiguration  = configuration as OrderPipelinesProcessorConfiguration;
     base.Configure(configuration);
 }
 protected override object GetElementKey(ConfigurationElement element)
 {
     return String.Concat(
         ((EtlAgentsCollectionElement)element).EtlAgentType,
         ((EtlAgentsCollectionElement)element).ConnectionString,
         ((EtlAgentsCollectionElement)element).SchemaName);
 }
 protected override void Reset(ConfigurationElement parentElement)
 {
     WsdlHelpGeneratorElement element = (WsdlHelpGeneratorElement) parentElement;
     WebContext hostingContext = base.EvaluationContext.HostingContext as WebContext;
     if (hostingContext != null)
     {
         string path = hostingContext.Path;
         bool flag = path == null;
         this.actualPath = element.actualPath;
         if (flag)
         {
             path = HostingEnvironment.ApplicationVirtualPath;
         }
         if ((path != null) && !path.EndsWith("/", StringComparison.Ordinal))
         {
             path = path + "/";
         }
         if ((path == null) && (parentElement != null))
         {
             this.virtualPath = element.virtualPath;
         }
         else if (path != null)
         {
             this.virtualPath = path;
         }
     }
     base.Reset(parentElement);
 }
		protected override object GetElementKey (ConfigurationElement element)
		{
			if (!(element is AuthenticationModuleElement))
				throw new ArgumentException ("element");

			return ((AuthenticationModuleElement)element).Type;
		}
 protected override object GetElementKey(ConfigurationElement element)
 {
     var ele = element as IgnorePostfixConfigurationElement;
     if (ele == null)
         throw new ArgumentNullException("element", "element不能转换成 IgnoreConfigurationElement");
     return ele.Postfix;
 }
		protected override object GetElementKey (ConfigurationElement element)
		{
			//			if (BaseIndexOf (element) == -1)
			//				return "";

			return ((KeyValueConfigurationElement)element).Key;
		}
    protected int BaseIndexOf (ConfigurationElement element)
    {
      Contract.Requires(element != null);
      Contract.Ensures(Contract.Result<int>() >= -1);

      return default(int);
    }
        private static IEnumerable<Argument> ReadConfigurationElement(ConfigurationElement element)
        {
            var arguments = new List<Argument>();

            var collection = element as ConfigurationElementCollection;

            if (collection != null)
            {
                foreach (ConfigurationElement child in collection)
                {
                    arguments.AddRange(ReadConfigurationElement(child));
                }
            }
            else
            {
                foreach (PropertyInfo property in element.GetType().GetProperties())
                {
                    object propertyValue = property.GetValue(element, null);

                    if (typeof (ConfigurationElement).IsAssignableFrom(property.PropertyType))
                    {
                        arguments.AddRange(ReadConfigurationElement((ConfigurationElement) propertyValue));
                    }

                    var argument = new Argument(property, propertyValue);
                    if (argument.Include())
                    {
                        arguments.Add(argument);
                    }
                }
            }
            return arguments;
        }
 protected override object GetElementKey(ConfigurationElement element)
 {
     var ele = element as ServiceConfigurationElement;
     if (ele == null)
         throw new ArgumentNullException("element", "element不能转换成 ServiceConfigurationElement");
     return ele.Key;
 }
Example #14
0
 protected override object GetElementKey(ConfigurationElement element)
 {
     var server = element as DbConnect;
     if (server == null)
         return string.Empty;
     return server.Name;
 }
        protected override object GetElementKey(ConfigurationElement element)
        {
            if (element == null)
                throw new ArgumentNullException("element");

            return ((RepositoryElement)element).Name;
        }
        /// <summary>
        /// Return the key for the passed filte element
        /// </summary>
        /// <param name="element"></param>
        /// <returns></returns>
        protected override object GetElementKey(ConfigurationElement element)
        {
            FilterElement filterElement = (FilterElement)element;

            // Each filter element should be unique
            return filterElement.TypeName + filterElement.InitializeData + filterElement.Negate.ToString();
        }
        public override bool OverrideWithGroupPolicies(ConfigurationSection configurationObject,
            bool readGroupPolicies, IRegistryKey machineKey, IRegistryKey userKey)
        {
            called = true;
            this.configurationObject = configurationObject;
            this.readGroupPolicies = readGroupPolicies;
            this.machineKey = machineKey;
            this.userKey = userKey;

            IRegistryKey policyKey = GetPolicyKey(machineKey, userKey);
            if (policyKey != null)
            {
                if (!policyKey.GetBoolValue(PolicyValueName).Value)
                {
                    return false;
                }

                TestsConfigurationSection section = configurationObject as TestsConfigurationSection;
                if (section != null)
                {
                    try
                    {
                        section.Value = policyKey.GetStringValue(ValuePropertyName);
                    }
                    catch (RegistryAccessException)
                    { }
                }
            }

            return true;
        }
 protected override object GetElementKey(ConfigurationElement element)
 {
     if (element == null) throw new ArgumentNullException("element");
     var e = element as ExceptionElement;
     if (e == null) throw new ArgumentException("Value must be ExceptionElement.", "element");
     return e.Path;
 }
Example #19
0
 protected override object GetElementKey(ConfigurationElement element)
 {
     FileElement fe = element as FileElement;
       if (fe == null)
     throw new Exception(string.Format("Element was not of type {0}", typeof(FileElement).FullName));
       return fe.Path;
 }
Example #20
0
 protected override object GetElementKey(ConfigurationElement element)
 {
     var elem = element as AppConfigElement;
     if (elem == null)
         throw new ConfigurationErrorsException ("Child of applications element is not AppConfigElement");
     return elem.Name;
 }
        /// <summary>
        /// Gets the element key for autofac component configuration element composed from component name and type.
        /// </summary>
        /// <param name="element">Autofac component configuration element</param>
        /// <returns>An <see cref="System.Object" /> that acts as the key for the specified <see cref="ConfigurationElement" />.</returns>
        protected override object GetElementKey(ConfigurationElement element)
        {
            Guard.NotNull("element", element);

            var component = (ComponentConfigurationElement)element;
            return component.Name + component.TypeString;
        }
 internal static Type GetType(string typeName, string propertyName, ConfigurationElement configElement, XmlNode node, bool checkAptcaBit, bool ignoreCase)
 {
     Type type;
     try
     {
         type = BuildManager.GetType(typeName, true, ignoreCase);
     }
     catch (Exception exception)
     {
         if (((exception is ThreadAbortException) || (exception is StackOverflowException)) || (exception is OutOfMemoryException))
         {
             throw;
         }
         if (node != null)
         {
             throw new ConfigurationErrorsException(exception.Message, exception, node);
         }
         if (configElement != null)
         {
             throw new ConfigurationErrorsException(exception.Message, exception, configElement.ElementInformation.Properties[propertyName].Source, configElement.ElementInformation.Properties[propertyName].LineNumber);
         }
         throw new ConfigurationErrorsException(exception.Message, exception);
     }
     if (checkAptcaBit)
     {
         if (node != null)
         {
             HttpRuntime.FailIfNoAPTCABit(type, node);
             return type;
         }
         HttpRuntime.FailIfNoAPTCABit(type, (configElement != null) ? configElement.ElementInformation : null, propertyName);
     }
     return type;
 }
Example #23
0
 protected override object GetElementKey(ConfigurationElement element)
 {
     if (element == null) throw new ArgumentNullException("element");
     var le = element as LocaleElement;
     if (le == null) throw new ArgumentException("Value must be LocaleElement.", "element");
     return le.Prefix;
 }
 internal static void CheckBaseType(Type expectedBaseType, Type userBaseType, string propertyName, ConfigurationElement configElement)
 {
     if (!expectedBaseType.IsAssignableFrom(userBaseType))
     {
         throw new ConfigurationErrorsException(System.Web.SR.GetString("Invalid_type_to_inherit_from", new object[] { userBaseType.FullName, expectedBaseType.FullName }), configElement.ElementInformation.Properties[propertyName].Source, configElement.ElementInformation.Properties[propertyName].LineNumber);
     }
 }
 /// <summary>
 /// 向配置元素集合添加配置元素。
 /// </summary>
 /// <param name="index"></param>
 /// <param name="element"></param>
 protected override void BaseAdd(int index, ConfigurationElement element)
 {
     if (!this.ValidateSlaveConnectionStringElement(element))
     {
         base.BaseAdd(index, element);
     }
 }
            protected override object GetElementKey(ConfigurationElement element)
            {
                if (element == null)
                    throw new ArgumentNullException("element");

                return ((EtcdClient)element).Uri;
            }
Example #27
0
        protected internal virtual string SerializeSection(ConfigurationElement parentElement, string name,
            ConfigurationSaveMode saveMode)
        {
            if ((CurrentConfiguration != null) &&
                (CurrentConfiguration.TargetFramework != null) &&
                !ShouldSerializeSectionInTargetVersion(CurrentConfiguration.TargetFramework))
                return string.Empty;

            ValidateElement(this, null, true);

            ConfigurationElement tempElement = CreateElement(GetType());
            tempElement.Unmerge(this, parentElement, saveMode);

            StringWriter strWriter = new StringWriter(CultureInfo.InvariantCulture);
            XmlTextWriter writer = new XmlTextWriter(strWriter)
            {
                Formatting = Formatting.Indented,
                Indentation = 4,
                IndentChar = ' '
            };

            tempElement.DataToWriteInternal = saveMode != ConfigurationSaveMode.Minimal;

            if ((CurrentConfiguration != null) && (CurrentConfiguration.TargetFramework != null))
                _configRecord.SectionsStack.Push(this);

            tempElement.SerializeToXmlElement(writer, name);

            if ((CurrentConfiguration != null) && (CurrentConfiguration.TargetFramework != null))
                _configRecord.SectionsStack.Pop();

            writer.Flush();
            return strWriter.ToString();
        }
 internal static void CheckAssignableType(Type baseType, Type baseType2, Type type, ConfigurationElement configElement, string propertyName)
 {
     if (!baseType.IsAssignableFrom(type) && !baseType2.IsAssignableFrom(type))
     {
         throw new ConfigurationErrorsException(System.Web.SR.GetString("Type_doesnt_inherit_from_type", new object[] { type.FullName, baseType.FullName }), configElement.ElementInformation.Properties[propertyName].Source, configElement.ElementInformation.Properties[propertyName].LineNumber);
     }
 }
        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;
            }
        }
Example #30
0
        protected override object GetElementKey(ConfigurationElement element)
        {
            if (element == null)
                throw new ArgumentNullException("element");

            return ((DependenceConf)element).Assembly;
        }
 protected override object GetElementKey(System.Configuration.ConfigurationElement element)
 {
     return(((StoreConfigurationElement)element).TableName);
 }
Example #32
0
 /// <summary>
 /// Gets the element key for a specified configuration element when overridden in a derived class.
 /// </summary>
 /// <param name="element">The <see cref="T:System.Configuration.ConfigurationElement" /> to return the key for.</param>
 /// <returns>
 /// An <see cref="T:System.Object" /> that acts as the key for the specified <see cref="T:System.Configuration.ConfigurationElement" />.
 /// </returns>
 protected override object GetElementKey(System.Configuration.ConfigurationElement element)
 {
     return(string.Format("{0}-{1}", (( AttributeValueConfig )element).AttributeKey, (( AttributeValueConfig )element).EntityId));
 }
        /// <inheritdoc />
        protected override void Unmerge(System.Configuration.ConfigurationElement sourceElement, System.Configuration.ConfigurationElement parentElement, ConfigurationSaveMode saveMode)
        {
            base.Unmerge(sourceElement, parentElement, saveMode);

            IInternalConfigurationElement source = sourceElement as IInternalConfigurationElement;

            if (source == null)
            {
                return;
            }

            lock (_elements)
                _elements = source.ElementsClone;
        }
Example #34
0
 /// <summary>
 /// Get Element Key
 /// </summary>
 /// <param name="element"></param>
 /// <returns></returns>
 protected override object GetElementKey(System.Configuration.ConfigurationElement element)
 {
     return(((TcpServerConfigItem)element).HostName);
 }
Example #35
0
 protected override object GetElementKey(System.Configuration.ConfigurationElement element)
 {
     return(((Form)element).Name);
 }
 protected override object GetElementKey(System.Configuration.ConfigurationElement element)
 {
     return(((ADServerElement)element).Url.ToString());
 }
 protected override object GetElementKey(
     System.Configuration.ConfigurationElement element)
 {
     return(((RedisHost)element).Host);
 }
 /// <summary>
 ///   Gets the element key for a specified configuration element when overridden in a derived class.
 /// </summary>
 /// <param name="element">
 ///   The <see cref="System.Configuration.ConfigurationElement"/> to return the key for.
 /// </param>
 /// <returns>
 ///   An <see cref="object"/> that acts as the key for the specified <see cref="System.Configuration.ConfigurationElement"/>.
 /// </returns>
 protected override sealed object GetElementKey(System.Configuration.ConfigurationElement element)
 => GetElementKey((TValue)element);
Example #39
0
 protected override object GetElementKey(System.Configuration.ConfigurationElement element)
 {
     return(((SessionProvidersElement)(element)).Name);
 }
 protected override Object GetElementKey(ConfigurationElement element)
 {
     return(default(Object));
 }
 protected override object GetElementKey(System.Configuration.ConfigurationElement element)
 {
     return(((LoggingIgnoreInterfacesConfigurationElement)element).InterfaceType);
 }
 protected override object GetElementKey(System.Configuration.ConfigurationElement element)
 {
     return(((ParamElement)(element)).Name);
 }
Example #43
0
 protected override object GetElementKey(System.Configuration.ConfigurationElement element)
 {
     return(((Mapping)element).CodeRawString.Select(s => s.ToString()).Aggregate((n, acc) => n + acc));
 }
 protected override object GetElementKey(System.Configuration.ConfigurationElement element)
 {
     return(((DeduplicateElement)(element)).XMLElement);
 }
 internal ElementInformation(ConfigurationElement thisElement)
 {
     _thisElement = thisElement;
 }
Example #46
0
 protected override object GetElementKey(System.Configuration.ConfigurationElement element)
 {
     return((BoardConfig)element);
 }
 protected override object GetElementKey(System.Configuration.ConfigurationElement element)
 {
     return(((CascadeRemoveElement)(element)).Id);
 }
 protected internal override void Reset(ConfigurationElement parentSection)
 {
     _rawXml     = string.Empty;
     _isModified = false;
 }
 protected override Object GetElementKey(ConfigurationElement element)
 {
     return(((ProviderSettings)element).Name);
 }
Example #50
0
        protected internal virtual void DeserializeElement(XmlReader reader, bool serializeCollectionKey)
        {
            Hashtable readProps = new Hashtable();

            reader.MoveToContent();
            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;
            }

            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 ConfigurationException("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();
        }
 protected internal override string SerializeSection(ConfigurationElement parentSection, string name, ConfigurationSaveMode saveMode)
 {
     return(_rawXml);
 }
 /// <summary>
 /// Gets the element key for a specified configuration element when overridden in a derived class.
 /// </summary>
 /// <param name="element">The <see cref="T:System.Configuration.ConfigurationElement"></see> to return the key for.</param>
 /// <returns>
 /// An <see cref="T:System.Object"></see> that acts as the key for the specified <see cref="T:System.Configuration.ConfigurationElement"></see>.
 /// </returns>
 protected override object GetElementKey(System.Configuration.ConfigurationElement element)
 {
     return(((IndexusServerSetting)element).Key);
 }
Example #53
0
 protected internal override void Reset(ConfigurationElement parentSection)
 {
     base.Reset(parentSection);
 }
Example #54
0
 protected override object GetElementKey(System.Configuration.ConfigurationElement element)
 {
     return(((TwitterUser)element).ScreenName);
 }
Example #55
0
 protected internal override void Unmerge(
     ConfigurationElement sourceElement, ConfigurationElement parentElement,
     ConfigurationSaveMode saveMode)
 {
     base.Unmerge(sourceElement, parentElement, saveMode);
 }
 protected override object GetElementKey(System.Configuration.ConfigurationElement element)
 {
     return(((Site)element).Url);
 }
 protected override object GetElementKey(System.Configuration.ConfigurationElement element)
 {
     return(((TaskConfigurationElement)element).Key);
 }