/// <summary> /// Add a user to specified Group /// </summary> /// <param name="groupSyncInstructions"></param> /// <param name="singleGroupMembershipManager"></param> /// <param name="graphUser"></param> private void AddUserToGroupProvisioningTrackingManager( ProvisionFromDirectoryGroupsMembershipManager.SingleGroupManager singleGroupMembershipManager, Microsoft.Graph.User graphUser) { string emailCandidate = GetUserEmailFromGraphADUser(graphUser); IwsDiagnostics.Assert(!string.IsNullOrWhiteSpace(emailCandidate), "843-706: User principal name is NULL"); singleGroupMembershipManager.AddUser(emailCandidate); }
/// <summary> /// Itterate down a groups membership, looking in any sub-groups, and record all the members /// </summary> /// <param name="azureGraph"></param> /// <param name="thisGroupsMembers"></param> /// <param name="singleGroupMembershipManager"></param> /// <param name="groupSyncInstructions"></param> /// <returns></returns> async Task AzureRecurseGroupsGenerateGroupMembersList( GraphServiceClient azureGraph, IGroupMembersCollectionWithReferencesPage thisGroupsMembers, ProvisionFromDirectoryGroupsMembershipManager.SingleGroupManager singleGroupMembershipManager) { var thispage_members = thisGroupsMembers; do { if (thispage_members.Count > 0) { foreach (var thisMember in thispage_members) { var asUser = thisMember as Microsoft.Graph.User; var asSubGroup = thisMember as Microsoft.Graph.Group; //------------------------------------------------- //If it's a USER, then add it to our tracking list //------------------------------------------------- if (asUser != null) { //------------------------------------------------- //Add them to the list of users //------------------------------------------------- AddUserToGroupProvisioningTrackingManager( singleGroupMembershipManager, asUser); } //------------------------------------------------- //If it's a GROUP, then recurse down it //------------------------------------------------- else if (asSubGroup != null) { //----------------------------------------------------------------------------------- //Recurse down the subgroup and get its members //----------------------------------------------------------------------------------- var subGroupsMembers = await azureGraph.Groups[asSubGroup.Id].Members.Request().GetAsync(); await AzureRecurseGroupsGenerateGroupMembersList(azureGraph, subGroupsMembers, singleGroupMembershipManager); } } } //Go to the next page if (thispage_members.NextPageRequest != null) { thispage_members = await thispage_members.NextPageRequest.GetAsync(); } else { thispage_members = null; } } while (thispage_members != null); }