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

        SettingsXML.Save(Path.Combine(GetAppSettingsPath(), GetAppSettingsFilename()));
    }
        public void Setup()
        {
            settings = new SettingsContext();
            container = new TinyIoCContainer();

            logger = new Mock<ILogger>();
        }
 public void Setup()
 {
     settings = new SettingsContext(false, ".min");
     bundle = new BundleImpl();
     bundle.Extension = "css";
     bundle.Hash = new byte[1];
     generator = new BasicUrlGenerator<BundleImpl>(settings);
 }
        public void Setup()
        {
            settings = new SettingsContext();

            asset = new AssetBaseImpl();
            bundle = new StyleSheetBundle();
            bundle.Assets.Add(asset);
            processor = new ExpandPathProcessor(settings);
        }
        public void Setup()
        {
            directory = new Mock<IDirectory>();

            settings = new SettingsContext();
            settings.AppRootDirectory = directory.Object;

            runner = new Mock<IImagePipelineRunner>();
            processor = new ImageProcessor(settings, runner.Object);
        }
    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();

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

        try
        {
            SettingsXML.Save(Path.Combine(GetAppSettingsPath(), GetAppSettingsFilename()));
        }
        catch (Exception ex)
        {
        }
        //Ignore if cant save, device been ejected
    }
    // Will be called when MySettingsClass.GetPreviousVersion(propName) is called
    // This method's job is to retrieve a setting value from the previous version
    // of the settings w/o updating the setting at the storage location
    public SettingsPropertyValue GetPreviousVersion(SettingsContext context, SettingsProperty prop)
    {
        // If there's no previous setting version, return an empty property
        // NOTE: the LFSP returns an empty property for all app-scoped settings, so so do we
        string previousVersion = GetPreviousVersionNumber();
        if (IsApplicationScoped(prop) || string.IsNullOrEmpty(previousVersion))
        {
            // NOTE: can't just return null, as the settings engine turns that into
            // a default property -- have to return a SettingsPropertyValue object
            // with the PropertyValue set to null to really build an empty property
            SettingsPropertyValue propval = new SettingsPropertyValue(prop);
            propval.PropertyValue = null;
            return propval;
        }

        // Get the property value from the previous version
        // NOTE: if it's null, the settings machinery will assume the current default value
        // ideally, we'd want to use the previous version's default value, but a) that's
        // likely to be the current default value and b) if it's not, that data is lost
        return GetPropertyValue(prop, previousVersion);
    }
    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.º 12
0
    public override void SetPropertyValues(SettingsContext context, SettingsPropertyValueCollection collection)
    {
        Monitor.Enter(SetValuesLock);

        try
        {

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

            SyncToDisk();
        }
        catch
        {
            // ignore
        }
        finally
        {
            Monitor.Exit(SetValuesLock);
        }
    }
Ejemplo n.º 13
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 virtual void SetPropertyValues(SettingsContext context, SettingsPropertyValueCollection values) {}
	public virtual SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection properties) {}
	public virtual SettingsPropertyValue GetPreviousVersion(SettingsContext context, SettingsProperty property) {}
    // 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.º 18
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;
    }
    // SetPropertyValue is invoked when ApplicationSettingsBase.Save is called
    // ASB makes sure to pass each provider only the values marked for that provider,
    // whether on a per setting or setting class-wide basis
    public override void SetPropertyValues(SettingsContext context, SettingsPropertyValueCollection propvals)
    {
        // Iterate through the settings to be stored
        string version = GetCurrentVersionNumber();
        foreach (SettingsPropertyValue propval in propvals)
        {
            // If property hasn't been set, no need to save it
            if (!propval.IsDirty || (propval.SerializedValue == null)) { continue; }

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

            using (RegistryKey key = CreateRegKey(propval.Property, version))
            {
                key.SetValue(propval.Name, propval.SerializedValue);
            }
        }
    }
    public override void SetPropertyValues(SettingsContext context,	SettingsPropertyValueCollection properties)
    {
        // Get information about the user who owns the profile
        string username    = (string) context["UserName"];
        bool authenticated = (bool) context["IsAuthenticated"];

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

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

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

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

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

        // Save the profile data
        StreamWriter writer = null;

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

            writer.WriteLine(names);

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

            if (buf != null && buf.Length > 0) writer.WriteLine(Convert.ToBase64String(buf));
            else writer.WriteLine();
        }
        finally
        {
            if (writer != null)	writer.Close();
        }
    }
    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;
    }
Ejemplo n.º 22
0
 public override void SetPropertyValues(SettingsContext context, SettingsPropertyValueCollection collection)
 {
     IProfile dal = Snitz.Membership.Helpers.Factory<IProfile>.Create("Profile");
         dal.TableName = _table;
         dal.SetPropertyValues(context, collection);
 }
    public override void SetPropertyValues(SettingsContext sc, SettingsPropertyValueCollection properties)
    {
        #region Check The Function Parameters Are Valid
        // check we have the user profile information.
        if (sc == null)
        {
            return;
        }

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

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

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

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

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

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

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

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

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

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

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

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

                    // execute the stored procedure
                    // if no rows were affected, then throw an error, because nothing has been saved!
                    if (SetPropertyCommand.ExecuteNonQuery() == 0)
                    {
                        throw new ProviderException(String.Format("Updating the profile property '{0}' in the database failed!", spv.Name));
                    }
                }
            }
        }
        catch (Exception e)
        {
            // if anything went wrong, throw an exception
            throw new ProviderException(String.Format(
                "Error setting profile property value to database.\nUsername: '******'\nIs Authenticated: {1}",
                username, isAuthenticated.ToString()), e);
        }
        #endregion
    }
    // Save any of the applications settings that have changed (flagged as "dirty")
    public override void SetPropertyValues(SettingsContext sContext, SettingsPropertyValueCollection settingsColl)
    {
        // Set the values in XML
        foreach (SettingsPropertyValue spVal in settingsColl)
        {
            SetSetting(spVal);
        }

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

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

            // Uncomment the following line to enable a console message for console-based apps
            //Console.WriteLine("Error writing configuration file to disk: " + ex.Message);
        }
    }
    // Retrieve settings from the configuration file
    public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext sContext, SettingsPropertyCollection settingsColl)
    {
        // Create a collection of values to return
        SettingsPropertyValueCollection retValues = new SettingsPropertyValueCollection();

        // Create a temporary SettingsPropertyValue to reuse
        SettingsPropertyValue setVal;

        // Loop through the list of settings that the application has requested and add them
        // to our collection of return values.
        foreach (SettingsProperty sProp in settingsColl)
        {
            setVal = new SettingsPropertyValue(sProp);
            setVal.IsDirty = false;
            setVal.SerializedValue = GetSetting(sProp);
            retValues.Add(setVal);
        }
        return retValues;
    }
	public void Initialize(SettingsContext context, SettingsPropertyCollection properties, SettingsProviderCollection providers) {}
Ejemplo n.º 27
0
    public override void SetPropertyValues(SettingsContext context, SettingsPropertyValueCollection collection)
    {
        string username = (string)context["UserName"];
        bool isAuthenticated = (bool)context["IsAuthenticated"];

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

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

        foreach (SettingsPropertyValue propValue in collection)
        {
            values[propValue.Property.Name] = propValue.PropertyValue;
        }
    }
	public virtual void Reset(SettingsContext context) {}
Ejemplo n.º 29
0
    public override void SetPropertyValues(SettingsContext context, SettingsPropertyValueCollection propvals)
    {
        //Iterate through the settings to be stored
        //Only dirty settings are included in propvals, and only ones relevant to this provider
        foreach (SettingsPropertyValue propval in propvals)
        {
            SetValue(propval);
        }

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

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

            SettingsXML.Save(System.IO.Path.Combine(GetAppSettingsPath(), GetAppSettingsFilename()));
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
    }
	public virtual void Upgrade(SettingsContext context, SettingsPropertyCollection properties) {}