Add() публичный Метод

public Add ( SettingsPropertyValue property ) : void
property SettingsPropertyValue
Результат void
		public void AddDuplicate ()
		{
			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.Add (val);

			Assert.AreEqual (1, col.Count, "A2");
		}
        public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection collection)
        {
            CreateExeMap();

            if (values == null)
            {
                values = new SettingsPropertyValueCollection();
                string groupName = context ["GroupName"] as string;
                groupName = NormalizeInvalidXmlChars(groupName);                  // we likely saved the element removing the non valid xml chars.
                LoadProperties(exeMapCurrent, collection, ConfigurationUserLevel.None, "applicationSettings", false, groupName);
                LoadProperties(exeMapCurrent, collection, ConfigurationUserLevel.None, "userSettings", false, groupName);

                LoadProperties(exeMapCurrent, collection, ConfigurationUserLevel.PerUserRoaming, "userSettings", true, groupName);
                LoadProperties(exeMapCurrent, collection, ConfigurationUserLevel.PerUserRoamingAndLocal, "userSettings", true, groupName);

                // create default values if not exist
                foreach (SettingsProperty p in collection)
                {
                    if (values [p.Name] == null)
                    {
                        values.Add(new SettingsPropertyValue(p));
                    }
                }
            }
            return(values);
        }
Пример #3
0
        /// <summary>
        /// Retrieves the values of settings from the given config file (as opposed to using
        /// the configuration for the current context)
        /// </summary>
        private SettingsPropertyValueCollection GetSettingValuesFromFile(string configFileName, string sectionName, bool userScoped, SettingsPropertyCollection properties)
        {
            SettingsPropertyValueCollection values = new SettingsPropertyValueCollection();
            IDictionary settings = ClientSettingsStore.ReadSettingsFromFile(configFileName, sectionName, userScoped);

            // Map each SettingProperty to the right StoredSetting and deserialize the value if found.
            foreach (SettingsProperty setting in properties)
            {
                string settingName          = setting.Name;
                SettingsPropertyValue value = new SettingsPropertyValue(setting);

                if (settings.Contains(settingName))
                {
                    StoredSetting ss          = (StoredSetting)settings[settingName];
                    string        valueString = ss.Value.InnerXml;

                    // We need to un-escape string serialized values
                    if (ss.SerializeAs == SettingsSerializeAs.String)
                    {
                        valueString = Escaper.Unescape(valueString);
                    }

                    value.SerializedValue = valueString;
                    value.IsDirty         = true;
                    values.Add(value);
                }
            }

            return(values);
        }
		public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection props)
		{
			XmlSettingsFile localFile = XmlSettingsFile.GetLocalSettingsFile(GetTypeFromContext(context));
			XmlSettingsFile roamingFile = XmlSettingsFile.GetRoamingSettingsFile(GetTypeFromContext(context));
			SettingsPropertyValueCollection values = new SettingsPropertyValueCollection();

			foreach (SettingsProperty setting in props)
			{
				SettingsPropertyValue value = new SettingsPropertyValue(setting);
				value.IsDirty = false;

				if (IsRoaming(setting))
				{
					value.SerializedValue = roamingFile.GetValue(setting);
				}
				else
				{
					value.SerializedValue = localFile.GetValue(setting);
				}

				values.Add(value);
			}

			return values;
		}
        /// <summary>
        /// Returns the collection of settings property values for the specified application instance and settings property group.
        /// </summary>
        /// <returns>
        /// A <see cref="T:System.Configuration.SettingsPropertyValueCollection"/> containing the values for the specified settings property group.
        /// </returns>
        /// <param name="context">A <see cref="T:System.Configuration.SettingsContext"/> describing the current application use.
        ///                 </param><param name="collection">A <see cref="T:System.Configuration.SettingsPropertyCollection"/> containing the settings property group whose values are to be retrieved.
        ///                 </param><filterpriority>2</filterpriority>
        public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection collection)
        {
            var username = (string) context["UserName"];
            var isAuthenticated = (bool) context["IsAuthenticated"];
            Profile profile = ProfileManager.Instance.GetCurrentUser(username);

            var svc = new SettingsPropertyValueCollection();

            foreach (SettingsProperty prop in collection)
            {
                var pv = new SettingsPropertyValue(prop);

                switch (pv.Property.Name)
                {
                    case _PROFILE_SHOPPINGCART:
                        pv.PropertyValue = CartList.GetCart(profile.UniqueID, true);
                        break;
                    case _PROFILE_WISHLIST:
                        pv.PropertyValue = CartList.GetCart(profile.UniqueID, false);
                        break;
                    case _PROFILE_ACCOUNT:
                        if (isAuthenticated)
                            pv.PropertyValue = new Address(profile);
                        break;
                    default:
                        throw new ApplicationException(string.Format("{0} name.", _ERR_INVALID_PARAMETER));
                }

                svc.Add(pv);
            }
            return svc;
        }
        private void SaveCore()
        {
            if (Properties == null || _PropertyValues == null || Properties.Count == 0)
            {
                return;
            }

            foreach (SettingsProvider prov in Providers)
            {
                SettingsPropertyValueCollection ppcv = new SettingsPropertyValueCollection();
                foreach (SettingsPropertyValue pp in PropertyValues)
                {
                    if (pp.Property.Provider == prov)
                    {
                        ppcv.Add(pp);
                    }
                }
                if (ppcv.Count > 0)
                {
                    prov.SetPropertyValues(Context, ppcv);
                }
            }
            foreach (SettingsPropertyValue pp in PropertyValues)
            {
                pp.IsDirty = false;
            }
        }
Пример #7
0
        public override void Save()
        {
#if (CONFIGURATION_DEP)
            Context.CurrentSettings = this;
            /* ew.. this needs to be more efficient */
            foreach (SettingsProvider provider in Providers)
            {
                SettingsPropertyValueCollection cache = new SettingsPropertyValueCollection();

                foreach (SettingsPropertyValue val in PropertyValues)
                {
                    if (val.Property.Provider == provider)
                    {
                        cache.Add(val);
                    }
                }

                if (cache.Count > 0)
                {
                    provider.SetPropertyValues(Context, cache);
                }
            }
            Context.CurrentSettings = null;
#endif
        }
		private static void SetSharedPropertyValues(ApplicationSettingsBase settings, Dictionary<string, string> values)
		{
			foreach (SettingsProvider provider in settings.Providers)
			{
				ISharedApplicationSettingsProvider sharedSettingsProvider = GetSharedSettingsProvider(provider);
				if (sharedSettingsProvider == null)
					throw new NotSupportedException("Setting shared values is not supported.");

				var properties = GetPropertiesForProvider(settings, provider);
				SettingsPropertyValueCollection settingsValues = new SettingsPropertyValueCollection();

				foreach (var value in values)
				{
					SettingsProperty property = properties[value.Key];
					if (property == null)
						continue;

					settingsValues.Add(new SettingsPropertyValue(property) { SerializedValue = value.Value, IsDirty = true });
				}

				sharedSettingsProvider.SetSharedPropertyValues(settings.Context, settingsValues);
			}

			SaveIfDirty(settings);
			settings.Reload();
		}
        public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context,
            SettingsPropertyCollection collection)
        {
            var properties = new SettingsPropertyValueCollection();
            if (collection.Count < 1)
                return properties;

            var username = (string) context["UserName"];
            foreach (SettingsProperty property in collection)
            {
                properties.Add(new SettingsPropertyValue(property));
            }

            var db = new MyLifeEntities();
            var profile = db.tblProfiles.Where(item => item.UserName == username).FirstOrDefault();
            if (profile != null)
            {
                var names =
                    profile.PropertyNames.Split(new[] {";#"}, StringSplitOptions.RemoveEmptyEntries);
                var values =
                    profile.PropertyValues.Split(new[] {";#"}, StringSplitOptions.RemoveEmptyEntries);
                if (names.Length > 0 && values.Length > 0)
                {
                    for (var i = 0; i < names.Length; i++)
                    {
                        var property = properties[names[i]];
                        if (property == null) continue;
                        property.PropertyValue = Base64Serializer.Deserialize(values[i]);
                    }
                }
            }

            return properties;
        }
Пример #10
0
		/// <summary>
		/// Returns the collection of settings property values for the specified application instance and settings property group.
		/// </summary>
		/// <param name="context">A System.Configuration.SettingsContext describing the current application use.</param>
		/// <param name="collection">A System.Configuration.SettingsPropertyCollection containing the settings property group whose values are to be retrieved.</param>
		/// <returns>A System.Configuration.SettingsPropertyValueCollection containing the values for the specified settings property group.</returns>
		public override SettingsPropertyValueCollection GetPropertyValues(
			SettingsContext context, SettingsPropertyCollection collection)
		{
			string username        = (string)context["UserName"];
			bool   isAuthenticated = (bool)  context["IsAuthenticated"];

			SettingsPropertyValueCollection svc = new SettingsPropertyValueCollection();

			foreach (SettingsProperty prop in collection)
			{
				SettingsPropertyValue pv = new SettingsPropertyValue(prop);

				switch (pv.Property.Name)
				{
					case PROFILE_SHOPPINGCART: pv.PropertyValue = GetCartItems(username, true);  break;
					case PROFILE_WISHLIST:     pv.PropertyValue = GetCartItems(username, false); break;
					case PROFILE_ACCOUNT:
						if (isAuthenticated)
							pv.PropertyValue = GetAccountInfo(username);
						break;

					default:
						throw new ApplicationException(ERR_INVALID_PARAMETER + " name.");
				}

				svc.Add(pv);
			}

			return svc;
		}
Пример #11
0
        private void LoadPropertyValue(SettingsPropertyCollection collection, SettingElement element, bool allowOverwrite)
        {
            SettingsProperty prop = collection [element.Name];

            if (prop == null)               // see bug #343459
            {
                prop = new SettingsProperty(element.Name);
                collection.Add(prop);
            }

            SettingsPropertyValue value = new SettingsPropertyValue(prop);

            value.IsDirty         = false;
            value.SerializedValue = element.Value.ValueXml != null ? element.Value.ValueXml.InnerText : prop.DefaultValue;
            try
            {
                if (allowOverwrite)
                {
                    values.Remove(element.Name);
                }
                values.Add(value);
            } catch (ArgumentException) {
                throw new ConfigurationErrorsException();
            }
        }
        public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection collection)
        {
            // set all of the inherited default values first in case we have failure later
            SettingsPropertyValueCollection settings = new SettingsPropertyValueCollection();
            foreach (SettingsProperty prop in collection)
            {
                SettingsPropertyValue spv = new SettingsPropertyValue(prop);
                spv.SerializedValue = prop.DefaultValue;
                settings.Add(spv);
            }

            // now read in overridden user settings
            try
            {
                Configuration config = null;
                ClientSettingsSection clientSettings = GetUserSettings(out config, true);
                foreach (SettingsPropertyValue spv in settings)
                {
                    DeserializeFromXmlElement(spv.Property, spv, clientSettings);
                }
            }
            catch
            {
                // suppress
            }

            return settings;
        }
Пример #13
0
		/// <summary>
		/// Must override this, this is the bit that matches up the designer properties to the dictionary values
		/// </summary>
		/// <param name="context"></param>
		/// <param name="collection"></param>
		/// <returns></returns>
		public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection collection) {
			//load the file
			if (!_loaded) {
				_loaded = true;
				LoadValuesFromFile();
			}

			//collection that will be returned.
			SettingsPropertyValueCollection values = new SettingsPropertyValueCollection();

			//itterate thought the properties we get from the designer, checking to see if the setting is in the dictionary
			foreach (SettingsProperty setting in collection) {
				SettingsPropertyValue value = new SettingsPropertyValue(setting);
				value.IsDirty = false;

				//need the type of the value for the strong typing
				var t = Type.GetType(setting.PropertyType.FullName);

				if (SettingsDictionary.ContainsKey(setting.Name)) {
					value.SerializedValue = SettingsDictionary[setting.Name].value;
					value.PropertyValue = Convert.ChangeType(SettingsDictionary[setting.Name].value, t);
				}
				else //use defaults in the case where there are no settings yet
				{
					value.SerializedValue = setting.DefaultValue;
					value.PropertyValue = Convert.ChangeType(setting.DefaultValue, t);
				}

				values.Add(value);
			}
			return values;
		}
 private void SaveCore()
 {
     if (((this.Properties != null) && (this._PropertyValues != null)) && (this.Properties.Count != 0))
     {
         foreach (SettingsProvider provider in this.Providers)
         {
             SettingsPropertyValueCollection collection = new SettingsPropertyValueCollection();
             foreach (SettingsPropertyValue value2 in this.PropertyValues)
             {
                 if (value2.Property.Provider == provider)
                 {
                     collection.Add(value2);
                 }
             }
             if (collection.Count > 0)
             {
                 provider.SetPropertyValues(this.Context, collection);
             }
         }
         foreach (SettingsPropertyValue value3 in this.PropertyValues)
         {
             value3.IsDirty = false;
         }
     }
 }
        void InternalSave()
        {
#if (CONFIGURATION_DEP)
            Context.CurrentSettings = this;
            /* ew.. this needs to be more efficient */
            foreach (SettingsProvider provider in Providers)
            {
                SettingsPropertyValueCollection cache = new SettingsPropertyValueCollection();

                foreach (SettingsPropertyValue val in PropertyValues)
                {
                    if (val.Property.Provider == provider)
                    {
                        cache.Add(val);
                    }
                }

                if (cache.Count > 0)
                {
                    provider.SetPropertyValues(Context, cache);
                }
            }
            Context.CurrentSettings = null;
#else
            throw new NotImplementedException("No useful Save implemented.");
#endif
        }
Пример #16
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);
    }
        public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context,
            SettingsPropertyCollection collection)
        {
            SettingsPropertyValueCollection result = new SettingsPropertyValueCollection();
            if (collection.Count < 1)
                return result;

            string userEmail = (string) context["UserName"]; //Эта строка мне пока не понятна
            if (string.IsNullOrEmpty(userEmail))
                return result;

            var user = UserService.GetByEmail(userEmail);
            var profile = ProfileService.GetProfile(user);

            foreach (SettingsProperty prop in collection)
            {
                SettingsPropertyValue svp = new SettingsPropertyValue(prop)
                {
                    PropertyValue = profile.GetType().GetProperty(prop.Name).GetValue(profile, null)
                };

                result.Add(svp);
            }

            return result;
        }
Пример #18
0
        void SaveCore()
        {
            //
            // Copied from ApplicationSettingsBase
            //
#if (CONFIGURATION_DEP)
            /* ew.. this needs to be more efficient */
            foreach (SettingsProvider provider in Providers)
            {
                SettingsPropertyValueCollection cache = new SettingsPropertyValueCollection();

                foreach (SettingsPropertyValue val in PropertyValues)
                {
                    if (val.Property.Provider == provider)
                    {
                        cache.Add(val);
                    }
                }

                if (cache.Count > 0)
                {
                    provider.SetPropertyValues(Context, cache);
                }
            }
#endif
        }
 public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection collection)
 {
     SettingsPropertyValueCollection v = new SettingsPropertyValueCollection();
     value = new SettingsPropertyValue(new SettingsProperty("Style"));
     value.PropertyValue = "null";
     v.Add(value);
     return v;
 }
		public static SettingsPropertyValueCollection ToSettingsPropertyValueCollection(this IEnumerable<SettingsPropertyValue> values)
		{
			var c = new SettingsPropertyValueCollection();
			foreach (var value in values)
			{
				c.Add(value);
			}
			return c;
		}
        /// <summary>
        /// Loads the settings from the database. This is only called when a propery in the Settings object
        /// is used the first time, each time after that the assembly uses it's local cache
        /// </summary>
        /// <param name="context"></param>
        /// <param name="properties"></param>
        /// <returns>The requested settings</returns>
        public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection properties) {
            SettingsPropertyValueCollection values = new SettingsPropertyValueCollection();
            string section = GetSectionName(context);
            settings = SnapShot.GetFor(section);
            foreach (SettingsProperty property in properties) {

                SpecialSettingAttribute attribute = property.Attributes[typeof(SpecialSettingAttribute)] as SpecialSettingAttribute;
                if (attribute != null && (attribute.SpecialSetting == SpecialSetting.ConnectionString))
                    values.Add(GetConnectionStringValue(section, property));
                else if (IsApplicationSetting(property))
                    values.Add(GetApplcationSetting(property));
                else
                    throw new ConfigurationErrorsException("User settings are not supported in this provider");
            }
            
            return values;

        }
        public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection collection)
        {
            // коллекция, которая возвращает значения свойств профиля
            var result = new SettingsPropertyValueCollection();

            if (collection == null || collection.Count < 1 || context == null)
            {
                return result;
            }

            // получаем из контекста имя пользователя - логин в системе
            var username = (string)context["UserName"];
            if (String.IsNullOrEmpty(username)) return result;


            // получаем id пользователя из таблицы Users по логину
            var firstOrDefault = userService.GetUserEntityByEmail(username);
            if (firstOrDefault != null)
            {
                int userId = firstOrDefault.Id;
                // по этому id извлекаем профиль из таблицы профилей
                ProfileEntity profile = profileService.GetProfileByUserId(userId);
                if (profile != null)
                {
                    foreach (SettingsProperty prop in collection)
                    {
                        var spv = new SettingsPropertyValue(prop)
                        {
                            PropertyValue = profile.GetType().GetProperty(prop.Name).GetValue(profile, null)
                        };
                        result.Add(spv);
                    }
                }
                else
                {
                    foreach (SettingsProperty prop in collection)
                    {
                        var svp = new SettingsPropertyValue(prop) { PropertyValue = null };
                        result.Add(svp);
                    }
                }
            }
            return result;
        }
		public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection props) {
			var values = new SettingsPropertyValueCollection();
			foreach (SettingsProperty property in props) {
				var value2 = new SettingsPropertyValue(property) {
					IsDirty = false,
					SerializedValue = GetValue(property)
				};
				values.Add(value2);
			}
			return values;
		}
Пример #24
0
		public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection collection)
		{
			SettingsPropertyValueCollection values = new SettingsPropertyValueCollection();

			foreach (SettingsProperty property in collection)
			{
				if (SettingsPropertyExtensions.IsUserScoped(property))
				{
					SettingsPropertyValue value = SimpleSettingsStore.Instance.CurrentUserValues[property.Name] ?? new SettingsPropertyValue(property);
					values.Add(value);
				}
				else
				{
					SettingsPropertyValue value = SimpleSettingsStore.Instance.CurrentSharedValues[property.Name] ?? new SettingsPropertyValue(property);
					values.Add(value);
				}
			}

			return values;
		}
        public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection collection)
        {
            SettingsPropertyValueCollection spCollection = new SettingsPropertyValueCollection();
            foreach (SettingsProperty settingsProperty in collection)
            {
                SettingsPropertyValue spVal = new SettingsPropertyValue(settingsProperty);
                spVal.PropertyValue = String.Empty;
                spCollection.Add(spVal);
            }

            return spCollection;
        }
		public override SettingsPropertyValueCollection GetPropertyValues (SettingsContext context,
										   SettingsPropertyCollection properties)
		{
#if TARGET_JVM
			SettingsPropertyValueCollection pv = new SettingsPropertyValueCollection ();
			foreach (SettingsProperty prop in properties)
				pv.Add (new SettingsPropertyValue (prop));
			return pv;
#else
			return impl.GetPropertyValues (context, properties);
#endif
		}
        public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection collection)
        {
            var result = new SettingsPropertyValueCollection();

            if (collection == null || collection.Count < 1 || context == null)
            {
                return result;
            }

            var username = (string)context["UserName"];
            if (String.IsNullOrEmpty(username)) return result;

            var db = new UserContext();
            var firstOrDefault = db.Users.FirstOrDefault(u => u.Email.Equals(username));
            if (firstOrDefault != null)
            {
                int userId = firstOrDefault.ID;
                Profile profile = db.Profiles.FirstOrDefault(u => u.UserID == userId);
                if (profile != null)
                {
                    foreach (SettingsProperty prop in collection)
                    {
                        var spv = new SettingsPropertyValue(prop)
                        {
                            PropertyValue = profile.GetType().GetProperty(prop.Name).GetValue(profile, null)
                        };
                        result.Add(spv);
                    }
                }
                else
                {
                    foreach (SettingsProperty prop in collection)
                    {
                        var svp = new SettingsPropertyValue(prop) { PropertyValue = null };
                        result.Add(svp);
                    }
                }
            }
            return result;
        }
        private void LoadPropertyValue(SettingsPropertyCollection collection, SettingElement element, bool allowOverwrite)
        {
            SettingsProperty prop = collection [element.Name];

            if (prop == null) // see bug #343459
            {
                prop = new SettingsProperty(element.Name);
                collection.Add(prop);
            }

            SettingsPropertyValue value = new SettingsPropertyValue(prop);

            value.IsDirty = false;
            if (element.Value.ValueXml != null)
            {
                switch (value.Property.SerializeAs)
                {
                case SettingsSerializeAs.Xml:
                    value.SerializedValue = element.Value.ValueXml.InnerXml;
                    break;

                case SettingsSerializeAs.String:
                    value.SerializedValue = element.Value.ValueXml.InnerText;
                    break;

                case SettingsSerializeAs.Binary:
                    value.SerializedValue = Convert.FromBase64String(element.Value.ValueXml.InnerText);
                    break;
                }
            }
            else
            {
                value.SerializedValue = prop.DefaultValue;
            }
            try
            {
                if (allowOverwrite)
                {
                    values.Remove(element.Name);
                }
                values.Add(value);
            }
            catch (ArgumentException ex)
            {
                throw new ConfigurationErrorsException(string.Format(
                                                           CultureInfo.InvariantCulture,
                                                           "Failed to load value for '{0}'.",
                                                           element.Name), ex);
            }
        }
Пример #29
0
        public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context,
                                                                          SettingsPropertyCollection properties)
        {
#if TARGET_JVM
            SettingsPropertyValueCollection pv = new SettingsPropertyValueCollection();
            foreach (SettingsProperty prop in properties)
            {
                pv.Add(new SettingsPropertyValue(prop));
            }
            return(pv);
#else
            return(impl.GetPropertyValues(context, properties));
#endif
        }
Пример #30
0
        public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection collection)
        {
            var result = new SettingsPropertyValueCollection();

            if (collection == null || collection.Count < 1 || context == null)
            {
                return result;
            }

            var userName = (string)context["UserName"];
            if (String.IsNullOrEmpty(userName))
            {
                return result;
            }

            UserEntity user = UserService.GetUserByLogin(userName);
            if (userName != null)
            {
                foreach (SettingsProperty property in collection)
                {
                    var spv = new SettingsPropertyValue(property)
                    {
                        PropertyValue = user.GetType().GetProperty(property.Name).GetValue(user, null)
                    };
                    result.Add(spv);
                }
            }
            else
            {
                foreach (SettingsProperty property in collection)
                {
                    var svp = new SettingsPropertyValue(property) { PropertyValue = null };
                    result.Add(svp);
                }
            }
            return result;
        }
        public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection props)
        {
            // Create new collection of values
            SettingsPropertyValueCollection values = new SettingsPropertyValueCollection();

            // Iterate through the settings to be retrieved
            foreach (SettingsProperty setting in props)
            {
                SettingsPropertyValue value = new SettingsPropertyValue(setting);
                value.IsDirty = false;
                value.SerializedValue = (string)GetRegKey(setting).GetValue(setting.Name);
                values.Add(value);
            }
            return values;
        }
        public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection collection)
        {
            Configuration config = null;
            ClientSettingsSection clientSettings = null;

            // set all of the inherited default values first in case we have failure later
            SettingsPropertyValueCollection settings = new SettingsPropertyValueCollection();
            foreach (SettingsProperty prop in collection)
            {
                SettingsPropertyValue spv = new SettingsPropertyValue(prop);
                spv.SerializedValue = prop.DefaultValue;
                settings.Add(spv);
            }

            // now read in app-level settings
            config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            ConfigurationSectionGroup configSectionGroup = config.GetSectionGroup(APP_SETTINGS_SECTION_GROUP_NAME);
            if (configSectionGroup != null)
            {
                ConfigurationSection configSection = configSectionGroup.Sections[APP_SETTINGS_SECTION_NAME];
                if (configSection != null)
                {
                    clientSettings = (ClientSettingsSection)configSection;
                    foreach (SettingsPropertyValue spv in settings)
                    {
                        DeserializeFromXmlElement(spv.Property, spv, clientSettings);
                    }
                }
            }

            // now read in overridden user settings
            try
            {
                config = null;
                clientSettings = GetUserSettings(out config, true);
                foreach (SettingsPropertyValue spv in settings)
                {
                    DeserializeFromXmlElement(spv.Property, spv, clientSettings);
                }
            }
            catch
            {
                // suppress
            }

            return settings;
        }
Пример #33
0
        public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection props)
        {
            // Create new collection of values
            SettingsPropertyValueCollection values = new SettingsPropertyValueCollection();
            string sectionName = this.GetSectionName(context);
            string settingKey = (string)context["SettingsKey"];

            // Iterate through the settings to be retrieved
            foreach (SettingsProperty setting in props)
            {
                SettingsPropertyValue value = new SettingsPropertyValue(setting);
                value.IsDirty = false;
                value.SerializedValue = getValue(setting, context);

                values.Add(value);
            }
            return values;
        }
        private static SettingsPropertyValueCollection GetSettingsValues(SettingsPropertyCollection properties, IDictionary<string, string> storedValues)
        {
            // Create new collection of values
            SettingsPropertyValueCollection values = new SettingsPropertyValueCollection();

			foreach (SettingsProperty setting in properties)
            {
				var value = new SettingsPropertyValue(setting)
				{
					SerializedValue = storedValues.ContainsKey(setting.Name) ? storedValues[setting.Name] : null,
					IsDirty = false
				};

                // use the stored value, or set the SerializedValue to null, which tells .NET to use the default value
                values.Add(value);
            }

            return values;
        }
Пример #35
0
        /// <summary>
        /// Retrieve settings from the configuration file.
        /// </summary>
        /// <param name="sContext">Provides contextual information that the provider can use when persisting settings.</param>
        /// <param name="settingsColl">Contains a collection of <see cref="SettingsProperty"/> objects.</param>
        /// <returns>A collection of settings property values that map <see cref="SettingsProperty"/> objects to <see cref="SettingsPropertyValue"/> objects.</returns>
        public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext sContext, SettingsPropertyCollection settingsColl)
        {
            // Create a collection of values to return
            SettingsPropertyValueCollection retValues = new SettingsPropertyValueCollection();

            // Create a temporary SettingsPropertyValue to reuse
            SettingsPropertyValue setVal;

            // Loop through the list of settings that the application has requested and add them
            // to our collection of return values.
            foreach (SettingsProperty sProp in settingsColl)
            {
                setVal                 = new SettingsPropertyValue(sProp);
                setVal.IsDirty         = false;
                setVal.SerializedValue = GetSetting(sProp);
                retValues.Add(setVal);
            }
            return(retValues);
        }
        public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection props)
        {
            lock (_locker)
            {
                // create new collection of values
                SettingsPropertyValueCollection values = new SettingsPropertyValueCollection();

                // iterate through the settings to be retrieved
                foreach (SettingsProperty prop in props)
                {
                    SettingsPropertyValue value = new SettingsPropertyValue(prop);
                    value.SerializedValue = _GetValue(prop);
                    value.IsDirty = false;
                    values.Add(value);
                }

                return values;
            }
        }
Пример #37
0
        public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context,
                                                                          SettingsPropertyCollection collection)
        {
            if (Settings.ClientSpecificMode)
            {
                var values = (Dictionary<SettingsProperty, object>) context[ValuesName];
                var result = new SettingsPropertyValueCollection();

                foreach (SettingsProperty setting in collection)
                {
                    object propertyValue = values.ContainsKey(setting)
                                               ? values[setting]
                                               : base.GetPropertyValues(context,
                                                                        new SettingsPropertyCollection {setting})[
                                                     setting.Name].PropertyValue;
                    var value = new SettingsPropertyValue(setting)
                                    {
                                        IsDirty = false,
                                        PropertyValue = propertyValue
                                    };
                    result.Add(value);
                }
                return result;
            }
            try
            {
                return base.GetPropertyValues(context, collection);
            }
            catch (ConfigurationErrorsException)
            {
                //A user-scoped setting was encountered but the current configuration only supports application-scoped settings.
                //example - Asp.Net web-site

                foreach (SettingsProperty setting in collection)
                {
                    setting.Attributes.Remove(typeof (UserScopedSettingAttribute));
                    setting.Attributes.Add(typeof (ApplicationScopedSettingAttribute),
                                           new ApplicationScopedSettingAttribute());
                }
                return base.GetPropertyValues(context, collection);
            }
        }
        public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection collection)
        {
            if (this.Error != null)
            {
                throw this.Error;
            }
            SettingsPropertyValueCollection spvc = new SettingsPropertyValueCollection();
            if (this.User == null)
            {
                return spvc;
            }
            foreach (SettingsProperty prop in collection)
            {
                SettingsPropertyValue propValue = new SettingsPropertyValue(prop);
                propValue.PropertyValue = typeof(MockUser).GetProperty(prop.Name).GetValue(this.User, null);
                spvc.Add(propValue);
            }

            return spvc;
        }
Пример #39
0
		void SaveCore ()
		{
			//
			// Copied from ApplicationSettingsBase
			//
#if (CONFIGURATION_DEP)
			/* ew.. this needs to be more efficient */
			foreach (SettingsProvider provider in Providers) {
				SettingsPropertyValueCollection cache = new SettingsPropertyValueCollection ();

				foreach (SettingsPropertyValue val in PropertyValues) {
					if (val.Property.Provider == provider)
						cache.Add (val);
				}

				if (cache.Count > 0)
					provider.SetPropertyValues (Context, cache);
			}
#endif
		}
 public override SettingsPropertyValueCollection GetPropertyValues(
     SettingsContext context,
     SettingsPropertyCollection collection)
 {
     var values = new SettingsPropertyValueCollection();
     foreach (SettingsProperty property in collection)
     {
         var value = new SettingsPropertyValue(property) {IsDirty = false};
         values.Add(value);
     }
     if (!File.Exists(SettingsPath))
         return values;
     try
     {
         using (var xtr = new XmlTextReader(SettingsPath))
         {
             var xDoc = new XmlDocument();
             xDoc.Load(xtr);
             var settingsNode = xDoc["Settings"];
             if (settingsNode == null)
                 return values;
             foreach (XmlNode node in settingsNode.GetElementsByTagName("Setting"))
             {
                 var name = node.Attributes?["Name"]?.Value;
                 if (string.IsNullOrEmpty(name))
                     continue;
                 var property = values[name];
                 if (property == null)
                     continue;
                 var value = node.InnerXml;
                 var dataType = property.Property.PropertyType;
                 property.PropertyValue = XmlDeserializeProperty(value, dataType);
             }
         }
     }
     catch (XmlException)
     {
         // Ignore
     }
     return values;
 }
Пример #41
0
        public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection collection)
        {
            if (!(bool)context["IsAuthenticated"])
                throw new BL.BLException("UserProfileProvider doesn't allow anonymous profiles");

            SettingsPropertyValueCollection svc = new SettingsPropertyValueCollection();
            var entry = UserProfileDac.GetProfileByUsername((string)context["UserName"]);

            foreach (SettingsProperty prop in collection)
            {
                var pv = new SettingsPropertyValue(prop);
                if (entry != null)
                    pv.PropertyValue = entry.NameObjectMap[prop.Name];
                svc.Add(pv);
            }
            if (entry != null)
            {
                UserProfileDac.UpdateActivityTime(entry.UserID, DateTime.Now);
            }
            return svc;
        }
Пример #42
0
        public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection collection)
        {
            CreateExeMap();

            if (values == null)
            {
                values = new SettingsPropertyValueCollection();
                LoadProperies(exeMapCurrent, collection, ConfigurationUserLevel.None, "applicationSettings", false);
                LoadProperies(exeMapCurrent, collection, ConfigurationUserLevel.None, "userSettings", false);

                LoadProperies(exeMapCurrent, collection, ConfigurationUserLevel.PerUserRoaming, "userSettings", true);
                LoadProperies(exeMapCurrent, collection, ConfigurationUserLevel.PerUserRoamingAndLocal, "userSettings", true);

                // create default values if not exist
                foreach (SettingsProperty p in collection)
                {
                    if (values [p.Name] == null)
                    {
                        values.Add(new SettingsPropertyValue(p));
                    }
                }
            }
            return(values);
        }
Пример #43
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);
                    }
                }
            }
        }
Пример #44
0
        private SettingsPropertyValueCollection GetSettingValuesFromFile(string configFileName, string sectionName, bool userScoped, SettingsPropertyCollection properties)
        {
            SettingsPropertyValueCollection values = new SettingsPropertyValueCollection();
            IDictionary dictionary = ClientSettingsStore.ReadSettingsFromFile(configFileName, sectionName, userScoped);

            foreach (SettingsProperty property in properties)
            {
                string name = property.Name;
                SettingsPropertyValue value2 = new SettingsPropertyValue(property);
                if (dictionary.Contains(name))
                {
                    StoredSetting setting  = (StoredSetting)dictionary[name];
                    string        innerXml = setting.Value.InnerXml;
                    if (setting.SerializeAs == SettingsSerializeAs.String)
                    {
                        innerXml = this.Escaper.Unescape(innerXml);
                    }
                    value2.SerializedValue = innerXml;
                    value2.IsDirty         = true;
                    values.Add(value2);
                }
            }
            return(values);
        }
Пример #45
0
        /// <summary>
        /// Abstract SettingsProvider method
        /// </summary>
        public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection properties)
        {
            SettingsPropertyValueCollection values = new SettingsPropertyValueCollection();
            string sectionName = GetSectionName(context);

            // Look for this section in both applicationSettingsGroup and userSettingsGroup
            IDictionary appSettings  = Store.ReadSettings(sectionName, false);
            IDictionary userSettings = Store.ReadSettings(sectionName, true);
            ConnectionStringSettingsCollection connStrings = Store.ReadConnectionStrings();

            // Now map each SettingProperty to the right StoredSetting and deserialize the value if found.
            foreach (SettingsProperty setting in properties)
            {
                string settingName          = setting.Name;
                SettingsPropertyValue value = new SettingsPropertyValue(setting);

                // First look for and handle "special" settings
                SpecialSettingAttribute attr = setting.Attributes[typeof(SpecialSettingAttribute)] as SpecialSettingAttribute;
                bool isConnString            = (attr != null) ? (attr.SpecialSetting == SpecialSetting.ConnectionString) : false;

                if (isConnString)
                {
                    string connStringName = sectionName + "." + settingName;
                    if (connStrings != null && connStrings[connStringName] != null)
                    {
                        value.PropertyValue = connStrings[connStringName].ConnectionString;
                    }
                    else if (setting.DefaultValue != null && setting.DefaultValue is string)
                    {
                        value.PropertyValue = setting.DefaultValue;
                    }
                    else
                    {
                        //No value found and no default specified
                        value.PropertyValue = string.Empty;
                    }

                    value.IsDirty = false; //reset IsDirty so that it is correct when SetPropertyValues is called
                    values.Add(value);
                    continue;
                }

                // Not a "special" setting
                bool isUserSetting = IsUserSetting(setting);

                if (isUserSetting && !ConfigurationManagerInternalFactory.Instance.SupportsUserConfig)
                {
                    // We encountered a user setting, but the current configuration system does not support
                    // user settings.
                    throw new ConfigurationErrorsException(SR.UserSettingsNotSupported);
                }

                IDictionary settings = isUserSetting ? userSettings : appSettings;

                if (settings.Contains(settingName))
                {
                    StoredSetting ss          = (StoredSetting)settings[settingName];
                    string        valueString = ss.Value.InnerXml;

                    // We need to un-escape string serialized values
                    if (ss.SerializeAs == SettingsSerializeAs.String)
                    {
                        valueString = Escaper.Unescape(valueString);
                    }

                    value.SerializedValue = valueString;
                }
                else if (setting.DefaultValue != null)
                {
                    value.SerializedValue = setting.DefaultValue;
                }
                else
                {
                    //No value found and no default specified
                    value.PropertyValue = null;
                }

                value.IsDirty = false; //reset IsDirty so that it is correct when SetPropertyValues is called
                values.Add(value);
            }

            return(values);
        }
Пример #46
0
        public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection properties)
        {
            SettingsPropertyValueCollection values = new SettingsPropertyValueCollection();
            string      sectionName = this.GetSectionName(context);
            IDictionary dictionary  = this.Store.ReadSettings(sectionName, false);
            IDictionary dictionary2 = this.Store.ReadSettings(sectionName, true);
            ConnectionStringSettingsCollection settingss = this.Store.ReadConnectionStrings();

            foreach (SettingsProperty property in properties)
            {
                string name = property.Name;
                SettingsPropertyValue   value2    = new SettingsPropertyValue(property);
                SpecialSettingAttribute attribute = property.Attributes[typeof(SpecialSettingAttribute)] as SpecialSettingAttribute;
                if ((attribute != null) ? (attribute.SpecialSetting == SpecialSetting.ConnectionString) : false)
                {
                    string str3 = sectionName + "." + name;
                    if ((settingss != null) && (settingss[str3] != null))
                    {
                        value2.PropertyValue = settingss[str3].ConnectionString;
                    }
                    else if ((property.DefaultValue != null) && (property.DefaultValue is string))
                    {
                        value2.PropertyValue = property.DefaultValue;
                    }
                    else
                    {
                        value2.PropertyValue = string.Empty;
                    }
                    value2.IsDirty = false;
                    values.Add(value2);
                }
                else
                {
                    bool flag2 = this.IsUserSetting(property);
                    if (flag2 && !ConfigurationManagerInternalFactory.Instance.SupportsUserConfig)
                    {
                        throw new ConfigurationErrorsException(System.SR.GetString("UserSettingsNotSupported"));
                    }
                    IDictionary dictionary3 = flag2 ? dictionary2 : dictionary;
                    if (dictionary3.Contains(name))
                    {
                        StoredSetting setting  = (StoredSetting)dictionary3[name];
                        string        innerXml = setting.Value.InnerXml;
                        if (setting.SerializeAs == SettingsSerializeAs.String)
                        {
                            innerXml = this.Escaper.Unescape(innerXml);
                        }
                        value2.SerializedValue = innerXml;
                    }
                    else if (property.DefaultValue != null)
                    {
                        value2.SerializedValue = property.DefaultValue;
                    }
                    else
                    {
                        value2.PropertyValue = null;
                    }
                    value2.IsDirty = false;
                    values.Add(value2);
                }
            }
            return(values);
        }