protected virtual SalesforceProfileProperty GetProviderProperty(ProfilePropertySettings property, string providerName)
        {
            if (string.IsNullOrEmpty(property.CustomProviderData))
            {
                return(null);
            }

            string[] data = property.CustomProviderData.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries);

            foreach (string providerStr in data)
            {
                string[] provideData = providerStr.Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries);

                if (provideData.Length == 2 && provideData[0] == providerName && !string.IsNullOrEmpty(provideData[1]))
                {
                    return(new SalesforceProfileProperty
                    {
                        Name = property.Name,
                        SalesforceName = provideData[1]
                    });
                }
            }

            return(null);
        }
Example #2
0
        static Type GetPropertyType(ProfileGroupSettings pgs, ProfilePropertySettings pps)
        {
            Type type = HttpApplication.LoadType(pps.Type);

            if (type != null)
            {
                return(type);
            }

            Type profileType = null;

            if (pgs == null)
            {
                profileType = ProfileParser.GetProfileCommonType(HttpContext.Current);
            }
            else
            {
                profileType = ProfileParser.GetProfileGroupType(HttpContext.Current, pgs.Name);
            }

            if (profileType == null)
            {
                return(null);
            }

            PropertyInfo pi = profileType.GetProperty(pps.Name);

            if (pi != null)
            {
                return(pi.PropertyType);
            }

            return(null);
        }
Example #3
0
        public void NameValidatorFailures()
        {
            ProfilePropertySettings p = new ProfilePropertySettings("Hi");
            bool f;

            f = false; try { p.Name = ""; } catch (ConfigurationErrorsException e) { f = true; } Assert.IsTrue(f, "A1");
            //			f = false; try { p.Name = "1Hi"; } catch (ConfigurationErrorsException e) { f = true; } Assert.IsTrue (f, "A2");
            //			f = false; try { p.Name = "Hi$"; } catch (ConfigurationErrorsException e) { f = true; } Assert.IsTrue (f, "A3");
            //			f = false; try { p.Name = "12345"; } catch (ConfigurationErrorsException e) { f = true; } Assert.IsTrue (f, "A3");
        }
Example #4
0
        public void NameValidatorSuccess()
        {
            ProfilePropertySettings p = new ProfilePropertySettings("Hi");

            p.Name = "hi";
            p.Name = "hi_there";
            p.Name = "string";
            p.Name = "Type";
            p.Name = "Property";
        }
Example #5
0
        public void Defaults()
        {
            ProfilePropertySettings p = new ProfilePropertySettings("Hi");

            Assert.AreEqual("Hi", p.Name, "A1");
            Assert.IsFalse(p.AllowAnonymous, "A2");
            Assert.AreEqual("", p.CustomProviderData, "A3");
            Assert.AreEqual("", p.DefaultValue, "A4");
            Assert.AreEqual("", p.Provider, "A5");
            Assert.IsFalse(p.ReadOnly, "A6");
            Assert.AreEqual(SerializationMode.ProviderSpecific, p.SerializeAs, "A7");
            Assert.AreEqual("string", p.Type, "A8");
        }
Example #6
0
 private static void SetProviderForProperty(ProfilePropertySettings pps)
 {
     if ((pps.Provider == null) || (pps.Provider.Length < 1))
     {
         pps.ProviderInternal = ProfileManager.Provider;
     }
     else
     {
         pps.ProviderInternal = ProfileManager.Providers[pps.Provider];
     }
     if (pps.ProviderInternal == null)
     {
         throw new ConfigurationErrorsException(System.Web.SR.GetString("Profile_provider_not_found", new object[] { pps.Provider }), pps.ElementInformation.Properties["provider"].Source, pps.ElementInformation.Properties["provider"].LineNumber);
     }
 }
Example #7
0
        //////////////////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////////////////
        static private void SetProviderForProperty(ProfilePropertySettings pps)
        {
            if (pps.Provider == null || pps.Provider.Length < 1)
            {
                pps.ProviderInternal = ProfileManager.Provider; // Use default provider
            }
            else
            {
                pps.ProviderInternal = ProfileManager.Providers[pps.Provider]; // Use specified provider
            }

            // Provider not found?
            if (pps.ProviderInternal == null)
            {
                throw new ConfigurationErrorsException(SR.GetString(SR.Profile_provider_not_found, pps.Provider), pps.ElementInformation.Properties["provider"].Source, pps.ElementInformation.Properties["provider"].LineNumber);
            }
        }
Example #8
0
        static SettingsProperty CreateSettingsProperty(ProfileGroupSettings pgs, ProfilePropertySettings pps)
        {
            string           name = ((pgs == null) ? String.Empty : pgs.Name + ".") + pps.Name;
            SettingsProperty sp   = new SettingsProperty(name);

            sp.Attributes.Add("AllowAnonymous", pps.AllowAnonymous);
            sp.DefaultValue = pps.DefaultValue;
            sp.IsReadOnly   = pps.ReadOnly;
            sp.Provider     = ProfileManager.Provider;
            sp.ThrowOnErrorDeserializing = false;
            sp.ThrowOnErrorSerializing   = true;

            if (pps.Type.Length == 0 || pps.Type == "string")
            {
                sp.PropertyType = typeof(string);
            }
            else
            {
                sp.PropertyType = GetPropertyType(pgs, pps);
            }

            switch (pps.SerializeAs)
            {
            case SerializationMode.Binary:
                sp.SerializeAs = SettingsSerializeAs.Binary;
                break;

            case SerializationMode.ProviderSpecific:
                sp.SerializeAs = SettingsSerializeAs.ProviderSpecific;
                break;

            case SerializationMode.String:
                sp.SerializeAs = SettingsSerializeAs.String;
                break;

            case SerializationMode.Xml:
                sp.SerializeAs = SettingsSerializeAs.Xml;
                break;
            }

            return(sp);
        }
 public void Add(ProfilePropertySettings propertySettings)
 {
 }
 public void Set(ProfilePropertySettings propertySettings)
 {
 }
 public int IndexOf(ProfilePropertySettings propertySettings)
 {
 }
Example #12
0
 // Methods
 public void Add(ProfilePropertySettings propertySettings)
 {
 }
Example #13
0
 public int IndexOf(ProfilePropertySettings propertySettings)
 {
 }
Example #14
0
 public void Set(ProfilePropertySettings propertySettings)
 {
 }
Example #15
0
        public static void Main()
        {
            // Process the System.Web.Configuration.ProfileSectionobject.
            try
            {
                // Get the Web application configuration.
                System.Configuration.Configuration configuration =
                    System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("/aspnet");

                // Get the section.
                System.Web.Configuration.ProfileSection profileSection =
                    (System.Web.Configuration.ProfileSection)
                    configuration.GetSection("system.web/profile");
// <Snippet4>

// Get the current AutomaticSaveEnabled property value.
                Console.WriteLine(
                    "Current AutomaticSaveEnabled value: '{0}'", profileSection.AutomaticSaveEnabled);

// Set the AutomaticSaveEnabled property to false.
                profileSection.AutomaticSaveEnabled = false;

// </Snippet4>

// <Snippet5>

// Get the current DefaultProvider property value.
                Console.WriteLine(
                    "Current DefaultProvider value: '{0}'", profileSection.DefaultProvider);

// Set the DefaultProvider property to "AspNetSqlProvider".
                profileSection.DefaultProvider = "AspNetSqlProvider";

// </Snippet5>

// <Snippet6>

// Get the current Inherits property value.
                Console.WriteLine(
                    "Current Inherits value: '{0}'", profileSection.Inherits);

// Set the Inherits property to
// "CustomProfiles.MyCustomProfile, CustomProfiles.dll".
                profileSection.Inherits = "CustomProfiles.MyCustomProfile, CustomProfiles.dll";

// </Snippet6>

// <Snippet7>

// <Snippet10>
// Display all current root ProfilePropertySettings.
                Console.WriteLine("Current Root ProfilePropertySettings:");
                int rootPPSCtr = 0;
                foreach (ProfilePropertySettings rootPPS in profileSection.PropertySettings)
                {
                    Console.WriteLine("  {0}: ProfilePropertySetting '{1}'", ++rootPPSCtr,
                                      rootPPS.Name);
                }
// </Snippet10>

// <Snippet11>
// <Snippet14>
// Get and modify a root ProfilePropertySettings object.
                Console.WriteLine(
                    "Display and modify 'LastReadDate' ProfilePropertySettings:");
                ProfilePropertySettings profilePropertySettings =
                    profileSection.PropertySettings["LastReadDate"];
// </Snippet14>

// <Snippet15>
// Get the current ReadOnly property value.
                Console.WriteLine(
                    "Current ReadOnly value: '{0}'", profilePropertySettings.ReadOnly);

// Set the ReadOnly property to true.
                profilePropertySettings.ReadOnly = true;
// </Snippet15>

// <Snippet16>
// Get the current AllowAnonymous property value.
                Console.WriteLine(
                    "Current AllowAnonymous value: '{0}'", profilePropertySettings.AllowAnonymous);

// Set the AllowAnonymous property to true.
                profilePropertySettings.AllowAnonymous = true;
// </Snippet16>

// <Snippet17>
// Get the current SerializeAs property value.
                Console.WriteLine(
                    "Current SerializeAs value: '{0}'", profilePropertySettings.SerializeAs);

// Set the SerializeAs property to SerializationMode.Binary.
                profilePropertySettings.SerializeAs = SerializationMode.Binary;
// </Snippet17>

// <Snippet18>
// Get the current Type property value.
                Console.WriteLine(
                    "Current Type value: '{0}'", profilePropertySettings.Type);

// Set the Type property to "System.DateTime".
                profilePropertySettings.Type = "System.DateTime";
// </Snippet18>

// <Snippet19>
// Get the current DefaultValue property value.
                Console.WriteLine(
                    "Current DefaultValue value: '{0}'", profilePropertySettings.DefaultValue);

// Set the DefaultValue property to "March 16, 2004".
                profilePropertySettings.DefaultValue = "March 16, 2004";
// </Snippet19>

// <Snippet20>
// Get the current ProviderName property value.
                Console.WriteLine(
                    "Current ProviderName value: '{0}'", profilePropertySettings.Provider);

// Set the ProviderName property to "AspNetSqlRoleProvider".
                profilePropertySettings.Provider = "AspNetSqlRoleProvider";
// </Snippet20>

// <Snippet21>
// Get the current Name property value.
                Console.WriteLine(
                    "Current Name value: '{0}'", profilePropertySettings.Name);

// Set the Name property to "LastAccessDate".
                profilePropertySettings.Name = "LastAccessDate";
// </Snippet21>
// </Snippet11>

// <Snippet12>
// Display all current ProfileGroupSettings.
                Console.WriteLine("Current ProfileGroupSettings:");
                int PGSCtr = 0;
                foreach (ProfileGroupSettings propGroups in profileSection.PropertySettings.GroupSettings)
                {
                    Console.WriteLine("  {0}: ProfileGroupSetting '{1}'", ++PGSCtr,
                                      propGroups.Name);
                    int PPSCtr = 0;
                    foreach (ProfilePropertySettings props in propGroups.PropertySettings)
                    {
                        Console.WriteLine("    {0}: ProfilePropertySetting '{1}'", ++PPSCtr,
                                          props.Name);
                    }
                }
// </Snippet12>

// <Snippet13>
// Add a new group.
                ProfileGroupSettings newPropGroup = new ProfileGroupSettings("Forum");
                profileSection.PropertySettings.GroupSettings.Add(newPropGroup);

// <Snippet22>
// Add a new PropertySettings to the group.
                ProfilePropertySettings newProp = new ProfilePropertySettings("AvatarImage");
                newProp.Type = "System.String, System.dll";
                newPropGroup.PropertySettings.Add(newProp);
// </Snippet22>

// <Snippet1>
// Remove a PropertySettings from the group.
                newPropGroup.PropertySettings.Remove("AvatarImage");
                newPropGroup.PropertySettings.RemoveAt(0);
// </Snippet1>

// <Snippet2>
// Clear all PropertySettings from the group.
                newPropGroup.PropertySettings.Clear();
// </Snippet2>
// </Snippet13>

// </Snippet7>

// <Snippet8>

// Display all current Providers.
                Console.WriteLine("Current Providers:");
                int providerCtr = 0;
                foreach (ProviderSettings provider in profileSection.Providers)
                {
                    Console.WriteLine("  {0}: Provider '{1}' of type '{2}'", ++providerCtr,
                                      provider.Name, provider.Type);
                }

// Add a new provider.
                profileSection.Providers.Add(new ProviderSettings("AspNetSqlProvider", "...SqlProfileProvider"));

// </Snippet8>

// <Snippet9>

// Get the current Enabled property value.
                Console.WriteLine(
                    "Current Enabled value: '{0}'", profileSection.Enabled);

// Set the Enabled property to false.
                profileSection.Enabled = false;

// </Snippet9>

                // Update if not locked.
                if (!profileSection.SectionInformation.IsLocked)
                {
                    configuration.Save();
                    Console.WriteLine("** Configuration updated.");
                }
                else
                {
                    Console.WriteLine("** Could not update, section is locked.");
                }
            }
            catch (System.ArgumentException e)
            {
                // Unknown error.
                Console.WriteLine(
                    "A invalid argument exception detected in UsingProfileSection Main. Check your");
                Console.WriteLine("command line for errors.");
            }
        }
Example #16
0
 public static void AddDynamicProfileProperty(ProfilePropertySettings property)
 {
     BuildManager.ThrowIfPreAppStartNotRunning();
     s_dynamicProperties.Add(property);
 }
Example #17
0
        void AddProfileClassProperty(ProfileSection ps, CodeTypeDeclaration profileClass, ProfilePropertySettings pset)
        {
            string name = pset.Name;

            if (String.IsNullOrEmpty(name))
            {
                throw new HttpException("Profile property 'Name' attribute cannot be null.");
            }
            CodeMemberProperty property = new CodeMemberProperty();
            string             typeName = pset.Type;

            if (typeName == "string")
            {
                typeName = "System.String";
            }
            property.Name       = name;
            property.Type       = GetProfilePropertyType(typeName);
            property.Attributes = MemberAttributes.Public;

            CodeAttributeDeclarationCollection collection = new CodeAttributeDeclarationCollection();

            GetProfileProviderAttribute(ps, collection, pset.Provider);
            GetProfileSettingsSerializeAsAttribute(ps, collection, pset.SerializeAs);

            property.CustomAttributes = collection;
            CodeMethodReturnStatement ret  = new CodeMethodReturnStatement();
            CodeCastExpression        cast = new CodeCastExpression();

            ret.Expression = cast;

            CodeMethodReferenceExpression mref = new CodeMethodReferenceExpression(
                new CodeThisReferenceExpression(),
                "GetPropertyValue");
            CodeMethodInvokeExpression minvoke = new CodeMethodInvokeExpression(
                mref,
                new CodeExpression[] { new CodePrimitiveExpression(name) }
                );

            cast.TargetType = new CodeTypeReference(typeName);
            cast.Expression = minvoke;
            property.GetStatements.Add(ret);

            if (!pset.ReadOnly)
            {
                mref = new CodeMethodReferenceExpression(
                    new CodeThisReferenceExpression(),
                    "SetPropertyValue");
                minvoke = new CodeMethodInvokeExpression(
                    mref,
                    new CodeExpression[] { new CodePrimitiveExpression(name), new CodeSnippetExpression("value") }
                    );
                property.SetStatements.Add(minvoke);
            }


            profileClass.Members.Add(property);
        }
Example #18
0
        protected void Page_Load(object sender, EventArgs e)
        {
            var umbracoVersion = IO.Container.Resolve <IUmbracoVersion>();

            bool storePresent;

            IO.Container.Resolve <ICMSInstaller>().InstallStarterkit("demo", out storePresent);

            var admin         = User.GetUser(0);
            var configuration = WebConfigurationManager.OpenWebConfiguration("~");

            //  change UmbracoMembershipProvider to this:
            // <add name="UmbracoMembershipProvider" minRequiredPasswordLength="4" minRequiredNonalphanumericCharacters="0" type="umbraco.providers.members.UmbracoMembershipProvider" enablePasswordRetrieval="false" enablePasswordReset="false" requiresQuestionAndAnswer="false" defaultMemberTypeAlias="Customers" passwordFormat="Hashed" />

            var systemWeb = configuration.SectionGroups["system.web"];

            var membershipSection = (MembershipSection)systemWeb.Sections["membership"];

            var umbracoMembershipProvider = membershipSection.Providers["UmbracoMembershipProvider"];

            if (umbracoMembershipProvider.Parameters["defaultMemberTypeAlias"] != "Customers")
            {
                if (umbracoMembershipProvider.Parameters.Get("minRequiredPasswordLength") == null)
                {
                    umbracoMembershipProvider.Parameters.Add("minRequiredPasswordLength", "4");
                }

                if (umbracoMembershipProvider.Parameters.Get("minRequiredNonalphanumericCharacters") == null)
                {
                    umbracoMembershipProvider.Parameters.Add("minRequiredNonalphanumericCharacters", "0");
                }

                umbracoMembershipProvider.Parameters.Set("defaultMemberTypeAlias", "Customers");
            }


            // add profile to system.web, or add new fields if they are not there yet
            var profileSection = (ProfileSection)systemWeb.Sections["profile"];

            if (profileSection.DefaultProvider != "UmbracoMemberProfileProvider")
            {
                profileSection.DefaultProvider      = "UmbracoMemberProfileProvider";
                profileSection.Enabled              = true;
                profileSection.AutomaticSaveEnabled = false;

                //	<profile defaultProvider="UmbracoMemberProfileProvider" enabled="true" automaticSaveEnabled="false">
                //	<providers>
                //		<clear />
                //		<add name="UmbracoMemberProfileProvider" type="umbraco.providers.members.UmbracoProfileProvider, umbraco.providers" />
                //	</providers>
                //	<properties>
                //		<clear />
                //		<add name="customerFirstName" allowAnonymous="false" provider="UmbracoMemberProfileProvider" type="System.String" />
                //		<add name="customerLastName" allowAnonymous="false" provider="UmbracoMemberProfileProvider" type="System.String" />
                //		<add name="customerStreet" allowAnonymous="false" provider="UmbracoMemberProfileProvider" type="System.String" />
                //		<add name="customerStreetNumber" allowAnonymous="false" provider="UmbracoMemberProfileProvider" type="System.String" />
                //		<add name="customerZipCode" allowAnonymous="false" provider="UmbracoMemberProfileProvider" type="System.String" />
                //		<add name="customerCity" allowAnonymous="false" provider="UmbracoMemberProfileProvider" type="System.String" />
                //		<add name="customerCountry" allowAnonymous="false" provider="UmbracoMemberProfileProvider" type="System.String" />
                //	</properties>
                //</profile>

                var providerSettings = new ProviderSettings
                {
                    Name = "UmbracoMemberProfileProvider",
                    Type =
                        "umbraco.providers.members.UmbracoProfileProvider, umbraco.providers"
                };

                profileSection.Providers.Add(providerSettings);
                profileSection.PropertySettings.Clear();
                var customerFirstName = new ProfilePropertySettings("customerFirstName", false, SerializationMode.String,
                                                                    "UmbracoMemberProfileProvider", string.Empty, "System.String", false, string.Empty);
                profileSection.PropertySettings.Add(customerFirstName);
                var customerLastName = new ProfilePropertySettings("customerLastName", false, SerializationMode.String,
                                                                   "UmbracoMemberProfileProvider", string.Empty, "System.String", false, string.Empty);
                profileSection.PropertySettings.Add(customerLastName);
                var customerStreet = new ProfilePropertySettings("customerStreet", false, SerializationMode.String,
                                                                 "UmbracoMemberProfileProvider", string.Empty, "System.String", false, string.Empty);
                profileSection.PropertySettings.Add(customerStreet);
                var customerStreetNumber = new ProfilePropertySettings("customerStreetNumber", false, SerializationMode.String,
                                                                       "UmbracoMemberProfileProvider", string.Empty, "System.String", false, string.Empty);
                profileSection.PropertySettings.Add(customerStreetNumber);
                var customerZipCode = new ProfilePropertySettings("customerZipCode", false, SerializationMode.String,
                                                                  "UmbracoMemberProfileProvider", string.Empty, "System.String", false, string.Empty);
                profileSection.PropertySettings.Add(customerZipCode);
                var customerCity = new ProfilePropertySettings("customerCity", false, SerializationMode.String,
                                                               "UmbracoMemberProfileProvider", string.Empty, "System.String", false, string.Empty);
                profileSection.PropertySettings.Add(customerCity);
                var customerCountry = new ProfilePropertySettings("customerCountry", false, SerializationMode.String,
                                                                  "UmbracoMemberProfileProvider", string.Empty, "System.String", false, string.Empty);
                profileSection.PropertySettings.Add(customerCountry);
            }

            configuration.Save();

            // generate new membertype based on properties above
            // add them to both customer profile and order

            var customersType = MemberType.GetByAlias("Customers");

            if (customersType == null)
            {
                try
                {
                    customersType = MemberType.MakeNew(admin, "Customers");
                }
                catch
                {
                    Log.Instance.LogError("Umbraco Failed to create 'Customers' MemberType");
                    // Umbraco bug with SQLCE + MemberType.MakeNew requires this catch, membertype will not be created...
                }
            }

            var uwbsOrdersType = DocumentType.GetByAlias(Order.NodeAlias);

            if (customersType != null && uwbsOrdersType != null)
            {
                var customerTab   = uwbsOrdersType.getVirtualTabs.FirstOrDefault(x => x.Caption.ToLowerInvariant() == "customer");
                var customerTabId = customerTab == null?uwbsOrdersType.AddVirtualTab("Customer") : customerTab.Id;

                var shippingTab   = uwbsOrdersType.getVirtualTabs.FirstOrDefault(x => x.Caption.ToLowerInvariant() == "shipping");
                var shippingTabId = shippingTab == null?uwbsOrdersType.AddVirtualTab("Shipping") : shippingTab.Id;

                // todo V7 version!
                var stringDataType             = umbracoVersion.GetDataTypeDefinition("Umbraco.Textbox", new Guid("0cc0eba1-9960-42c9-bf9b-60e150b429ae"));
                var stringDataTypeDef          = new DataTypeDefinition(stringDataType.Id);
                var textboxMultipleDataType    = umbracoVersion.GetDataTypeDefinition("Umbraco.TextboxMultiple", new Guid("c6bac0dd-4ab9-45b1-8e30-e4b619ee5da3"));
                var textboxMultipleDataTypeDef = new DataTypeDefinition(textboxMultipleDataType.Id);

                foreach (var propertyKey in profileSection.PropertySettings.AllKeys)
                {
                    customersType.AddPropertyType(stringDataTypeDef, propertyKey, "#" + UppercaseFirstCharacter(propertyKey));

                    if (uwbsOrdersType.PropertyTypes.All(x => x.Alias.ToLowerInvariant() != propertyKey.ToLowerInvariant()))
                    {
                        var property = uwbsOrdersType.AddPropertyType(stringDataTypeDef, propertyKey, "#" + UppercaseFirstCharacter(propertyKey));

                        var propertyShippingKey = propertyKey.Replace("customer", "shipping");

                        var shippingProperty = uwbsOrdersType.AddPropertyType(stringDataTypeDef, propertyShippingKey, "#" + UppercaseFirstCharacter(propertyShippingKey));

                        property.TabId         = customerTabId;
                        shippingProperty.TabId = shippingTabId;
                    }
                }

                customersType.Save();

                // todo V7 version!
                var extraMessageProperty = uwbsOrdersType.AddPropertyType(textboxMultipleDataTypeDef, "extraMessage", "#ExtraMessage");
                extraMessageProperty.TabId = customerTabId;

                uwbsOrdersType.Save();
            }

            // create membergroup "customers", as set in the UmbracoMembershipProvider -> defaultMemberTypeAlias
            if (MemberGroup.GetByName("Customers") == null)
            {
                MemberGroup.MakeNew("Customers", admin);
            }

            Document.RePublishAll();
            library.RefreshContent();
        }