Ejemplo n.º 1
0
		public static string GetDescription(SettingsProperty property)
		{
			SettingsDescriptionAttribute a = CollectionUtils.SelectFirst(property.Attributes,
						attribute => attribute is SettingsDescriptionAttribute) as SettingsDescriptionAttribute;

			return a == null ? "" : a.Description;
		}
Ejemplo n.º 2
0
        private void CreatePropNode(SettingsProperty setting, SettingsPropertyValue value, SettingsContext context)
        {
            string xPathQuery = getXPathQuerySection(setting, context);

            XmlNode groupNode = doc.SelectSingleNode(xPathQuery);

            if (groupNode == null)
            {
                groupNode = doc.CreateElement(GetSectionName(context));

                if (this.IsUserScoped(setting))
                {
                    userSettings.AppendChild(groupNode);
                }
                else
                {
                    appSettings.AppendChild(groupNode);
                }

            } //if (node == null)

            XmlNode nodeProp = doc.CreateElement(setting.Name);

            nodeProp.AppendChild(this.SerializeToXmlElement(setting, value));

            groupNode.AppendChild(nodeProp);
        }
Ejemplo n.º 3
0
        public Settings()
        {
            // // To add event handlers for saving and changing settings, uncomment the lines below:
            //
            // this.SettingChanging += this.SettingChangingEventHandler;
            //
            // this.SettingsSaving += this.SettingsSavingEventHandler;
            //

            for (int i = 0; i < MaxExternalTools; i++)
            {
                SettingsProperty newProp = new SettingsProperty(
                    "ExternalTool" + i, typeof(ExternalTool),
                    this.Providers[Path.GetFileName(System.Reflection.Assembly.GetEntryAssembly().Location)],
                    false,
                    null,
                    SettingsSerializeAs.String,
                    null,
                    true, true
                );
                this.Properties.Add(newProp);
            }

            this.SettingsLoaded += new System.Configuration.SettingsLoadedEventHandler(Settings_SettingsLoaded);
        }
Ejemplo n.º 4
0
    public void SettingValuesCreatesAnAppAndUserId()
    {
      MySQLProfileProvider provider = InitProfileProvider();
      SettingsContext ctx = new SettingsContext();
      ctx.Add("IsAuthenticated", false);
      ctx.Add("UserName", "user1");

      SettingsPropertyValueCollection values = new SettingsPropertyValueCollection();
      SettingsProperty property1 = new SettingsProperty("color");
      property1.PropertyType = typeof(string);
      property1.Attributes["AllowAnonymous"] = true;
      SettingsPropertyValue value = new SettingsPropertyValue(property1);
      value.PropertyValue = "blue";
      values.Add(value);

      provider.SetPropertyValues(ctx, values);

      DataTable dt = FillTable("SELECT * FROM my_aspnet_applications");
      Assert.AreEqual(1, dt.Rows.Count);
      dt = FillTable("SELECT * FROM my_aspnet_users");
      Assert.AreEqual(1, dt.Rows.Count);
      dt = FillTable("SELECT * FROM my_aspnet_profiles");
      Assert.AreEqual(1, dt.Rows.Count);

      values["color"].PropertyValue = "green";
      provider.SetPropertyValues(ctx, values);

      dt = FillTable("SELECT * FROM my_aspnet_applications");
      Assert.AreEqual(1, dt.Rows.Count);
      dt = FillTable("SELECT * FROM my_aspnet_users");
      Assert.AreEqual(1, dt.Rows.Count);
      dt = FillTable("SELECT * FROM my_aspnet_profiles");
      Assert.AreEqual(1, dt.Rows.Count);
    }
 private SettingsProperty CreateSetting(PropertyInfo propInfo)
 {
     object[] customAttributes = propInfo.GetCustomAttributes(false);
     SettingsProperty property = new SettingsProperty(this.Initializer);
     bool flag = this._explicitSerializeOnClass;
     property.Name = propInfo.Name;
     property.PropertyType = propInfo.PropertyType;
     for (int i = 0; i < customAttributes.Length; i++)
     {
         Attribute attribute = customAttributes[i] as Attribute;
         if (attribute != null)
         {
             if (attribute is DefaultSettingValueAttribute)
             {
                 property.DefaultValue = ((DefaultSettingValueAttribute) attribute).Value;
             }
             else if (attribute is ReadOnlyAttribute)
             {
                 property.IsReadOnly = true;
             }
             else if (attribute is SettingsProviderAttribute)
             {
                 string providerTypeName = ((SettingsProviderAttribute) attribute).ProviderTypeName;
                 Type type = Type.GetType(providerTypeName);
                 if (type == null)
                 {
                     throw new ConfigurationErrorsException(System.SR.GetString("ProviderTypeLoadFailed", new object[] { providerTypeName }));
                 }
                 SettingsProvider provider = SecurityUtils.SecureCreateInstance(type) as SettingsProvider;
                 if (provider == null)
                 {
                     throw new ConfigurationErrorsException(System.SR.GetString("ProviderInstantiationFailed", new object[] { providerTypeName }));
                 }
                 provider.Initialize(null, null);
                 provider.ApplicationName = ConfigurationManagerInternalFactory.Instance.ExeProductName;
                 SettingsProvider provider2 = this._providers[provider.Name];
                 if (provider2 != null)
                 {
                     provider = provider2;
                 }
                 property.Provider = provider;
             }
             else if (attribute is SettingsSerializeAsAttribute)
             {
                 property.SerializeAs = ((SettingsSerializeAsAttribute) attribute).SerializeAs;
                 flag = true;
             }
             else
             {
                 property.Attributes.Add(attribute.GetType(), attribute);
             }
         }
     }
     if (!flag)
     {
         property.SerializeAs = this.GetSerializeAs(propInfo.PropertyType);
     }
     return property;
 }
 public ProfilePropertyViewModel(SettingsProperty property, ProfilePropertyInputModel value)
 {
     Type = PropTypeFromPropertyType(property);
     Description = property.Name + " must be of type " + property.PropertyType.Name;
     if (property.PropertyType.IsValueType) Description += " and is required";
     Description += ".";
     Data = value;
 }
 public ProfilePropertyViewModel(SettingsProperty property, string value)
     : this(property, 
             new ProfilePropertyInputModel
             {
                 Name = property.Name,
                 Value = value
             })
 {
 }
            private Property CreateProperty(PropertyInfo property, SettingsProperty settingsProperty, SettingsPropertyValueCollection settingsPropertyValues)
            {
                var descriptor = new SettingsPropertyDescriptor(property);
                var settingsPropertyValue = settingsPropertyValues[settingsProperty.Name];
                var defaultValue = settingsProperty.DefaultValue;
                var serializedValue = settingsPropertyValue == null ? null : settingsPropertyValue.SerializedValue;

                return new Property(descriptor, (serializedValue ?? defaultValue).ToString());
            }
        public ProfilePropertyViewModel(SettingsProperty property, ProfilePropertyInputModel value)
        {
            Type = PropTypeFromPropertyType(property);
            Description = string.Format(property.PropertyType.IsValueType
                                            ? Resources.ProfilePropertyViewModel.RequiredPropertyMustBeOfType
                                            : Resources.ProfilePropertyViewModel.RequiredProperty,
                                        property.Name, property.PropertyType.Name);

            Data = value;
        }
Ejemplo n.º 10
0
		public void Add ()
		{
			SettingsPropertyCollection col = new SettingsPropertyCollection ();
			SettingsProperty test_prop = new SettingsProperty ("test_prop");

			Assert.AreEqual (0, col.Count, "A1");

			col.Add (test_prop);

			Assert.AreEqual (1, col.Count, "A2");
		}
Ejemplo n.º 11
0
 private static SettingsProperty AddSettingItem(string Name, Type type)
 {
     System.Configuration.SettingsProperty Property = new System.Configuration.SettingsProperty(Name);
     Property.DefaultValue = true;
     Property.IsReadOnly   = false;
     Property.PropertyType = type;
     Property.Provider     = AppSettings.Default.Providers["LocalFileSettingsProvider"];
     Property.Attributes.Add(typeof(System.Configuration.UserScopedSettingAttribute), new System.Configuration.UserScopedSettingAttribute());
     AppSettings.Default.Properties.Add(Property);
     return(Property);
 }
		public void Add (SettingsProperty property)
		{
			if (isReadOnly)
				throw new NotSupportedException ();

			OnAdd (property);

			/* actually do the add */
			items.Add (property.Name, property);

			OnAddComplete (property);
		}
 private bool IsRoaming(SettingsProperty prop)
 {
     foreach (DictionaryEntry entry in prop.Attributes)
     {
         Attribute attribute = (Attribute) entry.Value;
         if (attribute is SettingsManageabilityAttribute)
         {
             return true;
         }
     }
     return false;
 }
Ejemplo n.º 14
0
 ////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////
 public SettingsProperty(SettingsProperty propertyToCopy) 
 {
     _Name = propertyToCopy.Name;
     _IsReadOnly = propertyToCopy.IsReadOnly;
     _DefaultValue = propertyToCopy.DefaultValue;
     _SerializeAs = propertyToCopy.SerializeAs;
     _Provider = propertyToCopy.Provider;
     _PropertyType = propertyToCopy.PropertyType;
     _ThrowOnErrorDeserializing = propertyToCopy.ThrowOnErrorDeserializing;
     _ThrowOnErrorSerializing = propertyToCopy.ThrowOnErrorSerializing;
     _Attributes = new SettingsAttributeDictionary(propertyToCopy.Attributes);
 }
Ejemplo n.º 15
0
		public SettingsProperty (SettingsProperty propertyToCopy)
			: this (propertyToCopy.Name,
				propertyToCopy.PropertyType,
				propertyToCopy.Provider,
				propertyToCopy.IsReadOnly,
				propertyToCopy.DefaultValue,
				propertyToCopy.SerializeAs,
				new SettingsAttributeDictionary (propertyToCopy.Attributes),
				propertyToCopy.ThrowOnErrorDeserializing,
				propertyToCopy.ThrowOnErrorSerializing)
		{
		}
Ejemplo n.º 16
0
 private void ValidateProperty(string propertyName, Type propertyType)
 {
     System.Configuration.SettingsProperty property = Properties.Settings.Default.Properties[propertyName];
     if (property == null)
     {
         System.Configuration.SettingsProperty propInitializer = Properties.Settings.Default.Properties["Initializer"];
         property              = new System.Configuration.SettingsProperty(propInitializer);
         property.Name         = propertyName;
         property.PropertyType = propertyType;
         property.DefaultValue = null;
         Properties.Settings.Default.Properties.Add(property);
     }
 }
Ejemplo n.º 17
0
		static SettingsPropertyValue GetSettingConverter(Type type, string name)
		{
			TypeConverter c = TypeDescriptor.GetConverter(type);
			SettingsSerializeAs ssa;
			if (c.CanConvertFrom(typeof(string)) && c.CanConvertTo(typeof(string))) {
				ssa = SettingsSerializeAs.String;
			} else {
				ssa = SettingsSerializeAs.Xml;
			}
			SettingsProperty p = new SettingsProperty(name);
			p.PropertyType = type;
			p.SerializeAs = ssa;
			return new SettingsPropertyValue(p);
		}
		public void Remove ()
		{
			SettingsPropertyValueCollection col = new SettingsPropertyValueCollection ();
			SettingsProperty test_prop = new SettingsProperty ("test_prop");
			SettingsPropertyValue val = new SettingsPropertyValue (test_prop);

			col.Add (val);

			Assert.AreEqual (1, col.Count, "A1");

			col.Remove ("test_prop");

			Assert.AreEqual (0, col.Count, "A2");
		}
 private string GetValue(SettingsProperty setting)
 {
     try
     {
         return this.SettingsXML.SelectSingleNode("Settings/" + setting.Name).InnerText;
     }
     catch (Exception)
     {
         if (setting.DefaultValue != null)
         {
             return setting.DefaultValue.ToString();
         }
         return "";
     }
 }
Ejemplo n.º 20
0
        void AddProperty(String propertyName, Color defaultValue, Type propertyType)
        {
            String providerName = "LocalFileSettingsProvider";
            var    attributes   = new System.Configuration.SettingsAttributeDictionary();
            var    attr         = new System.Configuration.UserScopedSettingAttribute();

            attributes.Add(attr.TypeId, attr);
            SettingsProvider settingProvider = Properties.Settings.Default.Providers[providerName];
            var prop = new System.Configuration.SettingsProperty(
                new System.Configuration.SettingsProperty(propertyName, propertyType,
                                                          settingProvider, false, defaultValue,
                                                          System.Configuration.SettingsSerializeAs.String, attributes, false, false));

            MYAPPCS.Properties.Settings.Default.Properties.Add(prop);
        }
       ////////////////////////////////////////////////////////////
       ////////////////////////////////////////////////////////////
       public void Add(SettingsProperty property)
       {
           if (_ReadOnly)
               throw new NotSupportedException();

           OnAdd(property);
           _Hashtable.Add(property.Name, property);
           try {
               OnAddComplete(property);
           }
           catch {
               _Hashtable.Remove(property.Name);
               throw;
           }
       }
Ejemplo n.º 22
0
        static void TestApplicationSettings()
        {
            Console.WriteLine();
            Console.WriteLine("Settings Designer Settings");
            Console.WriteLine();
            string applicationSettingsKey1Name  = "ApplicationSettingsKey1";
            string applicationSettingsKey1Value = Properties.Settings.Default.ApplicationSettingsKey1;

            Console.WriteLine("String ApplicationSettings Value of \"{0}\" is \"{1}\"", applicationSettingsKey1Name, applicationSettingsKey1Value);

            var applicationSettingsPropertyCollection = Properties.Settings.Default.Properties;

            System.Configuration.SettingsProperty applicationSettingsProperty = applicationSettingsPropertyCollection[applicationSettingsKey1Name];
            string applicationSettingsPropertyName1  = applicationSettingsProperty.Name;
            string applicationSettingsPropertyValue1 = (string)applicationSettingsProperty.DefaultValue;

            Console.WriteLine("Object ApplicationSettings Value of \"{0}\" is \"{1}\"", applicationSettingsKey1Name, applicationSettingsKey1Value);
        }
Ejemplo n.º 23
0
        public WindowSettings(SettingsBase settings, Form form, string prefix)
        {
            if (settings == null) throw new ArgumentNullException("settings");
            if (form == null) throw new ArgumentNullException("form");

            _form = form;
            _settings = settings;

            if (string.IsNullOrEmpty(prefix))
                prefix = form.GetType().Name;

            var properties = settings.Properties;
            _location = properties[prefix + "Location"];
            _size = properties[prefix + "Size"];
            _windowState = properties[prefix + "WindowState"];

            form.Load += OnFormLoad;
            form.Closing += OnFormClosing;
            form.Disposed += OnFormDisposed;
        }
Ejemplo n.º 24
0
        public static void Save(MainWindowViewModel vm)
        {
            //add lang setting
            System.Configuration.SettingsProperty langproperty = new System.Configuration.SettingsProperty("SelectedLang");
            langproperty.DefaultValue = true;
            langproperty.IsReadOnly   = false;
            langproperty.PropertyType = typeof(int);
            langproperty.Provider     = AppSettings.Default.Providers["LocalFileSettingsProvider"];
            langproperty.Attributes.Add(typeof(System.Configuration.UserScopedSettingAttribute), new System.Configuration.UserScopedSettingAttribute());
            AppSettings.Default.Properties.Add(langproperty);
            AppSettings.Default["SelectedLang"] = vm.settingsTabViewModel.SelectedLangItem;

            SaveCheckBoxes(vm.cleanerTabViewModel.ListOfWindowsElements);
            //for plugins
            SaveCheckBoxes(vm.cleanerTabViewModel.ListOfOtherElemets);
            //for registry tab
            SaveRegistryCheckBoxes(vm);
            //
            AppSettings.Default.Save();
            AppSettings.Default.Properties.Clear();
        }
Ejemplo n.º 25
0
		public void Ctor_1 ()
		{
			SettingsProperty p = new SettingsProperty ("property",
								   typeof (int),
								   null,
								   true,
								   10,
								   SettingsSerializeAs.Binary,
								   null,
								   true,
								   false);

			Assert.AreEqual ("property", p.Name, "A1");
			Assert.AreEqual (typeof (int), p.PropertyType, "A2");
			Assert.AreEqual (null, p.Provider, "A3");
			Assert.AreEqual (10, (int)p.DefaultValue, "A4");
			Assert.AreEqual (SettingsSerializeAs.Binary, p.SerializeAs, "A5");
			Assert.IsNull (p.Attributes, "A6");
			Assert.IsTrue (p.ThrowOnErrorDeserializing, "A7");
			Assert.IsFalse (p.ThrowOnErrorSerializing, "A8");
			Assert.IsTrue (p.IsReadOnly, "A9");
		}
Ejemplo n.º 26
0
        public void SaveToConfig(System.Configuration.ApplicationSettingsBase settings)
        {
            //settings.MRPath0 = files[0];
            for (int q = 0; q < files.Count; q++)
            {
                string pName = "MRU" + myName + q.ToString();
                try
                {
                    //if (settings[pName] == null)
                    if (!DoesSettingExist(pName))
                    {
                        //SettingsProvider prov = Properties.Settings.Default.Providers.
                        SettingsProperty prop = new System.Configuration.SettingsProperty(pName);
                        prop.PropertyType = typeof(string);
                        prop.Attributes.Add(typeof(UserScopedSettingAttribute), new UserScopedSettingAttribute());
                        //prop.Provider = prov;
                        prop.SerializeAs = SettingsSerializeAs.Xml;
                        SettingsPropertyValue valu = new SettingsPropertyValue(prop);
                        settings.Properties.Add(prop);



                        //settings[pName] = files[q];
                        settings.Save();
                        settings.Reload();
                    }
                    settings[pName] = files[q];
                }
                catch (Exception e)
                {
                    if (IsWizard)
                    {
                        string msg = e.Message;
                        //System.Diagnostics.Debugger.Break();
                    }
                }
            }
            settings.Save();
        }
Ejemplo n.º 27
0
		public void Properties ()
		{
			SettingsProperty p = new SettingsProperty ("property",
								   typeof (int),
								   null,
								   true,
								   10,
								   SettingsSerializeAs.String,
								   null,
								   true,
								   false);

			SettingsPropertyValue v = new SettingsPropertyValue (p);

			Assert.IsFalse (v.Deserialized, "A1");
			Assert.IsFalse (v.IsDirty, "A2");
			Assert.AreEqual ("property", v.Name, "A3");
			Assert.AreEqual (p, v.Property, "A4");
			Assert.AreEqual ((object)10, v.PropertyValue, "A5");
			Assert.AreEqual (null, v.SerializedValue, "A6");
			Assert.IsTrue (v.UsingDefaultValue, "A7");

			/* test that setting v.PropertyValue to
			 * something else causes SerializedValue to
			 * become not-null */
			v.PropertyValue = (object)5;
			Assert.AreEqual ("5", v.SerializedValue, "A9");

			/* test to see whether or not changing
			 * SerializeAs causes SerializedValue to
			 * change */
			p.SerializeAs = SettingsSerializeAs.Xml;
			Assert.AreEqual ("5", v.SerializedValue, "A11"); /* nope.. */

			/* only changing PropertyValue does */
			v.PropertyValue = (object)7;
			Assert.AreEqual ("<?xml version=\"1.0\" encoding=\"utf-16\"?>\n<int>7</int>", ((string)v.SerializedValue).Replace ("\r\n", "\n"), "A13");
		}
        public void GivenConfirmedUsersWhenSetPropertyValuesWithInvalidColumnsThenThrowNotSupportedException(
            string providerName, string membershipProviderName)
        {
            // arrange
            var testClass = this.WithProvider(providerName);
            var memProvider = this.WithMembershipProvider(membershipProviderName);
            var user = memProvider.WithConfirmedUser().Value;
            var context = new SettingsContext();
            context["UserName"] = user.UserName;
            var properties = new SettingsPropertyValueCollection
                                 {
                                     new SettingsPropertyValue(
                                         new SettingsProperty("invalidColumn")
                                             {
                                                 PropertyType = typeof(string)
                                             })
                                         {
                                             SerializedValue
                                                 =
                                                 "Value"
                                         }
                                 };
            if (memProvider.AsBetter().HasEmailColumnDefined)
            {
                var emailProperty = new SettingsProperty(memProvider.AsBetter().UserEmailColumn)
                                        {
                                            PropertyType =
                                                typeof(string)
                                        };
                properties.Add(
                    new SettingsPropertyValue(emailProperty) { PropertyValue = user.Email, Deserialized = true });
            }

            // act // assert
            Assert.Throws<NotSupportedException>(() => testClass.SetPropertyValues(context, properties));
        }
Ejemplo n.º 29
0
        public void AuthenticatedDateTime()
        {
            ProfileBase profile = ProfileBase.Create("foo", true);
            ResetAppId(profile.Providers["MySqlProfileProvider"] as MySQLProfileProvider);
            DateTime date = DateTime.Now;
            profile["BirthDate"] = date;
            profile.Save();

            SettingsPropertyCollection getProps = new SettingsPropertyCollection();
            SettingsProperty getProp1 = new SettingsProperty("BirthDate");
            getProp1.PropertyType = typeof(DateTime);
            getProp1.SerializeAs = SettingsSerializeAs.Xml;
            getProps.Add(getProp1);

            MySQLProfileProvider provider = InitProfileProvider();
            SettingsContext ctx = new SettingsContext();
            ctx.Add("IsAuthenticated", true);
            ctx.Add("UserName", "foo");

            SettingsPropertyValueCollection getValues = provider.GetPropertyValues(ctx, getProps);
            Assert.AreEqual(1, getValues.Count);
            SettingsPropertyValue getValue1 = getValues["BirthDate"];
            Assert.AreEqual(date, getValue1.PropertyValue);
        }
Ejemplo n.º 30
0
 public SettingsPropertyValue(SettingsProperty property)
 {
     this.property       = property;
     needPropertyValue   = true;
     needSerializedValue = true;
 }
Ejemplo n.º 31
0
 public SettingsProperty(SettingsProperty propertyToCopy)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 32
0
 public SettingsPropertyValue(SettingsProperty property)
 {
     Property = property;
 }
Ejemplo n.º 33
0
        public void SaveToConfig()
        {
            if (dirty)
            {
                //appSettings.MRPath0 = files[0];
                for (int q = 0; q < files.Count; q++)
                {
                    string pName = "MRU" + myName + q.ToString();
                    try
                    {
                        //if (settings[pName] == null)
                        if (!DoesSettingExist(pName))
                        {
                            // Requested Setting pName does NOT already exist amongst the default settings
                            // Thus, we need to create and add it

                            //SettingsProvider prov = Properties.Settings.Default.Providers.

                            // Create it, and set type and other properties
                            SettingsProperty prop = new System.Configuration.SettingsProperty(pName);
                            prop.PropertyType = typeof(string);
                            prop.IsReadOnly   = false;
                            prop.DefaultValue = "";
                            prop.Provider     = appSettings.Providers["LocalFileSettingsProvider"];
                            prop.Attributes.Add(typeof(UserScopedSettingAttribute), new UserScopedSettingAttribute());
                            //prop.Provider = prov;
                            prop.SerializeAs = SettingsSerializeAs.Xml;
                            SettingsPropertyValue valu = new SettingsPropertyValue(prop);

                            // Add it to the Default Settings
                            appSettings.Properties.Add(prop);

                            //settings[pName] = files[q];
                            appSettings.Save();
                            appSettings.Reload();
                        }
                        if (files[q] == null)
                        {
                            files[q] = "";
                        }

                        try
                        {
                            //!EXCEPTION HERE
                            string pn = pName;
                            appSettings[pName] = files[q];
                        }
                        catch (Exception e)
                        {
                            if (IsWizard)
                            {
                                string       msg = e.Message;
                                DialogResult dr  = MessageBox.Show(msg, "Most-Recently-Used Error", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Error);
                                if (dr == DialogResult.Abort)
                                {
                                    System.Diagnostics.Debugger.Break();
                                }
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        if (IsWizard)
                        {
                            string       msg = e.Message;
                            DialogResult dr  = MessageBox.Show(msg, "Most-Recently-Used Error", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Error);
                            if (dr == DialogResult.Abort)
                            {
                                System.Diagnostics.Debugger.Break();
                            }
                        }
                    }
                }
                appSettings.Save();
            }
        }
 // FIXME: implement
 public SettingsPropertyValue GetPreviousVersion(SettingsContext context, SettingsProperty property)
 {
     return(null);
 }
Ejemplo n.º 35
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);
            }
        }
 private static bool IsRoamingSetting(SettingsProperty setting)
 {
     bool flag = !ApplicationSettingsBase.IsClickOnceDeployed(AppDomain.CurrentDomain);
     bool flag2 = false;
     if (flag)
     {
         SettingsManageabilityAttribute attribute = setting.Attributes[typeof(SettingsManageabilityAttribute)] as SettingsManageabilityAttribute;
         flag2 = (attribute != null) && (0 == 0);
     }
     return flag2;
 }
Ejemplo n.º 37
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);
            }
        }
        /// <devdoc>
        ///     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.
        /// </devdoc>
        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 = SecurityUtils.SecureCreateInstance(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(SR.GetString(SR.ProviderInstantiationFailed, providerTypeName));
                            }
                        }
                        else
                        {
                            throw new ConfigurationErrorsException(SR.GetString(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);
        }
Ejemplo n.º 39
0
        // Retrieve values from the configuration file, or if the setting does not exist in the file,
        // retrieve the value from the application's default configuration
        private object GetSetting(SettingsProperty setProp)
        {
            object retVal;

            // Search for the specific settings node we are looking for in the configuration file.
            XmlNode SettingNode = XMLConfig.SelectSingleNode("//setting[@name='" + setProp.Name + "']");

            SettingNode = SettingNode == null ? null : SettingNode.FirstChild;

            // If it exists, return the InnerText or InnerXML of its first child node, depending on the setting type.
            if (SettingNode != null)
            {
                switch (setProp.SerializeAs)
                {
                case SettingsSerializeAs.String:
                    return(SettingNode.InnerText);

                case SettingsSerializeAs.Xml:
                    string xmlData = SettingNode.InnerXml;
                    return(@"" + xmlData);

                case SettingsSerializeAs.Binary:
                default:
                    throw new NotSupportedException();
                    //break;
                }
            }
            else
            {
                // Check to see if a default value is defined by the application.
                if ((setProp.DefaultValue != null))
                {
                    // If so, return that value, using the same rules for settings stored as Strings and XML as above
                    switch (setProp.SerializeAs)
                    {
                    case SettingsSerializeAs.String:
                        retVal = setProp.DefaultValue.ToString();
                        break;

                    case SettingsSerializeAs.Xml:
                        retVal = setProp.DefaultValue.ToString().Replace(@"<?xml version=""1.0"" encoding=""utf-16""?>", "");
                        break;

                    /*string xmlData = setProp.DefaultValue.ToString();
                     * XmlSerializer xs = new XmlSerializer(typeof(string[]));
                     * StringCollection sc = new StringCollection();
                     * object property = xs.Deserialize(new XmlTextReader(xmlData, XmlNodeType.Element, null));
                     * if (setProp.PropertyType == typeof(System.Collections.Specialized.StringCollection))
                     * {
                     *  string[] data = (string[])property;
                     *  sc.AddRange(data);
                     *  return sc;
                     * }
                     * throw new NotSupportedException();**/
                    //retVal = "";
                    //break;
                    case SettingsSerializeAs.Binary:
                    default:
                        throw new NotSupportedException();
                        //retVal = "";
                        //break;
                    }
                }
                else
                {
                    retVal = "";
                }
            }
            return(retVal);
        }
 private XmlNode SerializeToXmlElement(SettingsProperty setting, SettingsPropertyValue value)
 {
     XmlElement element = new XmlDocument().CreateElement("value");
     string serializedValue = value.SerializedValue as string;
     if ((serializedValue == null) && (setting.SerializeAs == SettingsSerializeAs.Binary))
     {
         byte[] inArray = value.SerializedValue as byte[];
         if (inArray != null)
         {
             serializedValue = Convert.ToBase64String(inArray);
         }
     }
     if (serializedValue == null)
     {
         serializedValue = string.Empty;
     }
     if (setting.SerializeAs == SettingsSerializeAs.String)
     {
         serializedValue = this.Escaper.Escape(serializedValue);
     }
     element.InnerXml = serializedValue;
     XmlNode oldChild = null;
     foreach (XmlNode node2 in element.ChildNodes)
     {
         if (node2.NodeType == XmlNodeType.XmlDeclaration)
         {
             oldChild = node2;
             break;
         }
     }
     if (oldChild != null)
     {
         element.RemoveChild(oldChild);
     }
     return element;
 }
 public SettingsPropertyValue GetPreviousVersion(SettingsContext context, SettingsProperty property) {
     if (_Properties == null)
         _Properties = new SettingsPropertyCollection();
     if (_Properties[property.Name] == null)
         _Properties.Add(property);
     GetPropertyValuesCore();
     return _PropertyValues[property.Name];
 }
Ejemplo n.º 42
0
 public SettingsPropertyValue GetPreviousVersion(SettingsContext context,
                                                 SettingsProperty property)
 {
     return(impl.GetPreviousVersion(context, property));
 }
 public SettingsPropertyValue(SettingsProperty property)
 {
     this._Property = property;
 }
 /// <devdoc>
 ///     Indicates whether a setting is roaming or not.
 /// </devdoc>
 private static bool IsRoamingSetting(SettingsProperty setting)
 {
     return(false);
 }
Ejemplo n.º 45
0
        ////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////
        // On* Methods for deriving classes to override.  These have
        // been modeled after the CollectionBase class but have
        // been stripped of their "index" parameters as there is no
        // visible index to this collection.

        protected virtual void OnAdd(SettingsProperty property)
        {
        }
Ejemplo n.º 46
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);
        }
Ejemplo n.º 47
0
		public void Remove_NonExistant ()
		{
			SettingsPropertyCollection col = new SettingsPropertyCollection ();
			SettingsProperty test_prop = new SettingsProperty ("test_prop");

			col.Add (test_prop);

			Assert.AreEqual (1, col.Count, "A1");

			col.Remove ("test_prop2");

			Assert.AreEqual (1, col.Count, "A2");
		}
Ejemplo n.º 48
0
 protected virtual void OnAddComplete(SettingsProperty property)
 {
 }
 private bool IsUserSetting(SettingsProperty setting)
 {
     bool flag = setting.Attributes[typeof(UserScopedSettingAttribute)] is UserScopedSettingAttribute;
     bool flag2 = setting.Attributes[typeof(ApplicationScopedSettingAttribute)] is ApplicationScopedSettingAttribute;
     if (flag && flag2)
     {
         throw new ConfigurationErrorsException(System.SR.GetString("BothScopeAttributes"));
     }
     if (!flag && !flag2)
     {
         throw new ConfigurationErrorsException(System.SR.GetString("NoScopeAttributes"));
     }
     return flag;
 }
Ejemplo n.º 50
0
 protected virtual void OnRemoveComplete(SettingsProperty property)
 {
 }
 public SettingsPropertyValue GetPreviousVersion(SettingsContext context, SettingsProperty property)
 {
     bool isRoaming = IsRoamingSetting(property);
     string previousConfigFileName = this.GetPreviousConfigFileName(isRoaming);
     if (!string.IsNullOrEmpty(previousConfigFileName))
     {
         SettingsPropertyCollection properties = new SettingsPropertyCollection();
         properties.Add(property);
         return this.GetSettingValuesFromFile(previousConfigFileName, this.GetSectionName(context), 1, properties)[property.Name];
     }
     return new SettingsPropertyValue(property) { PropertyValue = null };
 }
Ejemplo n.º 52
0
        /// <summary>
        /// Indicates whether a setting is roaming or not.
        /// </summary>
        private static bool IsRoamingSetting(SettingsProperty setting)
        {
            SettingsManageabilityAttribute manageAttr = setting.Attributes[typeof(SettingsManageabilityAttribute)] as SettingsManageabilityAttribute;

            return(manageAttr != null && ((manageAttr.Manageability & SettingsManageability.Roaming) == SettingsManageability.Roaming));
        }
Ejemplo n.º 53
0
		public virtual SettingsPropertyValue GetPreviousVersion(SettingsContext context, SettingsProperty property)
		{
			return SimpleSettingsStore.Instance.PreviousUserValues[property.Name];
		}
Ejemplo n.º 54
0
        public static void save_Setting(string setting_Name, string setting_Value)

        {
            //----------< save_Settings() >----------



            string property_name = setting_Name;



            //< Setting erstellen >

            SettingsProperty prop = null;

            if (Properties.Settings.Default.Properties[property_name] != null)

            {
                //< existing Setting >

                prop = Properties.Settings.Default.Properties[property_name];

                //</ existing Setting >
            }

            else

            {
                //< new Setting >

                prop = new System.Configuration.SettingsProperty(property_name);

                prop.PropertyType = typeof(string);

                Properties.Settings.Default.Properties.Add(prop);

                Properties.Settings.Default.Save();
                Properties.Settings.Default.Upgrade();

                //</ new Setting >
            }

            //</ Setting erstellen >



            //< set value  >

            Properties.Settings.Default.Properties[property_name].DefaultValue = setting_Value;

            //</ set value >



            //< Save Settings File >

            Properties.Settings.Default.Save();

            //</ Save Settings File >



            //----------</ save_Settings() >----------
        }