public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection collection)
        {
            var criticalSettings       = GetCriticalSettingsValues((Type)context["SettingsClassType"]);
            var standardSettingsValues = base.GetPropertyValues(context, collection);

            var mergedSettingsValues = new SettingsPropertyValueCollection();

            foreach (SettingsProperty property in collection)
            {
                // if a setting is defined in the critical settings file, that value always takes precedence over the local application settings value
                var key = property.Name;
                if (criticalSettings.ContainsKey(key))
                {
                    mergedSettingsValues.Add(new SettingsPropertyValue(property)
                    {
                        SerializedValue = criticalSettings[key]
                    });
                }
                else
                {
                    mergedSettingsValues.Add(standardSettingsValues[key]);
                }
            }
            return(mergedSettingsValues);
        }
예제 #2
0
        public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection collection)
        {
            try
            {
                var result = new SettingsPropertyValueCollection();

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

                // получаем из контекста имя пользователя - логин в системе
                var username = (string)context["UserName"];
                if (string.IsNullOrEmpty(username))
                {
                    result.Add(new SettingsPropertyValue(collection["ID"])
                    {
                        PropertyValue = 0
                    });
                    return(result);
                }
                var user = userService.GetUserByEmail(username) ?? userService.GetUserByLogin(username);
                int id   = user?.ID ?? 0;
                result.Add(new SettingsPropertyValue(collection["ID"])
                {
                    PropertyValue = id
                });
                return(result);
            }
            catch (Exception ex)
            {
                logger.Error(ex);
            }
            return(new SettingsPropertyValueCollection());
        }
        public override System.Configuration.SettingsPropertyValueCollection GetPropertyValues(System.Configuration.SettingsContext context, System.Configuration.SettingsPropertyCollection collection)
        {
            using (UsersContext db = new UsersContext())
            {
                SettingsPropertyValueCollection settings = new SettingsPropertyValueCollection();

                string      userName    = context["UserName"].ToString();
                UserProfile userProfile = db.UsersProfiles.Find(userName);

                if (userProfile == null)
                {
                    foreach (SettingsProperty profileProperty in collection)
                    {
                        SettingsPropertyValue value = new SettingsPropertyValue(collection[profileProperty.Name]);
                        value.PropertyValue = null;
                        settings.Add(value);
                    }
                }

                else

                {
                    foreach (SettingsProperty profileProperty in collection)
                    {
                        SettingsPropertyValue value = new SettingsPropertyValue(collection[profileProperty.Name]);
                        value.PropertyValue = userProfile.GetType().GetProperty(profileProperty.Name).GetValue(userProfile, null);
                        settings.Add(value);
                    }
                }

                return(settings);
            }
        }
예제 #4
0
        private SettingsPropertyValueCollection DefaultValues()
        {
            SettingsPropertyValueCollection values = new SettingsPropertyValueCollection();

            SettingsPropertyValue value;
            SettingsProperty      setting;

            setting = new SettingsProperty("StarLightInstallFolder");
            setting.DefaultValue = "C:\\Program Files\\StarLight\\";
            setting.PropertyType = "string".GetType();
            value = new SettingsPropertyValue(setting);
            values.Add(value);

            setting = new SettingsProperty("WeaveStrategiesFolder");
            setting.DefaultValue = "C:\\Program Files\\StarLight\\WeaveStrategies\\";
            setting.PropertyType = "string".GetType();
            value = new SettingsPropertyValue(setting);
            values.Add(value);

            setting = new SettingsProperty("JavaLocation");
            setting.DefaultValue = "";
            setting.PropertyType = "string".GetType();
            value = new SettingsPropertyValue(setting);
            values.Add(value);

            setting = new SettingsProperty("JavaOptions");
            setting.DefaultValue = "-Xmx512M";
            setting.PropertyType = "string".GetType();
            value = new SettingsPropertyValue(setting);
            values.Add(value);

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

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

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

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

            //var db = new UserService();
            // получаем id пользователя из таблицы Users по логину
            var firstOrDefault = UserService.GetUsers().FirstOrDefault(u => u.NickName.Equals(username));

            if (firstOrDefault != null)
            {
                int userId = firstOrDefault.Id;
                // по этому id извлекаем профиль из таблицы профилей
                ProfileDTO profile = ProfileService.GetProfiles().FirstOrDefault(u => u.UserId == userId);
                if (profile != null)
                {
                    foreach (SettingsProperty prop in collection)
                    {
                        var spv = new SettingsPropertyValue(prop)
                        {
                            PropertyValue = profile.GetType().GetProperty(prop.Name).GetValue(profile, null)
                        };
                        result.Add(spv);
                    }
                }
                else
                {
                    foreach (SettingsProperty prop in collection)
                    {
                        var svp = new SettingsPropertyValue(prop)
                        {
                            PropertyValue = null
                        };
                        result.Add(svp);
                    }
                }
            }
            return(result);
        }
        public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection collection)
        {
            // коллекция, которая возвращает значения свойств профиля
            var result = new SettingsPropertyValueCollection();

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

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

            if (string.IsNullOrEmpty(username))
            {
                return(result);
            }


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

            if (user != null)
            {
                var profile = profileService.GetProfileByUserId(user.Id);
                if (profile != null)
                {
                    foreach (SettingsProperty prop in collection)
                    {
                        var spv = new SettingsPropertyValue(prop)
                        {
                            PropertyValue = profile.GetType().GetProperty(prop.Name).GetValue(profile, null)
                        };
                        result.Add(spv);
                    }
                }
                else
                {
                    foreach (SettingsProperty prop in collection)
                    {
                        var svp = new SettingsPropertyValue(prop)
                        {
                            PropertyValue = null
                        };
                        result.Add(svp);
                    }
                }
            }
            return(result);
        }
        public void AddDuplicate()
        {
            SettingsPropertyValueCollection col = new SettingsPropertyValueCollection();
            SettingsProperty      test_prop     = new SettingsProperty("test_prop");
            SettingsPropertyValue val           = new SettingsPropertyValue(test_prop);

            col.Add(val);

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

            col.Add(val);

            Assert.AreEqual(1, col.Count, "A2");
        }
예제 #8
0
        public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection collection)
        {
            string userName        = (string)context["UserName"];
            bool   isAuthenticated = (bool)context["IsAuthenticated"];

            SettingsPropertyValueCollection spvc = new SettingsPropertyValueCollection();
            SettingsPropertyValue           spv  = null;

            foreach (SettingsProperty sp in collection)
            {
                spv = new SettingsPropertyValue(sp);
                switch (spv.Property.Name)
                {
                case shoppingCart:
                    spv.PropertyValue = GetShoppings(isAuthenticated, userName);
                    break;

                case accountInfo:
                    if (isAuthenticated)
                    {
                        spv.PropertyValue = GetAccountInfo(userName);
                    }
                    break;
                }
                spvc.Add(spv);
            }
            return(spvc);
        }
예제 #9
0
        private static SettingsPropertyValueCollection CreateSettingsCollectionFromPropertyCollection(
            SettingsPropertyCollection properties)
        {
            var propertyValues = new SettingsPropertyValueCollection();

            if (properties.Count > 0)
            {
                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;
                        }
                    }
                    propertyValues.Add(new SettingsPropertyValue(property));
                }
            }
            return(propertyValues);
        }
        public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext sc, SettingsPropertyCollection properties)
        {
            SettingsPropertyValueCollection values = new SettingsPropertyValueCollection();

            if (properties.Count == 0)
            {
                return(values);
            }

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

            if (string.IsNullOrEmpty(username))
            {
                return(values);
            }

            global::SoftFluent.Samples.GED.Security.User user = global::SoftFluent.Samples.GED.Security.User.LoadByUserName(username);

            foreach (SettingsProperty property in properties)
            {
                SettingsPropertyValue value = new SettingsPropertyValue(property);
                if (user != null)
                {
                    value.PropertyValue = ConvertUtilities.ChangeType(user.Properties[property.Name], property.PropertyType, property.DefaultValue);
                    value.Deserialized  = true;
                    value.IsDirty       = false;
                }
                values.Add(value);
            }
            return(values);
        }
        public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection collection)
        {
            var result = new SettingsPropertyValueCollection();

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

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

            if (string.IsNullOrEmpty(username))
            {
                return(result);
            }

            var profile = ProfileService.GetProfileByUserLogin(username);

            if (profile == null)
            {
                return(result);
            }
            foreach (var spv in from SettingsProperty prop in collection select new SettingsPropertyValue(prop)
            {
                PropertyValue = profile.GetType().GetProperty(prop.Name).GetValue(profile, null)
            })
            {
                result.Add(spv);
            }
            return(result);
        }
예제 #12
0
        public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection collection)
        {
            if (collection == null)
            {
                throw new ArgumentNullException("collection");
            }

            SettingsPropertyValueCollection values = new SettingsPropertyValueCollection();

            // Iterate through the settings to be retrieved
            foreach (SettingsProperty setting in collection)
            {
                SettingsPropertyValue value = new SettingsPropertyValue(setting);
                value.IsDirty = false;
                SettingElement element = section.Settings.Get(setting.Name);
                Trace.TraceInformation(string.Format("Retrieve for {0}.", setting.Name));
                if (element != null)
                {
                    value.PropertyValue = element.Value;
                    values.Add(value);
                }
            }

            return(values);
        }
예제 #13
0
        ////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////

        public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext sc, SettingsPropertyCollection properties)
        {
            SettingsPropertyValueCollection svc = new SettingsPropertyValueCollection();

            if (properties.Count < 1)
            {
                return(svc);
            }

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

            foreach (SettingsProperty prop in properties)
            {
                if (prop.SerializeAs == SettingsSerializeAs.ProviderSpecific)
                {
                    if (prop.PropertyType.IsPrimitive || prop.PropertyType == typeof(string))
                    {
                        prop.SerializeAs = SettingsSerializeAs.String;
                    }
                    else
                    {
                        prop.SerializeAs = SettingsSerializeAs.Xml;
                    }
                }
                svc.Add(new SettingsPropertyValue(prop));
            }

            if (!String.IsNullOrEmpty(username))
            {
                GetPropertyValuesFromDatabase(username, svc);
            }
            return(svc);
        }
예제 #14
0
        public void GivenConfirmedUsersWhenSetPropertyValuesWithValidColumnsThenSuccess(
            string providerName, string membershipProviderName)
        {
            // arrange
            var testClass   = this.WithProvider(providerName);
            var memProvider = this.WithMembershipProvider(membershipProviderName);
            var user        = memProvider.WithConfirmedUser().Value;
            var context     = new SettingsContext();

            context["UserName"] = user.UserName;
            var properties = new SettingsPropertyValueCollection();

            if (memProvider.AsBetter().HasEmailColumnDefined)
            {
                var emailProperty = new SettingsProperty(memProvider.AsBetter().UserEmailColumn)
                {
                    PropertyType =
                        typeof(string)
                };
                properties.Add(
                    new SettingsPropertyValue(emailProperty)
                {
                    PropertyValue = user.Email, Deserialized = true
                });
            }

            // act // assert
            Assert.DoesNotThrow(() => testClass.SetPropertyValues(context, properties));
        }
예제 #15
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);
        }
예제 #16
0
        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);
            }

            DataTable dt = new DataTable();

            using (SqlConnection cn = OpenConnection())
            {
                SqlCommand cmd = new SqlCommand(this.ExpandCommand(SQL_GetPropertyValues), cn);
                cmd.Parameters.Add("@UserName", SqlDbType.VarChar, CustomMembershipProvider.UserNameSize).Value = username;
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                da.Fill(dt);
                da.Dispose();
            }

            foreach (SettingsProperty property in collection)
            {
                SettingsPropertyValue value = new SettingsPropertyValue(property);
                if (dt.Rows.Count == 0)
                {
                    if (!(value.Property.DefaultValue == null ||
                          (value.Property.DefaultValue is string && String.IsNullOrEmpty((string)value.Property.DefaultValue))))
                    {
                        value.PropertyValue = Convert.ChangeType(value.Property.DefaultValue, value.Property.PropertyType);
                    }

                    value.IsDirty      = false;
                    value.Deserialized = true;
                }
                else
                {
                    string columnName = GetPropertyMapInfo(property).ColumnName; if (dt.Columns.IndexOf(columnName) == -1)
                    {
                        throw new ProviderException(String.Format("Column '{0}' required for property '{1}' was not found in table '{2}'.", columnName, property.Name, this.TableName));
                    }
                    object columnValue = dt.Rows[0][columnName];

                    if (!(columnValue is DBNull || columnValue == null))
                    {
                        value.PropertyValue = columnValue;
                        value.IsDirty       = false;
                        value.Deserialized  = true;
                    }
                }
                svc.Add(value);
            }

            return(svc);
        }
예제 #17
0
        public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection collection)
        {
            var       result      = new SettingsPropertyValueCollection();
            Hashtable hashRoaming = null;
            Hashtable hashLocal   = null;

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

                Hashtable hash;
                if (IsRoaming(property))
                {
                    hash = hashRoaming ?? (hashRoaming = ReadData(FileName(context, RoamingFileName, false)));
                }
                else
                {
                    hash = hashLocal ?? (hashLocal = ReadData(FileName(context, LocalFileName, false)));
                }

                var serialized = hash[property.Name];
                if (serialized != null)
                {
                    value.SerializedValue = serialized;
                }
            }

            return(result);
        }
        /// <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);
        }
예제 #19
0
        public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection collection)
        {
            // Create new collection of values
            var values = new SettingsPropertyValueCollection();

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

                try
                {
                    var text = File.ReadAllText(Path.Combine(Dir, $"{setting.Name}.json"));

                    value = JsonConvert.DeserializeObject(text, setting.PropertyType);
                }
                catch { }

                values.Add(new SettingsPropertyValue(setting)
                {
                    IsDirty       = false,
                    PropertyValue = value,
                });
            }
            return(values);
        }
예제 #20
0
        /* Addresses are part of the account and not part of the profile
         * void PopulateAddessesFromDatabase(Guid customerId, SettingsPropertyValueCollection props)
         * {
         *  CustomerAddressCollection addresses = ProfileContext.Current.GetCustomerAddresses(customerId);
         *  SettingsPropertyValue propValue = props["Addresses"];
         *  if (propValue != null)
         *  {
         *      propValue.Property.IsReadOnly = true;
         *      propValue.Deserialized = true;
         *      propValue.PropertyValue = addresses;
         *
         *      // Following two parameters will prevent the default SqlProfileProvider from saving the property into the database
         *      propValue.IsDirty = false;
         *      //propValue.UsingDefaultValue = false;
         *  }
         * }
         * */

        /// <summary>
        /// Updates the SQL Server profile database with the specified property values.
        /// </summary>
        /// <param name="sc">The <see cref="T:System.Configuration.SettingsContext"></see> that contains user profile information.</param>
        /// <param name="properties">A <see cref="T:System.Configuration.SettingsPropertyValueCollection"></see> containing profile information and values for the properties to be updated.</param>
        public override void SetPropertyValues(SettingsContext sc, SettingsPropertyValueCollection properties)
        {
            SettingsPropertyValue propValue = properties["Account"];

            if (propValue != null && propValue.IsDirty)
            {
                // Sasha: do we need to save the account info here?
                // it seems to cause account creationg when user is anonymous
                // so i will remove the following 3 lines for now

                /*
                 * Account account = (Account)propValue.PropertyValue;
                 * if (account!=null)
                 *  account.AcceptChanges();
                 * */

                // Following two parameters will prevent the default SqlProfileProvider from saving the property into the database
                propValue.IsDirty = false;
            }

            // Remove node so we dont have to save it
            properties.Remove(propValue.Name);

            // save using default provider
            base.SetPropertyValues(sc, properties);

            // Add property back
            properties.Add(propValue);
        }
        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();
        }
예제 #22
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);
        }
예제 #23
0
        ////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////
        // customProviderData = "Varname;SqlDbType;size"
        private void GetProfileDataFromSproc(SettingsPropertyCollection properties, SettingsPropertyValueCollection svc, string username, SqlConnection conn, bool userIsAuthenticated)
        {
            SqlCommand cmd = CreateSprocSqlCommand(_readSproc, conn, username, userIsAuthenticated);

            try {
                cmd.Parameters.RemoveAt("@IsUserAnonymous"); //anonymous flag not needed on get

                List <ProfileColumnData> columnData = new List <ProfileColumnData>(properties.Count);
                foreach (SettingsProperty prop in properties)
                {
                    SettingsPropertyValue value = new SettingsPropertyValue(prop);
                    svc.Add(value);

                    string persistenceData = prop.Attributes["CustomProviderData"] as string;
                    // If we can't find the table/column info we will ignore this data
                    if (String.IsNullOrEmpty(persistenceData))
                    {
                        // REVIEW: Perhaps we should throw instead?
                        continue;
                    }
                    string[] chunk = persistenceData.Split(new char[] { ';' });
                    if (chunk.Length != 3)
                    {
                        // REVIEW: Perhaps we should throw instead?
                        continue;
                    }
                    string varname = chunk[0];
                    // REVIEW: Should we ignore case?
                    SqlDbType datatype = (SqlDbType)Enum.Parse(typeof(SqlDbType), chunk[1], true);

                    int size = 0;
                    if (!Int32.TryParse(chunk[2], out size))
                    {
                        throw new ArgumentException("Unable to parse as integer: " + chunk[2]);
                    }

                    columnData.Add(new ProfileColumnData(varname, value, null /* not needed for get */, datatype));
                    cmd.Parameters.Add(CreateOutputParam(varname, datatype, size));
                }

                cmd.ExecuteNonQuery();
                for (int i = 0; i < columnData.Count; ++i)
                {
                    ProfileColumnData     colData   = columnData[i];
                    object                val       = cmd.Parameters[colData.VariableName].Value;
                    SettingsPropertyValue propValue = colData.PropertyValue;

                    //Only initialize a SettingsPropertyValue for non-null values
                    if (!(val is DBNull || val == null))
                    {
                        propValue.PropertyValue = val;
                        propValue.IsDirty       = false;
                        propValue.Deserialized  = true;
                    }
                }
            }
            finally {
                cmd.Dispose();
            }
        }
예제 #24
0
        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;

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

                svc.Add(pv);
            }
            return(svc);
        }
예제 #25
0
        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;
                try
                {
                    using (RegistryKey key = GetRegKey(setting, false))
                    {
                        if (key != null)
                        {
                            value.SerializedValue = key.GetValue(setting.Name);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(string.Format("Error in GetPropertyValues: {0}\n{1}", ex.Message, ex.StackTrace));
                }
                values.Add(value);
            }
            return(values);
        }
예제 #26
0
        public void AnonymousUserSettingNonAnonymousProperties()
        {
            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"] = false;
            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(0, dt.Rows.Count);
            dt = FillTable("SELECT * FROM my_aspnet_Users");
            Assert.AreEqual(0, dt.Rows.Count);
            dt = FillTable("SELECT * FROM my_aspnet_Profiles");
            Assert.AreEqual(0, dt.Rows.Count);
        }
        public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection collection)
        {
            string userName = (string)context["UserName"];

            var propertyValues = collection.Cast <SettingsProperty>()
                                 .Select(p => new SettingsPropertyValue(p))
                                 .ToArray();

            if (repository.ContainsKey(userName))
            {
                var userProperties = repository[userName];

                foreach (var pv in propertyValues)
                {
                    pv.PropertyValue = userProperties[pv.Name];
                }
            }

            var result = new SettingsPropertyValueCollection();

            foreach (var pv in propertyValues)
            {
                result.Add(pv);
            }

            return(result);
        }
예제 #28
0
        /// <summary>
        /// Returns the collection of settings property values for the current umbraco member.
        /// </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>
        public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection collection)
        {
            SettingsPropertyValueCollection settings = new SettingsPropertyValueCollection();

            if (collection.Count == 0)
            {
                return(settings);
            }

            foreach (SettingsProperty property in collection)
            {
                SettingsPropertyValue pv = new SettingsPropertyValue(property);
                settings.Add(pv);
            }

            // get the current user
            string username = (string)context["UserName"];
            Member m        = Member.GetMemberFromLoginName(username);

            if (m == null)
            {
                throw new ProviderException(String.Format("No member with username '{0}' exists", username));
            }

            foreach (SettingsPropertyValue spv in settings)
            {
                if (m.getProperty(spv.Name) != null)
                {
                    spv.Deserialized  = true;
                    spv.PropertyValue = m.getProperty(spv.Name).Value;
                }
            }

            return(settings);
        }
예제 #29
0
        //------------------------------------------------------------------
        //BuildPropertyValueCollection
        //------------------------------------------------------------------
        public static SettingsPropertyValueCollection BuildPropertyValueCollection(ProfieProperityCollection propCollection)
        {
            SettingsPropertyValueCollection propertyValueCollection = new SettingsPropertyValueCollection();
            SettingsProperty      p;
            SettingsPropertyValue p_Value;

            foreach (ProfieProperity prop in propCollection.Properities)
            {
                //------------------------------------
                p = new SettingsProperty(prop.PropName);
                p.PropertyType = prop.PropType;
                p.DefaultValue = prop.PropDefaultValue;
                //------------------------------------------------------------
                //For retriving
                //if (p.SerializeAs == SettingsSerializeAs.ProviderSpecific)
                //{
                //    if (p.PropertyType.IsPrimitive || (p.PropertyType == typeof(string)))
                //        p.SerializeAs = SettingsSerializeAs.String;
                //    else
                //        p.SerializeAs = SettingsSerializeAs.Xml;
                //}
                //-------------------------------------------------------------
                //Value
                p_Value = new SettingsPropertyValue(p);
                //p_Value.PropertyValue = txtName.Text;
                propertyValueCollection.Add(p_Value);
                //------------------------------------
            }
            return(propertyValueCollection);
        }
예제 #30
0
        public void SetPropertyValues_SetSettingsPropertyValue_SameValueIsSavedForUser()
        {
            var userRepository = A.Fake <IUserRepository>();
            var originalUser   = A.Fake <IUser>();
            var clonedUser     = A.Fake <IUser>();

            A.CallTo(() => userRepository.GetUserByUserName("username", null)).Returns(originalUser);
            A.CallTo(() => originalUser.IsReadOnly).Returns(true);
            A.CallTo(() => originalUser.CreateWritable()).Returns(clonedUser);
            var genericproperty = new Property <string>("propertyName", null, CultureInfo.InvariantCulture);

            A.CallTo(() => clonedUser.Properties.GetProperty("propertyName", Context.DefaultContext)).Returns(genericproperty);
            var profileProvider     = GetProfileProvider(userRepository);
            var settings            = new SettingsPropertyValueCollection();
            var settingProperyValue = GetSettingProperyValue("propertyName", "propertyValue");

            settings.Add(settingProperyValue);

            var context = GetContext("username");

            profileProvider.SetPropertyValues(context, settings);

            Assert.AreEqual("propertyValue", genericproperty.Value);
            A.CallTo(() => userRepository.SaveUser(clonedUser)).MustHaveHappened(Repeated.Exactly.Once);
        }
    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;
    }
예제 #33
0
파일: ProfileReader.cs 프로젝트: pcstx/OA
        /// <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 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;
    }
    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;
    }
예제 #36
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;
    }
예제 #38
0
    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(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);
    }
예제 #40
0
    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 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;
    }