// 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);
    }
Ejemplo n.º 2
0
 private static string GetDefaultValue(SettingsProperty setting)
 {
     return(setting.DefaultValue?.ToString() ?? string.Empty);
 }
        public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection properties)
        {
            ExTraceGlobals.ProgramFlowTracer.TraceFunction <ExchangeSettingsProvider>(0L, "-->ExchangeSettingsProvider.GetPropertyValues: {0}", this);
            SettingsPropertyValueCollection settingsPropertyValueCollection = new SettingsPropertyValueCollection();
            string      key        = (string)context["SettingsKey"];
            IDictionary dictionary = (IDictionary)this.settingsStore[key];

            foreach (object obj in properties)
            {
                SettingsProperty      settingsProperty      = (SettingsProperty)obj;
                string                name                  = settingsProperty.Name;
                SettingsPropertyValue settingsPropertyValue = new SettingsPropertyValue(settingsProperty);
                if (dictionary == null || !dictionary.Contains(name))
                {
                    goto IL_114;
                }
                ExTraceGlobals.DataFlowTracer.TraceFunction <string, object, Type>(0L, "*--ExchangeSettingsProvider.GetPropertyValues: Converting and setting value: {0} = {1} as {2}", name, dictionary[name], settingsProperty.PropertyType);
                if (dictionary[name] != null || !settingsProperty.PropertyType.IsValueType)
                {
                    try
                    {
                        settingsPropertyValue.PropertyValue = Convert.ChangeType(dictionary[name], settingsProperty.PropertyType);
                        goto IL_24D;
                    }
                    catch (InvalidCastException arg)
                    {
                        ExTraceGlobals.DataFlowTracer.TraceError <InvalidCastException>(0L, "Exception in ExchangeSettingsProvider.GetPropertyValues: {0}", arg);
                        settingsPropertyValue.PropertyValue = settingsPropertyValue.Property.DefaultValue;
                        goto IL_24D;
                    }
                    goto IL_114;
                }
                settingsPropertyValue.PropertyValue = settingsPropertyValue.Property.DefaultValue;
IL_24D:
                settingsPropertyValueCollection.Add(settingsPropertyValue);
                continue;
IL_114:
                if (string.IsNullOrEmpty((string)settingsProperty.DefaultValue))
                {
                    ExTraceGlobals.DataFlowTracer.TraceFunction <string, Type>(0L, "*--ExchangeSettingsProvider.GetPropertyValues: Setting to null: {0} as {1}", name, settingsProperty.PropertyType);
                    settingsPropertyValue.PropertyValue = null;
                    goto IL_24D;
                }
                if (typeof(Enum).IsAssignableFrom(settingsProperty.PropertyType))
                {
                    ExTraceGlobals.DataFlowTracer.TraceFunction <string, object, Type>(0L, "*--ExchangeSettingsProvider.GetPropertyValues: Converting and setting enum value: {0} = {1} as {2}", name, settingsProperty.DefaultValue, settingsProperty.PropertyType);
                    settingsPropertyValue.PropertyValue = EnumValidator.Parse(settingsProperty.PropertyType, (string)settingsProperty.DefaultValue, EnumParseOptions.IgnoreCase);
                    goto IL_24D;
                }
                MethodInfo method = settingsProperty.PropertyType.GetMethod("Parse", BindingFlags.Static | BindingFlags.Public, null, new Type[]
                {
                    typeof(string)
                }, null);
                if (null != method)
                {
                    ExTraceGlobals.DataFlowTracer.TraceFunction <string, object, Type>(0L, "*--ExchangeSettingsProvider.GetPropertyValues: Parsing value: {0} = {1} as {2}", name, settingsProperty.DefaultValue, settingsProperty.PropertyType);
                    settingsPropertyValue.PropertyValue = method.Invoke(null, new object[]
                    {
                        settingsProperty.DefaultValue
                    });
                    goto IL_24D;
                }
                ExTraceGlobals.DataFlowTracer.TraceFunction <string, object, Type>(0L, "*--ExchangeSettingsProvider.GetPropertyValues: Using default value: {0} = {1} as {2}", name, settingsProperty.DefaultValue, settingsProperty.PropertyType);
                settingsPropertyValue.SerializedValue = settingsProperty.DefaultValue;
                goto IL_24D;
            }
            ExTraceGlobals.ProgramFlowTracer.TraceFunction <ExchangeSettingsProvider>(0L, "<--ExchangeSettingsProvider.GetPropertyValues: {0}", this);
            return(settingsPropertyValueCollection);
        }
Ejemplo n.º 4
0
 ProfilePropertyViewModel.ProfilePropertyType PropTypeFromPropertyType(SettingsProperty prop)
 {
     return(prop.PropertyType == typeof(Boolean) ?
            ProfilePropertyViewModel.ProfilePropertyType.Boolean :
            ProfilePropertyViewModel.ProfilePropertyType.String);
 }
 // Creates a sub-key under HKCU\Software\CompanyName\ProductName\version
 RegistryKey CreateRegKey(SettingsProperty prop, string version)
 {
     Debug.Assert(!IsApplicationScoped(prop), "Can't get Registry key for a read-only Application scoped setting: " + prop.Name);
     return Registry.LocalMachine.CreateSubKey(GetSubKeyPath(version));
 }
    // Retrieve values from the configuration file, or if the setting does not exist in the file,
    // retrieve the value from the application's default configuration
    private object GetSetting(SettingsProperty setProp)
    {
        object retVal;
        try
        {
            // Search for the specific settings node we are looking for in the configuration file.
            // If it exists, return the InnerText or InnerXML of its first child node, depending on the setting type.

            // If the setting is serialized as a string, return the text stored in the config
            if (setProp.SerializeAs.ToString() == "String")
            {
                return XMLConfig.SelectSingleNode("//setting[@name='" + setProp.Name + "']").FirstChild.InnerText;
            }

            // If the setting is stored as XML, deserialize it and return the proper object.  This only supports
            // StringCollections at the moment - I will likely add other types as I use them in applications.
            else
            {
                string settingType = setProp.PropertyType.ToString();
                string xmlData = XMLConfig.SelectSingleNode("//setting[@name='" + setProp.Name + "']").FirstChild.InnerXml;
                XmlSerializer xs = new XmlSerializer(typeof(string[]));
                string[] data = (string[])xs.Deserialize(new XmlTextReader(xmlData, XmlNodeType.Element, null));

                switch (settingType)
                {
                    case "System.Collections.Specialized.StringCollection":
                        StringCollection sc = new StringCollection();
                        sc.AddRange(data);
                        return sc;
                    default:
                        return "";
                }
            }
        }
        catch (Exception)
        {
            // Check to see if a default value is defined by the application.
            // If so, return that value, using the same rules for settings stored as Strings and XML as above
            if ((setProp.DefaultValue != null))
            {
                if (setProp.SerializeAs.ToString() == "String")
                {
                    retVal = setProp.DefaultValue.ToString();
                }
                else
                {
                    string settingType = setProp.PropertyType.ToString();
                    string xmlData = setProp.DefaultValue.ToString();
                    XmlSerializer xs = new XmlSerializer(typeof(string[]));
                    string[] data = (string[])xs.Deserialize(new XmlTextReader(xmlData, XmlNodeType.Element, null));

                    switch (settingType)
                    {
                        case "System.Collections.Specialized.StringCollection":
                            StringCollection sc = new StringCollection();
                            sc.AddRange(data);
                            return sc;

                        default: return "";
                    }
                }
            }
            else
            {
                retVal = "";
            }
        }
        return retVal;
    }
	public virtual SettingsPropertyValue GetPreviousVersion(SettingsContext context, SettingsProperty property) {}
Ejemplo n.º 8
0
 static bool IsRoaming(SettingsProperty property)
 {
     return(property.Attributes.ContainsKey(typeof(SettingsManageabilityAttribute)));
 }
Ejemplo n.º 9
0
 public SettingsPropertyValueSerializable(SettingsProperty property) : base(property)
 {
 }
Ejemplo n.º 10
0
 public SalesforceProfileProperty(SettingsProperty property, string salesforceName)
     : base(property)
 {
     this.SalesforceName = salesforceName;
 }
 // Looks in the "attribute bag" for a given property to determine if it is user-scoped
 bool IsUserScoped(SettingsProperty prop)
 {
     return HasSettingScope(prop, typeof(UserScopedSettingAttribute));
 }
 // Looks in the "attribute bag" for a given property to determine if it is app-scoped
 bool IsApplicationScoped(SettingsProperty prop)
 {
     return HasSettingScope(prop, typeof(ApplicationScopedSettingAttribute));
 }
    // Checks for app or user-scoped based on the attributeType argument
    // Also checks for sanity, i.e. a setting not marked as both or neither scope
    // (just like the LFSP)
    bool HasSettingScope(SettingsProperty prop, Type attributeType)
    {
        // TODO: add support for roaming
        Debug.Assert((attributeType == typeof(ApplicationScopedSettingAttribute)) || (attributeType == typeof(UserScopedSettingAttribute)));
        bool isAppScoped = prop.Attributes[typeof(ApplicationScopedSettingAttribute)] != null;
        bool isUserScoped = prop.Attributes[typeof(UserScopedSettingAttribute)] != null;

        // Check constraints
        if (isUserScoped && isAppScoped)
        {
            throw new Exception("Can't mark a setting as User and Application-scoped: " + prop.Name);
        }
        else if (!isUserScoped && !isAppScoped)
        {
            throw new Exception("Must mark a setting as User or Application-scoped: " + prop.Name);
        }

        // Return scope check result
        if (attributeType == typeof(ApplicationScopedSettingAttribute))
        {
            return isAppScoped;
        }
        else if (attributeType == typeof(UserScopedSettingAttribute))
        {
            return isUserScoped;
        }
        else
        {
            Debug.Assert(false);
            return false;
        }
    }
    SettingsPropertyValue GetPropertyValue(SettingsProperty prop, string version)
    {
        SettingsPropertyValue value = new SettingsPropertyValue(prop);

        // Only User-scoped settings can be found in the Registry.
        // By leaving the Application-scoped setting's value at null,
        // we get the "default" value
        if (IsUserScoped(prop))
        {
            using (RegistryKey key = CreateRegKey(prop, version))
            {
                value.SerializedValue = key.GetValue(prop.Name);
            }
        }

        value.IsDirty = false;
        return value;
    }
 // do nothing
 public SettingsPropertyValue GetPreviousVersion(SettingsContext context, SettingsProperty property) => new SettingsPropertyValue(property);
Ejemplo n.º 16
0
 private static bool IsUserScoped(SettingsProperty property)
 {
     return(SettingsPropertyExtensions.IsUserScoped(property));
 }
Ejemplo n.º 17
0
 public ProfileColumnData(string col, SettingsProperty pv, object val, SqlDbType type)
 {
     EnsureValidTableOrColumnName(col);
         ColumnName = col;
         PropertyValue = pv;
         Value = val;
         DataType = type;
 }
Ejemplo n.º 18
0
 // Methods
 public void Add(SettingsProperty property)
 {
 }
    public ProfileInfoCollection FindProfilesByPropertyValue(SettingsProperty property, SearchOperator searchOperator, object value)
    {
        // instantiate an empty ProfileInfoCollection to use it for return
        ProfileInfoCollection pic = new ProfileInfoCollection();

        // try and open the connection and get the results
        try
        {
            // get the connection we're going to use
            using (SqlConnection conn = new SqlConnection(_connectionStringName))
            {

                // instantiate a SettingsPropertyValue from the property
                // to use it to serialize the value for comparison with the database
                SettingsPropertyValue spv = new SettingsPropertyValue(property);
                spv.PropertyValue = value;

                // set common parameters of the aspnet_Profile_FindProfiles stored procedure
                SqlCommand FindProfilesCommand = new SqlCommand("aspnet_Profile_FindProfiles", conn);
                FindProfilesCommand.CommandType = CommandType.StoredProcedure;
                FindProfilesCommand.CommandTimeout = _commandTimeout;
                FindProfilesCommand.Parameters.Add("@ApplicationName", System.Data.SqlDbType.NVarChar, 256).Value = base.ApplicationName;
                FindProfilesCommand.Parameters.Add("@PropertyName", System.Data.SqlDbType.NVarChar, 256).Value = property.Name;
                FindProfilesCommand.Parameters.Add("@OperatorType", System.Data.SqlDbType.Int).Value = (Int32)searchOperator;

                // if the serialized property value is of type string
                // carry on if the size is within allowed limits
                Boolean bTooBig = false;
                if (spv.SerializedValue is String)
                {
                    // if the serialized value is bigger than the PropertyValueString column's length
                    if (((String)spv.SerializedValue).Length > Int32.MaxValue)
                    {
                        bTooBig = true;
                    }
                    else
                    {
                        if (searchOperator == SearchOperator.Contains || searchOperator == SearchOperator.FreeText)
                        {
                            // if the searchOperator is a freetext operator then pass the value unaltered
                            FindProfilesCommand.Parameters.Add("@PropertyValueString",
                                System.Data.SqlDbType.NVarChar, Int32.MaxValue).Value = spv.PropertyValue;
                            FindProfilesCommand.Parameters.Add("@PropertyValueBinary",
                                System.Data.SqlDbType.VarBinary, Int32.MaxValue).Value = DBNull.Value;
                        }
                        else
                        {
                            // otherwise serialise the value before passing it
                            FindProfilesCommand.Parameters.Add("@PropertyValueString",
                                System.Data.SqlDbType.NVarChar, Int32.MaxValue).Value = spv.SerializedValue;
                            FindProfilesCommand.Parameters.Add("@PropertyValueBinary",
                                System.Data.SqlDbType.VarBinary, Int32.MaxValue).Value = DBNull.Value;
                        }

                        // set the parameter @PropertyType to indicate the property is a string
                        FindProfilesCommand.Parameters.Add("@PropertyType", System.Data.SqlDbType.Bit).Value = 0;
                    }
                }
                else
                {
                    if (((SqlBinary)spv.SerializedValue).Length > Int32.MaxValue)
                    {
                        bTooBig = true;
                    }
                    else
                    {
                        if (searchOperator == SearchOperator.Contains || searchOperator == SearchOperator.FreeText)
                        {
                            // if the searchOperator is a freetext operator then pass the value unaltered to the
                            // @PropertyValueString because we are passing a string anyway not a binary
                            FindProfilesCommand.Parameters.Add("@PropertyValueString",
                                System.Data.SqlDbType.NVarChar, Int32.MaxValue).Value = spv.PropertyValue;
                            FindProfilesCommand.Parameters.Add("@PropertyValueBinary",
                                System.Data.SqlDbType.VarBinary, Int32.MaxValue).Value = DBNull.Value;
                        }
                        else
                        {
                            // otherwise just serialise the value and pass it to the @PropertyBinaryValue
                            FindProfilesCommand.Parameters.Add("@PropertyValueString",
                                System.Data.SqlDbType.NVarChar, Int32.MaxValue).Value = DBNull.Value;
                            FindProfilesCommand.Parameters.Add("@PropertyValueBinary",
                                System.Data.SqlDbType.VarBinary, Int32.MaxValue).Value = spv.SerializedValue;
                        }

                        // set the parameter @PropertyType to indicate the property is a binary
                        FindProfilesCommand.Parameters.Add("@PropertyType", System.Data.SqlDbType.Bit).Value = 1;
                    }
                }

                if (bTooBig)
                {
                    // if the size is out of limits throw an exception
                    throw new ProviderException("Property value length is too big.");
                }

                // Open the database
                conn.Open();

                // Get a DataReader for the results we need
                using (SqlDataReader rdr = FindProfilesCommand.ExecuteReader(CommandBehavior.CloseConnection))
                {
                    while (rdr.Read())
                    {
                        // create a ProfileInfo with the data you got back from the current record of the SqlDataReader
                        ProfileInfo pi = new ProfileInfo(rdr.GetString(rdr.GetOrdinal("UserName")),
                            rdr.GetBoolean(rdr.GetOrdinal("IsAnonymous")),
                            DateTime.SpecifyKind(rdr.GetDateTime(rdr.GetOrdinal("LastActivityDate")), DateTimeKind.Utc),
                            DateTime.SpecifyKind(rdr.GetDateTime(rdr.GetOrdinal("LastUpdatedDate")), DateTimeKind.Utc), 0);

                        // add the ProfileInfo you just created to the ProfileInfoCollection that we will return
                        pic.Add(pi);
                    }
                }
            }
        }
        catch (Exception e)
        {
            // if anything went wrong, throw an exception
            throw new ProviderException("An error occured while finding profiles with your search criteria!", e);
        }

        return pic;
    }
Ejemplo n.º 20
0
 public SettingsPropertyValue GetPreviousVersion(SettingsContext context, SettingsProperty property)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 21
0
    private string GetValue(SettingsProperty setting)
    {
        Monitor.Enter(GetLock);

        string ret = "";

        try
        {
            ret = SettingsXML.SelectSingleNode(SETTINGSROOT + "/" + setting.Name).InnerText;
        }
        catch
        {
            if (setting.DefaultValue != null)
            {
                ret = setting.DefaultValue.ToString();
            }
            else
            {
                ret = "";
            }
        }
        finally
        {
            Monitor.Exit(GetLock);
        }
        return ret;
    }
Ejemplo n.º 22
0
 public static string CreateSettingValue(SettingsProperty property, MigrationScope migrationScope, SettingValue settingValue)
 {
     return(CreateSettingValue(SettingsPropertyHelper.GetDescriptor(property), migrationScope, settingValue));
 }
Ejemplo n.º 23
0
 private bool IsRoaming(SettingsProperty prop)
 {
     //Determine if the setting is marked as Roaming
     foreach (DictionaryEntry d in prop.Attributes)
     {
         Attribute a = (Attribute)d.Value;
         if (a is System.Configuration.SettingsManageabilityAttribute)
         {
             return true;
         }
     }
     return false;
 }
 public SettingsProperty(SettingsProperty propertyToCopy)
 {
 }
Ejemplo n.º 25
0
        //////////////////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////////////////
        static private void InitializeStatic()
        {
            if (!ProfileManager.Enabled || s_Initialized)
            {
                if (s_InitializeException != null)
                {
                    throw s_InitializeException;
                }
                return;
            }
            lock (s_InitializeLock) {
                if (s_Initialized)
                {
                    if (s_InitializeException != null)
                    {
                        throw s_InitializeException;
                    }
                    return;
                }

                try {
                    ProfileSection config       = MTConfigUtil.GetProfileAppConfig();
                    bool           fAnonEnabled = (HostingEnvironment.IsHosted ? AnonymousIdentificationModule.Enabled : true);
                    Type           baseType     = ProfileBase.InheritsFromType;
                    bool           hasLowTrust  = HttpRuntime.HasAspNetHostingPermission(AspNetHostingPermissionLevel.Low);

                    s_Properties = new SettingsPropertyCollection();

                    // Step 0: Add all dynamic profile properties set programatically during PreAppStart
                    ProfileBase.AddPropertySettingsFromConfig(baseType, fAnonEnabled, hasLowTrust, ProfileManager.DynamicProfileProperties, null);

                    //////////////////////////////////////////////////////////////////////
                    // Step 1: Add Properties from the base class (if not ProfileBase)
                    if (baseType != typeof(ProfileBase))
                    {
                        //////////////////////////////////////////////////////////////////////
                        // Step 2: Construct a hashtable containing a list of all the property-names in the ProfileBase type
                        PropertyInfo[]      baseProps      = typeof(ProfileBase).GetProperties();
                        NameValueCollection baseProperties = new NameValueCollection(baseProps.Length);
                        foreach (PropertyInfo baseProp in baseProps)
                        {
                            baseProperties.Add(baseProp.Name, String.Empty);
                        }

                        //////////////////////////////////////////////////////////////////////
                        // Step 3: For each property in the derived class, add it to the s_Properties class.
                        PropertyInfo[] props = baseType.GetProperties();
                        foreach (PropertyInfo prop in props)
                        {
                            if (baseProperties[prop.Name] == null)   //not in the base class

                            {
                                ProfileProvider     prov           = hasLowTrust ? ProfileManager.Provider : null;
                                bool                readOnly       = false;
                                SettingsSerializeAs serializeAs    = SettingsSerializeAs.ProviderSpecific;
                                string              defaultValue   = String.Empty;
                                bool                allowAnonymous = false;
                                string              customData     = null;

                                //////////////////////////////////////////////////////////////////////
                                // Step 4: For the property, get the attributes
                                Attribute[] attribs = Attribute.GetCustomAttributes(prop, true);

                                foreach (Attribute attrib in attribs)
                                {
                                    if (attrib is SettingsSerializeAsAttribute)
                                    {
                                        serializeAs = ((SettingsSerializeAsAttribute)attrib).SerializeAs;
                                    }
                                    else if (attrib is SettingsAllowAnonymousAttribute)
                                    {
                                        allowAnonymous = ((SettingsAllowAnonymousAttribute)attrib).Allow;
                                        if (!fAnonEnabled && allowAnonymous)
                                        {
                                            throw new ConfigurationErrorsException(SR.GetString(SR.Annoymous_id_module_not_enabled, prop.Name), config.ElementInformation.Properties["inherits"].Source, config.ElementInformation.Properties["inherits"].LineNumber);
                                        }
                                    }
                                    else if (attrib is System.ComponentModel.ReadOnlyAttribute)
                                    {
                                        readOnly = ((System.ComponentModel.ReadOnlyAttribute)attrib).IsReadOnly;
                                    }
                                    else if (attrib is DefaultSettingValueAttribute)
                                    {
                                        defaultValue = ((DefaultSettingValueAttribute)attrib).Value;
                                    }
                                    else if (attrib is CustomProviderDataAttribute)
                                    {
                                        customData = ((CustomProviderDataAttribute)attrib).CustomProviderData;
                                    }
                                    else if (hasLowTrust && attrib is ProfileProviderAttribute)
                                    {
                                        prov = ProfileManager.Providers[((ProfileProviderAttribute)attrib).ProviderName];
                                        if (prov == null)
                                        {
                                            throw new ConfigurationErrorsException(SR.GetString(SR.Profile_provider_not_found, ((ProfileProviderAttribute)attrib).ProviderName), config.ElementInformation.Properties["inherits"].Source, config.ElementInformation.Properties["inherits"].LineNumber);
                                        }
                                    }
                                }
                                //////////////////////////////////////////////////////////////////////
                                // Step 5: Add the property to the s_Properties
                                SettingsAttributeDictionary settings = new SettingsAttributeDictionary();
                                settings.Add("AllowAnonymous", allowAnonymous);
                                if (!string.IsNullOrEmpty(customData))
                                {
                                    settings.Add("CustomProviderData", customData);
                                }
                                SettingsProperty sp = new SettingsProperty(prop.Name, prop.PropertyType, prov, readOnly, defaultValue, serializeAs, settings, false, true);
                                s_Properties.Add(sp);
                            }
                        }
                    }

                    //////////////////////////////////////////////////////////////////////
                    //////////////////////////////////////////////////////////////////////
                    // Step 6: Add all properties from config
                    if (config.PropertySettings != null)
                    {
                        AddPropertySettingsFromConfig(baseType, fAnonEnabled, hasLowTrust, config.PropertySettings, null);
                        foreach (ProfileGroupSettings pgs in config.PropertySettings.GroupSettings)
                        {
                            AddPropertySettingsFromConfig(baseType, fAnonEnabled, hasLowTrust, pgs.PropertySettings, pgs.Name);
                        }
                    }
                }
                catch (Exception e) {
                    if (s_InitializeException == null)
                    {
                        s_InitializeException = e;
                    }
                }
                // If there are no properties, create an empty collection.
                if (s_Properties == null)
                {
                    s_Properties = new SettingsPropertyCollection();
                }
                // Make the properties collection read-only
                s_Properties.SetReadOnly();
                s_Initialized = true;
            }

            // Throw an exception if there was an exception during initialization
            if (s_InitializeException != null)
            {
                throw s_InitializeException;
            }
        }
Ejemplo n.º 26
0
        public static SettingsPropertyValueCollection DeserializeSettingsPropertyValueCollection(List <ProfilePropertyValueContract> oSerializedSettingsPropertyValueCollection)
        {
            #region VARIABLES

            System.Configuration.SettingsPropertyValueCollection oSettingsPropertyValueCollection;


            string sCurrentPropertyName;
            Type   oCurrentPropertyType;
            string sCurrentPropertyDefaultValue;
            SettingsPropertyValue oSettingsCurrentPropertyValue;
            SettingsProperty      oCurrentSettingsProperty;


            #endregion

            oSettingsPropertyValueCollection = null;


            if (oSerializedSettingsPropertyValueCollection != null)
            {
                oSettingsPropertyValueCollection = new SettingsPropertyValueCollection();

                foreach (var oPropertySerialized in oSerializedSettingsPropertyValueCollection)
                {
                    if (oPropertySerialized.ProfileProperty != null)
                    {
                        sCurrentPropertyName = oPropertySerialized.ProfileProperty.Name;

                        if (!string.IsNullOrEmpty(sCurrentPropertyName))
                        {
                            oCurrentSettingsProperty = new SettingsProperty(sCurrentPropertyName);

                            if (oPropertySerialized.ProfileProperty.Type != null)
                            {
                                oCurrentPropertyType = !string.IsNullOrEmpty(oPropertySerialized.ProfileProperty.Type)? Type.GetType(oPropertySerialized.ProfileProperty.Type) : typeof(string);
                                oCurrentSettingsProperty.PropertyType = oCurrentPropertyType;


                                oCurrentSettingsProperty.IsReadOnly = oPropertySerialized.ProfileProperty.IsReadOnly;


                                sCurrentPropertyDefaultValue = oPropertySerialized.ProfileProperty.DefaultValue;
                                if (!string.IsNullOrEmpty(sCurrentPropertyDefaultValue))
                                {
                                    oCurrentSettingsProperty.DefaultValue = sCurrentPropertyDefaultValue;
                                }



                                if (oPropertySerialized.ProfileProperty.Attributes != null)
                                {
                                    foreach (var oPropertyAttributeSerialized in oPropertySerialized.ProfileProperty.Attributes)
                                    {
                                        oCurrentSettingsProperty.Attributes.Add(oPropertyAttributeSerialized.Key, oPropertyAttributeSerialized.Value);
                                    }
                                }

                                //Must set the type to use the PropertyValue  otherwise you will get " NullReferenceException when trying to access the PropertyValue"
                                oSettingsCurrentPropertyValue = new SettingsPropertyValue(oCurrentSettingsProperty);

                                if (!string.IsNullOrEmpty(oPropertySerialized.Value))
                                {
                                    oSettingsCurrentPropertyValue.PropertyValue = oPropertySerialized.Value;;
                                }
                                else
                                {
                                    oSettingsCurrentPropertyValue.PropertyValue = null;
                                }

                                oSettingsPropertyValueCollection.Add(oSettingsCurrentPropertyValue);
                            }
                        }
                    }
                }
            }

            return(oSettingsPropertyValueCollection);
        }
 public SettingsPropertyValue GetPreviousVersion(SettingsContext context, SettingsProperty property)
 {
     ExTraceGlobals.ProgramFlowTracer.TraceFunction <ExchangeSettingsProvider>(0L, "*--ExchangeSettingsProvider.GetPreviousVersion: {0}", this);
     throw new NotSupportedException();
 }
Ejemplo n.º 28
0
        static SettingsProperty CreateSettingsProperty(PropertyInfo property)
        {
            SettingsProperty sp = new SettingsProperty(property.Name);

            Attribute [] attributes             = (Attribute [])property.GetCustomAttributes(false);
            SettingsAttributeDictionary attDict = new SettingsAttributeDictionary();
            bool defaultAssigned = false;

            sp.SerializeAs  = SettingsSerializeAs.ProviderSpecific;
            sp.PropertyType = property.PropertyType;
            sp.IsReadOnly   = false;
            sp.ThrowOnErrorDeserializing = false;
            sp.ThrowOnErrorSerializing   = true;

            for (int i = 0; i < attributes.Length; i++)
            {
                if (attributes [i] is DefaultSettingValueAttribute)
                {
                    sp.DefaultValue = ((DefaultSettingValueAttribute)attributes [i]).Value;
                    defaultAssigned = true;
                }
                else if (attributes [i] is SettingsProviderAttribute)
                {
                    Type providerType = HttpApplication.LoadType(((SettingsProviderAttribute)attributes [i]).ProviderTypeName);
                    sp.Provider = (SettingsProvider)Activator.CreateInstance(providerType);
                    sp.Provider.Initialize(null, null);
                }
                else if (attributes [i] is SettingsSerializeAsAttribute)
                {
                    sp.SerializeAs = ((SettingsSerializeAsAttribute)attributes [i]).SerializeAs;
                }
                else if (attributes [i] is SettingsAllowAnonymousAttribute)
                {
                    sp.Attributes ["AllowAnonymous"] = ((SettingsAllowAnonymousAttribute)attributes [i]).Allow;
                }
                else if (attributes [i] is CustomProviderDataAttribute)
                {
                    sp.Attributes ["CustomProviderData"] = ((CustomProviderDataAttribute)attributes [i]).CustomProviderData;
                }
                else if (attributes [i] is ApplicationScopedSettingAttribute ||
                         attributes [i] is UserScopedSettingAttribute ||
                         attributes [i] is SettingsDescriptionAttribute ||
                         attributes [i] is SettingAttribute)
                {
                    attDict.Add(attributes [i].GetType(), attributes [i]);
                }
            }

            if (sp.Provider == null)
            {
                sp.Provider = ProfileManager.Provider;
            }

            if (sp.Attributes ["AllowAnonymous"] == null)
            {
                sp.Attributes ["AllowAnonymous"] = false;
            }

            if (!defaultAssigned && sp.PropertyType == typeof(string) && sp.DefaultValue == null)
            {
                sp.DefaultValue = String.Empty;
            }

            return(sp);
        }
Ejemplo n.º 29
0
 set => SetValue(SettingsProperty, value);
Ejemplo n.º 30
0
        static void InitProperties()
        {
            SettingsPropertyCollection properties = new SettingsPropertyCollection();

            ProfileSection config = (ProfileSection)WebConfigurationManager.GetSection("system.web/profile");
            RootProfilePropertySettingsCollection ps = config.PropertySettings;

            for (int i = 0; i < ps.GroupSettings.Count; i++)
            {
                ProfileGroupSettings pgs = ps.GroupSettings [i];
                ProfilePropertySettingsCollection ppsc = pgs.PropertySettings;

                for (int s = 0; s < ppsc.Count; s++)
                {
                    SettingsProperty settingsProperty = CreateSettingsProperty(pgs, ppsc [s]);
                    ValidateProperty(settingsProperty, ppsc [s].ElementInformation);
                    properties.Add(settingsProperty);
                }
            }

            for (int s = 0; s < ps.Count; s++)
            {
                SettingsProperty settingsProperty = CreateSettingsProperty(null, ps [s]);
                ValidateProperty(settingsProperty, ps [s].ElementInformation);
                properties.Add(settingsProperty);
            }

            if (config.Inherits.Length > 0)
            {
                Type profileType = ProfileParser.GetProfileCommonType(HttpContext.Current);
                if (profileType != null)
                {
                    Type properiesType = profileType.BaseType;
                    for (; ;)
                    {
                        PropertyInfo [] pi = properiesType.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly);
                        if (pi.Length > 0)
                        {
                            for (int i = 0; i < pi.Length; i++)
                            {
                                properties.Add(CreateSettingsProperty(pi [i]));
                            }
                        }

                        if (properiesType.BaseType == null ||
                            properiesType.BaseType == typeof(ProfileBase))
                        {
                            break;
                        }

                        properiesType = properiesType.BaseType;
                    }
                }
            }

            properties.SetReadOnly();
            lock (Profiles_SettingsPropertyCollection) {
                if (_properties == null)
                {
                    _properties = properties;
                }
            }
        }
 public virtual SettingsPropertyValue GetPreviousVersion(SettingsContext context, SettingsProperty property)
 {
 }
 public SettingsPropertyValue GetPreviousVersion(SettingsContext context, SettingsProperty property)
 {
     return(_provider.GetPreviousVersion(context, property));
 }
Ejemplo n.º 33
0
 public SettingsPropertyValue GetPreviousVersion(SettingsContext context, SettingsProperty property)
 {
     // do nothing
     return(new SettingsPropertyValue(property));
 }
 static bool IsRoaming(SettingsProperty property)
 {
     return(property.Attributes
            .Cast <DictionaryEntry>()
            .Any(a => a.Value is SettingsManageabilityAttribute));
 }
 private static bool IsUserScoped(SettingsProperty property)
 {
     return(CollectionUtils.Contains(property.Attributes.Values, attribute => attribute is UserScopedSettingAttribute));
 }
Ejemplo n.º 36
0
 private static bool IsRoaming(SettingsProperty prop)
 {
     return(prop.Attributes.Cast <DictionaryEntry>().Select <DictionaryEntry, Attribute>((Func <DictionaryEntry, Attribute>)(d => (Attribute)d.Value)).OfType <SettingsManageabilityAttribute>().Any <SettingsManageabilityAttribute>());
 }
Ejemplo n.º 37
0
        public static void save_Setting(string setting_Name, string setting_Value)

        {
            //----------< save_Settings() >----------



            string property_name = setting_Name;



            //< Setting erstellen >

            SettingsProperty prop = null;

            if (Properties.Settings.Default.Properties[property_name] != null)

            {
                //< existing Setting >

                prop = Properties.Settings.Default.Properties[property_name];

                //</ existing Setting >
            }

            else

            {
                //< new Setting >

                prop = new System.Configuration.SettingsProperty(property_name);

                prop.PropertyType = typeof(string);

                Properties.Settings.Default.Properties.Add(prop);

                Properties.Settings.Default.Save();
                Properties.Settings.Default.Upgrade();

                //</ new Setting >
            }

            //</ Setting erstellen >



            //< set value  >

            Properties.Settings.Default.Properties[property_name].DefaultValue = setting_Value;

            //</ set value >



            //< Save Settings File >

            Properties.Settings.Default.Save();

            //</ Save Settings File >



            //----------</ save_Settings() >----------
        }
 private bool IsUserScoped(SettingsProperty settingsProperty)
 {
     return(CollectionUtils.Contains(settingsProperty.Attributes.Values,
                                     delegate(object obj) { return obj is UserScopedSettingAttribute; }));
 }
 // Constructors
 public SettingsPropertyValue(SettingsProperty property)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="SettingsPropertyColumn"/> class.
 /// </summary>
 /// <param name="settings">
 /// The settings.
 /// </param>
 /// <param name="dataType">
 /// The data type.
 /// </param>
 /// <param name="size">
 /// The size.
 /// </param>
 public SettingsPropertyColumn(SettingsProperty settings, SqlDbType dataType, int size)
 {
     this.DataType = dataType;
     this.Settings = settings;
     this.Size     = size;
 }
 // Methods
 public void Add(SettingsProperty property)
 {
 }
Ejemplo n.º 42
0
 private static bool IsUserScoped(SettingsProperty property)
 {
     return((from DictionaryEntry entry in property.Attributes select(Attribute) entry.Value).OfType <UserScopedSettingAttribute>().Any());
 }
    string GetValue(SettingsProperty setting)
    {
        string ret = "";

        try
        {
            ret = SettingsXML.SelectSingleNode(SETTINGSROOT + "/" + setting.Name).InnerText;
        }
        catch (Exception)
        {
            if (setting.DefaultValue != null)
                ret = setting.DefaultValue.ToString();
        }

        return ret;
    }
Ejemplo n.º 44
0
 public SettingsPropertyValue GetPreviousVersion(SettingsContext context, SettingsProperty property)
 {
     return(value);
 }
Ejemplo n.º 45
0
    private string GetValue(SettingsProperty setting)
    {
        string ret = "";

        try
        {
            if (IsRoaming(setting))
            {
                ret = SettingsXML.SelectSingleNode(SETTINGSROOT + "/" + setting.Name).InnerText;
            }
            else
            {
                ret = SettingsXML.SelectSingleNode(SETTINGSROOT + "/" + Environment.MachineName + "/" + setting.Name).InnerText;
            }

        }
        catch (Exception ex)
        {
            if ((setting.DefaultValue != null))
            {
                ret = setting.DefaultValue.ToString();
            }
            else
            {
                ret = "";
            }
        }

        return ret;
    }
Ejemplo n.º 46
0
 /// <summary>
 /// Returns the value of the named settings property for the previous version of the same application.
 /// </summary>
 /// <param name="context">A <c>System.Configuration.SettingsContext</c> that describes where the application settings property is used.</param>
 /// <param name="property">The <c>System.Configuration.SettingsProperty</c> whose value is to be returned.</param>
 /// <returns>A <c>System.Configuration.SettingsPropertyValue</c> representing the application setting if found; otherwise, <c>null</c>.</returns>
 public SettingsPropertyValue GetPreviousVersion(SettingsContext context, SettingsProperty property)
 {
     throw new NotSupportedException("Get Previous Version is not supported");
 }
        void Verify_PropertyChangedFired(string propertyName, SettingsProperty settingsProperty)
        {
            //------------Setup for test--------------------------
            var propertyChanged = false;
            var viewModel = new TestSettingsViewModel(new Mock<IEventAggregator>().Object, new Mock<IPopupController>().Object, AsyncWorkerTests.CreateSynchronousAsyncWorker().Object, new Mock<IWin32Window>().Object);
            viewModel.PropertyChanged += (sender, args) =>
            {
                if(args.PropertyName == propertyName)
                {
                    propertyChanged = true;
                }
            };

            //------------Execute Test---------------------------
            switch(settingsProperty)
            {
                case SettingsProperty.HasErrors:
                    viewModel.HasErrors = true;
                    break;
                case SettingsProperty.IsDirty:
                    viewModel.IsDirty = true;
                    break;
                case SettingsProperty.IsSaved:
                    viewModel.IsSaved = true;
                    break;
            }

            //------------Assert Results-------------------------
            Assert.IsTrue(propertyChanged);
        }
 public SettingsProperty(SettingsProperty propertyToCopy)
 {
 }