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;
    }
Ejemplo n.º 4
0
        private void Upgrade(SettingsContext context, SettingsPropertyCollection properties, string user)
        {
            Type   settingsClass = (Type)context["SettingsClassType"];
            string settingsKey   = (string)context["SettingsKey"];
            bool   isUserUpgrade = !String.IsNullOrEmpty(user);

            SettingsGroupDescriptor     group          = new SettingsGroupDescriptor(settingsClass);
            Dictionary <string, string> previousValues = GetPreviousSettingsValues(group, user, settingsKey);
            bool oldValuesExist = previousValues != null && previousValues.Count > 0;

            if (!oldValuesExist)
            {
                return; //nothing to migrate.
            }
            var upgradedValues = new SettingsPropertyValueCollection();

            foreach (SettingsProperty property in properties)
            {
                if (isUserUpgrade && !IsUserScoped(property))
                {
                    continue;
                }

                string oldValue;
                if (!previousValues.TryGetValue(property.Name, out oldValue))
                {
                    continue;
                }

                //Unconditionally save every old value; let the store sort out what to do.
                upgradedValues.Add(new SettingsPropertyValue(property)
                {
                    SerializedValue = oldValue, IsDirty = true
                });
            }

            if (upgradedValues.Count > 0)
            {
                SetPropertyValues(context, upgradedValues, user);
            }
        }
Ejemplo n.º 5
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 (string.IsNullOrWhiteSpace(username))
            {
                return(settingsPropertyValueCollection);
            }

            IMongoQuery query        = Query.And(Query.EQ("ApplicationName", ApplicationName), Query.EQ("Username", username));
            var         bsonDocument = _mongoCollection.FindOneAs <BsonDocument>(query);

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

                object value = BsonTypeMapper.MapToDotNetValue(bsonDocument[settingsPropertyValue.Name]);

                if (value != null)
                {
                    settingsPropertyValue.PropertyValue = value;
                    settingsPropertyValue.IsDirty       = false;
                    settingsPropertyValue.Deserialized  = true;
                }
            }

            UpdateBuilder update = Update.Set("LastActivityDate", DateTime.Now);

            _mongoCollection.Update(query, update);

            return(settingsPropertyValueCollection);
        }
        /// <summary>
        /// </summary>
        /// <param name="context"></param>
        /// <param name="collection"></param>
        /// <returns></returns>
        public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context,
                                                                          SettingsPropertyCollection collection)
        {
            // Create a collection of values to return
            var retValues = new SettingsPropertyValueCollection();

            // Create a temporary SettingsPropertyValue to reuse

            // Loop through the list of settings that the application has requested and add them to
            // our collection of return values.
            foreach (var value in from SettingsProperty property in collection
                     select new SettingsPropertyValue(property)
            {
                IsDirty = false,
                SerializedValue = GetSetting(property)
            })
            {
                retValues.Add(value);
            }
            return(retValues);
        }
		{ } // private constructor


        /// <summary>
        /// The sole public constructor accepts the parameters required to fully
        /// initialize the object.
        /// </summary>
        /// <param name="psettingsPropertyValueCollection">
        /// Pass a reference to a System.Configuration.SettingsPropertyCollection
        /// collection from which to obtain default values.
        /// </param>
        /// <param name="pstrInternalName">
        /// The InternalName is a string that is used to identify the parameter.
        /// The OperatingParametersCollection enforces unique values.
        /// </param>
        /// <param name="pstrDisplayName">
        /// Display name is technically optional, since it defaults to the
        /// internal name if this parameter is a null reference or the empty
        /// string.
        /// 
        /// If the parameter contains substring DISPLAY_NAME_SUBSTITUTION_TOKEN,
        /// treat it as the format string from which to construct the name of a
        /// string resource in the calling assembly that is the actual display
        /// name. The format string is constructed by calling string.Format to
        /// substitute the value of the InternalName property for substring
        /// DISPLAY_NAME_SUBSTITUTION_TOKEN, which is a valid format item token.
        /// 
        /// If the calling assembly contains no like named string, fall back to
        /// InternalName, the default value.
        /// </param>
        /// <param name="penmParameterType">
        /// The parameter type must be a valid member of the enumeration mapped
        /// to the T generic type placeholder.
        /// </param>
        /// <param name="penmDefaultParameterSource">
        /// The parameter type must be a valid member of the enumeration mapped
        /// to the U generic type placeholder.
        /// </param>
        public OperatingParameterBase (
			SettingsPropertyCollection psettingsPropertyValueCollection ,
			string pstrInternalName ,
			string pstrDisplayName ,
			T penmParameterType ,
			U penmDefaultParameterSource )
		{
            if ( string.IsNullOrEmpty ( pstrInternalName ) )
                throw new ArgumentNullException ( nameof ( pstrInternalName ) );

			_strInternalName = pstrInternalName;
			_strDisplayName = string.IsNullOrEmpty ( pstrDisplayName ) 
				? pstrInternalName
				: pstrDisplayName;

            lock ( s_syncRoot )
            {   // Make it thread-safe.
                if ( s_settingsForEntryAssembly == null )
                {   // Set it once only.
                    if ( psettingsPropertyValueCollection != null )
                    {   // Do nothing if the input parameter is null.
                        s_settingsForEntryAssembly = AppSettingsForEntryAssembly.GetTheSingleInstance ( psettingsPropertyValueCollection );
                    }   // TRUE (anticipated outcome) block, if ( psettingsPropertyValueCollection != null )
                    else
                    {
                        throw new ArgumentNullException ( );
                    }   // FALSE (unanticipated outcome) block, if ( psettingsPropertyValueCollection != null )
                }   // if ( s_settingsPropertyValueCollection == null )

                ParseDisplayName ( );
                _enmParameterType = penmParameterType;

                if ( CheckForDefaultValueInAppSettings ( _strInternalName , ref _strValue ) )
                {   // Store the default value, flip the associated switch, identify the source, and flag the parameter as initialized.
                    _fHasDefaultValueInAppSettings = true;
                    _enmParameterSource = penmDefaultParameterSource;
                    _enmState = ParameterState.Initialized;
                }   // TRUE (The application cofiguration defines a default value.) block, if ( CheckForDefaultValueInAppSettings ( _stInternalName , ref _strValue ) )
            }   // lock ( s_syncRoot )
        }   // Public OperatingParameterBase constructor
Ejemplo n.º 8
0
        public void GivenConfirmedUsersWhenGetPropertyValuesWithValidColumnsThenPropertyReturnedSuccessfully(
            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 SettingsPropertyCollection();

            if (memProvider.AsBetter().HasEmailColumnDefined)
            {
                properties.Add(
                    new SettingsProperty(memProvider.AsBetter().UserEmailColumn)
                {
                    PropertyType = typeof(string)
                });
            }

            properties.Add(new SettingsProperty(memProvider.AsBetter().UserIdColumn)
            {
                PropertyType = typeof(int)
            });

            // act
            var profile = testClass.GetPropertyValues(context, properties);

            // assert
            Assert.That(profile, Is.Not.Null);
            Assert.That(profile[memProvider.AsBetter().UserIdColumn], Is.Not.Null);
            Assert.That(profile[memProvider.AsBetter().UserIdColumn].PropertyValue, Is.GreaterThan(0));
            Assert.That(profile[memProvider.AsBetter().UserIdColumn].IsDirty, Is.False);
            if (memProvider.AsBetter().HasEmailColumnDefined)
            {
                Assert.That(profile[memProvider.AsBetter().UserEmailColumn].PropertyValue, Is.EqualTo(user.Email));
                Assert.That(profile[memProvider.AsBetter().UserEmailColumn].IsDirty, Is.False);
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Adds default properties to the settings storage of <paramref name="settingsStorageType"/> type.
        /// Properties are taken from the type definition. Only those are taken which are decorated with
        /// <see cref="DefaultSettingValueAttribute"/> attribute (i.e. have default values)
        /// </summary>
        /// <param name="settingsStorageType">Type of the settings storage to take properties from</param>
        /// <param name="propertyCollection">Collection to add instances of <see cref="SettingsProperty"/> to</param>
        /// <param name="propertyValueCollection">Collection to add corresponding instances of <see cref="SettingsPropertyValue"/> to</param>
        public static void AddDefaultProperties(
            Type settingsStorageType,
            SettingsPropertyCollection propertyCollection,
            SettingsPropertyValueCollection propertyValueCollection)
        {
            IEnumerable <PropertyInfo> settingProperties = GetPropertiesWithAttribute(settingsStorageType, typeof(DefaultSettingValueAttribute));

            foreach (PropertyInfo settingProperty in settingProperties)
            {
                DefaultSettingValueAttribute defaultValueAttribute = settingProperty.GetCustomAttributes(typeof(DefaultSettingValueAttribute), false)[0]
                                                                     as DefaultSettingValueAttribute;
                if (defaultValueAttribute != null)
                {
                    SettingsProperty setting = BuildSettingsProperty(
                        settingProperty.Name, defaultValueAttribute.Value, settingProperty.PropertyType, settingProperty.GetCustomAttributes(true));
                    SettingsPropertyValue settingValue = BuildSettingsPropertyValue(setting);

                    propertyCollection.Add(setting);
                    propertyValueCollection.Add(settingValue);
                }
            }
        }
        public void Upgrade(SettingsContext context, SettingsPropertyCollection properties)
        {
            Version previousVersion = GetPreviousVersionNumber();

            if (previousVersion != null)
            {
                Reset(context);

                XmlDocument previousSettingsDoc = GetVersionedSettingsDocument(previousVersion);
                if (previousSettingsDoc != null)
                {
                    foreach (SettingsProperty property in properties)
                    {
                        SettingsPropertyValue oldValue = GetPropertyValue(previousSettingsDoc, property);
                        if (oldValue.PropertyValue != null)
                        {
                            SetPropertyValue(CurrentSettingsDocument, oldValue);
                        }
                    }
                }
            }
        }
Ejemplo n.º 11
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Reads <paramref name="values"/> properties from the config file in
        /// <paramref name="configMap"/>. Which config file to read is specified in
        /// <paramref name="userLevel"/>.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private static bool ReadProperties(SettingsContext context,
                                           SettingsPropertyCollection properties, ExeConfigurationFileMap configMap,
                                           ConfigurationUserLevel userLevel, SettingsPropertyValueCollection values)
        {
            var isReadingAppConfig     = (userLevel == ConfigurationUserLevel.None);
            var isReadingRoamingConfig = (userLevel == ConfigurationUserLevel.PerUserRoaming);
            var config         = ConfigurationManager.OpenMappedExeConfiguration(configMap, userLevel);
            var groupName      = (string)context["GroupName"];
            var configSettings = GetSection(config, groupName,
                                            isReadingAppConfig ? "applicationSettings" : "userSettings");

            // Create new collection of values
            foreach (SettingsProperty setting in properties)
            {
                var value = values[setting.Name];
                if (value == null)
                {
                    values.Add(new SettingsPropertyValue(setting));
                    value = values[setting.Name];
                    //value.IsDirty = true;
                    //value.SerializedValue = setting.DefaultValue;
                }

                if (IsUserScoped(setting) && isReadingRoamingConfig && !IsRoaming(setting) ||
                    !isReadingAppConfig && IsApplicationScoped(setting))
                {
                    continue;
                }

                var elem = configSettings.Settings.Get(setting.Name);
                if (elem != null)
                {
                    SetProperty(value, elem);
                }
            }

            return(config.HasFile);
        }
Ejemplo n.º 12
0
        public void ExceptionalGetPropertyValues()
        {
            SettingsPropertyCollection props = new SettingsPropertyCollection();
            SettingsProviderCollection provs = new SettingsProviderCollection();

            MyProvider3 p = new MyProvider3();
            MySettings  s = new MySettings();

            props.Add(new SettingsProperty("Foo", typeof(string), p, false, 10, SettingsSerializeAs.String, null, true, true));
            provs.Add(p);

            s.Initialize(new SettingsContext(), props, provs);
            Assert.AreEqual(0, s.Context.Count, "#0");
            try {
                Assert.AreEqual(100, s.Foo, "#1");
                Assert.Fail("#2");
#if !TARGET_JVM
            } catch (Win32Exception) {
#else
            } catch (CustomerException) {
#endif
            }
        }
        /// <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);
        }
            public void SerializesAndDeserializes()
            {
                // Arrange
                var provider = new ServiceSettingsProvider();

                provider.GetSettingsWriter = () => sw;
                var context = new SettingsContext();
                var values  = new SettingsPropertyValueCollection();

                var property = SettingsUtil.CreateProperty <EncryptedSecret>("myProp");

                property.SerializeAs = SettingsSerializeAs.Xml;
                var value           = new SettingsPropertyValue(property);
                var encryptedSecret = new EncryptedSecret("mySecret", 1000);

                value.PropertyValue = encryptedSecret;
                values.Add(value);

                // Act
                provider.SetPropertyValues(context, values);

                // Arrange
                provider.GetSettingsReader = () => new StringReader(sw.ToString());
                var properties = new SettingsPropertyCollection();

                properties.Add(property);

                // Act
                var values2 = provider.GetPropertyValues(context, properties);
                var myProp  = values2["myProp"].PropertyValue;

                // Assert
                Assert.IsAssignableFrom <EncryptedSecret>(myProp);
                var encryptedSecret2 = (EncryptedSecret)myProp;

                Assert.Equal("mySecret", encryptedSecret2.Decrypt());
            }
Ejemplo n.º 15
0
        // Will be called when MySettingsClass.Upgrade() is called
        // This method's job is to update the location where the settings are stored
        // with the previous version's values. GetPropertyValues, overriden from the
        // SettingsProvider base, will be called to retrieve the new values from the
        // storage location
        public void Upgrade(SettingsContext context, SettingsPropertyCollection properties)
        {
            // If there's no previous version, do nothing (just like the LFSP)
            string previousVersion = GetPreviousVersionNumber();

            if (string.IsNullOrEmpty(previousVersion))
            {
                return;
            }

            // Delete the current setting values
            Reset(context);

            // Copy the old settings to the new version
            string currentVersion = GetCurrentVersionNumber();

            using (
                RegistryKey keyPrevious =
                    Registry.CurrentUser.OpenSubKey(GetSubKeyPath(previousVersion), false))
            {
                using (
                    RegistryKey keyCurrent =
                        Registry.CurrentUser.CreateSubKey(GetSubKeyPath(currentVersion),
                                                          RegistryKeyPermissionCheck.
                                                          ReadWriteSubTree))
                {
                    foreach (string valueName in keyPrevious.GetValueNames())
                    {
                        object serializedValue = keyPrevious.GetValue(valueName);
                        if (serializedValue != null)
                        {
                            keyCurrent.SetValue(valueName, serializedValue);
                        }
                    }
                }
            }
        }
Ejemplo n.º 16
0
        public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection propertyCollection)
        {
            if (propertyCollection == null || propertyCollection.Count < 1)
            {
                return(new SettingsPropertyValueCollection());
            }
            lock (_lock) {
                if (_SettingsBaseClass == null && context != null)
                {
                    Type oType = context["SettingsClassType"] as Type;
                    if (oType != null)
                    {
                        _SettingsBaseClass = oType.InvokeMember("Default", BindingFlags.GetProperty | BindingFlags.Public | BindingFlags.Static,
                                                                null, null, null, CultureInfo.InvariantCulture) as ApplicationSettingsBase;
                    }
                }
                _PropertyValues = new SettingsPropertyValueCollection();
                _Properties     = propertyCollection;

                StoreKnownTypes(propertyCollection);
                GetPropertyValuesCore();
                return(_PropertyValues);
            }
        }
Ejemplo n.º 17
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);
        }
Ejemplo n.º 18
0
        public void Upgrade(SettingsContext context, SettingsPropertyCollection properties)
        {
            foreach (SettingsProperty property in properties)
            {
                if (!SettingsPropertyExtensions.IsUserScoped(property))
                {
                    continue;
                }

                SettingsPropertyValue previousValue = SimpleSettingsStore.Instance.PreviousUserValues[property.Name];
                if (previousValue == null)
                {
                    continue;
                }

                SettingsPropertyValue currentValue = SimpleSettingsStore.Instance.CurrentUserValues[property.Name];
                if (currentValue == null)
                {
                    continue;
                }

                currentValue.PropertyValue = previousValue.PropertyValue;
            }
        }
Ejemplo n.º 19
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);
        }
Ejemplo n.º 20
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);
        }
Ejemplo n.º 21
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);
        }
Ejemplo n.º 22
0
        public TransportSettingsPropertyValueCollection GetPropertyValues(string applicationName, TransportSettingsContext context, TransportSettingsPropertyCollection collection)
        {
            _Provider.ApplicationName = _ApplicationName;

            var settingscontext = new SettingsContext {
                { "UserName", context.Username }, { "IsAuthenticated", context.IsAuthenticated }
            };

            var settingspropertycollection = new SettingsPropertyCollection();

            foreach (TransportSettingsProperty settingsproperty in collection)
            {
                settingspropertycollection.Add(ConvertSettingsProperty(settingsproperty));
            }

            var returncollection = new TransportSettingsPropertyValueCollection();

            foreach (SettingsPropertyValue settingspropertyvalue in _Provider.GetPropertyValues(settingscontext, settingspropertycollection))
            {
                returncollection.Add(ConvertSettingsPropertyValue(settingspropertyvalue));
            }

            return(returncollection);
        }
        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);
        }
Ejemplo n.º 24
0
 public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection collection)
 {
     IProfile dal = Snitz.Membership.Helpers.Factory<IProfile>.Create("Profile");
         dal.TableName = _table;
         SettingsPropertyValueCollection vc =  dal.GetPropertyValues(context, collection);
         return vc;
 }
Ejemplo n.º 25
0
Archivo: Profile.cs Proyecto: pcstx/OA
 public Profile()
 {
     state = ProfileState.Anonymous;
     defualtProfileSettings = ProfileBase.Properties;
 }
    // Will be called when MySettingsClass.Upgrade() is called
    // This method's job is to update the location where the settings are stored
    // with the previous version's values. GetPropertyValues, overriden from the
    // SettingsProvider base, will be called to retrieve the new values from the
    // storage location
    public void Upgrade(SettingsContext context, SettingsPropertyCollection properties)
    {
        // If there's no previous version, do nothing (just like the LFSP)
        string previousVersion = GetPreviousVersionNumber();
        if (string.IsNullOrEmpty(previousVersion)) { return; }

        // Delete the current setting values
        Reset(context);

        // Copy the old settings to the new version
        string currentVersion = GetCurrentVersionNumber();
        using (RegistryKey keyPrevious = Registry.LocalMachine.OpenSubKey(GetSubKeyPath(previousVersion), false))
        using (RegistryKey keyCurrent = Registry.LocalMachine.CreateSubKey(GetSubKeyPath(currentVersion), RegistryKeyPermissionCheck.ReadWriteSubTree))
        {
            foreach (string valueName in keyPrevious.GetValueNames())
            {
                object serializedValue = keyPrevious.GetValue(valueName);
                if (serializedValue != null) { keyCurrent.SetValue(valueName, serializedValue); }
            }
        }
    }
Ejemplo n.º 27
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;
    }
Ejemplo n.º 28
0
        /// <summary>
        /// Retrieves profile property information and values from a SQL Server profile database.
        /// </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.SettingsPropertyCollection"></see> containing profile information for the properties to be retrieved.</param>
        /// <returns>
        /// A <see cref="T:System.Configuration.SettingsPropertyValueCollection"></see> containing profile property information and values.
        /// </returns>
        public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext sc, SettingsPropertyCollection properties)
        {
            SettingsPropertyValueCollection props = base.GetPropertyValues(sc, properties);

            // Retrieve the data from the Database
            string userName = (string)sc["UserName"];

            if (!String.IsNullOrEmpty(userName))
            {
                MembershipUser user = Membership.GetUser(userName);
                if (user != null)
                {
                    PopulateAccountFromDatabase(new Guid(user.ProviderUserKey.ToString()), props);
                }
            }

            if (props["PageSettings"] != null)
            {
                props["PageSettings"].Property.SerializeAs = SettingsSerializeAs.Binary;
            }

            return(props);
        }
Ejemplo n.º 29
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);
        }
Ejemplo n.º 30
0
        public SettingsPropertyValueCollection GetPropertyValues(string currentUser, SettingsContext context, SettingsPropertyCollection collection, out int errorNumber, out string errorDescription)
        {
            errorNumber      = 0;
            errorDescription = string.Empty;


            SettingsPropertyValueCollection settings = new SettingsPropertyValueCollection();

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

            foreach (SettingsProperty property in collection)
            {
                if (property.SerializeAs == SettingsSerializeAs.ProviderSpecific)
                {
                    if (property.PropertyType.IsPrimitive || property.PropertyType == typeof(System.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 ~/App_Data/Profile_Data

            //' Load the profile
            if (!string.IsNullOrEmpty(username))
            {
                string[] names;
                string   values;
                byte[]   buf;

                string databaseNames;
                string databaseValues;


                DataTable table = base.ExecuteFill(CommandType.StoredProcedure, "Framework_ProfileGetProperties",
                                                   true, currentUser,
                                                   base.Parameters.Create("@ReturnValue", DbType.Int32, ParameterDirection.ReturnValue, null),
                                                   base.Parameters.Create("@ApplicationName", DbType.String, _applicationName),
                                                   base.Parameters.Create("@UserName", DbType.String, username));


                errorNumber      = base.ExecutionStatus.ErrorNumber;
                errorDescription = base.ExecutionStatus.ErrorDescription;

                if (errorNumber > 0 || !string.IsNullOrEmpty(errorDescription))
                {
                    return(settings);
                }


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

                databaseNames  = Convert.ToString(table.Rows[0]["PropertyNames"]);
                databaseValues = Convert.ToString(table.Rows[0]["PropertyValuesString"]);
                buf            = (byte[])table.Rows[0]["PropertyValuesBinary"];

                names  = databaseNames.Split(':');
                values = databaseValues;


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

            return(settings);
        }
    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 void Initialize(SettingsContext context, SettingsPropertyCollection properties, SettingsProviderCollection providers) {}
	public virtual void Upgrade(SettingsContext context, SettingsPropertyCollection properties) {}
Ejemplo n.º 34
0
        public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection collection)
        {
            // коллекция, которая возвращает значения свойств профиля
            SettingsPropertyValueCollection result = new SettingsPropertyValueCollection();

            if (collection == null || collection.Count < 1 || context == null)
            {
                return(result);
            }
            // получаем из контекста имя пользователя - логин в системе
            string username = (string)context["UserName"];

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

            UserContext db = new UserContext();
            // получаем id пользователя из таблицы Users по логину
            int userId = db.Users.Where(u => u.Email.Equals(username)).FirstOrDefault().Id;
            // по этому id извлекаем профиль из таблицы профилей
            Profile profile = db.Profiles.Where(u => u.UserId == userId).FirstOrDefault();

            if (profile != null)
            {
                foreach (SettingsProperty prop in collection)
                {
                    SettingsPropertyValue svp = new SettingsPropertyValue(prop);
                    svp.PropertyValue = profile.GetType().GetProperty(prop.Name).GetValue(profile, null);
                    result.Add(svp);
                }
            }
            else
            {
                foreach (SettingsProperty prop in collection)
                {
                    SettingsPropertyValue svp = new SettingsPropertyValue(prop);
                    svp.PropertyValue = null;
                    result.Add(svp);
                }
            }
            return(result);
        }
Ejemplo n.º 35
0
        public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection collection)
        {
            SettingsPropertyValueCollection values = new SettingsPropertyValueCollection();

            foreach (SettingsProperty property in collection)
            {
                SettingsPropertyValue value2 = new SettingsPropertyValue(property)
                {
                    SerializedValue = this.ORQDXIXSVMHEUQKWSBBRZO(property)
                };
                values.Add(value2);
            }
            return(values);
        }
Ejemplo n.º 36
0
        public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection collection)
        {
            lock (_Lock)
            {
                SettingsPropertyValueCollection valueCollection = new SettingsPropertyValueCollection();

                XmlDocument doc = new XmlDocument();
                if (File.Exists(Filename))
                {
                    try
                    {
                        doc.LoadXml(File.ReadAllText(Filename));
                    }
                    catch (XmlException)
                    {
                        doc = new XmlDocument();
                    }
                    catch (IOException)
                    {
                        doc = new XmlDocument();
                    }
                }
                else
                {
                    // Create the directory and the file.
                    try
                    {
                        Directory.CreateDirectory(Path.GetDirectoryName(Filename));
                        File.Create(Filename).Close();
                    }
                    catch (IOException)
                    {
                        // Couldn't create the file. Ignore for now.
                    }
                }

                XmlNode root = SetupDocument(doc);

                XmlNode appRoot  = root.SelectSingleNode("ApplicationSettings");
                XmlNode userRoot = root.SelectSingleNode("UserSettings");

                // Get the settings
                foreach (SettingsProperty setting in collection)
                {
                    XmlNode node = IsUserScoped(setting) ? userRoot.SelectSingleNode(setting.Name) : appRoot.SelectSingleNode(setting.Name);

                    // Add the property to the list.
                    SettingsPropertyValue value = new SettingsPropertyValue(setting);
                    value.IsDirty         = false;
                    value.SerializedValue = node != null ? node.InnerText : setting.DefaultValue;
                    valueCollection.Add(value);
                }

                return(valueCollection);
            }
        }
    // 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;
    }
Ejemplo n.º 38
0
        public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext sc, SettingsPropertyCollection properties)
        {
            SettingsPropertyValueCollection settings = new SettingsPropertyValueCollection();

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

            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));
            }

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

            DbDataReader reader;

            using (DbConnection connection = CreateConnection()) {
                DerbyProfileHelper.Profile_GetProperties(connection, ApplicationName, username, DateTime.UtcNow, out reader);
                if (reader != null)
                {
                    using (reader) {
                        if (reader.Read())
                        {
                            string  allnames     = reader.GetString(0);
                            string  allvalues    = reader.GetString(1);
                            int     binaryLen    = (int)reader.GetBytes(2, 0, null, 0, 0);
                            byte [] binaryvalues = new byte [binaryLen];
                            reader.GetBytes(2, 0, binaryvalues, 0, binaryLen);

                            DecodeProfileData(allnames, allvalues, binaryvalues, settings);
                        }
                    }
                }
            }
            return(settings);
        }
	public virtual SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection properties) {}
Ejemplo n.º 40
0
 public void Upgrade(SettingsContext context, SettingsPropertyCollection properties)
 {
 }
Ejemplo n.º 41
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;
    }
Ejemplo n.º 42
0
        public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection props)
        {
            //Create new collection of values
            var values = new SettingsPropertyValueCollection();

            //Iterate through the settings to be retrieved
            foreach (SettingsProperty setting in props)
            {
                var value = new SettingsPropertyValue(setting)
                {
                    IsDirty         = false,
                    SerializedValue = GetValue(setting)
                };
                values.Add(value);
            }
            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;
    }
Ejemplo n.º 44
0
                public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection collection)
                {
                    SettingsPropertyValueCollection result = new SettingsPropertyValueCollection();
                    SettingsProperty property = new SettingsProperty("StringPropertyWithProvider", typeof(string), this, false, DefaultStringPropertyValue, SettingsSerializeAs.String, new SettingsAttributeDictionary(), false, false);

                    result.Add(new SettingsPropertyValue(new SettingsProperty(property)));
                    return(result);
                }
 // Methods
 public abstract virtual SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection collection)
 {
 }