public void Update(User mergeUser, IEnumerable <string> fields) { var userProfile = mergeUser as SPSiteUser; if (userProfile == null) { return; } SP.ListItem spUser = userProfile.Profile; foreach (string fieldName in fields) { SetSanitizeUserFieldValue(spUser, fieldName, mergeUser[fieldName]); } spUser.Update(); spcontext.ExecuteQuery(); }
public void Update(User mergeUser, IEnumerable <string> fields) { var accountName = mergeUser.Fields["AccountName"].ToString(); if (String.IsNullOrEmpty(accountName)) { return; } var userProfile = mergeUser as SPFarmUser; if (userProfile == null) { return; } var fieldList = fields.ToList(); var userProfileHashData = userProfile.Profile.ToDictionary(p => p.Name, p => p); var updatedUserProfileData = new PropertyData[fieldList.Count]; for (int i = 0; i < updatedUserProfileData.Length; i++) { PropertyData propertyData; if (userProfileHashData.TryGetValue(fieldList[i], out propertyData) && propertyData != null) { var value = mergeUser[fieldList[i]]; DateTime dateValue; if (value != null && DateTime.TryParse(value.ToString(), out dateValue) && dateValue.Year < 1753) { continue; } SetSanitizeUserFieldValue(propertyData, value); updatedUserProfileData[i] = propertyData; } } farmUserProfileService.ModifyUserPropertyByAccountName(accountName, updatedUserProfileData); }
public static MergeResult MergeUsers(InternalApi.Entities.User externalUser, InternalApi.Entities.User internalUser, IEnumerable <InternalApi.Entities.UserFieldMapping> mapping) { var res = MergeResult.None; var hasNullField = false; try { foreach (var map in mapping) { var internalFieldVal = internalUser[map.InternalUserFieldId]; var externalFieldVal = externalUser[map.ExternalUserFieldId]; hasNullField |= internalFieldVal == null; if (map.SyncDirection == InternalApi.Entities.SyncDirection.Export && internalFieldVal != null && !internalFieldVal.Equals(externalFieldVal)) { internalUser[map.InternalUserFieldId] = externalUser[map.ExternalUserFieldId]; res |= MergeResult.InternalUpdated; } if (map.SyncDirection == InternalApi.Entities.SyncDirection.Import && externalFieldVal != null && !externalFieldVal.Equals(internalFieldVal)) { externalUser[map.ExternalUserFieldId] = internalUser[map.InternalUserFieldId]; res |= MergeResult.ExternalUpdated; } } } catch (Exception ex) { SPLog.UserProfileUpdated(ex, String.Format("Could Not Merge User: {0}/{1}", internalUser.Id, internalUser.Email ?? String.Empty)); } if (res == MergeResult.None && hasNullField) { SPLog.Info(string.Format("Profile Sync no fields merged for ({0}:{1}). Please verify __CommunityServer__Service__ contains the Administrators role.", internalUser.Id, internalUser.Email)); } return(res); }