public override void SetPropertyValues(SettingsContext context, SettingsPropertyValueCollection propvals)
    {
        foreach (SettingsPropertyValue propval in propvals)
            SetValue(propval);

        SettingsXML.Save(Path.Combine(GetAppSettingsPath(), GetAppSettingsFilename()));
    }
Example #2
0
 /// <summary>
 /// To instantiate a new instance of ProfileReader, you must supply an 
 /// instance of ProfileData or the individual ProfileData Properties. If PropertyNames or 
 /// PropertyValues is null, and exception will be thrown.
 /// </summary>
 /// <param name="names">Names of the properties</param>
 /// <param name="values">Values</param>
 /// <param name="binary">Any binary serlialized objects</param>
 public ProfileReader(string names, string values, byte[] binary)
 {
     ProfileData pd = new ProfileData();
     pd.PropertyNames = names;
     pd.PropertyValues = values;
     pd.PropertyValuesBinary = binary;
     _propertyValue = ProfileReader.Parse(pd);
 }
    public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection props)
    {
        var values = new SettingsPropertyValueCollection();

        foreach (SettingsProperty setting in props)
        {
            var value = new SettingsPropertyValue(setting);
            value.IsDirty = false;
            value.SerializedValue = GetValue(setting);
            values.Add(value);
        }
        return values;
    }
    public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection props)
    {
        // Create new collection of values
        SettingsPropertyValueCollection values = new SettingsPropertyValueCollection();
        string version = GetCurrentVersionNumber();

        // Iterate through the settings to be retrieved
        foreach (SettingsProperty prop in props)
        {
            SettingsPropertyValue value = GetPropertyValue(prop, version);
            Debug.Assert(value != null);
            values.Add(value);
        }

        return values;
    }
    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 = GetValue(setting);
            values.Add(value);
        }
        return values;
    }
    public override void SetPropertyValues(SettingsContext context, SettingsPropertyValueCollection propvals)
    {
        //Iterate through the settings to be stored
        //Only dirty settings are included in propvals, and only ones relevant to this provider
        foreach (SettingsPropertyValue propval in propvals)
        {
            SetValue(propval);
        }

        try
        {
            SettingsXML.Save(Path.Combine(GetAppSettingsPath(), GetAppSettingsFilename()));
        }
        catch (Exception ex)
        {
        }
        //Ignore if cant save, device been ejected
    }
        public override void SetPropertyValues(SettingsContext context, SettingsPropertyValueCollection collection)
        {
            var username = context["UserName"] as string;

            var xrm = CrmConfigurationManager.CreateContext(ContextName);

            var entity = GetProfileEntity(xrm, username);

            if (collection.Count < 1 || string.IsNullOrEmpty(username) || entity == null)
            {
                return;
            }

            var userIsAuthenticated = (context["IsAuthenticated"] as bool?).GetValueOrDefault();

            if (!userIsAuthenticated && collection.Cast <SettingsPropertyValue>().Any(propertyValue => (propertyValue.Property.Attributes["AllowAnonymous"] as bool?).GetValueOrDefault()))
            {
                throw new NotSupportedException("Anonymous properties aren't supported.");
            }

            var propertyValuesToUpdate = collection.Cast <SettingsPropertyValue>().Where(value => value.IsDirty && !value.UsingDefaultValue);

            foreach (var propertyValue in propertyValuesToUpdate)
            {
                var logicalName = GetCustomProviderData(propertyValue.Property);

                entity.SetAttributeValue(logicalName, propertyValue.PropertyValue);
            }

            entity.SetAttributeValue(_attributeMapLastActivityDate, DateTime.UtcNow);

            entity.SetAttributeValue(_attributeMapLastUpdatedDate, DateTime.UtcNow);

            xrm.UpdateObject(entity);

            xrm.SaveChanges();
        }
 /// <summary>
 /// Parses the profile data.
 /// </summary>
 /// <param name="names">The names.</param>
 /// <param name="values">The values.</param>
 /// <param name="binaries">The buffer.</param>
 /// <param name="properties">The properties.</param>
 protected internal virtual void ParseProfileData(
     string[] names, string values, byte[] binaries, SettingsPropertyValueCollection properties)
 {
     try
     {
         for (int num1 = 0; num1 < (names.Length / 4); num1++)
         {
             string text1 = names[num1 * 4];
             SettingsPropertyValue value1 = properties[text1];
             if (value1 != null)
             {
                 int num2 = int.Parse(names[(num1 * 4) + 2], CultureInfo.InvariantCulture);
                 int num3 = int.Parse(names[(num1 * 4) + 3], CultureInfo.InvariantCulture);
                 if ((num3 == -1) && !value1.Property.PropertyType.IsValueType)
                 {
                     value1.PropertyValue = null;
                     value1.IsDirty       = false;
                     value1.Deserialized  = true;
                 }
                 if (((names[(num1 * 4) + 1] == "S") && (num2 >= 0)) && ((num3 > 0) && (values.Length >= (num2 + num3))))
                 {
                     value1.SerializedValue = values.Substring(num2, num3);
                 }
                 if (((names[(num1 * 4) + 1] == "B") && (num2 >= 0)) && ((num3 > 0) && (binaries.Length >= (num2 + num3))))
                 {
                     byte[] buffer1 = new byte[num3];
                     Buffer.BlockCopy(binaries, num2, buffer1, 0, num3);
                     value1.SerializedValue = buffer1;
                 }
             }
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine(ex);
     }
 }
        public override void SetPropertyValues(SettingsContext context, SettingsPropertyValueCollection collection)

        {
            try

            {
                Configuration config = null;

                ClientSettingsSection clientSettings = GetUserSettings(out config, false);

                clientSettings.Settings.Clear();

                foreach (SettingsPropertyValue spv in collection)

                {
                    SettingValueElement sve = new SettingValueElement();

                    sve.ValueXml = SerializeToXmlElement(spv.Property, spv);

                    SettingElement se = new SettingElement(spv.Name, spv.Property.SerializeAs);

                    se.Value = sve;

                    clientSettings.Settings.Add(se);
                }

                config.Save();

                config = null;
            }

            catch

            {
                // suppress
            }
        }
Example #10
0
        /// <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);
        }
        /// <summary>
        /// Returns the collection of settings property values for the specified application instance and settings property group.
        /// </summary>
        /// <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>
        /// <returns>
        /// A <see cref="T:System.Configuration.SettingsPropertyValueCollection"/> containing the values for the specified settings property group.
        /// </returns>
        /// <remarks>
        /// </remarks>
        public override SettingsPropertyValueCollection GetPropertyValues(
            SettingsContext context, SettingsPropertyCollection collection)
        {
            var svc = new SettingsPropertyValueCollection();

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

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

            if (String.IsNullOrEmpty(username))
            {
                return(svc);
            }

            SqlConnection conn = null;

            try
            {
                conn = new SqlConnection(this._sqlConnectionString);
                conn.Open();

                this.GetProfileDataFromSproc(collection, svc, username, conn, userIsAuthenticated);
            }
            finally
            {
                if (conn != null)
                {
                    conn.Close();
                }
            }

            return(svc);
        }
Example #12
0
        public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection collection)
        {
            var settingsPropertyValueCollection = new SettingsPropertyValueCollection();

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

            var username = (string)context["UserName"];

            if (username.IsNullOrWhiteSpace() || collection.Count < 1)
            {
                return(settingsPropertyValueCollection);
            }

            User user = mongoGateway.GetByUserName(ApplicationName, username);

            foreach (SettingsProperty property in collection)
            {
                var propertyValue = new SettingsPropertyValue(property);

                if (user.Values.ContainsKey(propertyValue.Name))
                {
                    propertyValue.PropertyValue = user.Values[propertyValue.Name];
                    propertyValue.IsDirty       = false;
                    propertyValue.Deserialized  = true;
                }

                settingsPropertyValueCollection.Add(propertyValue);
            }

            user.LastActivityDate = DateTime.Now;
            mongoGateway.UpdateUser(user);

            return(settingsPropertyValueCollection);
        }
        /// <summary>
        /// Gets the property values.
        /// </summary>
        /// <param name="propertyNames">The property names.</param>
        /// <param name="stringValues">The string values.</param>
        /// <param name="binaryValues">The binary values.</param>
        /// <param name="svc">The SVC.</param>
        protected virtual void GetPropertyValues(
            string propertyNames,
            string stringValues,
            string binaryValues,
            SettingsPropertyValueCollection svc)
        {
            // property names are not provided, then nothing to parse for
            if (propertyNames.IsNullOrEmpty())
            {
                return;
            }

            // any values are not provided, then nothing to parse for
            if (stringValues.IsNullOrEmpty() && binaryValues.IsNullOrEmpty())
            {
                return;
            }

            /// decode
            Encoding encoding = Encoding.UTF8;

            string[] names  = encoding.GetString(Convert.FromBase64String(propertyNames)).Split(':');
            string   values = null;

            byte[] binaries = null;

            if (!stringValues.IsNullOrEmpty())
            {
                values = encoding.GetString(Convert.FromBase64String(stringValues));
            }
            if (!binaryValues.IsNullOrEmpty())
            {
                binaries = Convert.FromBase64String(binaryValues);
            }

            ParseProfileData(names, values, binaries, svc);
        }
        /// <summary>
        /// Must override this, this is the bit that does the saving to file.  Called when Settings.Save() is called
        /// </summary>
        /// <param name="context"></param>
        /// <param name="collection"></param>
        public override void SetPropertyValues(SettingsContext context, SettingsPropertyValueCollection collection)
        {
            //grab the values from the collection parameter and update the values in our dictionary.
            foreach (SettingsPropertyValue value in collection)
            {
                try
                {
                    Type t = GetType(value.Property.PropertyType.FullName);

                    var setting = new SettingStruct()
                    {
                        value = (value.PropertyValue == null ? String.Empty
                                 //: value.PropertyValue.ToString()),
                            : (string)(TypeDescriptor.GetConverter(t).ConvertToInvariantString(value.PropertyValue))),

                        name        = value.Name,
                        serializeAs = value.Property.SerializeAs.ToString()
                    };

                    if (!SettingsDictionary.ContainsKey(value.Name))
                    {
                        SettingsDictionary.Add(value.Name, setting);
                    }
                    else
                    {
                        SettingsDictionary[value.Name] = setting;
                    }
                }
                catch (Exception ee)
                {
                    Console.WriteLine(ee.Message);
                }
            }

            //now that our local dictionary is up-to-date, save it to disk.
            SaveValuesToFile();
        }
        /// <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 (true)// Edit 14-11-15 can load more than once  if (!_loaded)
            {
                //_loaded = true;
                SettingsDictionary = new Dictionary <string, SettingStruct>(); // Edit
                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 override void SetPropertyValues(SettingsContext context, SettingsPropertyValueCollection collection)
        {
            // получаем логин пользователя
            var username = (string)context["UserName"];

            if (string.IsNullOrEmpty(username) || collection.Count < 1)
            {
                return;
            }

            // получаем пользователя из таблицы Users по email
            var user = userService.GetUserByEmail(username);

            if (user != null)
            {
                var profile = profileService.GetProfileByUserId(user.Id);
                // если такой профиль уже есть изменяем его
                if (profile != null)
                {
                    foreach (SettingsPropertyValue val in collection)
                    {
                        profile.GetType().GetProperty(val.Property.Name).SetValue(profile, val.PropertyValue);
                    }
                }
                else
                {
                    // если нет, то создаем новый профиль и добавляем его
                    profile = new BLL.Interfacies.Entities.ProfileEntity();
                    foreach (SettingsPropertyValue val in collection)
                    {
                        profile.GetType().GetProperty(val.Property.Name).SetValue(profile, val.PropertyValue);
                    }
                    profile.UserId = user.Id;
                    profileService.CreateProfile(profile);
                }
            }
        }
Example #17
0
 private void NapDuLieu()
 {
     try
     {
         listSettings = Settings.Default.PropertyValues;
         gridControlCauHinh.DataSource = listSettings;
         foreach (GridColumn item in gridViewCauHinh.Columns)
         {
             if (item.FieldName == nameof(SettingsPropertyValue.Name) || item.FieldName == nameof(SettingsPropertyValue.PropertyValue))
             {
                 item.Visible = true;
             }
             else
             {
                 item.Visible = false;
             }
         }
         gridViewCauHinh.BestFitColumns();
     }
     catch (Exception ex)
     {
         XtraMessageBox.Show(ex.ToString());
     }
 }
Example #18
0
        private SettingsPropertyValueCollection GetPropertyValues(Guid userId, IEnumerable collection)
        {
            var properties = new SettingsPropertyValueCollection();

            foreach (SettingsProperty property in collection)
            {
                var value = new SettingsPropertyValue(property);

                switch (property.Name)
                {
                case EmployerProfile:
                    value.PropertyValue = _profilesQuery.GetEmployerProfile(userId) ?? new EmployerProfile();
                    break;

                case MemberProfile:
                    value.PropertyValue = _profilesQuery.GetMemberProfile(userId) ?? new MemberProfile();
                    break;
                }

                properties.Add(value);
            }

            return(properties);
        }
Example #19
0
        private static SettingsPropertyValueCollection GetDefaultPropertyValues(IEnumerable collection)
        {
            var properties = new SettingsPropertyValueCollection();

            foreach (SettingsProperty property in collection)
            {
                var value = new SettingsPropertyValue(property);

                switch (property.Name)
                {
                case EmployerProfile:
                    value.PropertyValue = new EmployerProfile();
                    break;

                case MemberProfile:
                    value.PropertyValue = new MemberProfile();
                    break;
                }

                properties.Add(value);
            }

            return(properties);
        }
        public static void UpgradeSharedPropertyValues(LocalFileSettingsProvider provider, SettingsContext context, SettingsPropertyCollection properties, string previousExeConfigFilename, string currentExeConfigFilename = null)
        {
            SettingsPropertyValueCollection currentValues  = GetSharedPropertyValues(provider, context, properties, currentExeConfigFilename);
            SettingsPropertyValueCollection previousValues = GetPreviousSharedPropertyValues(provider, context, properties, previousExeConfigFilename);

            foreach (SettingsProperty property in properties)
            {
                SettingsPropertyValue previousValue = previousValues[property.Name];
                if (previousValue != null)
                {
                    SettingsPropertyValue currentValue = currentValues[property.Name];
                    if (currentValue == null)
                    {
                        currentValues.Add(previousValue);
                    }
                    else
                    {
                        currentValue.SerializedValue = previousValue.SerializedValue;
                    }
                }
            }

            SetSharedPropertyValues(provider, context, currentValues, currentExeConfigFilename);
        }
        /// <summary>
        /// SetPropertyValue is invoked when ApplicationSettingsBase.Save is called
        /// for only the values marked with this provider attribute.
        /// </summary>
        public override void SetPropertyValues(SettingsContext context, SettingsPropertyValueCollection collection)
        {
            // Validate arguments
            if (collection == null)
            {
                throw new ArgumentNullException("collection");
            }

            // Iterate through the settings to be stored
            foreach (SettingsPropertyValue property in collection)
            {
                RegistryKey key = GetRegKey(property.Property);
                if (property.SerializedValue != null)
                {
                    // Set value when non-default
                    key.SetValue(property.Name, property.SerializedValue);
                }
                else
                {
                    // Delete value when default or null (if exists)
                    key.DeleteValue(property.Name, false);
                }
            }
        }
Example #22
0
        public override void SetPropertyValues(SettingsContext context, SettingsPropertyValueCollection collection)
        {
            string userName = (string)context["UserName"];

            if (!string.IsNullOrWhiteSpace(userName))
            {
                using (ZcrlContext zc = new ZcrlContext())
                {
                    var requiredProfile = (from p in zc.Profiles
                                           where (p.RelatedUser.Login == userName)
                                           select p).FirstOrDefault();

                    if (requiredProfile != null)
                    {
                        foreach (SettingsPropertyValue propVal in collection)
                        {
                            requiredProfile.GetType().GetProperty(propVal.Property.Name).SetValue(requiredProfile, propVal.PropertyValue);
                        }

                        zc.SaveChanges();
                    }
                }
            }
        }
        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;
                    }
                }
            }
        }
        /// <summary>
        /// Must override this, this is the bit that does the saving to file.  Called when Settings.Save() is called
        /// </summary>
        /// <param name="context"></param>
        /// <param name="collection"></param>
        public override void SetPropertyValues(SettingsContext context, SettingsPropertyValueCollection collection)
        {
            //grab the values from the collection parameter and update the values in our dictionary.
            foreach (SettingsPropertyValue value in collection)
            {
                var setting = new SettingStruct()
                {
                    value       = (value.PropertyValue == null ? String.Empty : value.PropertyValue.ToString()),
                    name        = value.Name,
                    serializeAs = value.Property.SerializeAs.ToString()
                };
                if (!SettingsDictionary.ContainsKey(value.Name))
                {
                    SettingsDictionary.Add(value.Name, setting);
                }
                else
                {
                    SettingsDictionary[value.Name] = setting;
                }
            }

            //now that our local dictionary is up-to-date, save it to disk.
            SaveValuesToFile();
        }
Example #25
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="context"></param>
 /// <param name="collection"></param>
 /// <returns></returns>
 public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection collection)
 {
     try
     {
         SettingsPropertyValueCollection coll = new SettingsPropertyValueCollection();
         if (collection.Count >= 1)
         {
             string userName = (string)context["UserName"];
             foreach (SettingsProperty prop in collection)
             {
                 if (prop.SerializeAs == SettingsSerializeAs.ProviderSpecific)
                 {
                     if (prop.PropertyType.IsPrimitive || (prop.PropertyType == typeof(string)))
                     {
                         prop.SerializeAs = SettingsSerializeAs.String;
                     }
                     else
                     {
                         prop.SerializeAs = SettingsSerializeAs.Xml;
                     }
                 }
                 coll.Add(new SettingsPropertyValue(prop));
             }
             if (!string.IsNullOrEmpty(userName))
             {
                 lock (SyncRoot)
                 {
                     bool isAuthenticated = Convert.ToBoolean(context["IsAuthenticated"]);
                     GetPropertyValues(userName, coll, isAuthenticated);
                 }
             }
         }
         return(coll);
     }
     catch { throw; }
 }
Example #26
0
        public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context,
                                                                          SettingsPropertyCollection collection)
        {
            string username        = (string)context["UserName"];
            bool   isAuthenticated = (bool)context["IsAuthenticated"];
            SettingsPropertyValueCollection settingsPropertyValueCollection = new SettingsPropertyValueCollection();

            foreach (SettingsProperty settingsProperty in collection)
            {
                SettingsPropertyValue settingsPropertyValue = new SettingsPropertyValue(settingsProperty)
                {
                    PropertyValue = settingsProperty.DefaultValue
                };
                settingsPropertyValueCollection.Add(settingsPropertyValue);
            }

            SqlDatabase sqlDatabase = new SqlDatabase(_connectionString);
            DbCommand   dbCommand   = sqlDatabase.GetStoredProcCommand("adm.NlayerSP_ObtenerPerfilUsuario");

            sqlDatabase.AddInParameter(dbCommand, "Aplicacion", DbType.String, _applicationName);
            sqlDatabase.AddInParameter(dbCommand, "Login", DbType.String, username);
            sqlDatabase.AddInParameter(dbCommand, "SoloActividad", DbType.Boolean, true);
            sqlDatabase.AddInParameter(dbCommand, "EstaAutenticado", DbType.Boolean, isAuthenticated);

            using (IDataReader dataReader = sqlDatabase.ExecuteReader(dbCommand))
            {
                while (dataReader.Read())
                {
                    SettingsPropertyValue settingsPropertyValue =
                        settingsPropertyValueCollection[dataReader.GetString(0)];
                    settingsPropertyValue.PropertyValue = dataReader.GetString(1);
                }
            }

            return(settingsPropertyValueCollection);
        }
        string GetPrice(int pId)
        {
            decimal?price1 = null;
            decimal?price2 = null;
            decimal?price3 = null;
            decimal?p      = null;

            if (Context.User.Identity.IsAuthenticated)
            {
                SettingsPropertyValueCollection spvc = this.Context.Profile.PropertyValues;
                User u = spvc["AccountInfo"].PropertyValue as User;
                price1 = ProductPrices.GetPriceMarket(u.UserID, pId);
                price2 = ProductPrices.GetPriceMember(u.UserID, pId);
                price3 = ProductPrices.GetPricePromote(u.UserID, pId);
                p      = GlobalSettings.GetMinPrice(price1, price2);
                return(GlobalSettings.GetPrice(p, price3));
            }
            else
            {
                price1 = ProductPrices.GetPriceDefault(pId);
                price3 = ProductPrices.GetPricePromote(0, pId);
                return(GlobalSettings.GetPrice(price1, price3));
            }
        }
        /// <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);
        }
Example #29
0
        public override SettingsPropertyValueCollection GetPropertyValues(
            SettingsContext context,
            SettingsPropertyCollection collection
            )
        {
            var result = new SettingsPropertyValueCollection();

            foreach (SettingsProperty property in collection)
            {
                var value = new SettingsPropertyValue(property);
                if (KnownProperties.Contains(property.Name))
                {
                    value.PropertyValue = Settings
                                          .Current
                                          .GetType()
                                          .GetField(value.Property.Name)
                                          .GetValue(Settings.Current);
                }

                result.Add(value);
            }

            return(result);
        }
Example #30
0
        public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context,
                                                                          SettingsPropertyCollection collection)
        {
            var results = new SettingsPropertyValueCollection();

            if (collection.Count < 1)
            {
                return(results);
            }

            var username = (string)context["UserName"];

            foreach (SettingsProperty prop in collection)
            {
                if (prop.SerializeAs == SettingsSerializeAs.ProviderSpecific)
                {
                    if (prop.PropertyType.IsPrimitive || prop.PropertyType == typeof(string))
                    {
                        prop.SerializeAs = SettingsSerializeAs.String;
                    }
                    else
                    {
                        prop.SerializeAs = SettingsSerializeAs.Xml;
                    }
                }

                results.Add(new SettingsPropertyValue(prop));
            }

            if (!string.IsNullOrWhiteSpace(username))
            {
                GetPropertyValuesFromDatabase(username, results);
            }

            return(results);
        }
Example #31
0
        public override void SetPropertyValues(SettingsContext context, SettingsPropertyValueCollection collection)
        {
            lock (LockObject)
            {
                // We need to forget any cached version of the XML. Otherwise, when more than one lot of settings
                // is saved in the same file, the provider that is doing the save for one of them may have stale
                // (or missing) settings for the other. We want to write the dirty properties over a current
                // version of everything else that has been saved in the file.
                _settingsXml = null;

                //Iterate through the settings to be stored, only dirty settings for this provider are in collection
                foreach (SettingsPropertyValue propval in collection)
                {
                    var groupName = context["GroupName"].ToString();
                    var groupNode = SettingsXml.SelectSingleNode("/configuration/userSettings/" + context["GroupName"]);
                    if (groupNode == null)
                    {
                        var parentNode = SettingsXml.SelectSingleNode("/configuration/userSettings");
                        groupNode = SettingsXml.CreateElement(groupName);
                        parentNode.AppendChild(groupNode);
                    }
                    var section = (XmlElement)SettingsXml.SelectSingleNode("/configuration/configSections/sectionGroup/section");
                    if (section == null)
                    {
                        var parentNode = SettingsXml.SelectSingleNode("/configuration/configSections/sectionGroup");
                        section = SettingsXml.CreateElement("section");
                        section.SetAttribute("name", groupName);
                        section.SetAttribute("type", String.Format("{0}, {1}", typeof(ClientSettingsSection), Assembly.GetAssembly(typeof(ClientSettingsSection))));
                        parentNode.AppendChild(section);
                    }
                    SetValue(groupNode, propval);
                }
                Directory.CreateDirectory(UserConfigLocation);
                RobustIO.SaveXml(SettingsXml, Path.Combine(UserConfigLocation, UserConfigFileName));
            }
        }
        public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection collection)
        {
            XDocument xmlDoc = GetXmlDoc();
            SettingsPropertyValueCollection values = new SettingsPropertyValueCollection();

            // iterate through settings to be retrieved
            foreach (SettingsProperty setting in collection)
            {
                SettingsPropertyValue value = new SettingsPropertyValue(setting);
                value.IsDirty = false;
                //Set serialized value to xml element from file. This will be deserialized by SettingsPropertyValue when needed.
                var loadedValue = getXmlValue(xmlDoc, XmlConvert.EncodeLocalName((string)context["GroupName"]), setting);
                if (loadedValue != null)
                {
                    value.SerializedValue = loadedValue;
                }
                else
                {
                    value.PropertyValue = null;
                }
                values.Add(value);
            }
            return(values);
        }
        GetPropertyValues(SettingsContext context,
                          SettingsPropertyCollection ppc)
        {
            string username        = (string)context["UserName"];
            bool   isAuthenticated = (bool)context["IsAuthenticated"];

            // The serializeAs attribute is ignored in this provider implementation.

            SettingsPropertyValueCollection svc =
                new SettingsPropertyValueCollection();

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

                switch (prop.Name)
                {
                case "StockSymbols":
                    pv.PropertyValue = GetStockSymbols(username, isAuthenticated);
                    break;

                case "ZipCode":
                    pv.PropertyValue = GetZipCode(username, isAuthenticated);
                    break;

                default:
                    throw new ProviderException("Unsupported property.");
                }

                svc.Add(pv);
            }

            UpdateActivityDates(username, isAuthenticated, true);

            return(svc);
        }
Example #34
0
        /// <summary>
        /// Gets property values
        /// </summary>
        /// <param name="context"></param>
        /// <param name="collection"></param>
        /// <returns></returns>
        public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context,
                                                                          SettingsPropertyCollection collection)
        {
            SettingsPropertyValueCollection svc = new SettingsPropertyValueCollection();

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

            string username = (string)context["UserName"];

            if (String.IsNullOrEmpty(username))
            {
                return(svc);
            }

            NpgsqlConnection conn = null;

            try
            {
                conn = new NpgsqlConnection(_NpgsqlConnectionString);
                conn.Open();

                GetProfileDataFromTable(collection, svc, username, conn);
            }
            finally
            {
                if (conn != null)
                {
                    conn.Close();
                }
            }

            return(svc);
        }
Example #35
0
 public override void SetPropertyValues(SettingsContext context, SettingsPropertyValueCollection collection)
 {
     if (Settings.ClientSpecificMode)
     {
         var values = (Dictionary <SettingsProperty, object>)context[ValuesName];
         foreach (SettingsPropertyValue propval in collection)
         {
             if (propval.IsDirty)
             {
                 values[propval.Property] = propval.PropertyValue;
             }
         }
     }
     else
     {
         try
         {
             base.SetPropertyValues(context, collection);
         }
         catch (ConfigurationErrorsException)
         {
         }
     }
 }
        public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection requestedProperties)
        {
            SettingsPropertyValueCollection properties = new SettingsPropertyValueCollection();

            if (requestedProperties.Count > 0)
            {
                User u = GetUser(context);
                if (u != null)
                {
                    foreach (SettingsProperty requestedProperty in requestedProperties)
                    {
                        SettingsPropertyValue property = new SettingsPropertyValue(requestedProperty);
                        object _propertyValue          = u[requestedProperty.Name];
                        //SettingsPropertyValue should automatically resort to .DefaultValue
                        // unless .PropertyValue was set
                        if (null != _propertyValue)
                        {
                            property.PropertyValue = _propertyValue;
                        }
                        properties.Add(property);
                    }
                }
                else
                {
                    //fill in properties, allowed for anonymous users..
                    foreach (SettingsProperty requestedProperty in requestedProperties)
                    {
                        if ((bool?)requestedProperty.Attributes["AllowAnonymous"] ?? false)
                        {
                            properties.Add(new SettingsPropertyValue(requestedProperty));
                        }
                    }
                }
            }
            return(properties);
        }
 public abstract virtual void SetPropertyValues(SettingsContext context, SettingsPropertyValueCollection collection)
 {
 }
Example #38
0
 /// <summary>
 /// To instantiate a new instance of ProfileReader, you must supply an 
 /// instance of ProfileData or the individual ProfileData Properties. If PropertyNames or 
 /// PropertyValues is null, and exception will be thrown.
 /// </summary>
 /// <param name="pd">Object representing a users profile data</param>
 public ProfileReader(ProfileData pd)
 {
     _propertyValue = ProfileReader.Parse(pd);
 }
Example #39
0
        /// <summary>
        /// Parses the ProfileData object and populates the SettingsPropertyValueCollection with the values
        /// </summary>
        /// <param name="pd">Data to parse</param>
        /// <param name="properties">Data result container</param>
        internal static void ParseProfileData(ProfileData pd, SettingsPropertyValueCollection properties)
        {
            if(pd.PropertyNames == null)
                return;

            string[] names = pd.PropertyNames.Split(':');
            for (int i = 0; i < (names.Length / 4); i++)
            {
                string propName = names[i * 4];
                SettingsPropertyValue spv = properties[propName];
                if (spv == null)
                {
                    continue;
                }
                int index = int.Parse(names[(i * 4) + 2], CultureInfo.InvariantCulture);
                int len = int.Parse(names[(i * 4) + 3], CultureInfo.InvariantCulture);
                if (len == -1)
                {
                    if (!spv.Property.PropertyType.IsValueType)
                    {
                        spv.PropertyValue = null;
                        spv.IsDirty = false;
                        spv.Deserialized = true;
                    }
                    continue;
                }
                if (((names[(i * 4) + 1] == "S") && (index >= 0)) && (len > 0) && (pd.PropertyValues != null) && (pd.PropertyValues.Length >= (index + len)))
                {
                    spv.SerializedValue = pd.PropertyValues.Substring(index, len);
                }
                if (((names[(i * 4) + 1] == "B") && (index >= 0)) && (len > 0) && (pd.PropertyValuesBinary != null) && (pd.PropertyValuesBinary.Length >= (index + len)))
                {
                    byte[] buffer = new byte[len];
                    Buffer.BlockCopy(pd.PropertyValuesBinary, index, buffer, 0, len);
                    spv.SerializedValue = buffer;
                }
            }
        }
Example #40
0
        /// <summary>
        /// Generates a SettingsPropertyValueCollection for the specified ProfileData.
        /// </summary>
        internal static SettingsPropertyValueCollection GetPropertyValues(ProfileData pd)
        {
            //NOTE: Can we cache/clone/copy this collection. Chances are when we use it, we will
            //access it many times in a row.
            SettingsPropertyValueCollection spvc = new SettingsPropertyValueCollection();

            foreach (SettingsProperty p in ProfileBase.Properties)
            {
                if (p.SerializeAs == SettingsSerializeAs.ProviderSpecific)
                {
                    if (p.PropertyType.IsPrimitive || (p.PropertyType == typeof(string)))
                    {
                        p.SerializeAs = SettingsSerializeAs.String;
                    }
                    else
                    {
                        p.SerializeAs = SettingsSerializeAs.Xml;
                    }
                }
                spvc.Add(new SettingsPropertyValue(p));
            }

            try
            {
                ParseProfileData(pd, spvc);
            }
            catch (Exception)
            {
            }
            return spvc;
        }
    public override System.Configuration.SettingsPropertyValueCollection GetPropertyValues(System.Configuration.SettingsContext context, System.Configuration.SettingsPropertyCollection collection)
    {
        //JH
        string username = (string)context["UserName"];

        SettingsPropertyValueCollection svc = new SettingsPropertyValueCollection();

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

        activity(username, "Got Property Values", false);

        return svc;
    }
    public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext sc, SettingsPropertyCollection properties)
    {
        // create the collection to return
        SettingsPropertyValueCollection spvc = new SettingsPropertyValueCollection();

        #region Check The Function Parameters Are Valid
        // check we have the user profile information.
        if (sc == null)
        {
            return spvc;
        }

        // check we do have the profile information for the properties to be retrieved.
        // check we do have properties in the profile
        if (properties == null || properties.Count < 1)
        {
            return spvc;
        }

        // get the username
        // get if the user is authenticated
        // if the username is null or empty, return empty property value collection
        Boolean isAuthenticated = (Boolean)sc["IsAuthenticated"];
        String username = (String)sc["UserName"];
        if (String.IsNullOrEmpty(username))
        {
            return spvc;
        }
        #endregion

        #region Fill the collection to return with the profile properties initialized to their default values
        foreach (SettingsProperty sp in properties)
        {
            // If the serialization is up to us to decide, try and see if it can be serialised as a string
            // otherwise serialise as XML
            if (sp.SerializeAs == SettingsSerializeAs.ProviderSpecific)
            {
                // If it is a primitive type or a string, then just store it as a string
                if (sp.PropertyType.IsPrimitive || (sp.PropertyType == typeof(string)))
                {
                    sp.SerializeAs = SettingsSerializeAs.String;
                }
                else // Else serialize it as XML
                {
                    sp.SerializeAs = SettingsSerializeAs.Xml;
                }
            }

            // create a property value based on the profile property settings, including default value
            // Add the property value to the collection to return
            spvc.Add(new SettingsPropertyValue(sp));
        }
        #endregion

        #region Retrieve the stored property values from the database
        try
        {
            GetNonDefaultPropertyValuesForUser(username, spvc);
        }
        catch (Exception e)
        {
            // if anything went wrong, throw an exception
            throw new ProviderException(String.Format(
                "Error getting profile property values from database.\nUsername: '******'\nIs Authenticated: {1}",
                username, isAuthenticated.ToString()), e);
        }
        #endregion

        return spvc;
    }
Example #43
0
    public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection collection)
    {
        string username = (string)context["UserName"];
        bool isAuthenticated = (bool)context["IsAuthenticated"];

        Dictionary<string, object> values = _profileValues.ContainsKey(username) ? _profileValues[username] : null;

        SettingsPropertyValueCollection spvc = new SettingsPropertyValueCollection();

        foreach (SettingsProperty prop in collection)
        {
            SettingsPropertyValue spv = new SettingsPropertyValue(prop);
            if (values != null && values.ContainsKey(prop.Name))
            {
                spv.PropertyValue = values[prop.Name];
            }
            else
            {
                spv.PropertyValue = prop.DefaultValue;
            }
            spvc.Add(spv);
        }
        return spvc;
    }
    // Retrieve settings from the configuration file
    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 void SetPropertyValues(SettingsContext context, SettingsPropertyValueCollection collection)
 {
     IProfile dal = Snitz.Membership.Helpers.Factory<IProfile>.Create("Profile");
         dal.TableName = _table;
         dal.SetPropertyValues(context, collection);
 }
    private void EncodeProfileData(ref string allNames, ref string allValues, ref byte[] buf, SettingsPropertyValueCollection properties, bool userIsAuthenticated)
    {
        StringBuilder names = new StringBuilder();
        StringBuilder values = new StringBuilder();
        MemoryStream stream = new MemoryStream();

        try
        {
            foreach (SettingsPropertyValue pp in properties)
            {
                // Ignore this property if the user is anonymous and
                // the property's AllowAnonymous property is false
                if (!userIsAuthenticated && !(bool) pp.Property.Attributes["AllowAnonymous"]) continue;

                // Ignore this property if it's not dirty and is
                // currently assigned its default value
                if (!pp.IsDirty && pp.UsingDefaultValue) continue;

                int len = 0, pos = 0;
                string propValue = null;

                // If Deserialized is true and PropertyValue is null,
                // then the property's current value is null (which
                // we'll represent by setting len to -1)
                if (pp.Deserialized && pp.PropertyValue == null)
                {
                    len = -1;
                }

                // Otherwise get the property value from
                // SerializedValue
                else
                {
                    object sVal = pp.SerializedValue;

                    // If SerializedValue is null, then the property's
                    // current value is null
                    if (sVal == null)
                    {
                        len = -1;
                    }

                    // If sVal is a string, then encode it as a string
                    else if (sVal is string)
                    {
                        propValue = (string) sVal;
                        len = propValue.Length;
                        pos = values.Length;
                    }

                // If sVal is binary, then encode it as a byte
                    // array
                    else
                    {
                        byte[] b2 = (byte[]) sVal;
                        pos = (int) stream.Position;
                        stream.Write(b2, 0, b2.Length);
                        stream.Position = pos + b2.Length;
                        len = b2.Length;
                    }
                }

                // Add a string conforming to the following format
                // to "names:"
                //
                // "name:B|S:pos:len"
                //    ^   ^   ^   ^
                //    |   |   |   |
                //    |   |   |   +--- Length of data
                //    |   |   +------- Offset of data
                //    |   +----------- Location (B="buf", S="values")
                //    +--------------- Property name

                names.Append(pp.Name + ":" + ((propValue != null) ? "S" : "B") + ":" + pos.ToString(CultureInfo.InvariantCulture) + ":" + len.ToString(CultureInfo.InvariantCulture) + ":");

                // If the propery value is encoded as a string, add the
                // string to "values"
                if (propValue != null) values.Append(propValue);
            }

            // Copy the binary property values written to the
            // stream to "buf"
            buf = stream.ToArray();
        }
        finally
        {
            if (stream != null) stream.Close();
        }

        allNames = names.ToString();
        allValues = values.ToString();
    }
    private void DecodeProfileData(string[] names, string values, byte[] buf, SettingsPropertyValueCollection properties)
    {
        if (names == null || values == null || buf == null || properties == null) return;

        for (int i = 0; i < names.Length; i += 4)
        {
            // Read the next property name from "names" and retrieve
            // the corresponding SettingsPropertyValue from
            // "properties"
            string name = names[i];
            SettingsPropertyValue pp = properties[name];

            if (pp == null) continue;

            // Get the length and index of the persisted property value
            int pos = Int32.Parse(names[i + 2], CultureInfo.InvariantCulture);
            int len = Int32.Parse(names[i + 3], CultureInfo.InvariantCulture);

            // If the length is -1 and the property is a reference
            // type, then the property value is null
            if (len == -1 && !pp.Property.PropertyType.IsValueType)
            {
                pp.PropertyValue = null;
                pp.IsDirty = false;
                pp.Deserialized = true;
            }

        // If the property value was peristed as a string,
            // restore it from "values"
            else if (names[i + 1] == "S" && pos >= 0 && len > 0 && values.Length >= pos + len)
                pp.SerializedValue = values.Substring(pos, len);

        // If the property value was peristed as a byte array,
            // restore it from "buf"
            else if (names[i + 1] == "B" && pos >= 0 && len > 0 && buf.Length >= pos + len)
            {
                byte[] buf2 = new byte[len];
                Buffer.BlockCopy(buf, pos, buf2, 0, len);
                pp.SerializedValue = buf2;
            }
        }
    }
    // 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);
            }
        }
    }
    // Save any of the applications settings that have changed (flagged as "dirty")
    public override void SetPropertyValues(SettingsContext sContext, SettingsPropertyValueCollection settingsColl)
    {
        // Set the values in XML
        foreach (SettingsPropertyValue spVal in settingsColl)
        {
            SetSetting(spVal);
        }

        // Write the XML file to disk
        try
        {
            XMLConfig.Save(System.IO.Path.Combine(GetAppPath(), GetSettingsFilename()));
        }
        catch (Exception ex)
        {
            // Create an informational message for the user if we cannot save the settings.
            // Enable whichever applies to your application type.

            // Uncomment the following line to enable a MessageBox for forms-based apps
            System.Windows.Forms.MessageBox.Show(ex.Message, "Error writting configuration file to disk", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);

            // Uncomment the following line to enable a console message for console-based apps
            //Console.WriteLine("Error writing configuration file to disk: " + ex.Message);
        }
    }
 private void DeleteUnusedSettings(SettingsPropertyValueCollection settingsColl)
 {
     XmlNodeList settings = XMLConfig.SelectNodes("//setting");
     XmlNode AppPropertiesSettings = settings[0].ParentNode;
     foreach (XmlNode setting in settings)
     {
         string searchName = setting.Attributes["name"].Value;
         foreach (SettingsPropertyValue value in settingsColl)
         {
             if (value.Name == searchName)
             {
                 searchName = null;
                 break;
             }
         }
         if (searchName != null)
         {
             AppPropertiesSettings.RemoveChild(setting);
         }
     }
 }
Example #51
0
    public override void SetPropertyValues(SettingsContext context, SettingsPropertyValueCollection collection)
    {
        string username = (string)context["UserName"];
        bool isAuthenticated = (bool)context["IsAuthenticated"];

        Dictionary<string, object> values = _profileValues.ContainsKey(username) ? _profileValues[username] : null;

        if (values == null)
        {
            values = new Dictionary<string, object>();
            _profileValues[username] = values;
        }

        foreach (SettingsPropertyValue propValue in collection)
        {
            values[propValue.Property.Name] = propValue.PropertyValue;
        }
    }
    public override void SetPropertyValues(SettingsContext context, SettingsPropertyValueCollection collection)
    {
        Monitor.Enter(SetValuesLock);

        try
        {

            foreach (SettingsPropertyValue propval in collection)
            {
                SetValue(propval);
            }

            SyncToDisk();
        }
        catch
        {
            // ignore
        }
        finally
        {
            Monitor.Exit(SetValuesLock);
        }
    }
    private void GetNonDefaultPropertyValuesForUser(String username, SettingsPropertyValueCollection spvc)
    {
        try
        {
            // Get the connection we're going to use
            using (SqlConnection conn = new SqlConnection(_connectionStringName))
            {
                // set the command object to the stored procedure used to get the properties
                // set the command to use the connection
                // set the command timeout value
                // initialize the stored procedure parameters to their values
                SqlCommand GetPropertiesCommand = new SqlCommand("aspnet_Profile_GetProperties", conn);
                GetPropertiesCommand.CommandTimeout = _commandTimeout;
                GetPropertiesCommand.CommandType = CommandType.StoredProcedure;
                GetPropertiesCommand.Parameters.Add("@ApplicationName", SqlDbType.NVarChar, 256).Value = base.ApplicationName;
                GetPropertiesCommand.Parameters.Add("@UserName", SqlDbType.NVarChar, 256).Value = username;
                GetPropertiesCommand.Parameters.Add("@CurrentTimeUtc", SqlDbType.DateTime).Value = DateTime.UtcNow;

                // open the connection
                conn.Open();

                // using a DataReader populated with the stored procedure
                using (SqlDataReader dReader = GetPropertiesCommand.ExecuteReader(CommandBehavior.CloseConnection))
                {
                    // while there is anything to read
                    while (dReader.Read())
                    {
                        // get the property value corresponding to the PropertyName field in the reader
                        SettingsPropertyValue spv = spvc[dReader.GetString(dReader.GetOrdinal("PropertyName"))];

                        // if there is such a profile property
                        if (spv != null)
                        {
                            // get its value from the reader
                            GetPropertyValueFromReader(spv, dReader);
                        }
                    }
                }
            }
        }
        catch (Exception e)
        {
            // if anything went wrong, throw an exception to be handled by the calling function
            throw e;
        }
    }
    public override void SetPropertyValues(SettingsContext sc, SettingsPropertyValueCollection properties)
    {
        #region Check The Function Parameters Are Valid
        // check we have the user profile information.
        if (sc == null)
        {
            return;
        }

        // check we do have the profile information for the properties to be retrieved.
        // check we do have properties in the profile
        if (properties == null || properties.Count < 1)
        {
            return;
        }

        // get the username
        // get if the user is authenticated
        // if the username is null or empty, quit
        String username = (String)sc["UserName"];
        Boolean isAuthenticated = (Boolean)sc["IsAuthenticated"];
        if (String.IsNullOrEmpty(username))
        {
            return;
        }
        #endregion

        #region Build A List Of Items To Be Actually Saved
        // build a list
        List<SettingsPropertyValue> columnData = new List<SettingsPropertyValue>(properties.Count);

        // add all properties to be saved to the list
        foreach (SettingsPropertyValue spv in properties)
        {
            // iIf the property is dirty "written to or used", add it to the list
            if (spv.IsDirty)
            {
                // if the user is anonymous and the property is not marked "AllowAnonymous", skip this property
                if (!isAuthenticated && !((Boolean)spv.Property.Attributes["AllowAnonymous"]))
                {
                    continue;
                }

                // add the property to the list
                columnData.Add(spv);
            }
        }

        // if the list is empty, quit
        if (columnData.Count < 1)
        {
            return;
        }
        #endregion

        #region Save The List To The Database
        try
        {
            // make a conection
            using (SqlConnection conn = new SqlConnection(_connectionStringName))
            {
                // set the command object to the stored procedure used to save the properties
                // set the command to use the connection
                // set the command timeout value
                // initialize the common stored procedure parameters to their values
                SqlCommand SetPropertyCommand = new SqlCommand("aspnet_Profile_SetProperty", conn);
                SetPropertyCommand.CommandTimeout = _commandTimeout;
                SetPropertyCommand.CommandType = CommandType.StoredProcedure;
                SetPropertyCommand.Parameters.Add("@ApplicationName", SqlDbType.NVarChar, 256).Value = base.ApplicationName;
                SetPropertyCommand.Parameters.Add("@PropertyName", SqlDbType.NVarChar, 256);
                SetPropertyCommand.Parameters.Add("@PropertyUsingDefaultValue", SqlDbType.Bit);
                SetPropertyCommand.Parameters.Add("@PropertyValueString", SqlDbType.NVarChar, Int32.MaxValue);
                SetPropertyCommand.Parameters.Add("@PropertyValueBinary", SqlDbType.VarBinary, Int32.MaxValue);
                SetPropertyCommand.Parameters.Add("@UserName", SqlDbType.NVarChar, 256).Value = username;
                SetPropertyCommand.Parameters.Add("@IsUserAnonymous", SqlDbType.Bit).Value = !isAuthenticated;
                SetPropertyCommand.Parameters.Add("@CurrentTimeUtc", SqlDbType.DateTime).Value = DateTime.UtcNow;

                // for each property on the list
                foreach (SettingsPropertyValue spv in columnData)
                {
                    // set the rest of the stored procedure parameters according to each specific property features
                    SetPropertyCommand.Parameters["@PropertyName"].Value = spv.Property.Name;

                    // if the property is using the same value as DdefaultValue
                    // otherwise continue your normal insert/update procedure
                    if (spv.Property.DefaultValue.Equals(spv.SerializedValue) == true)
                    {
                        // just mark the procedures parameter @PropertyUsingDefaultValue to true
                        // to remove the entry from the database so it switches back to default
                        // the other values are not really significant so use DBNull
                        SetPropertyCommand.Parameters["@PropertyUsingDefaultValue"].Value = 1;
                        SetPropertyCommand.Parameters["@PropertyValueString"].Value = DBNull.Value;
                        SetPropertyCommand.Parameters["@PropertyValueBinary"].Value = DBNull.Value;
                    }
                    else
                    {
                        // set the parameter @PropertyUsingDefaultValue to false so the procedure would insert/update
                        SetPropertyCommand.Parameters["@PropertyUsingDefaultValue"].Value = 0;

                        // if the property value is null, set both string and binary values to null
                        // otherwise set the appropriate one to the property value after it has been serialized properly
                        if ((spv.Deserialized && spv.PropertyValue == null) || (!spv.Deserialized && spv.SerializedValue == null))
                        {
                            SetPropertyCommand.Parameters["@PropertyValueString"].Value = DBNull.Value;
                            SetPropertyCommand.Parameters["@PropertyValueBinary"].Value = DBNull.Value;
                        }
                        else
                        {
                            // get the serialized property value
                            //spv.SerializedValue = SerializePropertyValue(spv.Property, spv.PropertyValue);

                            // set the approporiate parameter of the stored procedure to the serialized value
                            // if the serialized value is a string store it in the @PropertyValueString parameter and set the other to DBNull
                            // otherwise store the value in the @PropertyValueBinary and set the other to DBNull
                            if (spv.SerializedValue is String)
                            {
                                SetPropertyCommand.Parameters["@PropertyValueString"].Value = spv.SerializedValue;
                                SetPropertyCommand.Parameters["@PropertyValueBinary"].Value = DBNull.Value;
                            }
                            else
                            {
                                SetPropertyCommand.Parameters["@PropertyValueString"].Value = DBNull.Value;
                                SetPropertyCommand.Parameters["@PropertyValueBinary"].Value = spv.SerializedValue;
                            }
                        }
                    }

                    // if the connection is closed, open it
                    if (conn.State == ConnectionState.Closed)
                    {
                        conn.Open();
                    }

                    // execute the stored procedure
                    // if no rows were affected, then throw an error, because nothing has been saved!
                    if (SetPropertyCommand.ExecuteNonQuery() == 0)
                    {
                        throw new ProviderException(String.Format("Updating the profile property '{0}' in the database failed!", spv.Name));
                    }
                }
            }
        }
        catch (Exception e)
        {
            // if anything went wrong, throw an exception
            throw new ProviderException(String.Format(
                "Error setting profile property value to database.\nUsername: '******'\nIs Authenticated: {1}",
                username, isAuthenticated.ToString()), e);
        }
        #endregion
    }
    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);
    }
    public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection collection)
    {
        Monitor.Enter(GetValuesLock);
        SettingsPropertyValueCollection values = new SettingsPropertyValueCollection();

        //Iterate through the settings to be retrieved
        foreach(SettingsProperty setting in collection)
        {
            SettingsPropertyValue value = new SettingsPropertyValue(setting);

            value.IsDirty = false;
            value.SerializedValue = GetValue(setting);
            values.Add(value);
        }

        Monitor.Exit(GetValuesLock);
        return values;
    }
    public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection properties)
    {
        SettingsPropertyValueCollection settings = new SettingsPropertyValueCollection();

        // Do nothing if there are no properties to retrieve
        if (properties.Count == 0)
            return settings;

        // For properties lacking an explicit SerializeAs setting, set
        // SerializeAs to String for strings and primitives, and XML
        // for everything else
        foreach (SettingsProperty property in properties)
        {
            if (property.SerializeAs == SettingsSerializeAs.ProviderSpecific)
            {
                if (property.PropertyType.IsPrimitive || property.PropertyType == typeof(String))
                {
                    property.SerializeAs = SettingsSerializeAs.String;
                }
                else
                {
                    property.SerializeAs = SettingsSerializeAs.Xml;
                }
            }
            settings.Add(new SettingsPropertyValue(property));
        }

        // Get the user name or anonymous user ID
        string username = (string) context["UserName"];

        // NOTE: Consider validating the user name here to prevent
        // malicious user names such as "../Foo" from targeting
        // directories other than Profile_Data

        // Load the profile
        if (!String.IsNullOrEmpty(username))
        {
            StreamReader reader = null;
            string[] names;
            string values;
            byte[] buf = null;

            try
            {
                // Open the file containing the profile data
                try
                {
                    string path =	string.Format(ProfilePathFormatString,	username.Replace('\\', '_'));
                    reader		  = new StreamReader(path);
                }
                catch (IOException)
                {
                    // Not an error if file doesn't exist
                    return settings;
                }

                // Read names, values, and buf from the file
                names = reader.ReadLine().Split(':');

                values = reader.ReadLine();
                if (!string.IsNullOrEmpty(values))
                {
                    UnicodeEncoding encoding = new UnicodeEncoding();
                    values = encoding.GetString
                            (Convert.FromBase64String(values));
                }

                string temp = reader.ReadLine();
                if (!String.IsNullOrEmpty(temp))
                {
                    buf = Convert.FromBase64String(temp);
                }
                else
                    buf = new byte[0];
            }
            finally
            {
                if (reader != null)
                    reader.Close();
            }

            // Decode names, values, and buf and initialize the
            // SettingsPropertyValueCollection returned to the caller
            DecodeProfileData(names, values, buf, settings);
        }

        return settings;
    }
	public virtual void SetPropertyValues(SettingsContext context, SettingsPropertyValueCollection values) {}
    public override void SetPropertyValues(SettingsContext context, SettingsPropertyValueCollection propvals)
    {
        //Iterate through the settings to be stored
        //Only dirty settings are included in propvals, and only ones relevant to this provider
        foreach (SettingsPropertyValue propval in propvals)
        {
            SetValue(propval);
        }

        try
        {
            string settingsFile = System.IO.Path.Combine(GetAppSettingsPath(), GetAppSettingsFilename());

            if(!File.Exists(settingsFile)) {
                Directory.CreateDirectory(GetAppSettingsPath());
                File.Create(settingsFile).Close();
            }

            SettingsXML.Save(System.IO.Path.Combine(GetAppSettingsPath(), GetAppSettingsFilename()));
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
    }
    public override void SetPropertyValues(SettingsContext context,	SettingsPropertyValueCollection properties)
    {
        // Get information about the user who owns the profile
        string username    = (string) context["UserName"];
        bool authenticated = (bool) context["IsAuthenticated"];

        // NOTE: Consider validating the user name here to prevent
        // malicious user names such as "../Foo" from targeting
        // directories other thanProfile_Data

        // Do nothing if there is no user name or no properties
        if (String.IsNullOrEmpty(username) || properties.Count == 0) return;

        // Format the profile data for saving
        string names  = String.Empty;
        string values = String.Empty;
        byte[] buf    = null;

        EncodeProfileData(ref names, ref values, ref buf,	properties, authenticated);

        // Do nothing if no properties need saving
        if (names == String.Empty) return;

        // Save the profile data
        StreamWriter writer = null;

        try
        {
            string path = string.Format(ProfilePathFormatString, username.Replace('\\', '_'));
            writer			= new StreamWriter(path, false);

            writer.WriteLine(names);

            if (!String.IsNullOrEmpty(values))
            {
                UnicodeEncoding encoding = new UnicodeEncoding();
                writer.WriteLine(Convert.ToBase64String(encoding.GetBytes(values)));
            }
            else
            {
                writer.WriteLine();
            }

            if (buf != null && buf.Length > 0) writer.WriteLine(Convert.ToBase64String(buf));
            else writer.WriteLine();
        }
        finally
        {
            if (writer != null)	writer.Close();
        }
    }