Beispiel #1
0
 private void CalculateProfilePropertySettingsHash(ProfilePropertySettingsCollection settings, HashCodeCombiner hashCombiner)
 {
     foreach (ProfilePropertySettings settings2 in settings)
     {
         hashCombiner.AddObject(settings2.Name);
         hashCombiner.AddObject(settings2.Type);
     }
 }
 private void CalculateProfilePropertySettingsHash(ProfilePropertySettingsCollection settings, HashCodeCombiner hashCombiner)
 {
     foreach (ProfilePropertySettings settings2 in settings)
     {
         hashCombiner.AddObject(settings2.Name);
         hashCombiner.AddObject(settings2.Type);
     }
 }
 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 AddProfilePropertySettingsForCompilation(ProfilePropertySettingsCollection propertyCollection, Hashtable ht, string groupName)
 {
     foreach (ProfilePropertySettings settings in propertyCollection)
     {
         ProfileNameTypeStruct struct2 = new ProfileNameTypeStruct();
         if (groupName != null)
         {
             struct2.Name = groupName + "." + settings.Name;
         }
         else
         {
             struct2.Name = settings.Name;
         }
         Type typeInternal = settings.TypeInternal;
         if (typeInternal == null)
         {
             typeInternal = ResolvePropertyTypeForCommonTypes(settings.Type.ToLower(CultureInfo.InvariantCulture));
         }
         if (typeInternal == null)
         {
             typeInternal = BuildManager.GetType(settings.Type, false);
         }
         if (typeInternal == null)
         {
             struct2.PropertyCodeRefType = new CodeTypeReference(settings.Type);
         }
         else
         {
             struct2.PropertyCodeRefType = new CodeTypeReference(typeInternal);
         }
         struct2.PropertyType = typeInternal;
         settings.TypeInternal = typeInternal;
         struct2.IsReadOnly = settings.ReadOnly;
         struct2.LineNumber = settings.ElementInformation.Properties["name"].LineNumber;
         struct2.FileName = settings.ElementInformation.Properties["name"].Source;
         ht.Add(struct2.Name, struct2);
     }
 }
        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);
            }
        }
 //////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////
 private static void AddProfilePropertySettingsForCompilation(ProfilePropertySettingsCollection propertyCollection, Hashtable ht, string groupName) {
     foreach (ProfilePropertySettings pps in propertyCollection) {
         ProfileNameTypeStruct prop = new ProfileNameTypeStruct();
         if (groupName != null) {
             prop.Name = groupName + "." + pps.Name;
         }
         else {
             prop.Name = pps.Name;
         }
         Type t = pps.TypeInternal;
         if (t == null)
             t = ResolvePropertyTypeForCommonTypes(pps.Type.ToLower(System.Globalization.CultureInfo.InvariantCulture));
         if (t == null)
             t = BuildManager.GetType(pps.Type, false);
         if (t == null) {
             prop.PropertyCodeRefType = new CodeTypeReference(pps.Type);
         }
         else {
             prop.PropertyCodeRefType = new CodeTypeReference(t);
         }
         prop.PropertyType = t;
         pps.TypeInternal = t;
         prop.IsReadOnly = pps.ReadOnly;
         prop.LineNumber = pps.ElementInformation.Properties["name"].LineNumber;
         prop.FileName = pps.ElementInformation.Properties["name"].Source;
         ht.Add(prop.Name, prop);
     }
 }
Beispiel #7
0
		void BuildProfileClass (ProfileSection ps, string className, ProfilePropertySettingsCollection psc,
					CodeNamespace ns, string baseClass, bool baseIsGlobal,
					SortedList <string, string> groupProperties)
		{
			CodeTypeDeclaration profileClass = new CodeTypeDeclaration (className);
			CodeTypeReference cref = new CodeTypeReference (baseClass);
			if (baseIsGlobal)
				cref.Options |= CodeTypeReferenceOptions.GlobalReference;
			profileClass.BaseTypes.Add (cref);
			profileClass.TypeAttributes = TypeAttributes.Public;
			ns.Types.Add (profileClass);
			
			foreach (ProfilePropertySettings pset in psc)
				AddProfileClassProperty (ps, profileClass, pset);
			if (groupProperties != null && groupProperties.Count > 0)
				foreach (KeyValuePair <string, string> group in groupProperties)
					AddProfileClassGroupProperty (group.Key, group.Value, profileClass);
			AddProfileClassGetProfileMethod (profileClass);
		}