当前位置: 首页>>代码示例>>C#>>正文


C# UserProfile.Commit方法代码示例

本文整理汇总了C#中UserProfile.Commit方法的典型用法代码示例。如果您正苦于以下问题:C# UserProfile.Commit方法的具体用法?C# UserProfile.Commit怎么用?C# UserProfile.Commit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UserProfile的用法示例。


在下文中一共展示了UserProfile.Commit方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SetPicture


//.........这里部分代码省略.........

                if (path.Contains("$(domain)") || path.Contains("@(domain)"))
                {
                    path = path.Replace("@(domain)", "$(domain)");
                    if (up["AccountName"] != null && up["AccountName"].Value != null)
                        path = path.Replace("$(domain)", up["AccountName"].Value.ToString().Split('\\')[0]);
                    else
                    {
                        if (!ignoreMissingData)
                            throw new ArgumentException(String.Format("Unable to determine domain from existing profile data ({0}).", up.ID));
                        return;
                    }
                }

                if (path.Contains("$(email)") || path.Contains("@(email)"))
                {
                    path = path.Replace("@(email)", "$(email)");
                    if (up["WorkEmail"] != null && up["WorkEmail"].Value != null)
                        path = path.Replace("$(email)", up["WorkEmail"].Value.ToString());
                    else
                    {
                        if (!ignoreMissingData)
                            throw new ArgumentException(String.Format("Unable to determine email from existing profile data ({0}).", up.ID));
                        return;
                    }
                }

                if (path.Contains("$(firstname)") || path.Contains("@(firstname)"))
                {
                    path = path.Replace("@(firstname)", "$(firstname)");
                    if (up["FirstName"] != null && up["FirstName"].Value != null)
                        path = path.Replace("$(firstname)", up["FirstName"].Value.ToString());
                    else
                    {
                        if (!ignoreMissingData)
                            throw new ArgumentException(String.Format("Unable to determine first name from existing profile data ({0}).", up.ID));
                        return;
                    }
                }

                if (path.Contains("$(lastname)") || path.Contains("@(lastname)"))
                {
                    path = path.Replace("@(lastname)", "$(lastname)");
                    if (up["LastName"] != null && up["LastName"].Value != null)
                        path = path.Replace("$(lastname)", up["LastName"].Value.ToString());
                    else
                    {
                        if (!ignoreMissingData)
                            throw new ArgumentException(String.Format("Unable to determine lastname from existing profile data ({0}).", up.ID));
                        return;
                    }
                }

                if (path.Contains("$(employeeid)") || path.Contains("@(employeeid)"))
                {
                    path = path.Replace("@(employeeid)", "$(employeeid)");
                    if (up["EmployeeID"] != null && up["EmployeeID"].Value != null)
                    {
                        path = path.Replace("$(employeeid)", up["EmployeeID"].Value.ToString());
                    }
                    else
                    {
                        if (!ignoreMissingData)
                            throw new ArgumentException(String.Format("Unable to determine Employee ID from existing profile data ({0}).", up.ID));
                        return;
                    }
                }
            }

            if (validateUrl && !String.IsNullOrEmpty(path))
            {
                Logger.Write("Validating URL \"{0}\" for \"{1}\".", path, up["AccountName"].Value.ToString());

                try
                {
                    //Create a request for the URL.
                    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(path);
                    request.AllowAutoRedirect = false;
                    request.Credentials = CredentialCache.DefaultCredentials;
                    HttpWebResponse serverResponse = (HttpWebResponse)request.GetResponse();
                    if (serverResponse.StatusCode != HttpStatusCode.OK)
                    {
                        Logger.Write("Unable to find picture. Setting PictureURL property to empty string.");
                        path = String.Empty;
                    }
                    serverResponse.Close();
                }
                catch (Exception ex)
                {
                    Exception ex1 = new Exception(String.Format("Exception occured validating URL \"{0}\" (property not updated):\r\n{1}", path, ex.Message), ex);
                    Logger.WriteException(new ErrorRecord(ex1, null, ErrorCategory.InvalidData, up));
                    return;
                }
            }

            Logger.Write("Setting picture for \"{0}\" to \"{1}\".", up["AccountName"].Value.ToString(), path);

            up["PictureURL"].Value = path;
            up.Commit();
        }
开发者ID:GSoft-SharePoint,项目名称:PowerShell-SPCmdlets,代码行数:101,代码来源:SetPictureUrl.cs

示例2: UpdateUserProfile

        /// <summary>
        /// Updates existing SharePoint user profile
        /// </summary>
        /// <param name="site">SPSite objec</param>
        /// <param name="p">The existing SP profile to be updated</param>
        /// <param name="profile">Profile record, which is imported from 1C</param>
        /// <returns>true on success, false on failed</returns>
        bool UpdateUserProfile(SPSite site, UserProfile p, RecordUserProfile profile)
        {
            string strDisplayName = "";

            try
            {
                strDisplayName = string.Format("{0} {1}{2}",
                    profile.FirstName.Trim(), (profile.MiddleName.Trim().Length > 0) ? (profile.MiddleName.Trim() + " ") : (""),
                    profile.LastName);

                if (Properties.Settings.Default.updateProfileDisplayName && p.DisplayName != strDisplayName)
                    p.DisplayName = strDisplayName;

                if (Properties.Settings.Default.updateFirstName)
                    UpdateSPStringProfileField(ref p, "FirstName", profile.FirstName);
                if (Properties.Settings.Default.updateLastName)
                    UpdateSPStringProfileField(ref p, "LastName", profile.LastName);
                if (Properties.Settings.Default.updateBirthday)
                    UpdateSPProfileField(ref p, "SPS-Birthday", profile.Birthday);

                if (Properties.Settings.Default.updatePhoneWork)
                    UpdateSPStringProfileField(ref p, "WorkPhone", profile.PhoneWork);
                if (Properties.Settings.Default.updatePhoneHome)
                    UpdateSPStringProfileField(ref p, "HomePhone", profile.PhoneHome);
                if (Properties.Settings.Default.updateEmailWork)
                    UpdateSPStringProfileField(ref p, "WorkEmail", profile.EmailWork);
                if (Properties.Settings.Default.updateSeparateDivision)
                    UpdateSPStringProfileField(ref p, "Office", profile.SeparateDivision);
                if (Properties.Settings.Default.updateSubDivision)
                    UpdateSPStringProfileField(ref p, "Department", profile.SubDivision);
                if (Properties.Settings.Default.updatePosition)
                {
                    UpdateSPStringProfileField(ref p, "Title", profile.Position);
                    UpdateSPStringProfileField(ref p, "SPS-JobTitle", profile.Position);
                }
                if (Properties.Settings.Default.updateDateOfEmployment && profile.EmploymentDate != null)
                    UpdateSPProfileField(ref p, "SPS-HireDate", profile.EmploymentDate);

                // Custom fields
                if (Properties.Settings.Default.updateMiddleName)
                    UpdateSPStringProfileField(ref p, "Mr-MiddleName", profile.MiddleName);
                if (Properties.Settings.Default.updateINN)
                    UpdateSPStringProfileField(ref p, "Mr-Inn", profile.INN);
                if (Properties.Settings.Default.updateSSN)
                    UpdateSPStringProfileField(ref p, "Mr-Ssn", profile.SSN);
                if (Properties.Settings.Default.updateOrganization)
                    UpdateSPStringProfileField(ref p, "Mr-Organization", profile.Organization);

                // Photos
                if (Properties.Settings.Default.updatePhoto && profile.Photo != null)
                {
                    if (Properties.Settings.Default.forceUpdatePhoto == true ||
                        p["PictureUrl"].Value == null || p["PictureUrl"].Value.ToString().Length < 1)
                    {
                        if (imageUploader != null)
                        {
                            imageUploader.UploadPhoto(p, profile.Photo);
                            string pictureUrl = String.Format("{0}/{1}/{2}_MThumb.jpg", site.Url,
                                imageUploader.GetSubfolderName(), imageUploader.GetFileNameFromAccount(p));
                            WriteSPProfileField(ref p, "PictureUrl", pictureUrl);
                        }
                    }
                }
                else
                {
                    if (Properties.Settings.Default.forceUpdatePhoto == true &&
                        p["PictureUrl"].Value != null && p["PictureUrl"].Value.ToString().Length > 0)
                    {
                        // TODO: Remove image?
                        WriteSPProfileField(ref p, "PictureUrl", null);
                    }
                }

                p.Commit();
            }
            catch (Exception ex)
            {
                string sError = string.Format("UpdateUserProfile() The error was occured while updating profile:\nAccount name: {0}\nDisplayName: {1}\nError:\n\n{2}\n---\n",
                    (p != null && p["AccountName"].Value != null) ? (" \"" + p["AccountName"].Value.ToString() + "\"") : (""),
                    strDisplayName, ex.ToString());

                TextWriter errorWriter = Console.Error;
                Console.WriteLine(sError);
                errorWriter.WriteLine(sError);
                return false;
            }
            return true;
        }
开发者ID:sergiygladkyy,项目名称:Mriya,代码行数:95,代码来源:Program.cs


注:本文中的UserProfile.Commit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。