Exemple #1
0
        /// <summary>
        /// Gets the profile subtype property manager.
        /// </summary>
        /// <param name="site">The site.</param>
        /// <returns>The profile subtype property manager.</returns>
        public ProfileSubtypePropertyManager GetProfileSubtypePropertyManager(SPSite site)
        {
            var context = SPServiceContext.GetContext(site);
            var profileSubTypeManager = ProfileSubtypeManager.Get(context);
            var profileSubtype        = profileSubTypeManager.GetProfileSubtype(ProfileSubtypeManager.GetDefaultProfileName(ProfileType.User));

            return(profileSubtype.Properties);
        }
Exemple #2
0
        static void MaritalStatus()
        {
            //Code example adds a new property called Marital Status.
            using (SPSite site = new SPSite("http://servername"))
            {
                //SPServiceContext context = SPServiceContext.GetContext(site);
                //ClientContext context = new ClientContext(site);
                //ServerContext context = ServerContext.GetContext(site);
                UserProfileConfigManager upcm = new UserProfileConfigManager();

                try
                {
                    ProfilePropertyManager ppm = upcm.ProfilePropertyManager;

                    // create core property
                    CorePropertyManager cpm = ppm.GetCoreProperties();
                    CoreProperty        cp  = cpm.Create(false);
                    cp.Name        = "MaritalStatus";
                    cp.DisplayName = "Marital Status";
                    cp.Type        = PropertyDataType.StringSingleValue;
                    cp.Length      = 100;

                    cpm.Add(cp);

                    // create profile type property
                    ProfileTypePropertyManager ptpm = ppm.GetProfileTypeProperties(ProfileType.User);
                    ProfileTypeProperty        ptp  = ptpm.Create(cp);

                    ptpm.Add(ptp);

                    // create profile subtype property
                    ProfileSubtypeManager         psm  = ProfileSubtypeManager.Get();
                    ProfileSubtype                ps   = psm.GetProfileSubtype(ProfileSubtypeManager.GetDefaultProfileName(ProfileType.User));
                    ProfileSubtypePropertyManager pspm = ps.Properties;
                    ProfileSubtypeProperty        psp  = pspm.Create(ptp);

                    psp.PrivacyPolicy  = PrivacyPolicy.OptIn;
                    psp.DefaultPrivacy = Privacy.Organization;

                    pspm.Add(psp);
                }
                catch (DuplicateEntryException e)
                {
                    Console.WriteLine(e.Message);
                    Console.Read();
                }
                catch (System.Exception e2)
                {
                    Console.WriteLine(e2.Message);
                    Console.Read();
                }
            }
        }
Exemple #3
0
        public void CreateUIDProperty()
        {
            var propManager = _propertyManager.GetCoreProperties();

            var property = propManager.GetPropertyByName(UUID_PROPERTY);

            if (property != null)
            {
                return;
            }

            Logger.WriteInfo("Creating property '" + UUID_PROPERTY + "' in profile service");
            var profilePropMgr  = new UserProfileConfigManager(_context).ProfilePropertyManager;
            var corePropManager = profilePropMgr.GetCoreProperties();

            // Create the property.
            var coreProp = corePropManager.Create(false);

            coreProp.Name          = UUID_PROPERTY;
            coreProp.DisplayName   = "SPC UID";
            coreProp.Type          = PropertyDataType.String;
            coreProp.Length        = 36;
            coreProp.IsMultivalued = false;
            coreProp.IsSearchable  = true;
            corePropManager.Add(coreProp);

            // Create a profile type property and make the core property visible in the Details section page.
            var typePropManager = profilePropMgr.GetProfileTypeProperties(ProfileType.User);
            var typeProp        = typePropManager.Create(coreProp);

            typeProp.IsVisibleOnViewer = true;
            typePropManager.Add(typeProp);

            // Create a profile subtype property.
            var subtypeManager = ProfileSubtypeManager.Get(_context);
            var subtype        = subtypeManager.GetProfileSubtype(ProfileSubtypeManager.GetDefaultProfileName(ProfileType.User));
            var subtypePropMgr = profilePropMgr.GetProfileSubtypeProperties(subtype.Name);
            var subtypeProp    = subtypePropMgr.Create(typeProp);

            subtypeProp.IsUserEditable      = false;
            subtypeProp.DefaultPrivacy      = Privacy.Public;
            subtypeProp.UserOverridePrivacy = true;
            subtypePropMgr.Add(subtypeProp);

            Logger.WriteInfo("Created SPC UID property in profile service");
        }
Exemple #4
0
        /// <summary>
        /// Enumerates list of imported from 1C profile records and updates SP profiles
        /// </summary>
        /// <returns>true on success, false on failed</returns>
        bool UpdateProfiles()
        {
            int nAdded    = 0;
            int nModified = 0;

            try
            {
                string strSiteURL = Properties.Settings.Default.sharePointUserProfilesUrl;
                using (SPSite site = new SPSite(strSiteURL))
                {
                    SPWeb                 web     = site.OpenWeb();
                    SPServiceContext      context = SPServiceContext.GetContext(site);
                    UserProfileManager    upm     = new UserProfileManager(context);
                    ProfileSubtypeManager psm     = ProfileSubtypeManager.Get(context);

                    web.AllowUnsafeUpdates = true;

                    // choose default user profile subtype as the subtype
                    string         subtypeName = ProfileSubtypeManager.GetDefaultProfileName(ProfileType.User);
                    ProfileSubtype subType     = psm.GetProfileSubtype(subtypeName);

                    try
                    {
                        imageUploader = new SPProfilePhotoUploader(web);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("{0}\nImages will not be updated", ex.ToString());
                        imageUploader = null;
                    }

                    double total   = users1C.Count;
                    double rec     = 100.0 / total;
                    double current = 0.0;

                    Console.Write("Updated 0%");
                    foreach (RecordUserProfile profile in users1C.GetProfiles())
                    {
                        RecordUserProfile profileFound       = null;
                        string            profileAccountName = "";
                        bool profileExists = false;

                        // If LDAP is refer to account name then verify if such account is existing
                        if (profile.AccountName != null &&
                            profile.AccountName.Trim().Length > 0 &&
                            Properties.Settings.Default.accountNameIsAKey == true)
                        {
                            if (upm.UserExists(profile.AccountName.Trim()))
                            {
                                profileAccountName = profile.AccountName.Trim();
                                profileExists      = true;
                            }
                        }
                        // If innIsAKey option is true and account is not found then try to find
                        // profile by INN
                        if (profileExists == false &&
                            profile.INN != null &&
                            profile.INN.Trim().Length > 0 &&
                            Properties.Settings.Default.innIsAKey)
                        {
                            profileFound = GetProfileByINN(profile);
                            if (profileFound != null)
                            {
                                profileAccountName = profileFound.AccountName;
                                profileExists      = true;
                            }
                        }
                        // Find by Last name, First name, Middle name (FIO) and Birthday
                        if (profileExists == false)
                        {
                            profileFound = GetProfileByPersonName(profile);
                            if (profileFound != null)
                            {
                                profileAccountName = profileFound.AccountName;
                                profileExists      = true;
                            }
                        }

                        if (profileExists)
                        {
                            // get existing profile
                            UserProfile p = upm.GetUserProfile(profileAccountName);

                            if (UpdateUserProfile(site, p, profile))
                            {
                                nModified++;
                            }
                        }
                        else
                        {
                            // create a user profile and set properties
                            if (CreateUserProfile(site, upm, profile, subType))
                            {
                                nAdded++;
                            }
                        }
                        current += rec;
                        Console.Write("\rUpdated {0:F}%", current);
                    }
                    Console.Write("\r");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                return(false);
            }
            Console.WriteLine("Updated {0} records.", nModified);
            Console.WriteLine("Added {0} new records.", nAdded);
            return(true);
        }