зеркало из
1
0
Форкнуть 0

Adding Sample to enumerate groups a user is a member of #118 (#128)

Adding Sample to enumerate groups a user is a member of #118
This commit is contained in:
Justin Marks 2018-04-26 13:50:50 -07:00 коммит произвёл GitHub
Родитель 59bcd7a08f
Коммит 2096fca8c5
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 32 добавлений и 7 удалений

Просмотреть файл

@ -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;
}
}
}