Inheritance: ICloneable, ICollection, IEnumerable
		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();
		}
Ejemplo n.º 2
0
        public SettingsPropertyValueCollection LoadValues(string userName, SettingsPropertyCollection props)
        {
            var svc = new SettingsPropertyValueCollection();
            // holds sourcename->data pairs
            var loadedData = new Dictionary<string, IDictionary>();
            foreach (SettingsProperty prop in props) {
                EnsureDataLoaded(userName, prop.Name, loadedData);
                var pv = new SettingsPropertyValue(prop);

                object value = null;
                // lets try to locate property value
                foreach (var src in Sources)
                    if (src.FieldsMapping.ContainsKey(prop.Name)) {
                        value = loadedData[src.SourceName][ ResolveFieldName(prop.Name,src) ];
                        break;
                    }
                if (value == null || value == DBNull.Value) {
                    // leave default value
                } else {
                    pv.PropertyValue = value;
                    pv.IsDirty = false;
                }

                svc.Add(pv);
            }
            return svc;
        }
Ejemplo n.º 3
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;
		}
        public static SettingsPropertyValueCollection GetSharedPropertyValues(LocalFileSettingsProvider provider, SettingsContext context, SettingsPropertyCollection properties, string currentExeConfigFilename = null)
        {
			var settingsClass = (Type)context["SettingsClassType"];

            var systemConfiguration = String.IsNullOrEmpty(currentExeConfigFilename)
                              ? SystemConfigurationHelper.GetExeConfiguration()
                              : SystemConfigurationHelper.GetExeConfiguration(currentExeConfigFilename);

        	var storedValues = systemConfiguration.GetSettingsValues(settingsClass);

			// Create new collection of values
			var 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;
		}
Ejemplo n.º 5
0
		// SetPropertyValue is invoked when ApplicationSettingsBase.Save is called
		// ASB makes sure to pass each provider only the values marked for that provider,
		// whether on a per setting or setting class-wide basis
		public override void SetPropertyValues(SettingsContext context,
											   SettingsPropertyValueCollection propvals)
		{
			// Iterate through the settings to be stored
			string version = GetCurrentVersionNumber();
			foreach (SettingsPropertyValue propval in propvals)
			{
				// If property hasn't been set, no need to save it
				if (!propval.IsDirty || (propval.SerializedValue == null))
				{
					continue;
				}

				// Application-scoped settings can't change
				// NOTE: the settings machinery may cause or allow an app-scoped setting
				// to become dirty, in which case, like the LFSP, we ignore it instead
				// of throwning an exception
				if (IsApplicationScoped(propval.Property))
				{
					continue;
				}

				using (RegistryKey key = CreateRegKey(propval.Property, version))
				{
					key.SetValue(propval.Name, propval.SerializedValue);
				}
			}
		}
Ejemplo n.º 6
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Gets the property values from a config file.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context,
			SettingsPropertyCollection properties)
        {
            // Set the config files
            var configMap = SetConfigFiles();

            // Create new collection of values
            var values = new SettingsPropertyValueCollection();

            ReadProperties(context, properties, configMap, ConfigurationUserLevel.None,
                values);
            ReadProperties(context, properties, configMap,
                ConfigurationUserLevel.PerUserRoamingAndLocal, values);
            ReadProperties(context, properties, configMap, ConfigurationUserLevel.PerUserRoaming,
                values);

            // save new user config file
            try
            {
                SetPropertyValues(context, values);
            }
            catch
            {
            }

            return values;
        }
Ejemplo n.º 7
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;
		}
 public override void SetPropertyValues(SettingsContext context, SettingsPropertyValueCollection collection)
 {
     if (_localFileSettingProvider != null)
     {
         _localFileSettingProvider.SetPropertyValues(context, collection);
     }
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Updates the specified settings from this config class.
 /// </summary>
 /// <param name="settings">The settings.</param>
 public void Update(SettingsPropertyValueCollection settings)
 {
     foreach (PropertyInfo configProperty in this.GetType().GetProperties())
     {
         settings[configProperty.Name].PropertyValue = configProperty.GetValue(this, null);
     }
 }
		public object Clone ()
		{
			SettingsPropertyValueCollection col = new SettingsPropertyValueCollection ();
			col.items = (Hashtable)items.Clone ();

			return col;
		}
        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;
        }
Ejemplo n.º 12
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 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;
		}
        public override void SetPropertyValues(SettingsContext context, SettingsPropertyValueCollection collection)
        {
            lock (_syncLock)
            {
                // locate dirty values that should be saved
                var valuesToStore = new Dictionary<string, string>();
                foreach (SettingsPropertyValue value in collection)
                {
                    //If storing the shared values, we store everything, otherwise only store user values.
                     if (value.IsDirty)
                     {
                         valuesToStore[value.Name] = (string) value.SerializedValue;
                     }
                }

                if (valuesToStore.Count > 0)
                {
                    var settingsClass = (Type)context["SettingsClassType"];
                    var settingsKey = (string)context["SettingsKey"];
                    var group = new SettingsGroupDescriptor(settingsClass);
                  
                    if (group.HasUserScopedSettings)
                        throw new ConfigurationErrorsException(SR.SystemConfigurationSettingsProviderUserSetting);
                  
                    _store.PutSettingsValues(group, null, settingsKey, valuesToStore);

                    // successfully saved user settings are no longer dirty
                    foreach (var storedValue in valuesToStore)
                        collection[storedValue.Key].IsDirty = false;
                }
            }
        }
Ejemplo n.º 15
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;

                if (SettingsDictionary.ContainsKey(setting.Name))
                {
                    value.SerializedValue = SettingsDictionary[setting.Name].value;
                }
                else //use defaults in the case where there are no settings yet
                {
                    value.SerializedValue = setting.DefaultValue == null ? string.Empty : setting.DefaultValue.ToString();
                }

                values.Add(value);
            }
            return values;
        }
        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;
        }
        /// <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;
        }
        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;
        }
 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;
 }
Ejemplo n.º 20
0
		public override void SetPropertyValues (SettingsContext context,
							SettingsPropertyValueCollection values)
		{
#if SPEW
			Console.WriteLine (Environment.StackTrace);
#endif
			base.SetPropertyValues (context, values);
		}
Ejemplo n.º 21
0
		private SimpleSettingsStore()
		{
			_stores = new Dictionary<Store, SettingsPropertyValueCollection>();
			_stores[Store.CurrentUser] = CurrentUserValues = new SettingsPropertyValueCollection();
			_stores[Store.PreviousUser] = PreviousUserValues = new SettingsPropertyValueCollection();
			_stores[Store.CurrentShared] = CurrentSharedValues = new SettingsPropertyValueCollection();
			_stores[Store.PreviousShared] = PreviousSharedValues = new SettingsPropertyValueCollection();
		}
Ejemplo n.º 22
0
Archivo: DB.cs Proyecto: vzrus/VZF
        private static int PackProfileData(SettingsPropertyValueCollection collection, bool isAuthenticated,
ref string index, ref string stringData, ref byte[] binaryData)
        {
            bool itemsToSave = false;

            // first we need to determine if there are any items that need saving
            // this is an optimization
            foreach (SettingsPropertyValue value in collection)
            {
                if (!value.IsDirty) continue;
                if (value.Property.Attributes["AllowAnonymous"].Equals(false) &&
                    !isAuthenticated) continue;
                itemsToSave = true;
                break;
            }
            if (!itemsToSave) return 0;

            StringBuilder indexBuilder = new StringBuilder();
            StringBuilder stringDataBuilder = new StringBuilder();
            MemoryStream binaryBuilder = new MemoryStream();
            int count = 0;

            // ok, we have some values that need to be saved so we go back through
            foreach (SettingsPropertyValue value in collection)
            {
                // if the value has not been written to and is still using the default value
                // no need to save it
                if (value.UsingDefaultValue && !value.IsDirty) continue;

                // we don't save properties that require the user to be authenticated when the
                // current user is not authenticated.
                if (value.Property.Attributes["AllowAnonymous"].Equals(false) &&
                    !isAuthenticated) continue;

                count++;
                object propValue = value.SerializedValue;
                if ((value.Deserialized && value.PropertyValue == null) ||
                    value.SerializedValue == null)
                    indexBuilder.AppendFormat("{0}//0/-1:", value.Name);
                else if (propValue is string)
                {
                    indexBuilder.AppendFormat("{0}/0/{1}/{2}:", value.Name,
                        stringDataBuilder.Length, (propValue as string).Length);
                    stringDataBuilder.Append(propValue);
                }
                else
                {
                    byte[] binaryValue = (byte[])propValue;
                    indexBuilder.AppendFormat("{0}/1/{1}/{2}:", value.Name,
                        binaryBuilder.Position, binaryValue.Length);
                    binaryBuilder.Write(binaryValue, 0, binaryValue.Length);
                }
            }
            index = indexBuilder.ToString();
            stringData = stringDataBuilder.ToString();
            binaryData = binaryBuilder.ToArray();
            return count;
        }
            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 static SettingsPropertyValueCollection ToSettingsPropertyValueCollection(this IEnumerable<SettingsPropertyValue> values)
		{
			var c = new SettingsPropertyValueCollection();
			foreach (var value in values)
			{
				c.Add(value);
			}
			return c;
		}
		public override void SetPropertyValues(SettingsContext context, SettingsPropertyValueCollection propvals) {
			foreach (SettingsPropertyValue value2 in propvals) {
				SetValue(value2);
			}
			try {
				SettingsXML.Save(Path.Combine(GetAppSettingsPath(), GetAppSettingsFilename()));
			}
			catch (Exception) {
			}
		}
		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;
		}
Ejemplo n.º 27
0
		public override void SetPropertyValues(SettingsContext context, SettingsPropertyValueCollection collection)
		{
			foreach (SettingsPropertyValue value in collection)
			{
				SettingsPropertyValue existing = SimpleSettingsStore.Instance.CurrentUserValues[value.Name];
				if (existing == null)
					SimpleSettingsStore.Instance.CurrentUserValues.Add(existing = new SettingsPropertyValue(value.Property));

				existing.PropertyValue = value.PropertyValue;
			}
		}
        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 void Add ()
		{
			SettingsPropertyValueCollection col = new SettingsPropertyValueCollection ();
			SettingsProperty test_prop = new SettingsProperty ("test_prop");
			SettingsPropertyValue val = new SettingsPropertyValue (test_prop);

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

			col.Add (val);

			Assert.AreEqual (1, col.Count, "A2");
		}
Ejemplo n.º 31
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);
        }
        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);
                    }
                }
            }
        }
Ejemplo n.º 33
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);
        }
Ejemplo n.º 34
0
        public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection collection)
        {
            CreateExeMap();

            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);
        }
    public override void  SetPropertyValues(System.Configuration.SettingsContext context, System.Configuration.SettingsPropertyValueCollection collection)
    {//JH
        string username        = (string)context["UserName"];
        bool   isAuthenticated = (bool)context["IsAuthenticated"];
        Guid   uniqueID        = GetUniqueID(username, isAuthenticated, false);

        SettingsPropertyValueCollection svc = new SettingsPropertyValueCollection();

        foreach (SettingsProperty prop in collection)
        {
            SettingsPropertyValue pv = new SettingsPropertyValue(prop);
            svc.Add(pv);
        }

        activity(username, "Set property values", false);
    }
Ejemplo n.º 36
0
        /// <summary>
        /// Sets Profile the property values.
        /// </summary>
        /// <param name="context">Profile context.</param>
        /// <param name="settingsPropertyValues">The settings profile property values.</param>
        public override void SetPropertyValues(System.Configuration.SettingsContext context, System.Configuration.SettingsPropertyValueCollection settingsPropertyValues)
        {
            string username        = (string)context["UserName"];
            bool   isAuthenticated = (bool)context["IsAuthenticated"];
            int    userID          = GetUniqueID(username, isAuthenticated);

            foreach (SettingsPropertyValue pv in settingsPropertyValues)
            {
                if (pv.IsDirty)
                {
                    SetProperty(username, userID, isAuthenticated, (string)pv.Name, (string)pv.PropertyValue);
                }
            }
        }
Ejemplo n.º 37
0
        /// <summary>
        /// Set/store the property values for the user profile.
        /// </summary>
        /// <param name="context">Application context.</param>
        /// <param name="settingsPropertyValues">Profile property value settings.</param>
        public override void SetPropertyValues(System.Configuration.SettingsContext context, System.Configuration.SettingsPropertyValueCollection settingsPropertyValues)
        {
            if (true == (bool)context["IsAuthenticated"])
            {
                IObjectScope objScope = ORM.GetNewObjectScope();
                string       userName = GetUserName((string)context["UserName"]);
                objScope.Transaction.Begin();
                EmployeeProfile ep = ResolveEmployeeProfileByName(objScope, userName);
                if (null == ep)
                {
                    ep          = new EmployeeProfile();
                    ep.Employee = ResolveEmployeeByName(objScope, userName);
                    objScope.Add(ep);
                }
                foreach (SettingsPropertyValue settingsPropertyValue in settingsPropertyValues)
                {
                    switch (settingsPropertyValue.Property.Name)
                    {
                    case "Language":
                        ep.Language        = settingsPropertyValue.PropertyValue as String;
                        ep.LastUpdatedDate = DateTime.Now;
                        break;

                    case "StyleTheme":
                        ep.StyleTheme      = settingsPropertyValue.PropertyValue as String;
                        ep.LastUpdatedDate = DateTime.Now;
                        break;

                    case "Factory_Name":
                        ep.Factory_Name    = settingsPropertyValue.PropertyValue as String;
                        ep.LastUpdatedDate = DateTime.Now;
                        break;

                    case "Operation_Name":
                        ep.Operation_Name  = settingsPropertyValue.PropertyValue as String;
                        ep.LastUpdatedDate = DateTime.Now;
                        break;

                    case "WorkCenter_Name":
                        ep.WorkCenter_Name = settingsPropertyValue.PropertyValue as String;
                        ep.LastUpdatedDate = DateTime.Now;
                        break;

                    default:
                        throw new ProviderException("Unsupported property.");
                    }
                }
                objScope.Transaction.Commit();
            }
        }
Ejemplo n.º 38
0
 public abstract void SetPropertyValues(SettingsContext context,
                                        SettingsPropertyValueCollection collection);
Ejemplo n.º 39
0
        /// <summary>
        /// Sets the values of the specified group of property settings.
        /// </summary>
        /// <param name="context">A System.Configuration.SettingsContext describing the current application usage.</param>
        /// <param name="collection">A System.Configuration.SettingsPropertyValueCollection representing the group
        /// of property settings to set.</param>
        public void SetPropertyValues(System.Configuration.SettingsContext context, System.Configuration.SettingsPropertyValueCollection collection)
        {
            string username        = (string)context["UserName"];
            bool   isAuthenticated = (bool)context["IsAuthenticated"];

            // Get the profile for the current user name.
            Nequeo.DataAccess.CloudInteraction.Data.Profile profile = GetSpecificProfile(username);

            // If a profile exits.
            if (profile != null)
            {
                long profileID = profile.ProfileID;

                // For each property setting.
                foreach (SettingsPropertyValue pv in collection)
                {
                    bool   propertyFound = false;
                    string propertyName  = pv.Property.Name;

                    // Get the value for the current property name.
                    object value = GetProfilePropertyValue(profile, isAuthenticated, propertyName, out propertyFound);

                    // If the property has been found.
                    if (propertyFound)
                    {
                        // Update the property.
                        bool retUpdate = new Nequeo.DataAccess.CloudInteraction.Data.Extension.ProfileValue().
                                         Update.UpdateItemPredicate(
                            new Data.ProfileValue()
                        {
                            PropertyValue = pv.PropertyValue.ToString()
                        }, u =>
                            (u.ProfileID == profileID) &&
                            (u.PropertyName == propertyName)
                            );
                    }
                    else
                    {
                        // Insert the property.
                        bool retInsert = new Nequeo.DataAccess.CloudInteraction.Data.Extension.ProfileValue().
                                         Insert.InsertItem(
                            new Data.ProfileValue()
                        {
                            ProfileID     = profileID,
                            PropertyName  = propertyName,
                            PropertyType  = "System.String",
                            PropertyValue = pv.PropertyValue.ToString()
                        }
                            );
                    }
                }

                // Updates the LastActivityDate and LastUpdatedDate values when profile properties
                UpdateActivityDates(username, isAuthenticated, false);
            }
            else
            {
                // Make sure that the profile exists for the username if authenticated.
                if (isAuthenticated)
                {
                    throw new ProviderException("Profile username : "******" does not exist.");
                }
            }
        }
Ejemplo n.º 40
0
        private void SaveProperties(ExeConfigurationFileMap exeMap, SettingsPropertyValueCollection collection, ConfigurationUserLevel level, SettingsContext context, bool checkUserLevel)
        {
            Configuration config = ConfigurationManager.OpenMappedExeConfiguration(exeMap, level);

            UserSettingsGroup userGroup = config.GetSectionGroup("userSettings") as UserSettingsGroup;
            bool isRoaming = (level == ConfigurationUserLevel.PerUserRoaming);

            if (userGroup == null)
            {
                userGroup = new UserSettingsGroup();
                config.SectionGroups.Add("userSettings", userGroup);
            }
            ApplicationSettingsBase asb       = context.CurrentSettings;
            string class_name                 = NormalizeInvalidXmlChars((asb != null ? asb.GetType() : typeof(ApplicationSettingsBase)).FullName);
            ClientSettingsSection userSection = null;
            ConfigurationSection  cnf         = userGroup.Sections.Get(class_name);

            userSection = cnf as ClientSettingsSection;
            if (userSection == null)
            {
                userSection = new ClientSettingsSection();
                userGroup.Sections.Add(class_name, userSection);
            }

            bool hasChanges = false;

            if (userSection == null)
            {
                return;
            }

            foreach (SettingsPropertyValue value in collection)
            {
                if (checkUserLevel && value.Property.Attributes.Contains(typeof(SettingsManageabilityAttribute)) != isRoaming)
                {
                    continue;
                }
                // The default impl does not save the ApplicationScopedSetting properties
                if (value.Property.Attributes.Contains(typeof(ApplicationScopedSettingAttribute)))
                {
                    continue;
                }

                hasChanges = true;
                SettingElement element = userSection.Settings.Get(value.Name);
                if (element == null)
                {
                    element = new SettingElement(value.Name, value.Property.SerializeAs);
                    userSection.Settings.Add(element);
                }
                if (element.Value.ValueXml == null)
                {
                    element.Value.ValueXml = new XmlDocument().CreateElement("value");
                }
                switch (value.Property.SerializeAs)
                {
                case SettingsSerializeAs.Xml:
                    element.Value.ValueXml.InnerXml = StripXmlHeader(value.SerializedValue as string);
                    break;

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

                case SettingsSerializeAs.Binary:
                    element.Value.ValueXml.InnerText = value.SerializedValue != null?Convert.ToBase64String(value.SerializedValue as byte []) : string.Empty;

                    break;

                default:
                    throw new NotImplementedException();
                }
            }
            if (hasChanges)
            {
                config.Save(ConfigurationSaveMode.Minimal, true);
            }
        }
Ejemplo n.º 41
0
        /// <summary>
        /// Sets the property values.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="ppvc">The PPVC.</param>
        public override void SetPropertyValues(System.Configuration.SettingsContext context, System.Configuration.SettingsPropertyValueCollection ppvc)
        {
            MongoServer   server     = MongoServer.Create(connectionString); // connect to the mongoDB url.
            MongoDatabase ProviderDB = server.GetDatabase(pMongoProviderDatabaseName, SafeMode.True);

            MongoCollection <BsonDocument> profiles = ProviderDB.GetCollection(pMongoProviderProfileCollectionName);


            string username        = (string)context["UserName"];
            bool   isAuthenticated = (bool)context["IsAuthenticated"];

            // Create profile if does not exist.
            ObjectId existingProfileId = ObjectId.Empty;


            var query = Query.And(Query.EQ("ApplicationNameLowerCase", pApplicationName.ToLower()),
                                  Query.EQ("UsernameLowerCase", username.ToLower()));

            var existingProfile = profiles.FindOne(query);

            if (existingProfile != null)
            {
                existingProfileId = existingProfile["_id"].AsObjectId;
            }

            var profile = new BsonDocument();

            profile.Add("ApplicationName", pApplicationName)
            .Add("ApplicationNameLowerCase", pApplicationName.ToLower())
            .Add("Username", username)
            .Add("UsernameLowerCase", username.ToLower())
            .Add("LastActivityDate", DateTime.Now)
            .Add("LastUpdatedDate", DateTime.Now)
            .Add("IsAnonymous", !isAuthenticated);

            if (existingProfileId != ObjectId.Empty)
            {
                profile.Add("_id", existingProfileId);
            }

            foreach (SettingsPropertyValue pv in ppvc)
            {
                profile.Add(pv.Name, BsonValue.Create(pv.PropertyValue));
            }

            bool bSuccess = profiles.Save(profile).Ok;
        }
Ejemplo n.º 42
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="context"></param>
        /// <param name="collection"></param>
        public override void SetPropertyValues(System.Configuration.SettingsContext context, System.Configuration.SettingsPropertyValueCollection collection)
        {
            string userName    = (string)context["UserName"];
            bool   isAnonymous = !(bool)context["IsAuthenticated"];

            SettingsPropertyValueCollection propertyValues = new SettingsPropertyValueCollection();

            using (var dataStore = new ProductStore(SqlHelper.Current.GetConnection(_connectionString)))
            {
                bool retry      = true;
                int  retryCount = 0;
                while (retry && retryCount < 2)
                {
                    retryCount++;
                    var profile = (from p in dataStore.Profile
                                   join d in dataStore.ProfileData on p.Id equals d.ProfileId
                                   where p.ApplicationName == ApplicationName && p.Username == userName
                                   select new
                    {
                        Profile = p,
                        Data = d
                    }).FirstOrDefault();

                    if (profile == null)
                    {
                        retry = true;
                        CreateProfile(dataStore, userName);
                        dataStore.SubmitChanges();
                    }
                    else
                    {
                        retry = false;
                        foreach (var property in collection)
                        {
                            SettingsPropertyValue settingsPropertyValue = property as SettingsPropertyValue;
                            switch (settingsPropertyValue.Property.Name)
                            {
                            case "FirstName":
                                profile.Data.FirstName = (string)settingsPropertyValue.PropertyValue;
                                break;

                            case "LastName":
                                profile.Data.LastName = (string)settingsPropertyValue.PropertyValue;
                                break;

                            case "Phone":
                                profile.Data.Phone = (string)settingsPropertyValue.PropertyValue;
                                break;
                            }
                        }
                        profile.Profile.LastUpdated  = DateTime.Now;
                        profile.Profile.LastActivity = DateTime.Now;
                        dataStore.SubmitChanges();
                    }
                }
            }
        }
Ejemplo n.º 43
0
 public override void SetPropertyValues(SettingsContext context, SettingsPropertyValueCollection values)
 {
     throw new NotImplementedException();
 }
 public override void SetPropertyValues(System.Configuration.SettingsContext context, System.Configuration.SettingsPropertyValueCollection collection)
 {
     //do notting, we cannot write properties to PSU Passport Service
 }
Ejemplo n.º 45
0
        //-----------------------------------------------------------------

        #region --------------PrepareDataForSaving--------------
        //------------------------------------------------------
        //PrepareDataForSaving
        //------------------------------------------------------
        internal static void PrepareDataForSaving(ref string allNames, ref string allValues, System.Configuration.SettingsPropertyValueCollection properties)
        {
            System.Text.StringBuilder stringBuilder1 = new System.Text.StringBuilder();
            System.Text.StringBuilder stringBuilder2 = new System.Text.StringBuilder();
            try
            {
                try
                {
                    foreach (System.Configuration.SettingsPropertyValue settingsPropertyValue2 in properties)
                    {
                        if (settingsPropertyValue2.IsDirty || !settingsPropertyValue2.UsingDefaultValue)
                        {
                            int    i1 = 0, i2 = 0;
                            string s = null;
                            if (settingsPropertyValue2.PropertyValue == null)
                            {
                                i1 = -1;
                            }
                            else
                            {
                                object obj = settingsPropertyValue2.PropertyValue;
                                if (obj == null)
                                {
                                    i1 = -1;
                                }
                                else
                                {
                                    s  = obj.ToString();
                                    i1 = s.Length;
                                    i2 = stringBuilder2.Length;
                                }
                            }
                            stringBuilder1.Append(settingsPropertyValue2.Name + ":" + (s != null ? "S" : "B") + ":" + i2.ToString() + ":" + i1.ToString() + ":");
                            if (s != null)
                            {
                                stringBuilder2.Append(s);
                            }
                        }
                    }
                }
                finally
                {
                }
            }
            catch
            {
                throw;
            }
            allNames  = stringBuilder1.ToString();
            allValues = stringBuilder2.ToString();
        }
Ejemplo n.º 46
0
        //------------------------------------------------------
        #endregion
        internal static void ParseProfileData(string PropertyNames, string PropertyValuesString, System.Configuration.SettingsPropertyValueCollection properties)
        {
            //-------------------------------------------------------------
            string[] names  = null;
            string   values = null;

            char[] chArr = new char[] { ':' };
            names  = PropertyNames.Split(chArr);
            values = PropertyValuesString;
            //-------------------------------------------------------------
            if ((names == null) || (values == null) || (properties == null))
            {
                return;
            }
            try
            {
                for (int i1 = 0; i1 < (names.Length / 4); i1++)
                {
                    string s = names[i1 * 4];
                    System.Configuration.SettingsPropertyValue settingsPropertyValue = properties[s];
                    if (settingsPropertyValue != null)
                    {
                        //int i2 = System.Int32.Parse(names[(i1 * 4) + 2], System.Globalization.CultureInfo.InvariantCulture);
                        //int i3 = System.Int32.Parse(names[(i1 * 4) + 3], System.Globalization.CultureInfo.InvariantCulture);
                        int i2 = System.Int32.Parse(names[(i1 * 4) + 2]);
                        int i3 = System.Int32.Parse(names[(i1 * 4) + 3]);
                        if ((i3 == -1) && !settingsPropertyValue.Property.PropertyType.IsValueType)
                        {
                            settingsPropertyValue.PropertyValue = null;
                            settingsPropertyValue.IsDirty       = false;
                            //settingsPropertyValue.Deserialized = false;
                        }
                        //if (names[(i1 * 4) + 1] == "S\uFFFD" && (i2 >= 0) && (i3 > 0) && (values.Length >= (i2 + i3)))
                        if (names[(i1 * 4) + 1] == "S" && (i2 >= 0) && (i3 > 0) && (values.Length >= (i2 + i3)))
                        {
                            settingsPropertyValue.PropertyValue = values.Substring(i2, i3);
                        }
                        //if (names[(i1 * 4) + 1] == "B\uFFFD" && (i2 >= 0) && (i3 > 0) && (buf.Length >= (i2 + i3)))
                    }
                }
            }
            catch
            {
            }
        }
Ejemplo n.º 47
0
 public override void SetPropertyValues(System.Configuration.SettingsContext context, System.Configuration.SettingsPropertyValueCollection collection)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 48
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);
        }
        public override void SetPropertyValues(System.Configuration.SettingsContext context, System.Configuration.SettingsPropertyValueCollection collection)
        {
            using (UsersContext db = new UsersContext())
            {
                string      userName    = context["UserName"].ToString();
                UserProfile userProfile = db.UsersProfiles.Find(userName);
                if (userProfile == null)
                {
                    userProfile = new UserProfile();

                    foreach (SettingsPropertyValue profilePropertyValue in collection)
                    {
                        userProfile.GetType().GetProperty(profilePropertyValue.Name).SetValue(userProfile, profilePropertyValue.PropertyValue, null);
                    }

                    db.UsersProfiles.Add(userProfile);
                }

                else
                {
                    foreach (SettingsPropertyValue profilePropertyValue in collection)
                    {
                        userProfile.GetType().GetProperty(profilePropertyValue.Name).SetValue(userProfile, profilePropertyValue.PropertyValue, null);
                    }
                }

                db.SaveChanges();
            }
        }
Ejemplo n.º 50
0
        private void SaveProperties(ExeConfigurationFileMap exeMap, SettingsPropertyValueCollection collection, ConfigurationUserLevel level, SettingsContext context, bool checkUserLevel)
        {
            Configuration config = ConfigurationManager.OpenMappedExeConfiguration(exeMap, level);

            UserSettingsGroup userGroup = config.GetSectionGroup("userSettings") as UserSettingsGroup;
            bool isRoaming = (level == ConfigurationUserLevel.PerUserRoaming);

#if true // my reimplementation
            if (userGroup == null)
            {
                userGroup = new UserSettingsGroup();
                config.SectionGroups.Add("userSettings", userGroup);
                ApplicationSettingsBase asb = context.CurrentSettings;
                ClientSettingsSection   cs  = new ClientSettingsSection();
                string class_name           = NormalizeInvalidXmlChars((asb != null ? asb.GetType() : typeof(ApplicationSettingsBase)).FullName);
                userGroup.Sections.Add(class_name, cs);
            }

            bool hasChanges = false;

            foreach (ConfigurationSection section in userGroup.Sections)
            {
                ClientSettingsSection userSection = section as ClientSettingsSection;
                if (userSection == null)
                {
                    continue;
                }

                foreach (SettingsPropertyValue value in collection)
                {
                    if (checkUserLevel && value.Property.Attributes.Contains(typeof(SettingsManageabilityAttribute)) != isRoaming)
                    {
                        continue;
                    }
                    // The default impl does not save the ApplicationScopedSetting properties
                    if (value.Property.Attributes.Contains(typeof(ApplicationScopedSettingAttribute)))
                    {
                        continue;
                    }

                    hasChanges = true;
                    SettingElement element = userSection.Settings.Get(value.Name);
                    if (element == null)
                    {
                        element = new SettingElement(value.Name, value.Property.SerializeAs);
                        userSection.Settings.Add(element);
                    }
                    if (element.Value.ValueXml == null)
                    {
                        element.Value.ValueXml = new XmlDocument().CreateElement("value");
                    }
                    switch (value.Property.SerializeAs)
                    {
                    case SettingsSerializeAs.Xml:
                        element.Value.ValueXml.InnerXml = (value.SerializedValue as string) ?? string.Empty;
                        break;

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

                    case SettingsSerializeAs.Binary:
                        element.Value.ValueXml.InnerText = value.SerializedValue != null?Convert.ToBase64String(value.SerializedValue as byte []) : string.Empty;

                        break;

                    default:
                        throw new NotImplementedException();
                    }
                }
            }
            if (hasChanges)
            {
                config.Save(ConfigurationSaveMode.Minimal, true);
            }
#else // original impl. - likely buggy to miss some properties to save
            foreach (ConfigurationSection configSection in userGroup.Sections)
            {
                ClientSettingsSection userSection = configSection as ClientSettingsSection;
                if (userSection != null)
                {
/*
 *                                      userSection.Settings.Clear();
 *
 *                                      foreach (SettingsPropertyValue propertyValue in collection)
 *                                      {
 *                                              if (propertyValue.IsDirty)
 *                                              {
 *                                                      SettingElement element = new SettingElement(propertyValue.Name, SettingsSerializeAs.String);
 *                                                      element.Value.ValueXml = new XmlDocument();
 *                                                      element.Value.ValueXml.InnerXml = (string)propertyValue.SerializedValue;
 *                                                      userSection.Settings.Add(element);
 *                                              }
 *                                      }
 */
                    foreach (SettingElement element in userSection.Settings)
                    {
                        if (collection [element.Name] != null)
                        {
                            if (collection [element.Name].Property.Attributes.Contains(typeof(SettingsManageabilityAttribute)) != isRoaming)
                            {
                                continue;
                            }

                            element.SerializeAs             = SettingsSerializeAs.String;
                            element.Value.ValueXml.InnerXml = (string)collection [element.Name].SerializedValue;                                ///Value = XmlElement
                        }
                    }
                }
            }
            config.Save(ConfigurationSaveMode.Minimal, true);
#endif
        }
Ejemplo n.º 51
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);
        }
Ejemplo n.º 52
0
 public override void SetPropertyValues(SettingsContext context,
                                        SettingsPropertyValueCollection values)
 {
     impl.SetPropertyValues(context, values);
 }
 protected SettingsBase()
 {
     _PropertyValues = new SettingsPropertyValueCollection();
 }