Skip to content

Commit

Permalink
Add paging ability for projects (#166)
Browse files Browse the repository at this point in the history
When there are more than 100 projects in a collection, only 100 are loaded.

Resolves #162
  • Loading branch information
rjmurillo authored Aug 4, 2017
1 parent 3efa72e commit e504a1b
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/Qwiq.Core.Rest/WorkItemStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,28 @@ private void Dispose(bool disposing)

private IProjectCollection ProjectCollectionFactory()
{
const string continuationHeader = "x-ms-continuationtoken";

// See https://www.visualstudio.com/en-us/docs/integrate/api/tfs/projects
const ProjectState defaultStateFilter = ProjectState.WellFormed;
const int defaultNumberOfTeamProjects = 100;

// Use the page size configured by the client if it is higher than the default
// Otherwise, with a default of 50, we would need to make multiple trips to load all the data
var pageSize = Math.Max(defaultNumberOfTeamProjects, Configuration.PageSize);

using (var projectHttpClient = _tfs.Value.GetClient<ProjectHttpClient>())
{
var projects = (List<TeamProjectReference>)projectHttpClient.GetProjects(ProjectState.WellFormed).GetAwaiter().GetResult();
var projects = new List<TeamProjectReference>(pageSize);

var projectReferences = projectHttpClient.GetProjects(defaultStateFilter, pageSize).GetAwaiter().GetResult();
projects.AddRange(projectReferences);
while (projectHttpClient.LastResponseContext.Headers.Contains(continuationHeader))
{
projectReferences = projectHttpClient.GetProjects(defaultStateFilter, pageSize, projects.Count).GetAwaiter().GetResult();
projects.AddRange(projectReferences);
}

var projects2 = new List<IProject>(projects.Count + 1);

for (var i = 0; i < projects.Count; i++)
Expand Down

0 comments on commit e504a1b

Please sign in to comment.