示例#1
0
        /// <summary>
        /// Gets all team members for the given <paramref name="projectId" /> and <paramref name="teamId"/>.
        /// </summary>
        /// <param name="client">The <see cref="TeamHttpClient" /> to use.</param>
        /// <param name="connection">The connection for the <paramref name="client"/> that will be used to retrieve the identities for the team members.</param>
        /// <param name="projectId">The project identifier.</param>
        /// <param name="teamId">The team identifier whose members to retrieve.</param>
        /// <param name="pageSize">Page size to use while retrieving the projects.</param>
        /// <param name="userState">The user state object.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentNullException">
        /// </exception>
        /// <exception cref="System.ArgumentException">$The '{nameof(connection)}' parameter must be for the given '{nameof(client)}'</exception>
        public static async Task <IReadOnlyCollection <Identity> > GetAllTeamMembers(this TeamHttpClient client, VssConnection connection, string projectId, string teamId, int pageSize = 10, object userState = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }
            if (connection == null)
            {
                throw new ArgumentNullException(nameof(connection));
            }
            if (projectId == null)
            {
                throw new ArgumentNullException(nameof(projectId));
            }
            if (teamId == null)
            {
                throw new ArgumentNullException(nameof(teamId));
            }

            if (Equals(client.BaseAddress, connection.Uri))
            {
                throw new ArgumentException($"The '{nameof(connection)}' parameter must be for the base uri of the VSTS / TFS system", nameof(connection));
            }

            var result             = new List <Identity>();
            var identityReferences = new List <IdentityRef>();

            int currentPage = 0;
            var teamMembersForCurrentPage = (await client.GetTeamMembersAsync(projectId, teamId, pageSize, currentPage, userState, cancellationToken).ConfigureAwait(false)).ToList();

            while (teamMembersForCurrentPage.Count > 0)
            {
                cancellationToken.ThrowIfCancellationRequested();
                identityReferences.AddRange(teamMembersForCurrentPage);

                // check whether the recently returned item(s) were less than the max page size
                if (teamMembersForCurrentPage.Count < pageSize)
                {
                    break; // if so, break the loop as we've read all instances
                }
                // otherwise continue
                cancellationToken.ThrowIfCancellationRequested();
                teamMembersForCurrentPage = (await client.GetTeamMembersAsync(projectId, teamId, pageSize, currentPage, userState, cancellationToken).ConfigureAwait(false)).ToList();
            }

            cancellationToken.ThrowIfCancellationRequested();
            if (identityReferences.Count > 0)
            {
                using (var identityHttpClient = await connection.GetClientAsync <IdentityHttpClient>(cancellationToken).ConfigureAwait(false))
                {
                    result.AddRange(await identityHttpClient.ReadIdentitiesAsync(identityReferences.Select(identityReference => new Guid(identityReference.Id)).ToList(), cancellationToken: cancellationToken).ConfigureAwait(false));
                }
            }

            cancellationToken.ThrowIfCancellationRequested();
            return(result);
        }
示例#2
0
        public IEnumerable <IdentityRef> GetTeamMembers()
        {
            VssConnection             connection     = new VssConnection(_uri, _credentials);
            TeamHttpClient            teamHttpClient = connection.GetClient <TeamHttpClient>();
            IEnumerable <IdentityRef> results        = teamHttpClient.GetTeamMembersAsync(_configuration.Project, _configuration.Team).Result;

            return(results);
        }
示例#3
0
 public IEnumerable <IdentityRef> GetTeamMembers(string project, string team)
 {
     // create team object
     using (TeamHttpClient teamHttpClient = new TeamHttpClient(_uri, _credentials))
     {
         IEnumerable <IdentityRef> results = teamHttpClient.GetTeamMembersAsync(project, team).Result;
         return(results);
     }
 }
        public IEnumerable <IdentityRef> GetTeamMembers()
        {
            string project = _configuration.Project;
            string team    = _configuration.Team;

            // create team object
            using (TeamHttpClient teamHttpClient = new TeamHttpClient(_uri, _credentials))
            {
                IEnumerable <IdentityRef> results = teamHttpClient.GetTeamMembersAsync(project, team).Result;
                return(results);
            }
        }
        static void Main(string[] args)
        {
            String         collectionUri = "http://TFS2017:8080/tfs/defaultcollection";
            VssCredentials creds         = new VssClientCredentials();

            creds.Storage = new VssClientCredentialStorage();
            VssConnection      connection = new VssConnection(new Uri(collectionUri), creds);
            TeamHttpClient     thc        = connection.GetClient <TeamHttpClient>();
            List <IdentityRef> irs        = thc.GetTeamMembersAsync("TeamProject", "TeamProjectTeam").Result;

            foreach (IdentityRef ir in irs)
            {
                Console.WriteLine(ir.DisplayName);
            }
        }
        public IEnumerable <IdentityRef> GetTeamMembers()
        {
            Guid projectId = ClientSampleHelpers.FindAnyProject(this.Context).Id;
            Guid teamId    = ClientSampleHelpers.FindAnyTeam(this.Context, projectId).Id;

            VssConnection  connection = Context.Connection;
            TeamHttpClient teamClient = connection.GetClient <TeamHttpClient>();

            IEnumerable <IdentityRef> teamMembers = teamClient.GetTeamMembersAsync(projectId.ToString(), teamId.ToString()).Result;

            Console.WriteLine("Members of {0}:", teamId);
            foreach (var member in teamMembers)
            {
                Console.WriteLine("  " + member.DisplayName);
            }

            return(teamMembers);
        }