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);
        }
Ejemplo n.º 2
0
        public PagedGraphUsers GetAllUsers()
        {
            VssConnection   connection  = Context.Connection;
            GraphHttpClient graphClient = connection.GetClient <GraphHttpClient>();
            PagedGraphUsers users       = graphClient.GetUsersAsync().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);
        }