Наследование: System.Configuration.Provider.ProviderBase
        private static ISharedApplicationSettingsProvider GetSharedSettingsProvider(SettingsProvider provider)
        {
            if (provider is LocalFileSettingsProvider)
                return new ExtendedLocalFileSettingsProvider((LocalFileSettingsProvider)provider);

            return provider as ISharedApplicationSettingsProvider;
        }
Пример #2
0
        static void RedirectSettings(ApplicationSettingsBase settings, SettingsProvider provider)
        {
            settings.Providers.Add(provider);
            foreach (SettingsProperty property in settings.Properties)
            {
                property.Provider = provider;
            }

            settings.Reload();
        }
 public SettingsProperty(SettingsProperty propertyToCopy)
 {
     this._Name = propertyToCopy.Name;
     this._IsReadOnly = propertyToCopy.IsReadOnly;
     this._DefaultValue = propertyToCopy.DefaultValue;
     this._SerializeAs = propertyToCopy.SerializeAs;
     this._Provider = propertyToCopy.Provider;
     this._PropertyType = propertyToCopy.PropertyType;
     this._ThrowOnErrorDeserializing = propertyToCopy.ThrowOnErrorDeserializing;
     this._ThrowOnErrorSerializing = propertyToCopy.ThrowOnErrorSerializing;
     this._Attributes = new SettingsAttributeDictionary(propertyToCopy.Attributes);
 }
		private static SettingsPropertyCollection GetPropertiesForProvider(ApplicationSettingsBase settings, SettingsProvider provider)
        {
            SettingsPropertyCollection properties = new SettingsPropertyCollection();
            
            foreach (SettingsProperty property in settings.Properties)
            {
                if (property.Provider == provider)
                    properties.Add(property);
            }
            
            return properties;
        }
 public SettingsProperty(string name, Type propertyType, SettingsProvider provider, bool isReadOnly, object defaultValue, SettingsSerializeAs serializeAs, SettingsAttributeDictionary attributes, bool throwOnErrorDeserializing, bool throwOnErrorSerializing)
 {
     this._Name = name;
     this._PropertyType = propertyType;
     this._Provider = provider;
     this._IsReadOnly = isReadOnly;
     this._DefaultValue = defaultValue;
     this._SerializeAs = serializeAs;
     this._Attributes = attributes;
     this._ThrowOnErrorDeserializing = throwOnErrorDeserializing;
     this._ThrowOnErrorSerializing = throwOnErrorSerializing;
 }
Пример #6
0
        void CacheValuesByProvider(SettingsProvider provider)
        {
            SettingsPropertyCollection col = new SettingsPropertyCollection();

            foreach (SettingsProperty p in Properties)
            {
                if (p.Provider == provider)
                {
                    col.Add(p);
                }
            }

            if (col.Count > 0)
            {
                SettingsPropertyValueCollection vals = provider.GetPropertyValues(Context, col);
                PropertyValues.Add(vals);
            }

            OnSettingsLoaded(this, new SettingsLoadedEventArgs(provider));
        }
Пример #7
0
 public SettingsProperty(string name,
                         Type propertyType,
                         SettingsProvider provider,
                         bool isReadOnly,
                         object defaultValue,
                         SettingsSerializeAs serializeAs,
                         SettingsAttributeDictionary attributes,
                         bool throwOnErrorDeserializing,
                         bool throwOnErrorSerializing)
 {
     this.name         = name;
     this.propertyType = propertyType;
     this.provider     = provider;
     this.isReadOnly   = isReadOnly;
     this.defaultValue = defaultValue;
     this.serializeAs  = serializeAs;
     this.attributes   = attributes;
     this.throwOnErrorDeserializing = throwOnErrorDeserializing;
     this.throwOnErrorSerializing   = throwOnErrorSerializing;
 }
 private object GetPropertyValue(string propertyName)
 {
     if (this.PropertyValues[propertyName] == null)
     {
         if (this._firstLoad)
         {
             this._firstLoad = false;
             if (this.IsFirstRunOfClickOnceApp())
             {
                 this.Upgrade();
             }
         }
         object                  obj1     = base[propertyName];
         SettingsProperty        property = this.Properties[propertyName];
         SettingsProvider        provider = (property != null) ? property.Provider : null;
         SettingsLoadedEventArgs e        = new SettingsLoadedEventArgs(provider);
         this.OnSettingsLoaded(this, e);
     }
     return(base[propertyName]);
 }
 private void GetPropertiesFromProvider(SettingsProvider provider)
 {
     SettingsPropertyCollection collection = new SettingsPropertyCollection();
     foreach (SettingsProperty property in this.Properties)
     {
         if (property.Provider == provider)
         {
             collection.Add(property);
         }
     }
     if (collection.Count > 0)
     {
         foreach (SettingsPropertyValue value2 in provider.GetPropertyValues(this.Context, collection))
         {
             if (this._PropertyValues[value2.Name] == null)
             {
                 this._PropertyValues.Add(value2);
             }
         }
     }
 }
        private void GetPropertiesFromProvider(SettingsProvider provider)
        {
            SettingsPropertyCollection collection = new SettingsPropertyCollection();

            foreach (SettingsProperty property in this.Properties)
            {
                if (property.Provider == provider)
                {
                    collection.Add(property);
                }
            }
            if (collection.Count > 0)
            {
                foreach (SettingsPropertyValue value2 in provider.GetPropertyValues(this.Context, collection))
                {
                    if (this._PropertyValues[value2.Name] == null)
                    {
                        this._PropertyValues.Add(value2);
                    }
                }
            }
        }
        private void GetPropertiesFromProvider(SettingsProvider provider)
        {
            SettingsPropertyCollection ppc = new SettingsPropertyCollection();

            foreach (SettingsProperty pp in Properties)
            {
                if (pp.Provider == provider)
                {
                    ppc.Add(pp);
                }
            }

            if (ppc.Count > 0)
            {
                SettingsPropertyValueCollection ppcv = provider.GetPropertyValues(Context, ppc);
                foreach (SettingsPropertyValue p in ppcv)
                {
                    if (_PropertyValues[p.Name] == null)
                    {
                        _PropertyValues.Add(p);
                    }
                }
            }
        }
Пример #12
0
		///<summary>
		///Initializes the provider.
		///</summary>
		///
		///<param name="config">A collection of the name/value pairs representing the provider-specific attributes specified in the configuration for this provider.</param>
		///<param name="name">The friendly name of the provider.</param>
		public override void Initialize(string name, System.Collections.Specialized.NameValueCollection config)
		{
			lock (_syncLock)
			{
				// obtain a source provider
				try
				{
					ISettingsStore store = SettingsStore.Create();
					_sourceProvider = new SettingsStoreSettingsProvider(store);
				}
				catch (NotSupportedException)
				{
					Platform.Log(LogLevel.Warn, SR.LogConfigurationStoreNotFound);

					// default to LocalFileSettingsProvider as a last resort
					_sourceProvider = new ExtendedLocalFileSettingsProvider(new LocalFileSettingsProvider());
				}

				// init source provider
				// according to sample implementations, use the application name here
				_sourceProvider.Initialize(this.ApplicationName, config);
				base.Initialize(this.ApplicationName, config);
			}
		}
 protected ApplicationSettingsBase(IComponent owner, string settingsKey) : this(settingsKey)
 {
     if (owner == null)
     {
         throw new ArgumentNullException("owner");
     }
     this._owner = owner;
     if (owner.Site != null)
     {
         ISettingsProviderService service = owner.Site.GetService(typeof(ISettingsProviderService)) as ISettingsProviderService;
         if (service != null)
         {
             foreach (SettingsProperty property in this.Properties)
             {
                 SettingsProvider settingsProvider = service.GetSettingsProvider(property);
                 if (settingsProvider != null)
                 {
                     property.Provider = settingsProvider;
                 }
             }
             this.ResetProviders();
         }
     }
 }
Пример #14
0
        /// <summary>
        /// Retrieves the value of a setting. We need this method so we can fire the SettingsLoaded event
        /// when settings are loaded from the providers.Ideally, this should be fired from SettingsBase,
        /// but unfortunately that will not happen in Whidbey. Instead, we check to see if the value has already
        /// been retrieved. If not, we fire the load event, since we expect SettingsBase to load all the settings
        /// from this setting's provider.
        /// </summary>
        private object GetPropertyValue(string propertyName)
        {
            if (PropertyValues[propertyName] == null)
            {
                // we query the value first so that we initialize all values from value providers and so that we don't end up
                // on an infinite recursion when calling Properties[propertyName] as that calls this.
                _ = base[propertyName];
                SettingsProperty setting  = Properties[propertyName];
                SettingsProvider provider = setting?.Provider;

                Debug.Assert(provider != null, "Could not determine provider from which settings were loaded");

                SettingsLoadedEventArgs e = new SettingsLoadedEventArgs(provider);
                OnSettingsLoaded(this, e);

                // Note: we need to requery the value here in case someone changed it while
                // handling SettingsLoaded.
                return(base[propertyName]);
            }
            else
            {
                return(base[propertyName]);
            }
        }
Пример #15
0
        /// <summary>
        /// Creates a SettingsProperty object using the metadata on the given property
        /// and returns it.
        /// </summary>
        private SettingsProperty CreateSetting(PropertyInfo propertyInfo)
        {
            // Initialization method -
            // be careful not to access properties here to prevent stack overflow.

            object[]         attributes        = propertyInfo.GetCustomAttributes(false);
            SettingsProperty settingsProperty  = new SettingsProperty(Initializer);
            bool             explicitSerialize = _explicitSerializeOnClass;

            settingsProperty.Name         = propertyInfo.Name;
            settingsProperty.PropertyType = propertyInfo.PropertyType;

            for (int i = 0; i < attributes.Length; i++)
            {
                Attribute attribute = attributes[i] as Attribute;
                if (attribute == null)
                {
                    continue;
                }

                if (attribute is DefaultSettingValueAttribute)
                {
                    settingsProperty.DefaultValue = ((DefaultSettingValueAttribute)attribute).Value;
                }
                else if (attribute is ReadOnlyAttribute)
                {
                    settingsProperty.IsReadOnly = true;
                }
                else if (attribute is SettingsProviderAttribute)
                {
                    string providerTypeName = ((SettingsProviderAttribute)attribute).ProviderTypeName;
                    Type   providerType     = Type.GetType(providerTypeName);
                    if (providerType == null)
                    {
                        throw new ConfigurationErrorsException(SR.Format(SR.ProviderTypeLoadFailed, providerTypeName));
                    }

                    SettingsProvider settingsProvider = TypeUtil.CreateInstance(providerType) as SettingsProvider;

                    if (settingsProvider == null)
                    {
                        throw new ConfigurationErrorsException(SR.Format(SR.ProviderInstantiationFailed, providerTypeName));
                    }

                    settingsProvider.Initialize(null, null);
                    settingsProvider.ApplicationName = ConfigurationManagerInternalFactory.Instance.ExeProductName;

                    // See if we already have a provider of the same name in our collection. If so,
                    // re-use the existing instance, since we cannot have multiple providers of the same name.
                    SettingsProvider existing = _providers[settingsProvider.Name];
                    if (existing != null)
                    {
                        settingsProvider = existing;
                    }

                    settingsProperty.Provider = settingsProvider;
                }
                else if (attribute is SettingsSerializeAsAttribute)
                {
                    settingsProperty.SerializeAs = ((SettingsSerializeAsAttribute)attribute).SerializeAs;
                    explicitSerialize            = true;
                }
                else
                {
                    // This isn't an attribute we care about, so simply pass it on
                    // to the SettingsProvider.
                    //
                    // NOTE: The key is the type. So if an attribute was found at class
                    //       level and also property level, the latter overrides the former
                    //       for a given setting. This is exactly the behavior we want.

                    settingsProperty.Attributes.Add(attribute.GetType(), attribute);
                }
            }

            if (!explicitSerialize)
            {
                // Serialization method was not explicitly attributed.

                TypeConverter tc = TypeDescriptor.GetConverter(propertyInfo.PropertyType);
                if (tc.CanConvertTo(typeof(string)) && tc.CanConvertFrom(typeof(string)))
                {
                    // We can use string
                    settingsProperty.SerializeAs = SettingsSerializeAs.String;
                }
                else
                {
                    // Fallback is Xml
                    settingsProperty.SerializeAs = SettingsSerializeAs.Xml;
                }
            }

            return(settingsProperty);
        }
Пример #16
0
 public SettingsLoadedEventArgs(SettingsProvider provider)
 {
     this.provider = provider;
 }
 private static void InsertApplcationSetting(SettingsProvider.Section section, Action action) {
     var setting = new ApplicationSetting() {
         Name = action.Name,
         Value = action.Value
     };
     setting.Section = section;
 }
Пример #18
0
		void CreateSettingsProperty (PropertyInfo prop, SettingsPropertyCollection properties, ref SettingsProvider local_provider)
		{
			SettingsAttributeDictionary dict = new SettingsAttributeDictionary ();
			SettingsProvider provider = null;
			object defaultValue = null;
			SettingsSerializeAs serializeAs = SettingsSerializeAs.String;
			bool explicitSerializeAs = false;

			foreach (Attribute a in prop.GetCustomAttributes (false)) {
				/* the attributes we handle natively here */
				if (a is SettingsProviderAttribute) {
					Type provider_type = Type.GetType (((SettingsProviderAttribute)a).ProviderTypeName);
					provider = (SettingsProvider) Activator.CreateInstance (provider_type);
					provider.Initialize (null, null);
				}
				else if (a is DefaultSettingValueAttribute) {
					defaultValue = ((DefaultSettingValueAttribute)a).Value;
				}
				else if (a is SettingsSerializeAsAttribute) {
					serializeAs = ((SettingsSerializeAsAttribute)a).SerializeAs;
					explicitSerializeAs = true;
				}
				else if (a is ApplicationScopedSettingAttribute ||
					 a is UserScopedSettingAttribute) {
					dict.Add (a.GetType(), a);
				}
				else {
					dict.Add (a.GetType(), a);
				}
			}

			if (!explicitSerializeAs) {
				// DefaultValue is a string and if we can't convert from string to the 
				// property type then the only other option left is for the string to 
				// be XML.
				//
				TypeConverter converter = TypeDescriptor.GetConverter (prop.PropertyType);
				if (converter != null && 
				    (!converter.CanConvertFrom (typeof (string)) || 
				     !converter.CanConvertTo (typeof (string))))
					serializeAs = SettingsSerializeAs.Xml;
			}

			SettingsProperty setting =
				new SettingsProperty (prop.Name, prop.PropertyType, provider, false /* XXX */,
						      defaultValue /* XXX always a string? */, serializeAs, dict,
						      false, false);


			if (providerService != null)
				setting.Provider = providerService.GetSettingsProvider (setting);

			if (provider == null) {
				if (local_provider == null) {
					local_provider = new LocalFileSettingsProvider () as SettingsProvider;
					local_provider.Initialize (null, null);
				}
				setting.Provider = local_provider;
				// .NET ends up to set this to providers.
				provider = local_provider;
			}

			if (provider != null) {
				/* make sure we're using the same instance of a
				   given provider across multiple properties */
				SettingsProvider p = Providers[provider.Name];
				if (p != null)
					setting.Provider = p;
			}

			properties.Add (setting);

			if (setting.Provider != null && Providers [setting.Provider.Name] == null)
				Providers.Add (setting.Provider);
		}
Пример #19
0
 public SettingsProperty(string name, Type propertyType, SettingsProvider provider, bool isReadOnly, Object defaultValue, SettingsSerializeAs serializeAs, SettingsAttributeDictionary attributes, bool throwOnErrorDeserializing, bool throwOnErrorSerializing)
 {
 }
Пример #20
0
 public SettingsProperty(string name, Type propertyType, SettingsProvider provider, bool isReadOnly, object defaultValue, SettingsSerializeAs serializeAs, SettingsAttributeDictionary attributes, bool throwOnErrorDeserializing, bool throwOnErrorSerializing)
 {
     throw new NotImplementedException();
 }
 public SettingsLoadedEventArgs(SettingsProvider provider)
 {
 }
Пример #22
0
 public SettingsLoadedEventArgs(SettingsProvider provider)
 {
 }
Пример #23
0
		void CacheValuesByProvider (SettingsProvider provider)
		{
			SettingsPropertyCollection col = new SettingsPropertyCollection ();

			foreach (SettingsProperty p in Properties) {
				if (p.Provider == provider)
					col.Add (p);
			}

			if (col.Count > 0) {
				SettingsPropertyValueCollection vals = provider.GetPropertyValues (Context, col);
				PropertyValues.Add (vals);
			}

			OnSettingsLoaded (this, new SettingsLoadedEventArgs (provider));
		}
Пример #24
0
       private void GetPropertiesFromProvider(SettingsProvider provider)
       {
           SettingsPropertyCollection ppc = new SettingsPropertyCollection();
           foreach (SettingsProperty pp in Properties)
           {
               if (pp.Provider == provider)
               {
                   ppc.Add(pp);
               }
           }

           if (ppc.Count > 0)
           {
               SettingsPropertyValueCollection ppcv = provider.GetPropertyValues(Context, ppc);
               foreach (SettingsPropertyValue p in ppcv)
               {
                   if (_PropertyValues[p.Name] == null)
                       _PropertyValues.Add(p);
               }
           }
       }
 private SettingsPropertyCollection GetPropertiesForProvider(SettingsProvider provider)
 {
     SettingsPropertyCollection propertys = new SettingsPropertyCollection();
     foreach (SettingsProperty property in this.Properties)
     {
         if (property.Provider == provider)
         {
             propertys.Add(property);
         }
     }
     return propertys;
 }
Пример #26
0
        void CreateSettingsProperty(PropertyInfo prop, SettingsPropertyCollection properties, ref LocalFileSettingsProvider local_provider)
        {
            SettingsAttributeDictionary dict     = new SettingsAttributeDictionary();
            SettingsProvider            provider = null;
            object defaultValue             = null;
            SettingsSerializeAs serializeAs = SettingsSerializeAs.String;

            foreach (Attribute a in prop.GetCustomAttributes(false))
            {
                /* the attributes we handle natively here */
                if (a is SettingsProviderAttribute)
                {
                    Type provider_type = Type.GetType(((SettingsProviderAttribute)a).ProviderTypeName);
                    provider = (SettingsProvider)Activator.CreateInstance(provider_type);
                    provider.Initialize(null, null);
                }
                else if (a is DefaultSettingValueAttribute)
                {
                    defaultValue = ((DefaultSettingValueAttribute)a).Value;                     /* XXX this is a string.. do we convert? */
                    // note: for StringCollection, TypeDescriptor.GetConverter(prop.PropertyType) returns
                    // CollectionConverter, however this class cannot handle the XML serialized strings
                    if (prop.PropertyType == typeof(StringCollection))
                    {
                        XmlSerializer    xs     = new XmlSerializer(typeof(string[]));
                        string[]         values = (string[])xs.Deserialize(new StringReader((string)defaultValue));
                        StringCollection sc     = new StringCollection();
                        sc.AddRange(values);
                        defaultValue = sc;
                    }
                    else if (prop.PropertyType != typeof(string))
                    {
                        defaultValue = TypeDescriptor.GetConverter(prop.PropertyType).ConvertFromString((string)defaultValue);
                    }
                }
                else if (a is SettingsSerializeAsAttribute)
                {
                    serializeAs = ((SettingsSerializeAsAttribute)a).SerializeAs;
                }
                else if (a is ApplicationScopedSettingAttribute ||
                         a is UserScopedSettingAttribute)
                {
                    dict.Add(a.GetType(), a);
                }
                else
                {
                    dict.Add(a.GetType(), a);
                }
            }

            SettingsProperty setting =
                new SettingsProperty(prop.Name, prop.PropertyType, provider, false /* XXX */,
                                     defaultValue /* XXX always a string? */, serializeAs, dict,
                                     false, false);


            if (providerService != null)
            {
                setting.Provider = providerService.GetSettingsProvider(setting);
            }

            if (provider == null)
            {
                if (local_provider == null)
                {
                    local_provider = new LocalFileSettingsProvider();
                    local_provider.Initialize(null, null);
                }
                setting.Provider = local_provider;
                // .NET ends up to set this to providers.
                provider = local_provider;
            }

            if (provider != null)
            {
                /* make sure we're using the same instance of a
                 * given provider across multiple properties */
                SettingsProvider p = Providers[provider.Name];
                if (p != null)
                {
                    setting.Provider = p;
                }
            }

            properties.Add(setting);

            if (setting.Provider != null && Providers [setting.Provider.Name] == null)
            {
                Providers.Add(setting.Provider);
            }
        }
Пример #27
0
        /// <summary>
        /// Creates a SettingsProperty object using the metadata on the given property
        /// and returns it.
        ///
        /// Implementation note: Initialization method - be careful not to access properties here
        ///                      to prevent stack overflow.
        /// </summary>
        private SettingsProperty CreateSetting(PropertyInfo propInfo)
        {
            object[]         attributes        = propInfo.GetCustomAttributes(false);
            SettingsProperty sp                = new SettingsProperty(Initializer);
            bool             explicitSerialize = _explicitSerializeOnClass;

            sp.Name         = propInfo.Name;
            sp.PropertyType = propInfo.PropertyType;

            for (int i = 0; i < attributes.Length; i++)
            {
                Attribute attr = attributes[i] as Attribute;
                if (attr != null)
                {
                    if (attr is DefaultSettingValueAttribute)
                    {
                        sp.DefaultValue = ((DefaultSettingValueAttribute)attr).Value;
                    }
                    else if (attr is ReadOnlyAttribute)
                    {
                        sp.IsReadOnly = true;
                    }
                    else if (attr is SettingsProviderAttribute)
                    {
                        string providerTypeName = ((SettingsProviderAttribute)attr).ProviderTypeName;
                        Type   providerType     = Type.GetType(providerTypeName);
                        if (providerType != null)
                        {
                            SettingsProvider spdr = TypeUtil.CreateInstance(providerType) as SettingsProvider;

                            if (spdr != null)
                            {
                                spdr.Initialize(null, null);
                                spdr.ApplicationName = ConfigurationManagerInternalFactory.Instance.ExeProductName;

                                // See if we already have a provider of the same name in our collection. If so,
                                // re-use the existing instance, since we cannot have multiple providers of the same name.
                                SettingsProvider existing = _providers[spdr.Name];
                                if (existing != null)
                                {
                                    spdr = existing;
                                }

                                sp.Provider = spdr;
                            }
                            else
                            {
                                throw new ConfigurationErrorsException(string.Format(SR.ProviderInstantiationFailed, providerTypeName));
                            }
                        }
                        else
                        {
                            throw new ConfigurationErrorsException(string.Format(SR.ProviderTypeLoadFailed, providerTypeName));
                        }
                    }
                    else if (attr is SettingsSerializeAsAttribute)
                    {
                        sp.SerializeAs    = ((SettingsSerializeAsAttribute)attr).SerializeAs;
                        explicitSerialize = true;
                    }
                    else
                    {
                        // This isn't an attribute we care about, so simply pass it on
                        // to the SettingsProvider.
                        // NOTE: The key is the type. So if an attribute was found at class
                        //       level and also property level, the latter overrides the former
                        //       for a given setting. This is exactly the behavior we want.

                        sp.Attributes.Add(attr.GetType(), attr);
                    }
                }
            }

            if (!explicitSerialize)
            {
                sp.SerializeAs = GetSerializeAs(propInfo.PropertyType);
            }

            return(sp);
        }
		///<summary>
		///Initializes the provider.
		///</summary>
		///
		///<param name="config">A collection of the name/value pairs representing the provider-specific attributes specified in the configuration for this provider.</param>
		///<param name="name">The friendly name of the provider.</param>
		public override void Initialize(string name, NameValueCollection config)
		{
			lock (_syncLock)
			{
				// obtain a source provider
				if (SettingsStore.IsSupported)
				{
					try
					{
						ISettingsStore store = SettingsStore.Create();
						_sourceProvider = new SettingsStoreSettingsProvider(store);
					}
					catch (NotSupportedException ex)
					{
						// TODO: determine if we can safely treat other exceptions the same way here
						Platform.Log(LogLevel.Warn, ex, "Configuration store failed to initialize - defaulting to LocalFileSettingsProvider");

						// default to LocalFileSettingsProvider as a last resort
						_sourceProvider = new ExtendedLocalFileSettingsProvider(new LocalFileSettingsProvider());
					}
				}
				else
				{
					_sourceProvider = new ExtendedLocalFileSettingsProvider(new LocalFileSettingsProvider());
				}

				// init source provider
				// according to sample implementations, use the application name here
				_sourceProvider.Initialize(this.ApplicationName, config);
				base.Initialize(this.ApplicationName, config);
			}
		}
        private static void InsertConnectionString(ApplyOptions options, SettingsProviderDatabase database, SettingsProvider.Section section, Action action) {
            var name = new SqlConnectionName() {
                Name = action.Name
            };

            SqlConnectionString connection = null;
            if (!options.UseExistingConnectionStrings) {
                connection = database.SqlConnectionStrings.FirstOrDefault(c => c.ConnectionString == action.Value);
            }
            if (connection == null) {
                connection = new SqlConnectionString() {
                    ConnectionString = action.Value
                };
                database.AddToSqlConnectionStrings(connection);
            }

            database.AddToSqlConnectionNames(name);

            name.Section = section;
            name.SqlConnectionString = connection;
        }
 public SettingsProperty ToSettingsProperty(SettingsProvider Provider)
 {
     return new SettingsProperty
     (
         Name,
         Type.GetType(PropertyTypeName),
         Provider,
         IsReadOnly,
         DefaultValue,
         SerializeAs,
         Attributes,
         ThrowOnErrorDeserializing,
         ThrowOnErrorSerializing
     );
 }
 public SettingsProperty(string name, Type propertyType, SettingsProvider provider, bool isReadOnly, Object defaultValue, SettingsSerializeAs serializeAs, SettingsAttributeDictionary attributes, bool throwOnErrorDeserializing, bool throwOnErrorSerializing)
 {
 }
        public SettingsPropertyValue ToSettingsPropertyValue(SettingsProvider Provider)
        {
            SettingsPropertyValue value = new SettingsPropertyValue(Property.ToSettingsProperty(Provider));

            value.Deserialized = Deserialized;
            value.IsDirty = IsDirty;
            value.PropertyValue = PropertyValue;
            value.SerializedValue = SerializedValue;

            return value;
        }
        /// <devdoc>
        ///     Gets all the settings properties for this provider.
        /// </devdoc>
        private SettingsPropertyCollection GetPropertiesForProvider(SettingsProvider provider) {
           SettingsPropertyCollection properties = new SettingsPropertyCollection();
           foreach (SettingsProperty sp in Properties) {
               if (sp.Provider == provider) {
                   properties.Add(sp);
               }
           }

           return properties;
        }
        void CreateSettingsProperty(PropertyInfo prop, SettingsPropertyCollection properties, ref SettingsProvider local_provider)
        {
            SettingsAttributeDictionary dict     = new SettingsAttributeDictionary();
            SettingsProvider            provider = null;
            object defaultValue             = null;
            SettingsSerializeAs serializeAs = SettingsSerializeAs.String;
            bool explicitSerializeAs        = false;

            foreach (Attribute a in prop.GetCustomAttributes(false))
            {
                /* the attributes we handle natively here */
                if (a is SettingsProviderAttribute)
                {
                    var  providerTypeName = ((SettingsProviderAttribute)a).ProviderTypeName;
                    Type provider_type    = Type.GetType(providerTypeName);
                    if (provider_type == null)                      // Type failed to find the type by name
                    {
                        var typeNameParts = providerTypeName.Split('.');
                        if (typeNameParts.Length > 1)                          //Load the assembly that providerTypeName claims
                        {
                            var assy = Assembly.Load(typeNameParts[0]);
                            if (assy != null)
                            {
                                provider_type = assy.GetType(providerTypeName);                                 //try to get the type from that Assembly
                            }
                        }
                    }
                    provider = (SettingsProvider)Activator.CreateInstance(provider_type);
                    provider.Initialize(null, null);
                }
                else if (a is DefaultSettingValueAttribute)
                {
                    defaultValue = ((DefaultSettingValueAttribute)a).Value;
                }
                else if (a is SettingsSerializeAsAttribute)
                {
                    serializeAs         = ((SettingsSerializeAsAttribute)a).SerializeAs;
                    explicitSerializeAs = true;
                }
                else if (a is ApplicationScopedSettingAttribute ||
                         a is UserScopedSettingAttribute)
                {
                    dict.Add(a.GetType(), a);
                }
                else
                {
                    dict.Add(a.GetType(), a);
                }
            }

            if (!explicitSerializeAs)
            {
                // DefaultValue is a string and if we can't convert from string to the
                // property type then the only other option left is for the string to
                // be XML.
                //
                TypeConverter converter = TypeDescriptor.GetConverter(prop.PropertyType);
                if (converter != null &&
                    (!converter.CanConvertFrom(typeof(string)) ||
                     !converter.CanConvertTo(typeof(string))))
                {
                    serializeAs = SettingsSerializeAs.Xml;
                }
            }

            SettingsProperty setting =
                new SettingsProperty(prop.Name, prop.PropertyType, provider, false /* XXX */,
                                     defaultValue /* XXX always a string? */, serializeAs, dict,
                                     false, false);


            if (providerService != null)
            {
                setting.Provider = providerService.GetSettingsProvider(setting);
            }

            if (provider == null)
            {
                if (local_provider == null)
                {
                    local_provider = new LocalFileSettingsProvider() as SettingsProvider;
                    local_provider.Initialize(null, null);
                }
                setting.Provider = local_provider;
                // .NET ends up to set this to providers.
                provider = local_provider;
            }

            if (provider != null)
            {
                /* make sure we're using the same instance of a
                 * given provider across multiple properties */
                SettingsProvider p = Providers[provider.Name];
                if (p != null)
                {
                    setting.Provider = p;
                }
            }

            properties.Add(setting);

            if (setting.Provider != null && Providers [setting.Provider.Name] == null)
            {
                Providers.Add(setting.Provider);
            }
        }
 public SettingsLoadedEventArgs(SettingsProvider provider)
 {
     this._provider = provider;
 }
Пример #36
0
 public SettingsLoadedEventArgs(SettingsProvider provider)
 {
     throw new NotImplementedException();
 }
 private void Write13_SettingsProvider(string n, string ns, SettingsProvider o, bool isNullable, bool needType)
 {
     if (o == null)
     {
         if (isNullable)
         {
             base.WriteNullTagLiteral(n, ns);
         }
     }
     else if (!needType)
     {
         System.Type type = o.GetType();
         if (type != typeof(SettingsProvider))
         {
             if (type != typeof(ConfigurableSettingsProvider))
             {
                 throw base.CreateUnknownTypeException(o);
             }
             this.Write14_ConfigurableSettingsProvider(n, ns, (ConfigurableSettingsProvider) o, isNullable, true);
         }
     }
 }