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);
        }
Example #2
0
 public SettingsPropertySerializable(string name, Type propertyType, SettingsProvider provider, bool isReadOnly, object defaultValue, SettingsSerializeAs serializeAs, SettingsAttributeDictionary attributes, bool throwOnErrorDeserializing, bool throwOnErrorSerializing) : base(name, propertyType, provider, isReadOnly, defaultValue, serializeAs, attributes, throwOnErrorDeserializing, throwOnErrorSerializing)
 {
 }
Example #3
0
 public SettingsProperty(string name)
 {
     Name       = name;
     Attributes = new SettingsAttributeDictionary();
 }
 public SettingsAttributeDictionary(SettingsAttributeDictionary attributes)
 {
 }
Example #5
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;
            }
        }
 public SettingsProperty(string name, Type propertyType, SettingsProvider provider, bool isReadOnly, object defaultValue, SettingsSerializeAs serializeAs, SettingsAttributeDictionary attributes, bool throwOnErrorDeserializing, bool throwOnErrorSerializing)
 {
 }
Example #7
0
 private static void InitializeStatic()
 {
     if (!ProfileManager.Enabled || s_Initialized)
     {
         if (s_InitializeException != null)
         {
             throw s_InitializeException;
         }
     }
     else
     {
         lock (s_InitializeLock)
         {
             if (s_Initialized)
             {
                 if (s_InitializeException != null)
                 {
                     throw s_InitializeException;
                 }
                 return;
             }
             try
             {
                 ProfileSection profileAppConfig = MTConfigUtil.GetProfileAppConfig();
                 bool           fAnonEnabled     = HostingEnvironment.IsHosted ? AnonymousIdentificationModule.Enabled : true;
                 Type           inheritsFromType = InheritsFromType;
                 bool           hasLowTrust      = HttpRuntime.HasAspNetHostingPermission(AspNetHostingPermissionLevel.Low);
                 s_Properties = new SettingsPropertyCollection();
                 AddPropertySettingsFromConfig(inheritsFromType, fAnonEnabled, hasLowTrust, ProfileManager.DynamicProfileProperties, null);
                 if (inheritsFromType != typeof(ProfileBase))
                 {
                     PropertyInfo[]      properties = typeof(ProfileBase).GetProperties();
                     NameValueCollection values     = new NameValueCollection(properties.Length);
                     foreach (PropertyInfo info in properties)
                     {
                         values.Add(info.Name, string.Empty);
                     }
                     foreach (PropertyInfo info2 in inheritsFromType.GetProperties())
                     {
                         if (values[info2.Name] == null)
                         {
                             ProfileProvider     provider           = hasLowTrust ? ProfileManager.Provider : null;
                             bool                isReadOnly         = false;
                             SettingsSerializeAs providerSpecific   = SettingsSerializeAs.ProviderSpecific;
                             string              defaultValue       = string.Empty;
                             bool                allow              = false;
                             string              customProviderData = null;
                             foreach (Attribute attribute in Attribute.GetCustomAttributes(info2, true))
                             {
                                 if (attribute is SettingsSerializeAsAttribute)
                                 {
                                     providerSpecific = ((SettingsSerializeAsAttribute)attribute).SerializeAs;
                                 }
                                 else if (attribute is SettingsAllowAnonymousAttribute)
                                 {
                                     allow = ((SettingsAllowAnonymousAttribute)attribute).Allow;
                                     if (!fAnonEnabled && allow)
                                     {
                                         throw new ConfigurationErrorsException(System.Web.SR.GetString("Annoymous_id_module_not_enabled", new object[] { info2.Name }), profileAppConfig.ElementInformation.Properties["inherits"].Source, profileAppConfig.ElementInformation.Properties["inherits"].LineNumber);
                                     }
                                 }
                                 else if (attribute is ReadOnlyAttribute)
                                 {
                                     isReadOnly = ((ReadOnlyAttribute)attribute).IsReadOnly;
                                 }
                                 else if (attribute is DefaultSettingValueAttribute)
                                 {
                                     defaultValue = ((DefaultSettingValueAttribute)attribute).Value;
                                 }
                                 else if (attribute is CustomProviderDataAttribute)
                                 {
                                     customProviderData = ((CustomProviderDataAttribute)attribute).CustomProviderData;
                                 }
                                 else if (hasLowTrust && (attribute is ProfileProviderAttribute))
                                 {
                                     provider = ProfileManager.Providers[((ProfileProviderAttribute)attribute).ProviderName];
                                     if (provider == null)
                                     {
                                         throw new ConfigurationErrorsException(System.Web.SR.GetString("Profile_provider_not_found", new object[] { ((ProfileProviderAttribute)attribute).ProviderName }), profileAppConfig.ElementInformation.Properties["inherits"].Source, profileAppConfig.ElementInformation.Properties["inherits"].LineNumber);
                                     }
                                 }
                             }
                             SettingsAttributeDictionary attributes = new SettingsAttributeDictionary();
                             attributes.Add("AllowAnonymous", allow);
                             if (!string.IsNullOrEmpty(customProviderData))
                             {
                                 attributes.Add("CustomProviderData", customProviderData);
                             }
                             SettingsProperty property = new SettingsProperty(info2.Name, info2.PropertyType, provider, isReadOnly, defaultValue, providerSpecific, attributes, false, true);
                             s_Properties.Add(property);
                         }
                     }
                 }
                 if (profileAppConfig.PropertySettings != null)
                 {
                     AddPropertySettingsFromConfig(inheritsFromType, fAnonEnabled, hasLowTrust, profileAppConfig.PropertySettings, null);
                     foreach (ProfileGroupSettings settings in profileAppConfig.PropertySettings.GroupSettings)
                     {
                         AddPropertySettingsFromConfig(inheritsFromType, fAnonEnabled, hasLowTrust, settings.PropertySettings, settings.Name);
                     }
                 }
             }
             catch (Exception exception)
             {
                 if (s_InitializeException == null)
                 {
                     s_InitializeException = exception;
                 }
             }
             if (s_Properties == null)
             {
                 s_Properties = new SettingsPropertyCollection();
             }
             s_Properties.SetReadOnly();
             s_Initialized = true;
         }
         if (s_InitializeException != null)
         {
             throw s_InitializeException;
         }
     }
 }
Example #8
0
 public SettingsAttributeDictionary(SettingsAttributeDictionary attributes)
 {
 }