Adding Sample to enumerate groups a user is a member of #118
This commit is contained in:
Родитель
59bcd7a08f
Коммит
2096fca8c5
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using Microsoft.VisualStudio.Services.Graph.Client;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace GraphQuickStarts
|
||||
|
@ -32,16 +33,15 @@ namespace GraphQuickStarts
|
|||
Console.WriteLine("Executing Graph quick start samples...");
|
||||
Console.WriteLine("");
|
||||
|
||||
//instantiate objects & execute
|
||||
// Enumerate Users sample
|
||||
Samples.EnumerateUsers objUsers = new Samples.EnumerateUsers(connectionUrl, token);
|
||||
List<GraphUser> users = objUsers.RunEnumerateUsersUsingClientLib();
|
||||
|
||||
//execute the client lib code. If you want to run the direct http calls then adjust (see below)
|
||||
objUsers.RunEnumerateUsersUsingClientLib();
|
||||
// Enumber Group Memberships sample
|
||||
objUsers.RunEnumerateEnumerateGroupMembershipsUsingClientLib(users);
|
||||
|
||||
//instantiate objects & execute
|
||||
// Enumerate Members of Groups sample
|
||||
Samples.EnumerateMembersOfGroups objMembers = new Samples.EnumerateMembersOfGroups(connectionUrl, clientId, redirectURL);
|
||||
|
||||
//execute the client lib code. If you want to run the direct http calls then adjust (see below)
|
||||
objMembers.RunEnumerateMembersOfGroupsUsingClientLib(groupName);
|
||||
|
||||
Console.ReadKey();
|
||||
|
|
|
@ -69,5 +69,30 @@ namespace GraphQuickStarts.Samples
|
|||
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<string> RunEnumerateEnumerateGroupMembershipsUsingClientLib(List<GraphUser> users)
|
||||
{
|
||||
Uri uri = new Uri(_uri);
|
||||
VssBasicCredential credentials = new VssBasicCredential("", _personalAccessToken);
|
||||
|
||||
using (GraphHttpClient graphClient = new GraphHttpClient(uri, credentials))
|
||||
{
|
||||
List<string> memberships = new List<string>();
|
||||
|
||||
foreach (GraphUser user in users)
|
||||
{
|
||||
List<GraphMembership> groupMemberships = graphClient.GetMembershipsAsync(user.Descriptor).Result;
|
||||
foreach(GraphMembership membership in groupMemberships)
|
||||
{
|
||||
GraphGroup resolvedGroup = graphClient.GetGroupAsync(membership.ContainerDescriptor).Result;
|
||||
memberships.Add(String.Format("{0}:{1} --> {2}:{3}", user.DisplayName, user.PrincipalName, resolvedGroup.Origin, resolvedGroup.DisplayName));
|
||||
}
|
||||
}
|
||||
|
||||
return memberships;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче