Ejemplo n.º 1
0
        public static async IAsyncEnumerable <GraphUser> AsContinousEnumerationAsync(this PagedGraphUsers page, Func <string, Task <PagedGraphUsers> > nextPageCallback)
        {
            if (page is null)
            {
                throw new ArgumentNullException(nameof(page));
            }

            if (nextPageCallback is null)
            {
                throw new ArgumentNullException(nameof(nextPageCallback));
            }

            foreach (var user in page.GraphUsers ?? Enumerable.Empty <GraphUser>())
            {
                yield return(user);
            }

            var continuationToken = page.ContinuationToken?.SingleOrDefault();

            if (!string.IsNullOrEmpty(continuationToken))
            {
                var nextPage = await nextPageCallback(continuationToken)
                               .ConfigureAwait(false);

                await foreach (var user in nextPage.AsContinousEnumerationAsync(nextPageCallback))
                {
                    yield return(user);
                }
            }
        }
Ejemplo n.º 2
0
    internal static async IAsyncEnumerable <GraphUser> AsContinuousCollectionAsync(
        this PagedGraphUsers page,
        Func <string, Task <PagedGraphUsers> > getNextPage)
    {
        if (page is null)
        {
            throw new ArgumentNullException(nameof(page));
        }

        if (getNextPage is null)
        {
            throw new ArgumentNullException(nameof(getNextPage));
        }

        var currentPage = page;

        do
        {
            if (!(currentPage.GraphUsers?.Any() ?? false))
            {
                yield break;
            }

            foreach (var element in currentPage.GraphUsers)
            {
                yield return(element);
            }
        } while ((currentPage.ContinuationToken?.Any() ?? false) &&
                 (currentPage = await getNextPage(currentPage.ContinuationToken.First()).ConfigureAwait(false)) is not null);
    }
Ejemplo n.º 3
0
        internal PagedGraphUsers GetAllUsers()
        {
            GraphHttpClient graphClient = connection.GetClient <GraphHttpClient>();
            PagedGraphUsers users       = graphClient.ListUsersAsync().Result;

            return(users);
        }
Ejemplo n.º 4
0
        public PagedGraphUsers GetAllUsers()
        {
            VssConnection   connection  = Context.Connection;
            GraphHttpClient graphClient = connection.GetClient <GraphHttpClient>();
            PagedGraphUsers users       = graphClient.ListUsersAsync().Result;

            foreach (var user in users.GraphUsers)
            {
                Context.Log("{0} {1} {2}",
                            user.Descriptor.ToString().PadRight(8),
                            user.DisplayName.PadRight(20),
                            user.PrincipalName.PadRight(20)
                            );
            }

            return(users);
        }
        public List <GraphUser> RunEnumerateUsersUsingClientLib()
        {
            Uri uri = new Uri(_uri);
            VssBasicCredential credentials = new VssBasicCredential("", _personalAccessToken);

            using (GraphHttpClient graphClient = new GraphHttpClient(uri, credentials))
            {
                // Get the first page of Users
                PagedGraphUsers users = graphClient.GetUsersAsync().Result;
                if (users.GraphUsers.Count() > 0)
                {
                    List <GraphUser> graphUsers = new List <GraphUser>(users.GraphUsers);

                    // If there are more than a page's worth of users, continue retrieving users from the server a page at a time
                    if (users.ContinuationToken != null)
                    {
                        string continuationToken = users.ContinuationToken.FirstOrDefault();
                        while (continuationToken != null)
                        {
                            users = graphClient.GetUsersAsync(continuationToken: continuationToken).Result;
                            graphUsers.AddRange(users.GraphUsers);

                            if (users.ContinuationToken != null)
                            {
                                continuationToken = users.ContinuationToken.FirstOrDefault();
                            }
                            else
                            {
                                break;
                            }
                        }
                    }

                    return(graphUsers);
                }
            }

            return(null);
        }