-
Notifications
You must be signed in to change notification settings - Fork 5
/
WorkItemReader.cs
56 lines (43 loc) · 1.96 KB
/
WorkItemReader.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using System;
using System.Collections.Generic;
using System.Linq;
using AzureDevOpsCustomObjects.Extensions;
using AzureDevOpsCustomObjects.WorkItems;
using Microsoft.TeamFoundation.WorkItemTracking.WebApi;
using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models;
using Microsoft.VisualStudio.Services.Common;
using Microsoft.VisualStudio.Services.WebApi;
namespace AzureDevOpsCustomObjects
{
public class WorkItemReader
{
public WorkItemReader(string uri, string personalAccessToken, string projectName)
{
Uri = new Uri(uri);
PersonalAccessToken = personalAccessToken;
ProjectName = projectName;
var credentials = new VssBasicCredential(string.Empty, PersonalAccessToken);
var connection = new VssConnection(Uri, credentials);
WorkItemTrackingHttpClient = connection.GetClient<WorkItemTrackingHttpClient>();
}
private WorkItemTrackingHttpClient WorkItemTrackingHttpClient { get; }
private Uri Uri { get; }
private string ProjectName { get; }
private string PersonalAccessToken { get; }
public IEnumerable<AzureDevOpsWorkItem> All()
{
var workItemQuery = new Wiql()
{
Query = "Select * " +
"From WorkItems " +
"Where [System.TeamProject] = '" + ProjectName + "' "
};
var workItemQueryResult = WorkItemTrackingHttpClient.QueryByWiqlAsync(workItemQuery).Result;
if (!workItemQueryResult.WorkItems.Any())
return new List<AzureDevOpsWorkItem>();
var matchingWorkItemIds = workItemQueryResult.WorkItems.Select(item => item.Id).ToArray();
var workItems = WorkItemTrackingHttpClient.GetWorkItemsAsync(ProjectName, matchingWorkItemIds, expand : WorkItemExpand.Relations).Result;
return workItems.Select(item => item.ToAzureDevOpsWorkItem());
}
}
}