Inheritance: System.Collections.Hashtable
		public void GetUserScopedPropertyValues ()
		{
			SettingsAttributeDictionary dict = new SettingsAttributeDictionary ();
			UserScopedSettingAttribute attr = new UserScopedSettingAttribute ();
			dict.Add (attr.GetType(), attr);

			LocalFileSettingsProvider prov = new LocalFileSettingsProvider ();
			SettingsContext ctx = new SettingsContext ();
			SettingsProperty p = new SettingsProperty ("property",
								   typeof (int),
								   prov,
								   false,
								   10,
								   SettingsSerializeAs.Binary,
								   dict,
								   false,
								   false);
			SettingsPropertyCollection col = new SettingsPropertyCollection ();
			SettingsPropertyValueCollection vals;

			col.Add (p);

			prov.Initialize (null, null);

			vals = prov.GetPropertyValues (ctx, col);
			Assert.IsNotNull (vals, "A1");
			Assert.AreEqual (1, vals.Count, "A2");
		}
 ////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////
 public SettingsProperty(SettingsProperty propertyToCopy) 
 {
     _Name = propertyToCopy.Name;
     _IsReadOnly = propertyToCopy.IsReadOnly;
     _DefaultValue = propertyToCopy.DefaultValue;
     _SerializeAs = propertyToCopy.SerializeAs;
     _Provider = propertyToCopy.Provider;
     _PropertyType = propertyToCopy.PropertyType;
     _ThrowOnErrorDeserializing = propertyToCopy.ThrowOnErrorDeserializing;
     _ThrowOnErrorSerializing = propertyToCopy.ThrowOnErrorSerializing;
     _Attributes = new SettingsAttributeDictionary(propertyToCopy.Attributes);
 }
 public SettingsProperty(string name, Type propertyType, SettingsProvider provider, bool isReadOnly, object defaultValue, SettingsSerializeAs serializeAs, SettingsAttributeDictionary attributes, bool throwOnErrorDeserializing, bool throwOnErrorSerializing)
 {
     this._Name = name;
     this._PropertyType = propertyType;
     this._Provider = provider;
     this._IsReadOnly = isReadOnly;
     this._DefaultValue = defaultValue;
     this._SerializeAs = serializeAs;
     this._Attributes = attributes;
     this._ThrowOnErrorDeserializing = throwOnErrorDeserializing;
     this._ThrowOnErrorSerializing = throwOnErrorSerializing;
 }
Ejemplo n.º 4
0
        void AddProperty(String propertyName, Color defaultValue, Type propertyType)
        {
            String providerName = "LocalFileSettingsProvider";
            var    attributes   = new System.Configuration.SettingsAttributeDictionary();
            var    attr         = new System.Configuration.UserScopedSettingAttribute();

            attributes.Add(attr.TypeId, attr);
            SettingsProvider settingProvider = Properties.Settings.Default.Providers[providerName];
            var prop = new System.Configuration.SettingsProperty(
                new System.Configuration.SettingsProperty(propertyName, propertyType,
                                                          settingProvider, false, defaultValue,
                                                          System.Configuration.SettingsSerializeAs.String, attributes, false, false));

            MYAPPCS.Properties.Settings.Default.Properties.Add(prop);
        }
Ejemplo n.º 5
0
		public SettingsAttributeDictionary (SettingsAttributeDictionary attributes)
			: base (attributes)
		{
		}
 public SettingsAttributeDictionary(SettingsAttributeDictionary attributes) : base((Hashtable) attributes) { }
Ejemplo n.º 7
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;
		}
 ////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////
 public SettingsProperty(string name)
 {
     _Name       = name;
     _Attributes = new SettingsAttributeDictionary();
 }
Ejemplo n.º 9
0
        void CreateSettingsProperty(PropertyInfo prop, SettingsPropertyCollection properties, ref LocalFileSettingsProvider local_provider)
        {
            SettingsAttributeDictionary dict     = new SettingsAttributeDictionary();
            SettingsProvider            provider = null;
            object defaultValue             = null;
            SettingsSerializeAs serializeAs = SettingsSerializeAs.String;

            foreach (Attribute a in prop.GetCustomAttributes(false))
            {
                /* the attributes we handle natively here */
                if (a is SettingsProviderAttribute)
                {
                    Type provider_type = Type.GetType(((SettingsProviderAttribute)a).ProviderTypeName);
                    provider = (SettingsProvider)Activator.CreateInstance(provider_type);
                    provider.Initialize(null, null);
                }
                else if (a is DefaultSettingValueAttribute)
                {
                    defaultValue = ((DefaultSettingValueAttribute)a).Value;                     /* XXX this is a string.. do we convert? */
                    // note: for StringCollection, TypeDescriptor.GetConverter(prop.PropertyType) returns
                    // CollectionConverter, however this class cannot handle the XML serialized strings
                    if (prop.PropertyType == typeof(StringCollection))
                    {
                        XmlSerializer    xs     = new XmlSerializer(typeof(string[]));
                        string[]         values = (string[])xs.Deserialize(new StringReader((string)defaultValue));
                        StringCollection sc     = new StringCollection();
                        sc.AddRange(values);
                        defaultValue = sc;
                    }
                    else if (prop.PropertyType != typeof(string))
                    {
                        defaultValue = TypeDescriptor.GetConverter(prop.PropertyType).ConvertFromString((string)defaultValue);
                    }
                }
                else if (a is SettingsSerializeAsAttribute)
                {
                    serializeAs = ((SettingsSerializeAsAttribute)a).SerializeAs;
                }
                else if (a is ApplicationScopedSettingAttribute ||
                         a is UserScopedSettingAttribute)
                {
                    dict.Add(a.GetType(), a);
                }
                else
                {
                    dict.Add(a.GetType(), a);
                }
            }

            SettingsProperty setting =
                new SettingsProperty(prop.Name, prop.PropertyType, provider, false /* XXX */,
                                     defaultValue /* XXX always a string? */, serializeAs, dict,
                                     false, false);


            if (providerService != null)
            {
                setting.Provider = providerService.GetSettingsProvider(setting);
            }

            if (provider == null)
            {
                if (local_provider == null)
                {
                    local_provider = new LocalFileSettingsProvider();
                    local_provider.Initialize(null, null);
                }
                setting.Provider = local_provider;
                // .NET ends up to set this to providers.
                provider = local_provider;
            }

            if (provider != null)
            {
                /* make sure we're using the same instance of a
                 * given provider across multiple properties */
                SettingsProvider p = Providers[provider.Name];
                if (p != null)
                {
                    setting.Provider = p;
                }
            }

            properties.Add(setting);

            if (setting.Provider != null && Providers [setting.Provider.Name] == null)
            {
                Providers.Add(setting.Provider);
            }
        }
Ejemplo n.º 10
0
 public SettingsAttributeDictionary(SettingsAttributeDictionary attributes)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 11
0
		void CreateSettingsProperty (PropertyInfo prop, SettingsPropertyCollection properties, ref LocalFileSettingsProvider local_provider)
		{
			SettingsAttributeDictionary dict = new SettingsAttributeDictionary ();
			SettingsProvider provider = null;
			object defaultValue = null;
			SettingsSerializeAs serializeAs = SettingsSerializeAs.String;
			bool explicitSerializeAs = false;

			foreach (Attribute a in prop.GetCustomAttributes (false)) {
				/* the attributes we handle natively here */
				if (a is SettingsProviderAttribute) {
					Type provider_type = Type.GetType (((SettingsProviderAttribute)a).ProviderTypeName);
					provider = (SettingsProvider) Activator.CreateInstance (provider_type);
					provider.Initialize (null, null);
				}
				else if (a is DefaultSettingValueAttribute) {
					defaultValue = ((DefaultSettingValueAttribute)a).Value;
				}
				else if (a is SettingsSerializeAsAttribute) {
					serializeAs = ((SettingsSerializeAsAttribute)a).SerializeAs;
					explicitSerializeAs = true;
				}
				else if (a is ApplicationScopedSettingAttribute ||
					 a is UserScopedSettingAttribute) {
					dict.Add (a.GetType(), a);
				}
				else {
					dict.Add (a.GetType(), a);
				}
			}

			if (!explicitSerializeAs) {
				// DefaultValue is a string and if we can't convert from string to the 
				// property type then the only other option left is for the string to 
				// be XML.
				//
				TypeConverter converter = TypeDescriptor.GetConverter (prop.PropertyType);
				if (converter != null && 
				    (!converter.CanConvertFrom (typeof (string)) || 
				     !converter.CanConvertTo (typeof (string))))
					serializeAs = SettingsSerializeAs.Xml;
			}

			SettingsProperty setting =
				new SettingsProperty (prop.Name, prop.PropertyType, provider, false /* XXX */,
						      defaultValue /* XXX always a string? */, serializeAs, dict,
						      false, false);


			if (providerService != null)
				setting.Provider = providerService.GetSettingsProvider (setting);

			if (provider == null) {
				if (local_provider == null) {
					local_provider = new LocalFileSettingsProvider ();
					local_provider.Initialize (null, null);
				}
				setting.Provider = local_provider;
				// .NET ends up to set this to providers.
				provider = local_provider;
			}

			if (provider != null) {
				/* make sure we're using the same instance of a
				   given provider across multiple properties */
				SettingsProvider p = Providers[provider.Name];
				if (p != null)
					setting.Provider = p;
			}

			properties.Add (setting);

			if (setting.Provider != null && Providers [setting.Provider.Name] == null)
				Providers.Add (setting.Provider);
		}
Ejemplo n.º 12
0
        private static void AddPropertySettingsFromConfig(Type baseType, bool fAnonEnabled, bool hasLowTrust, ProfilePropertySettingsCollection settingsCollection, string groupName) {
            foreach (ProfilePropertySettings pps in settingsCollection) {
                string name = (groupName != null) ? (groupName + "." + pps.Name) : pps.Name;
                if (baseType != typeof(ProfileBase) && s_Properties[name] != null)
                    throw new ConfigurationErrorsException(SR.GetString(SR.Profile_property_already_added), null, pps.ElementInformation.Properties["name"].Source, pps.ElementInformation.Properties["name"].LineNumber);

                try {
                    if (pps.TypeInternal == null) {
                        pps.TypeInternal = ResolvePropertyType(pps.Type);
                    }
                }
                catch (Exception e) {
                    throw new ConfigurationErrorsException(SR.GetString(SR.Profile_could_not_create_type, e.Message), e, pps.ElementInformation.Properties["type"].Source, pps.ElementInformation.Properties["type"].LineNumber);
                }
                if (!fAnonEnabled) {
                    bool fAllowAnonymous = pps.AllowAnonymous;
                    if (fAllowAnonymous)
                        throw new ConfigurationErrorsException(SR.GetString(SR.Annoymous_id_module_not_enabled, pps.Name), pps.ElementInformation.Properties["allowAnonymous"].Source, pps.ElementInformation.Properties["allowAnonymous"].LineNumber);
                }
                if (hasLowTrust) {
                    SetProviderForProperty(pps);
                }
                else {
                    pps.ProviderInternal = null;
                }
                // Providers that use NetDataContractSerialzier do not require Serializable attributes any longer, only enforce this for the SqlProfileProvider
                bool requireSerializationCheck = pps.ProviderInternal == null || pps.ProviderInternal.GetType() == typeof(SqlProfileProvider);
                if (requireSerializationCheck && pps.SerializeAs == SerializationMode.Binary && !pps.TypeInternal.IsSerializable) {
                    throw new ConfigurationErrorsException(SR.GetString(SR.Property_not_serializable, pps.Name), pps.ElementInformation.Properties["serializeAs"].Source, pps.ElementInformation.Properties["serializeAs"].LineNumber);
                }

                SettingsAttributeDictionary settings = new SettingsAttributeDictionary();
                settings.Add("AllowAnonymous", pps.AllowAnonymous);
                if (!string.IsNullOrEmpty(pps.CustomProviderData))
                    settings.Add("CustomProviderData", pps.CustomProviderData);
                SettingsProperty sp = new SettingsProperty(name, pps.TypeInternal, pps.ProviderInternal, pps.ReadOnly, pps.DefaultValue, (SettingsSerializeAs)pps.SerializeAs, settings, false, true);
                s_Properties.Add(sp);
            }
        }
Ejemplo n.º 13
0
        } // OnValueLoading

        // ----------------------------------------------------------------------
        protected void CreateSettingProperty(string name, Type type, SettingsSerializeAs serializeAs, object defaultValue)
        {
            ApplicationSettings applicationSettings = ApplicationSettings;
            if (applicationSettings == null || applicationSettings.DefaultProvider == null)
            {
                return;
            }

            SettingsProperty settingsProperty = applicationSettings.Properties[name];
            if (settingsProperty != null)
            {
                return; // already present
            }

            SettingsAttributeDictionary attributes = new SettingsAttributeDictionary();
            SettingAttribute attribute;
            switch (Scope)
            {
                case SettingScope.Application:
                    // attribute = new ApplicationScopedSettingAttribute();
                    throw new NotImplementedException(); // currently not supported
                case SettingScope.User:
                    attribute = new UserScopedSettingAttribute();
                    break;
                default:
                    return;
            }
            attributes.Add(attribute.TypeId, attribute);

            settingsProperty = new SettingsProperty(
                name, // name
                type, // type
                applicationSettings.DefaultProvider, // settings provider
                false, // is readonly
                defaultValue, // default
                serializeAs, // serialize as
                attributes, // attribute
                ThrowOnErrorDeserializing, // throw on deserialization
                ThrowOnErrorSerializing); // throw on serialization

            applicationSettings.Properties.Add(settingsProperty);
        } // CreateSettingProperty
Ejemplo n.º 14
0
 public SettingsAttributeDictionary(SettingsAttributeDictionary attributes) : base((Hashtable)attributes)
 {
 }
 private static void AddPropertySettingsFromConfig(Type baseType, bool fAnonEnabled, bool hasLowTrust, ProfilePropertySettingsCollection settingsCollection, string groupName)
 {
     foreach (ProfilePropertySettings settings in settingsCollection)
     {
         string name = (groupName != null) ? (groupName + "." + settings.Name) : settings.Name;
         if ((baseType != typeof(ProfileBase)) && (s_Properties[name] != null))
         {
             throw new ConfigurationErrorsException(System.Web.SR.GetString("Profile_property_already_added"), null, settings.ElementInformation.Properties["name"].Source, settings.ElementInformation.Properties["name"].LineNumber);
         }
         try
         {
             if (settings.TypeInternal == null)
             {
                 settings.TypeInternal = ResolvePropertyType(settings.Type);
             }
         }
         catch (Exception exception)
         {
             throw new ConfigurationErrorsException(System.Web.SR.GetString("Profile_could_not_create_type", new object[] { exception.Message }), exception, settings.ElementInformation.Properties["type"].Source, settings.ElementInformation.Properties["type"].LineNumber);
         }
         if (!fAnonEnabled && settings.AllowAnonymous)
         {
             throw new ConfigurationErrorsException(System.Web.SR.GetString("Annoymous_id_module_not_enabled", new object[] { settings.Name }), settings.ElementInformation.Properties["allowAnonymous"].Source, settings.ElementInformation.Properties["allowAnonymous"].LineNumber);
         }
         if ((settings.SerializeAs == SerializationMode.Binary) && !settings.TypeInternal.IsSerializable)
         {
             throw new ConfigurationErrorsException(System.Web.SR.GetString("Property_not_serializable", new object[] { settings.Name }), settings.ElementInformation.Properties["serializeAs"].Source, settings.ElementInformation.Properties["serializeAs"].LineNumber);
         }
         if (hasLowTrust)
         {
             SetProviderForProperty(settings);
         }
         else
         {
             settings.ProviderInternal = null;
         }
         SettingsAttributeDictionary attributes = new SettingsAttributeDictionary();
         attributes.Add("AllowAnonymous", settings.AllowAnonymous);
         if (!string.IsNullOrEmpty(settings.CustomProviderData))
         {
             attributes.Add("CustomProviderData", settings.CustomProviderData);
         }
         SettingsProperty property = new SettingsProperty(name, settings.TypeInternal, settings.ProviderInternal, settings.ReadOnly, settings.DefaultValue, (SettingsSerializeAs) settings.SerializeAs, attributes, false, true);
         s_Properties.Add(property);
     }
 }
 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;
         }
     }
 }
 public SettingsProperty(string name, Type propertyType, SettingsProvider provider, bool isReadOnly, Object defaultValue, SettingsSerializeAs serializeAs, SettingsAttributeDictionary attributes, bool throwOnErrorDeserializing, bool throwOnErrorSerializing)
 {
 }
 public SettingsAttributeDictionary(SettingsAttributeDictionary attributes) : base(attributes)
 {
 }
Ejemplo n.º 19
0
 public SettingsProperty(string name, Type propertyType, SettingsProvider provider, bool isReadOnly, object defaultValue, SettingsSerializeAs serializeAs, SettingsAttributeDictionary attributes, bool throwOnErrorDeserializing, bool throwOnErrorSerializing)
 {
     this._Name         = name;
     this._PropertyType = propertyType;
     this._Provider     = provider;
     this._IsReadOnly   = isReadOnly;
     this._DefaultValue = defaultValue;
     this._SerializeAs  = serializeAs;
     this._Attributes   = attributes;
     this._ThrowOnErrorDeserializing = throwOnErrorDeserializing;
     this._ThrowOnErrorSerializing   = throwOnErrorSerializing;
 }
Ejemplo n.º 20
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.º 21
0
 public SettingsProperty(string name, Type propertyType, SettingsProvider provider, bool isReadOnly, object defaultValue, SettingsSerializeAs serializeAs, SettingsAttributeDictionary attributes, bool throwOnErrorDeserializing, bool throwOnErrorSerializing)
 {
     throw new NotImplementedException();
 }
        void CreateSettingsProperty(PropertyInfo prop, SettingsPropertyCollection properties, ref SettingsProvider local_provider)
        {
            SettingsAttributeDictionary dict     = new SettingsAttributeDictionary();
            SettingsProvider            provider = null;
            object defaultValue             = null;
            SettingsSerializeAs serializeAs = SettingsSerializeAs.String;
            bool explicitSerializeAs        = false;

            foreach (Attribute a in prop.GetCustomAttributes(false))
            {
                /* the attributes we handle natively here */
                if (a is SettingsProviderAttribute)
                {
                    var  providerTypeName = ((SettingsProviderAttribute)a).ProviderTypeName;
                    Type provider_type    = Type.GetType(providerTypeName);
                    if (provider_type == null)                      // Type failed to find the type by name
                    {
                        var typeNameParts = providerTypeName.Split('.');
                        if (typeNameParts.Length > 1)                          //Load the assembly that providerTypeName claims
                        {
                            var assy = Assembly.Load(typeNameParts[0]);
                            if (assy != null)
                            {
                                provider_type = assy.GetType(providerTypeName);                                 //try to get the type from that Assembly
                            }
                        }
                    }
                    provider = (SettingsProvider)Activator.CreateInstance(provider_type);
                    provider.Initialize(null, null);
                }
                else if (a is DefaultSettingValueAttribute)
                {
                    defaultValue = ((DefaultSettingValueAttribute)a).Value;
                }
                else if (a is SettingsSerializeAsAttribute)
                {
                    serializeAs         = ((SettingsSerializeAsAttribute)a).SerializeAs;
                    explicitSerializeAs = true;
                }
                else if (a is ApplicationScopedSettingAttribute ||
                         a is UserScopedSettingAttribute)
                {
                    dict.Add(a.GetType(), a);
                }
                else
                {
                    dict.Add(a.GetType(), a);
                }
            }

            if (!explicitSerializeAs)
            {
                // DefaultValue is a string and if we can't convert from string to the
                // property type then the only other option left is for the string to
                // be XML.
                //
                TypeConverter converter = TypeDescriptor.GetConverter(prop.PropertyType);
                if (converter != null &&
                    (!converter.CanConvertFrom(typeof(string)) ||
                     !converter.CanConvertTo(typeof(string))))
                {
                    serializeAs = SettingsSerializeAs.Xml;
                }
            }

            SettingsProperty setting =
                new SettingsProperty(prop.Name, prop.PropertyType, provider, false /* XXX */,
                                     defaultValue /* XXX always a string? */, serializeAs, dict,
                                     false, false);


            if (providerService != null)
            {
                setting.Provider = providerService.GetSettingsProvider(setting);
            }

            if (provider == null)
            {
                if (local_provider == null)
                {
                    local_provider = new LocalFileSettingsProvider() as SettingsProvider;
                    local_provider.Initialize(null, null);
                }
                setting.Provider = local_provider;
                // .NET ends up to set this to providers.
                provider = local_provider;
            }

            if (provider != null)
            {
                /* make sure we're using the same instance of a
                 * given provider across multiple properties */
                SettingsProvider p = Providers[provider.Name];
                if (p != null)
                {
                    setting.Provider = p;
                }
            }

            properties.Add(setting);

            if (setting.Provider != null && Providers [setting.Provider.Name] == null)
            {
                Providers.Add(setting.Provider);
            }
        }
Ejemplo n.º 23
0
 public SettingsProperty(string name, Type propertyType, SettingsProvider provider, bool isReadOnly, Object defaultValue, SettingsSerializeAs serializeAs, SettingsAttributeDictionary attributes, bool throwOnErrorDeserializing, bool throwOnErrorSerializing)
 {
 }
        private static void AddToColl(ProfilePropertyMetadata p, SettingsPropertyCollection retColl, bool isAuthenticated) {
            string propName = p.PropertyName;
            Type   propType = Type.GetType(p.TypeName, false, true);
            bool   allowAnon = p.AllowAnonymousAccess;
            bool   readOnly = p.IsReadOnly;

            if (!allowAnon && !isAuthenticated)
                return;

            SettingsSerializeAs serializeAs = (SettingsSerializeAs)p.SerializeAs;
            SettingsAttributeDictionary dict = new SettingsAttributeDictionary();
            dict.Add("AllowAnonymous", allowAnon);
            retColl.Add(new SettingsProperty(propName, propType, null, readOnly,p.DefaultValue, serializeAs, dict, true, true));
        }
Ejemplo n.º 25
0
 ////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////
 public SettingsProperty(string name) 
 {
     _Name = name;
     _Attributes = new SettingsAttributeDictionary();
 }