public override void Sync() { var mappedFields = fullProfileSyncService.Fields.ToList(); if (mappedFields.Count <= 0) { return; } var externalFields = new List <string>(); var externalUsersCount = 0; var internalFields = new List <string>(); var missingUserCount = 0; var missingUsers = new List <string>(); var nextIndex = 0; SplitMappedFields(mappedFields, internalFields, externalFields); do { var externalUsers = fullProfileSyncService.List(ref nextIndex); externalUsersCount += externalUsers.Count; if (externalUsers.Count <= 0) { break; } // sync every external user foreach (var externalUser in externalUsers) { var internalApiUser = PublicApi.Users.Get(new UsersGetOptions { Email = externalUser.Email }); if (internalApiUser != null) { var internalUser = InitInternalUser(internalApiUser); MergeAndUpdate(internalUser, internalFields, externalUser, externalFields, mappedFields); } else { if (missingUsers.Count < 100) { missingUsers.Add(externalUser.Email); } missingUserCount++; } } } while (true); SPLog.Info(string.Format("Profile Sync found {0} SharePoint user(s)", externalUsersCount)); if (missingUsers.Count > 0) { SPLog.Event(string.Format("Profile Sync could not find following Evolution user(s) {0}. Total not found: {1}", string.Join(", ", missingUsers.ToArray()), missingUserCount)); } UpdateLastRunStatus(Status.Succeeded); }
internal static SPConfiguration Get(string url, Authentication auth) { var config = new SPConfiguration(url, auth); using (var spcontext = new SPContext(url, auth)) { try { SP.Web web = spcontext.Site.RootWeb; var siteProfileFieldsQuery = spcontext.LoadQuery(web.SiteUserInfoList.Fields).Where(f => !f.Hidden); spcontext.ExecuteQuery(); config.SiteProfileFields = siteProfileFieldsQuery.Select(f => new ProfileField(f.StaticName, f.Title, !f.ReadOnlyField)).OrderBy(f => f.Title).ToList(); spcontext.Load(web.AllProperties, prop => prop[SPWebPropertyKey.SyncEnabled], prop => prop[SPWebPropertyKey.SiteSettings], prop => prop[SPWebPropertyKey.FarmSettings], prop => prop[SPWebPropertyKey.FarmSyncEnabled]); spcontext.ExecuteQuery(); ParseWebProperties(web, config); } catch (Exception) { SPLog.Info("Profile Sync properites do not exist in SharePoint. These are optional fields, no action is required."); } } config.FarmProfileFields = new List <ProfileField>(); using (var userProfileService = new ProfileService(url, auth)) { try { var properties = userProfileService.GetUserProfileSchema(); foreach (var property in properties.OrderBy(p => p.DisplayName)) { config.FarmProfileFields.Add(new ProfileField(property.Name, property.DisplayName, property.IsUserEditable)); } } catch (Exception ex) { SPLog.RoleOperationUnavailable(ex, ex.Message); } } return(config); }
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); }