This repository has been archived by the owner on Oct 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 511
/
CommentsSample.cs
61 lines (48 loc) · 2.31 KB
/
CommentsSample.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
60
61
using Microsoft.TeamFoundation.WorkItemTracking.WebApi;
using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models;
using Microsoft.VisualStudio.Services.WebApi;
using System;
using System.Collections.Generic;
namespace Microsoft.Azure.DevOps.ClientSamples.WorkItemTracking
{
[ClientSample(WitConstants.WorkItemTrackingWebConstants.RestAreaName, "workitemscomments")]
public class CommentsSample : ClientSample
{
[ClientSampleMethod]
public WorkItemComment GetSingleWorkItemComment()
{
WorkItem newWorkItem;
using (new ClientSampleHttpLoggerOutputSuppression())
{
WorkItemsSample witSample = new WorkItemsSample();
witSample.Context = this.Context;
newWorkItem = witSample.CreateWorkItem("Sample work item for comments", "Task");
Context.SetValue<WorkItem>("$newWorkItem", newWorkItem);
}
int id = Convert.ToInt32(newWorkItem.Id);
VssConnection connection = Context.Connection;
WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient<WorkItemTrackingHttpClient>();
WorkItemComment result = workItemTrackingClient.GetCommentAsync(id, 1).Result;
Console.WriteLine("Revision: {0}", result.Revision);
Console.WriteLine("Text: {0}", result.Text);
return result;
}
[ClientSampleMethod]
public WorkItemComments GetPageOfWorkItemComments()
{
int id = Convert.ToInt32(Context.GetValue<WorkItem>("$newWorkItem").Id);
VssConnection connection = Context.Connection;
WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient<WorkItemTrackingHttpClient>();
WorkItemComments result = workItemTrackingClient.GetCommentsAsync(id, 1).Result;
Console.WriteLine("Total Revision Count: {0}", result.TotalCount);
Console.WriteLine("From Revision Count: {0}", result.FromRevisionCount);
Console.WriteLine("Comments...");
foreach(var comment in result.Comments)
{
Console.WriteLine("{0}", comment.Text);
Console.WriteLine();
}
return result;
}
}
}