This repository was archived by the owner on Oct 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 527
/
Copy pathProgram.cs
59 lines (52 loc) · 2.15 KB
/
Program.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
57
58
59
using System;
using System.Threading.Tasks;
using Microsoft.TeamFoundation.WorkItemTracking.WebApi;
using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models;
using Microsoft.VisualStudio.Services.Common;
using Microsoft.VisualStudio.Services.WebApi;
namespace ConsoleApp
{
class Program
{
static void Main(string[] args)
{
if (args.Length == 3)
{
Uri orgUrl = new Uri(args[0]); // Organization URL, for example: https://dev.azure.com/fabrikam
String personalAccessToken = args[1]; // See https://docs.microsoft.com/azure/devops/integrate/get-started/authentication/pats
int workItemId = int.Parse(args[2]); // ID of a work item, for example: 12
// Create a connection
VssConnection connection = new VssConnection(orgUrl, new VssBasicCredential(string.Empty, personalAccessToken));
// Show details of a work item
ShowWorkItemDetails(connection, workItemId).Wait();
}
else
{
Console.WriteLine("Usage: ConsoleApp {orgUrl} {personalAccessToken} {workItemId}");
}
}
static private async Task ShowWorkItemDetails(VssConnection connection, int workItemId)
{
// Get an instance of the work item tracking client
WorkItemTrackingHttpClient witClient = connection.GetClient<WorkItemTrackingHttpClient>();
try
{
// Get the specified work item
WorkItem workitem = await witClient.GetWorkItemAsync(workItemId);
// Output the work item's field values
foreach (var field in workitem.Fields)
{
Console.WriteLine(" {0}: {1}", field.Key, field.Value);
}
}
catch (AggregateException aex)
{
VssServiceException vssex = aex.InnerException as VssServiceException;
if (vssex != null)
{
Console.WriteLine(vssex.Message);
}
}
}
}
}