Esempio n. 1
0
        // FIXME: there should be some validation of syntactic correctness of the member/class name
        // for the groups/properties. For now it's left to the compiler to report errors.
        //
        // CodeGenerator.IsValidLanguageIndependentIdentifier (id) - use that
        //
        bool ProcessCustomProfile(ProfileSection ps, AppCodeAssembly defasm)
        {
            CodeCompileUnit unit = new CodeCompileUnit();
            CodeNamespace   ns   = new CodeNamespace(null);

            unit.Namespaces.Add(ns);
            defasm.AddUnit(unit);

            ns.Imports.Add(new CodeNamespaceImport("System"));
            ns.Imports.Add(new CodeNamespaceImport("System.Configuration"));
            ns.Imports.Add(new CodeNamespaceImport("System.Web"));
            ns.Imports.Add(new CodeNamespaceImport("System.Web.Profile"));

            RootProfilePropertySettingsCollection props = ps.PropertySettings;

            if (props == null)
            {
                return(true);
            }

            SortedList <string, string> groupProperties = new SortedList <string, string> ();
            string groupName;

            foreach (ProfileGroupSettings pgs in props.GroupSettings)
            {
                groupName = MakeGroupName(pgs.Name);
                groupProperties.Add(groupName, pgs.Name);
                BuildProfileClass(ps, groupName, pgs.PropertySettings, ns,
                                  "System.Web.Profile.ProfileGroupBase", true, null);
            }

            string baseType = ps.Inherits;

            if (String.IsNullOrEmpty(baseType))
            {
                baseType = "System.Web.Profile.ProfileBase";
            }
            else
            {
                string[] parts = baseType.Split(new char[] { ',' });
                if (parts.Length > 1)
                {
                    baseType = parts [0].Trim();
                }
            }

            bool baseIsGlobal;

            if (baseType.IndexOf('.') != -1)
            {
                baseIsGlobal = true;
            }
            else
            {
                baseIsGlobal = false;
            }

            BuildProfileClass(ps, "ProfileCommon", props, ns, baseType, baseIsGlobal, groupProperties);
            return(true);
        }
Esempio n. 2
0
//		void PutCustomProfileInContext (HttpContext context, string assemblyName)
//		{
//			Type type = Type.GetType (String.Format ("ProfileCommon, {0}",
//								 Path.GetFileNameWithoutExtension (assemblyName)));
//			ProfileBase pb = Activator.CreateInstance (type) as ProfileBase;
//			if (pb != null)
//				context.Profile = pb;
//		}

        public static bool HaveCustomProfile(ProfileSection ps)
        {
            if (ps == null || !ps.Enabled)
            {
                return(false);
            }

            RootProfilePropertySettingsCollection props  = ps.PropertySettings;
            ProfileGroupSettingsCollection        groups = props != null ? props.GroupSettings : null;

            if (!String.IsNullOrEmpty(ps.Inherits) || (props != null && props.Count > 0) || (groups != null && groups.Count > 0))
            {
                return(true);
            }

            return(false);
        }
 /// <summary>
 /// Sets the properties list.
 /// </summary>
 /// <param name="settings">The settings.</param>
 private void SetPropertiesList(RootProfilePropertySettingsCollection settings)
 {
     foreach (ProfilePropertySettings propertyDefinition in settings)
     {
         string customProviderData = propertyDefinition.CustomProviderData.Trim();
         if ((!string.IsNullOrEmpty(customProviderData)) && customProviderData.StartsWith("crm|"))
         {
             string crmPropertyName = customProviderData.Split('|')[1];
             if (!string.IsNullOrEmpty(crmPropertyName))
             {
                 crmPropertyName = crmPropertyName.Trim();
                 var crmPropertyType = this.profileRepository.GetPropertyType(crmPropertyName).ToString();
                 this.propertyNames.Add(crmPropertyName, crmPropertyType);
             }
         }
     }
 }
Esempio n. 4
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;
                }
            }
        }