Родитель
feaed9f69f
Коммит
d1f12bdcd5
|
@ -6,19 +6,28 @@ using System.Collections.Generic;
|
|||
|
||||
namespace Microsoft.TeamServices.Samples.Client.WorkItemTracking
|
||||
{
|
||||
[ClientSample(WitConstants.WorkItemTrackingWebConstants.RestAreaName, WitConstants.WorkItemTrackingRestResources.WorkItems)]
|
||||
[ClientSample(WitConstants.WorkItemTrackingWebConstants.RestAreaName, "workitemscomments")]
|
||||
public class CommentsSample : ClientSample
|
||||
{
|
||||
[ClientSampleMethod]
|
||||
public WorkItemComment GetSingleWorkItemComment()
|
||||
{
|
||||
int id = 23; //TODO
|
||||
int revision = 1;
|
||||
WorkItem newWorkItem;
|
||||
|
||||
using (new ClientSampleHttpLoggerOutputSuppression())
|
||||
{
|
||||
WorkItemsSample witSample = new WorkItemsSample();
|
||||
witSample.Context = this.Context;
|
||||
newWorkItem = witSample.CreateWorkItem("Sample work item for comments");
|
||||
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, revision).Result;
|
||||
WorkItemComment result = workItemTrackingClient.GetCommentAsync(id, 1).Result;
|
||||
|
||||
Console.WriteLine("Revision: {0}", result.Revision);
|
||||
Console.WriteLine("Text: {0}", result.Text);
|
||||
|
@ -29,8 +38,8 @@ namespace Microsoft.TeamServices.Samples.Client.WorkItemTracking
|
|||
[ClientSampleMethod]
|
||||
public WorkItemComments GetPageOfWorkItemComments()
|
||||
{
|
||||
int id = 23; //TODO
|
||||
|
||||
int id = Convert.ToInt32(Context.GetValue<WorkItem>("$newWorkItem").Id);
|
||||
|
||||
VssConnection connection = Context.Connection;
|
||||
WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient<WorkItemTrackingHttpClient>();
|
||||
|
||||
|
|
|
@ -7,9 +7,52 @@ using System.Collections.Generic;
|
|||
|
||||
namespace Microsoft.TeamServices.Samples.Client.WorkItemTracking
|
||||
{
|
||||
[ClientSample(WitConstants.WorkItemTrackingWebConstants.RestAreaName, WitConstants.WorkItemTrackingRestResources.WorkItems)]
|
||||
[ClientSample(WitConstants.WorkItemTrackingWebConstants.RestAreaName, "workitemsrecyclebin")]
|
||||
public class RecycleBinSample : ClientSample
|
||||
{
|
||||
int _id;
|
||||
int[] _ids;
|
||||
|
||||
[ClientSampleMethod]
|
||||
public void CreateSampleData()
|
||||
{
|
||||
WorkItem workItem1;
|
||||
WorkItem workItem2;
|
||||
WorkItem workItem3;
|
||||
WorkItem newWorkItem;
|
||||
|
||||
using (new ClientSampleHttpLoggerOutputSuppression())
|
||||
{
|
||||
WorkItemsSample witSample = new WorkItemsSample();
|
||||
witSample.Context = this.Context;
|
||||
newWorkItem = witSample.CreateWorkItem("Sample work item for comments");
|
||||
|
||||
_id = Convert.ToInt32(newWorkItem.Id);
|
||||
|
||||
workItem1 = witSample.CreateWorkItem("Sample work item for comments #1");
|
||||
workItem2 = witSample.CreateWorkItem("Sample work item for comments #2");
|
||||
workItem3 = witSample.CreateWorkItem("Sample work item for comments #3");
|
||||
|
||||
_ids = new int[] { Convert.ToInt32(workItem1.Id), Convert.ToInt32(workItem2.Id), Convert.ToInt32(workItem3.Id) };
|
||||
}
|
||||
}
|
||||
|
||||
[ClientSampleMethod]
|
||||
public WorkItemDelete DeleteWorkItems()
|
||||
{
|
||||
int id = _id;
|
||||
int[] ids = _ids;
|
||||
|
||||
VssConnection connection = Context.Connection;
|
||||
WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient<WorkItemTrackingHttpClient>();
|
||||
|
||||
WorkItemDelete result = workItemTrackingClient.DeleteWorkItemAsync(id).Result;
|
||||
result = workItemTrackingClient.DeleteWorkItemAsync(ids[0]).Result;
|
||||
result = workItemTrackingClient.DeleteWorkItemAsync(ids[1]).Result;
|
||||
result = workItemTrackingClient.DeleteWorkItemAsync(ids[2]).Result;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
[ClientSampleMethod]
|
||||
public List<WorkItemDeleteReference> GetDeletedWorkItems()
|
||||
|
@ -23,16 +66,16 @@ namespace Microsoft.TeamServices.Samples.Client.WorkItemTracking
|
|||
|
||||
return results;
|
||||
}
|
||||
|
||||
|
||||
[ClientSampleMethod]
|
||||
public WorkItemDelete GetDeletedWorkItem()
|
||||
{
|
||||
int workItemId = -1; // TODO
|
||||
int id = _id;
|
||||
|
||||
VssConnection connection = Context.Connection;
|
||||
WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient<WorkItemTrackingHttpClient>();
|
||||
|
||||
WorkItemDelete result = workItemTrackingClient.GetDeletedWorkItemAsync(workItemId).Result;
|
||||
WorkItemDelete result = workItemTrackingClient.GetDeletedWorkItemAsync(id).Result;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -40,7 +83,7 @@ namespace Microsoft.TeamServices.Samples.Client.WorkItemTracking
|
|||
[ClientSampleMethod]
|
||||
public List<WorkItemDeleteReference> GetMultipledDeletedWorkItems()
|
||||
{
|
||||
int[] ids = { 72, 73, 81 }; //TODO
|
||||
int[] ids = _ids;
|
||||
|
||||
VssConnection connection = Context.Connection;
|
||||
WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient<WorkItemTrackingHttpClient>();
|
||||
|
@ -52,7 +95,7 @@ namespace Microsoft.TeamServices.Samples.Client.WorkItemTracking
|
|||
[ClientSampleMethod]
|
||||
public WorkItemDelete RestoreWorkItem()
|
||||
{
|
||||
int workItemId = -1; // TODO
|
||||
int id = _id;
|
||||
|
||||
VssConnection connection = Context.Connection;
|
||||
WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient<WorkItemTrackingHttpClient>();
|
||||
|
@ -61,7 +104,7 @@ namespace Microsoft.TeamServices.Samples.Client.WorkItemTracking
|
|||
IsDeleted = false
|
||||
};
|
||||
|
||||
WorkItemDelete result = workItemTrackingClient.RestoreWorkItemAsync(updateParameters, workItemId).Result;
|
||||
WorkItemDelete result = workItemTrackingClient.RestoreWorkItemAsync(updateParameters, id).Result;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -69,7 +112,7 @@ namespace Microsoft.TeamServices.Samples.Client.WorkItemTracking
|
|||
[ClientSampleMethod]
|
||||
public void RestoreMultipleWorkItems()
|
||||
{
|
||||
int[] ids = { 72, 73, 81 }; //TODO
|
||||
int[] ids = _ids;
|
||||
|
||||
VssConnection connection = Context.Connection;
|
||||
WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient<WorkItemTrackingHttpClient>();
|
||||
|
@ -89,22 +132,29 @@ namespace Microsoft.TeamServices.Samples.Client.WorkItemTracking
|
|||
[ClientSampleMethod]
|
||||
public void PermenentlyDeleteWorkItem()
|
||||
{
|
||||
int workItemId = -1; // TODO
|
||||
int id = _id;
|
||||
|
||||
VssConnection connection = Context.Connection;
|
||||
WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient<WorkItemTrackingHttpClient>();
|
||||
|
||||
workItemTrackingClient.DestroyWorkItemAsync(workItemId);
|
||||
WorkItemDelete result = workItemTrackingClient.DeleteWorkItemAsync(id).Result;
|
||||
|
||||
workItemTrackingClient.DestroyWorkItemAsync(id);
|
||||
}
|
||||
|
||||
[ClientSampleMethod]
|
||||
public void PermenentlyDeleteMultipleWorkItems()
|
||||
{
|
||||
int[] ids = { 72, 73, 81 }; //TODO
|
||||
int[] ids = _ids;
|
||||
|
||||
VssConnection connection = Context.Connection;
|
||||
WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient<WorkItemTrackingHttpClient>();
|
||||
|
||||
WorkItemDelete delResult;
|
||||
delResult = workItemTrackingClient.DeleteWorkItemAsync(ids[0]).Result;
|
||||
delResult = workItemTrackingClient.DeleteWorkItemAsync(ids[1]).Result;
|
||||
delResult = workItemTrackingClient.DeleteWorkItemAsync(ids[2]).Result;
|
||||
|
||||
List<WorkItemDeleteReference> result = workItemTrackingClient.GetDeletedWorkItemsAsync(ids).Result;
|
||||
|
||||
foreach(var item in result)
|
||||
|
|
|
@ -12,14 +12,91 @@ namespace Microsoft.TeamServices.Samples.Client.WorkItemTracking
|
|||
/// <summary>
|
||||
/// Client samples for managing work items in Team Services and Team Foundation Server.
|
||||
/// </summary>
|
||||
[ClientSample(WitConstants.WorkItemTrackingWebConstants.RestAreaName, WitConstants.WorkItemTrackingRestResources.WorkItems)]
|
||||
[ClientSample(WitConstants.WorkItemTrackingWebConstants.RestAreaName, "workitemssamples")]
|
||||
public class WorkItemsSample : ClientSample
|
||||
{
|
||||
[ClientSampleMethod]
|
||||
public WorkItem CreateWorkItem()
|
||||
{
|
||||
// Construct the object containing field values required for the new work item
|
||||
JsonPatchDocument patchDocument = new JsonPatchDocument();
|
||||
patchDocument.Add(
|
||||
new JsonPatchOperation()
|
||||
{
|
||||
Operation = Operation.Add,
|
||||
Path = "/fields/System.Title",
|
||||
Value = "Sample task 1"
|
||||
}
|
||||
);
|
||||
|
||||
// Get a client
|
||||
VssConnection connection = Context.Connection;
|
||||
WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient<WorkItemTrackingHttpClient>();
|
||||
|
||||
// Get the project to create the sample work item in
|
||||
TeamProjectReference project = ClientSampleHelpers.FindAnyProject(this.Context);
|
||||
|
||||
// Create the new work item
|
||||
WorkItem newWorkItem = workItemTrackingClient.CreateWorkItemAsync(patchDocument, project.Id, "Task").Result;
|
||||
|
||||
Console.WriteLine("Created work item ID {0} {1}", newWorkItem.Id, newWorkItem.Fields["System.Title"]);
|
||||
|
||||
// Save this newly created for later samples
|
||||
Context.SetValue<WorkItem>("$newWorkItem", newWorkItem);
|
||||
|
||||
return newWorkItem;
|
||||
}
|
||||
|
||||
[ClientSampleMethod]
|
||||
public WorkItem CreateWorkItem(string title)
|
||||
{
|
||||
// Construct the object containing field values required for the new work item
|
||||
JsonPatchDocument patchDocument = new JsonPatchDocument();
|
||||
patchDocument.Add(
|
||||
new JsonPatchOperation()
|
||||
{
|
||||
Operation = Operation.Add,
|
||||
Path = "/fields/System.Title",
|
||||
Value = title
|
||||
}
|
||||
);
|
||||
|
||||
// Get a client
|
||||
VssConnection connection = Context.Connection;
|
||||
WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient<WorkItemTrackingHttpClient>();
|
||||
|
||||
// Get the project to create the sample work item in
|
||||
TeamProjectReference project = ClientSampleHelpers.FindAnyProject(this.Context);
|
||||
|
||||
// Create the new work item
|
||||
WorkItem newWorkItem = workItemTrackingClient.CreateWorkItemAsync(patchDocument, project.Id, "Task").Result;
|
||||
|
||||
Console.WriteLine("Created work item ID {0} {1}", newWorkItem.Id, newWorkItem.Fields["System.Title"]);
|
||||
|
||||
return newWorkItem;
|
||||
}
|
||||
|
||||
[ClientSampleMethod]
|
||||
public void CreateSampleWorkItemData()
|
||||
{
|
||||
WorkItem newWorkItem;
|
||||
|
||||
newWorkItem = this.CreateWorkItem("Sample Task #1");
|
||||
Context.SetValue<WorkItem>("$newWorkItem1", newWorkItem);
|
||||
|
||||
newWorkItem = this.CreateWorkItem("Sample Task #2");
|
||||
Context.SetValue<WorkItem>("$newWorkItem2", newWorkItem);
|
||||
|
||||
newWorkItem = this.CreateWorkItem("Sample Task #3");
|
||||
Context.SetValue<WorkItem>("$newWorkItem3", newWorkItem);
|
||||
}
|
||||
|
||||
[ClientSampleMethod]
|
||||
public List<WorkItem> GetWorkItemsByIDs()
|
||||
{
|
||||
int[] workitemIds = new int[] { 1, 5, 6, 10 };
|
||||
Context.SetValue<int[]>("$workitemIds", new int[] { Convert.ToInt32(Context.GetValue<WorkItem>("$newWorkItem1").Id), Convert.ToInt32(Context.GetValue<WorkItem>("$newWorkItem2").Id), Convert.ToInt32(Context.GetValue<WorkItem>("$newWorkItem3").Id) });
|
||||
|
||||
int[] workitemIds = Context.GetValue<int[]>("$workitemIds");
|
||||
|
||||
VssConnection connection = Context.Connection;
|
||||
WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient<WorkItemTrackingHttpClient>();
|
||||
|
@ -37,13 +114,12 @@ namespace Microsoft.TeamServices.Samples.Client.WorkItemTracking
|
|||
[ClientSampleMethod]
|
||||
public List<WorkItem> GetWorkItemsWithSpecificFields()
|
||||
{
|
||||
int[] workitemIds = new int[] { 1, 5, 6, 10, 22, 50 };
|
||||
int[] workitemIds = Context.GetValue<int[]>("$workitemIds");
|
||||
|
||||
string[] fieldNames = new string[] {
|
||||
"System.Id",
|
||||
"System.Title",
|
||||
"System.WorkItemType",
|
||||
"Microsoft.VSTS.Scheduling.RemainingWork"
|
||||
"System.WorkItemType"
|
||||
};
|
||||
|
||||
VssConnection connection = Context.Connection;
|
||||
|
@ -66,13 +142,12 @@ namespace Microsoft.TeamServices.Samples.Client.WorkItemTracking
|
|||
[ClientSampleMethod]
|
||||
public List<WorkItem> GetWorkItemsAsOfDate()
|
||||
{
|
||||
int[] workitemIds = new int[] { 1, 5, 6, 10, 22, 50 };
|
||||
int[] workitemIds = Context.GetValue<int[]>("$workitemIds");
|
||||
|
||||
string[] fieldNames = new string[] {
|
||||
"System.Id",
|
||||
"System.Title",
|
||||
"System.WorkItemType",
|
||||
"Microsoft.VSTS.Scheduling.RemainingWork"
|
||||
"System.WorkItemType"
|
||||
};
|
||||
|
||||
DateTime asOfDate = new DateTime(2016, 12, 31);
|
||||
|
@ -97,7 +172,7 @@ namespace Microsoft.TeamServices.Samples.Client.WorkItemTracking
|
|||
[ClientSampleMethod]
|
||||
public List<WorkItem> GetWorkItemsWithLinksAndAttachments()
|
||||
{
|
||||
int[] workitemIds = new int[] { 1, 5, 6, 10, 22, 50 };
|
||||
int[] workitemIds = Context.GetValue<int[]>("$workitemIds");
|
||||
|
||||
VssConnection connection = Context.Connection;
|
||||
WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient<WorkItemTrackingHttpClient>();
|
||||
|
@ -108,20 +183,25 @@ namespace Microsoft.TeamServices.Samples.Client.WorkItemTracking
|
|||
{
|
||||
Console.WriteLine("Work item {0}", workitem.Id);
|
||||
|
||||
foreach (var relation in workitem.Relations)
|
||||
if (workitem.Relations == null)
|
||||
{
|
||||
Console.WriteLine(" {0} {1}", relation.Rel, relation.Url);
|
||||
Console.WriteLine(" No relations found on this work item");
|
||||
}
|
||||
else {
|
||||
foreach (var relation in workitem.Relations)
|
||||
{
|
||||
Console.WriteLine(" {0} {1}", relation.Rel, relation.Url);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return workitems;
|
||||
}
|
||||
|
||||
[ClientSampleMethod]
|
||||
public WorkItem GetWorkItemById()
|
||||
{
|
||||
int id = 12;
|
||||
int id = Convert.ToInt32(Context.GetValue<WorkItem>("$newWorkItem1").Id);
|
||||
|
||||
VssConnection connection = Context.Connection;
|
||||
WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient<WorkItemTrackingHttpClient>();
|
||||
|
@ -139,7 +219,7 @@ namespace Microsoft.TeamServices.Samples.Client.WorkItemTracking
|
|||
[ClientSampleMethod]
|
||||
public WorkItem GetWorkItemFullyExpanded()
|
||||
{
|
||||
int id = 5;
|
||||
int id = Convert.ToInt32(Context.GetValue<WorkItem>("$newWorkItem1").Id);
|
||||
|
||||
VssConnection connection = Context.Connection;
|
||||
WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient<WorkItemTrackingHttpClient>();
|
||||
|
@ -148,59 +228,37 @@ namespace Microsoft.TeamServices.Samples.Client.WorkItemTracking
|
|||
|
||||
Console.WriteLine(workitem.Id);
|
||||
Console.WriteLine("Fields: ");
|
||||
|
||||
foreach (var field in workitem.Fields)
|
||||
{
|
||||
Console.WriteLine(" {0}: {1}", field.Key, field.Value);
|
||||
}
|
||||
|
||||
Console.WriteLine("Relations: ");
|
||||
foreach (var relation in workitem.Relations)
|
||||
|
||||
if (workitem.Relations == null)
|
||||
{
|
||||
Console.WriteLine(" {0} {1}", relation.Rel, relation.Url);
|
||||
Console.WriteLine(" No relations found for this work item");
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var relation in workitem.Relations)
|
||||
{
|
||||
Console.WriteLine(" {0} {1}", relation.Rel, relation.Url);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return workitem;
|
||||
}
|
||||
|
||||
[ClientSampleMethod]
|
||||
public WorkItem CreateWorkItem()
|
||||
{
|
||||
// Construct the object containing field values required for the new work item
|
||||
JsonPatchDocument patchDocument = new JsonPatchDocument();
|
||||
patchDocument.Add(
|
||||
new JsonPatchOperation()
|
||||
{
|
||||
Operation = Operation.Add,
|
||||
Path = "/fields/System.Title",
|
||||
Value = "Sample task"
|
||||
}
|
||||
);
|
||||
|
||||
// Get a client
|
||||
VssConnection connection = Context.Connection;
|
||||
WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient<WorkItemTrackingHttpClient>();
|
||||
|
||||
// Get the project to create the sample work item in
|
||||
TeamProjectReference project = ClientSampleHelpers.FindAnyProject(this.Context);
|
||||
|
||||
// Create the new work item
|
||||
WorkItem newWorkItem = workItemTrackingClient.CreateWorkItemAsync(patchDocument, project.Id, "Task").Result;
|
||||
|
||||
Console.WriteLine("Created work item ID {0} {1}", newWorkItem.Id, newWorkItem.Fields["System.Title"]);
|
||||
|
||||
// Save this newly created for later samples
|
||||
Context.SetValue<WorkItem>("$newWorkItem", newWorkItem);
|
||||
|
||||
return newWorkItem;
|
||||
}
|
||||
}
|
||||
|
||||
[ClientSampleMethod]
|
||||
public WorkItem CreateAndLinkToWorkItem()
|
||||
{
|
||||
string title = "My new work item with links";
|
||||
string description = "This is a new work item that has a link also created on it.";
|
||||
string linkUrl = "https://integrate.visualstudio.com";
|
||||
|
||||
string linkUrl = Context.GetValue<WorkItem>("$newWorkItem1").Url; //get the url of a previously added work item
|
||||
|
||||
JsonPatchDocument patchDocument = new JsonPatchDocument();
|
||||
|
||||
patchDocument.Add(
|
||||
|
@ -210,16 +268,7 @@ namespace Microsoft.TeamServices.Samples.Client.WorkItemTracking
|
|||
Path = "/fields/System.Title",
|
||||
Value = title
|
||||
}
|
||||
);
|
||||
|
||||
patchDocument.Add(
|
||||
new JsonPatchOperation()
|
||||
{
|
||||
Operation = Operation.Add,
|
||||
Path = "/fields/Microsoft.VSTS.Scheduling.RemainingWork",
|
||||
Value = "4"
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
patchDocument.Add(
|
||||
new JsonPatchOperation()
|
||||
|
@ -306,15 +355,15 @@ namespace Microsoft.TeamServices.Samples.Client.WorkItemTracking
|
|||
TeamProjectReference project = ClientSampleHelpers.FindAnyProject(this.Context);
|
||||
|
||||
WorkItem result = workItemTrackingClient.CreateWorkItemAsync(patchDocument, project.Name, "Task", bypassRules: true).Result;
|
||||
|
||||
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
[ClientSampleMethod]
|
||||
public WorkItem ChangeFieldValue(int id)
|
||||
public WorkItem ChangeFieldValue()
|
||||
{
|
||||
int id = Convert.ToInt32(Context.GetValue<WorkItem>("$newWorkItem").Id);
|
||||
|
||||
JsonPatchDocument patchDocument = new JsonPatchDocument();
|
||||
|
||||
patchDocument.Add(
|
||||
|
@ -330,8 +379,8 @@ namespace Microsoft.TeamServices.Samples.Client.WorkItemTracking
|
|||
new JsonPatchOperation()
|
||||
{
|
||||
Operation = Operation.Add,
|
||||
Path = "/fields/Microsoft.VSTS.Common.Priority",
|
||||
Value = "2"
|
||||
Path = "/fields/System.Title",
|
||||
Value = "This is the new title for my work item"
|
||||
}
|
||||
);
|
||||
|
||||
|
@ -350,85 +399,12 @@ namespace Microsoft.TeamServices.Samples.Client.WorkItemTracking
|
|||
WorkItem result = workItemTrackingClient.UpdateWorkItemAsync(patchDocument, id).Result;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
[ClientSampleMethod]
|
||||
public WorkItem MoveToAnotherProject()
|
||||
{
|
||||
int id = -1;
|
||||
string targetProject = null;
|
||||
string targetAreaPath = null;
|
||||
string targetIterationPath = null;
|
||||
|
||||
JsonPatchDocument patchDocument = new JsonPatchDocument();
|
||||
|
||||
patchDocument.Add(
|
||||
new JsonPatchOperation() {
|
||||
Operation = Operation.Add,
|
||||
Path = "/fields/System.TeamProject",
|
||||
Value = targetProject
|
||||
}
|
||||
);
|
||||
|
||||
patchDocument.Add(
|
||||
new JsonPatchOperation() {
|
||||
Operation = Operation.Add,
|
||||
Path = "/fields/System.AreaPath",
|
||||
Value = targetAreaPath
|
||||
}
|
||||
);
|
||||
|
||||
patchDocument.Add(
|
||||
new JsonPatchOperation() {
|
||||
Operation = Operation.Add,
|
||||
Path = "/fields/System.IterationPath",
|
||||
Value = targetIterationPath
|
||||
}
|
||||
);
|
||||
|
||||
VssConnection connection = Context.Connection;
|
||||
WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient<WorkItemTrackingHttpClient>();
|
||||
|
||||
WorkItem result = workItemTrackingClient.UpdateWorkItemAsync(patchDocument, id).Result;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
[ClientSampleMethod]
|
||||
public WorkItem ChangeType()
|
||||
{
|
||||
int id = 12;
|
||||
|
||||
JsonPatchDocument patchDocument = new JsonPatchDocument();
|
||||
|
||||
patchDocument.Add(
|
||||
new JsonPatchOperation() {
|
||||
Operation = Operation.Add,
|
||||
Path = "/fields/System.WorkItemType",
|
||||
Value = "User Story"
|
||||
}
|
||||
);
|
||||
|
||||
patchDocument.Add(
|
||||
new JsonPatchOperation() {
|
||||
Operation = Operation.Add,
|
||||
Path = "/fields/System.State",
|
||||
Value = "Active"
|
||||
}
|
||||
);
|
||||
|
||||
VssConnection connection = Context.Connection;
|
||||
WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient<WorkItemTrackingHttpClient>();
|
||||
|
||||
WorkItem result = workItemTrackingClient.UpdateWorkItemAsync(patchDocument, id).Result;
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
[ClientSampleMethod]
|
||||
public WorkItem AddTags()
|
||||
{
|
||||
int id = 12;
|
||||
int id = Convert.ToInt32(Context.GetValue<WorkItem>("$newWorkItem2").Id);
|
||||
string[] tags = { "teamservices", "client", "sample" };
|
||||
|
||||
JsonPatchDocument patchDocument = new JsonPatchDocument();
|
||||
|
@ -453,8 +429,8 @@ namespace Microsoft.TeamServices.Samples.Client.WorkItemTracking
|
|||
[ClientSampleMethod]
|
||||
public WorkItem LinkToOtherWorkItem()
|
||||
{
|
||||
int sourceWorkItemId = 1;
|
||||
int targetWorkItemId = 1;
|
||||
int sourceWorkItemId = Convert.ToInt32(Context.GetValue<WorkItem>("$newWorkItem1").Id);
|
||||
int targetWorkItemId = Convert.ToInt32(Context.GetValue<WorkItem>("$newWorkItem2").Id);
|
||||
|
||||
VssConnection connection = Context.Connection;
|
||||
WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient<WorkItemTrackingHttpClient>();
|
||||
|
@ -476,7 +452,6 @@ namespace Microsoft.TeamServices.Samples.Client.WorkItemTracking
|
|||
}
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
WorkItem result = workItemTrackingClient.UpdateWorkItemAsync(patchDocument, sourceWorkItemId).Result;
|
||||
|
||||
|
@ -486,7 +461,7 @@ namespace Microsoft.TeamServices.Samples.Client.WorkItemTracking
|
|||
[ClientSampleMethod]
|
||||
public WorkItem UpdateLinkComment()
|
||||
{
|
||||
int id = 12;
|
||||
int id = Convert.ToInt32(Context.GetValue<WorkItem>("$newWorkItem1").Id);
|
||||
|
||||
JsonPatchDocument patchDocument = new JsonPatchDocument();
|
||||
|
||||
|
@ -516,7 +491,7 @@ namespace Microsoft.TeamServices.Samples.Client.WorkItemTracking
|
|||
|
||||
public WorkItem RemoveLink()
|
||||
{
|
||||
int id = 12;
|
||||
int id = Convert.ToInt32(Context.GetValue<WorkItem>("$newWorkItem1").Id);
|
||||
|
||||
JsonPatchDocument patchDocument = new JsonPatchDocument();
|
||||
|
||||
|
@ -546,8 +521,8 @@ namespace Microsoft.TeamServices.Samples.Client.WorkItemTracking
|
|||
[ClientSampleMethod]
|
||||
public WorkItem AddAttachment()
|
||||
{
|
||||
int id = -1;
|
||||
string filePath = null;
|
||||
int id = Convert.ToInt32(Context.GetValue<WorkItem>("$newWorkItem3").Id);
|
||||
string filePath = ClientSampleHelpers.GetSampleTextFile();
|
||||
|
||||
VssConnection connection = Context.Connection;
|
||||
WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient<WorkItemTrackingHttpClient>();
|
||||
|
@ -596,9 +571,9 @@ namespace Microsoft.TeamServices.Samples.Client.WorkItemTracking
|
|||
|
||||
[ClientSampleMethod]
|
||||
public WorkItem RemoveAttachment()
|
||||
{
|
||||
int id = -1;
|
||||
string rev = null;
|
||||
{
|
||||
int id = Convert.ToInt32(Context.GetValue<WorkItem>("$newWorkItem3").Id);
|
||||
string rev = "0";
|
||||
|
||||
JsonPatchDocument patchDocument = new JsonPatchDocument();
|
||||
|
||||
|
@ -630,9 +605,7 @@ namespace Microsoft.TeamServices.Samples.Client.WorkItemTracking
|
|||
[ClientSampleMethod]
|
||||
public WorkItem UpdateWorkItemAddHyperLink()
|
||||
{
|
||||
int id = -1;
|
||||
Uri url = null;
|
||||
string urlComment = null;
|
||||
int id = Convert.ToInt32(Context.GetValue<WorkItem>("$newWorkItem2").Id);
|
||||
|
||||
JsonPatchDocument patchDocument = new JsonPatchDocument();
|
||||
|
||||
|
@ -641,7 +614,7 @@ namespace Microsoft.TeamServices.Samples.Client.WorkItemTracking
|
|||
{
|
||||
Operation = Operation.Test,
|
||||
Path = "/rev",
|
||||
Value = "1"
|
||||
Value = "2"
|
||||
}
|
||||
);
|
||||
|
||||
|
@ -653,8 +626,7 @@ namespace Microsoft.TeamServices.Samples.Client.WorkItemTracking
|
|||
Value = new
|
||||
{
|
||||
rel = "Hyperlink",
|
||||
url = (url == null ? new Uri("http://www.visualstudio.com/team-services") : url),
|
||||
attributes = new { comment = (string.IsNullOrEmpty(urlComment) ? "Visual Studio Team Services" : urlComment) }
|
||||
url = "https://docs.microsoft.com/en-us/rest/api/vsts/"
|
||||
}
|
||||
}
|
||||
);
|
||||
|
@ -665,51 +637,13 @@ namespace Microsoft.TeamServices.Samples.Client.WorkItemTracking
|
|||
WorkItem result = workItemTrackingClient.UpdateWorkItemAsync(patchDocument, id).Result;
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
[ClientSampleMethod]
|
||||
public WorkItem UpdateWorkItemAddCommitLink()
|
||||
public WorkItem UpdateWorkItemUsingByPassRules()
|
||||
{
|
||||
int workItemId = 12;
|
||||
string commitUri = null; // vstfs:///Git/Commit/1435ac99-ba45-43e7-9c3d-0e879e7f2691%2Fd00dd2d9-55dd-46fc-ad00-706891dfbc48%2F3fefa488aac46898a25464ca96009cf05a6426e3
|
||||
int id = Convert.ToInt32(Context.GetValue<WorkItem>("$newWorkItem2").Id);
|
||||
|
||||
|
||||
JsonPatchDocument patchDocument = new JsonPatchDocument();
|
||||
|
||||
patchDocument.Add(
|
||||
new JsonPatchOperation()
|
||||
{
|
||||
Operation = Operation.Test,
|
||||
Path = "/rev",
|
||||
Value = "1"
|
||||
}
|
||||
);
|
||||
|
||||
patchDocument.Add(
|
||||
new JsonPatchOperation()
|
||||
{
|
||||
Operation = Operation.Add,
|
||||
Path = "/relations/-",
|
||||
Value = new
|
||||
{
|
||||
rel = "ArtifactLink",
|
||||
url = commitUri,
|
||||
attributes = new { comment = "Fixed in Commit" }
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
VssConnection connection = Context.Connection;
|
||||
WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient<WorkItemTrackingHttpClient>();
|
||||
|
||||
WorkItem result = workItemTrackingClient.UpdateWorkItemAsync(patchDocument, workItemId).Result;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
[ClientSampleMethod]
|
||||
public WorkItem UpdateWorkItemUsingByPassRules(int id)
|
||||
{
|
||||
JsonPatchDocument patchDocument = new JsonPatchDocument();
|
||||
|
||||
patchDocument.Add(
|
||||
|
@ -731,23 +665,138 @@ namespace Microsoft.TeamServices.Samples.Client.WorkItemTracking
|
|||
[ClientSampleMethod]
|
||||
public WorkItemDelete DeleteWorkItem()
|
||||
{
|
||||
WorkItem workitem;
|
||||
if (!Context.TryGetValue<WorkItem>("$newWorkItem", out workitem) || workitem.Id == null)
|
||||
{
|
||||
Console.WriteLine("Run the create sample before running this.");
|
||||
}
|
||||
int id = Convert.ToInt32(Context.GetValue<WorkItem>("$newWorkItem2").Id);
|
||||
|
||||
// Get a client
|
||||
VssConnection connection = Context.Connection;
|
||||
WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient<WorkItemTrackingHttpClient>();
|
||||
|
||||
// Delete the work item (but don't destroy it completely)
|
||||
WorkItemDelete results = workItemTrackingClient.DeleteWorkItemAsync(workitem.Id.Value, destroy: false).Result;
|
||||
WorkItemDelete results = workItemTrackingClient.DeleteWorkItemAsync(id, destroy: false).Result;
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
public WorkItem MoveToAnotherProject()
|
||||
{
|
||||
int id = -1;
|
||||
string targetProject = null;
|
||||
string targetAreaPath = null;
|
||||
string targetIterationPath = null;
|
||||
|
||||
JsonPatchDocument patchDocument = new JsonPatchDocument();
|
||||
|
||||
patchDocument.Add(
|
||||
new JsonPatchOperation()
|
||||
{
|
||||
Operation = Operation.Add,
|
||||
Path = "/fields/System.TeamProject",
|
||||
Value = targetProject
|
||||
}
|
||||
);
|
||||
|
||||
patchDocument.Add(
|
||||
new JsonPatchOperation()
|
||||
{
|
||||
Operation = Operation.Add,
|
||||
Path = "/fields/System.AreaPath",
|
||||
Value = targetAreaPath
|
||||
}
|
||||
);
|
||||
|
||||
patchDocument.Add(
|
||||
new JsonPatchOperation()
|
||||
{
|
||||
Operation = Operation.Add,
|
||||
Path = "/fields/System.IterationPath",
|
||||
Value = targetIterationPath
|
||||
}
|
||||
);
|
||||
|
||||
VssConnection connection = Context.Connection;
|
||||
WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient<WorkItemTrackingHttpClient>();
|
||||
|
||||
WorkItem result = workItemTrackingClient.UpdateWorkItemAsync(patchDocument, id).Result;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public WorkItem ChangeType()
|
||||
{
|
||||
WorkItem newWorkItem;
|
||||
using (new ClientSampleHttpLoggerOutputSuppression())
|
||||
{
|
||||
newWorkItem = this.CreateWorkItem("Another Sample Work Item");
|
||||
}
|
||||
|
||||
int id = Convert.ToInt32(newWorkItem.Id);
|
||||
|
||||
JsonPatchDocument patchDocument = new JsonPatchDocument();
|
||||
|
||||
patchDocument.Add(
|
||||
new JsonPatchOperation()
|
||||
{
|
||||
Operation = Operation.Add,
|
||||
Path = "/fields/System.WorkItemType",
|
||||
Value = "User Story"
|
||||
}
|
||||
);
|
||||
|
||||
patchDocument.Add(
|
||||
new JsonPatchOperation()
|
||||
{
|
||||
Operation = Operation.Add,
|
||||
Path = "/fields/System.State",
|
||||
Value = "Active"
|
||||
}
|
||||
);
|
||||
|
||||
VssConnection connection = Context.Connection;
|
||||
WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient<WorkItemTrackingHttpClient>();
|
||||
|
||||
WorkItem result = workItemTrackingClient.UpdateWorkItemAsync(patchDocument, id).Result;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public WorkItem UpdateWorkItemAddCommitLink()
|
||||
{
|
||||
int id = Convert.ToInt32(Context.GetValue<WorkItem>("$newWorkItem2").Id);
|
||||
string commitUri = null; // vstfs:///Git/Commit/1435ac99-ba45-43e7-9c3d-0e879e7f2691%2Fd00dd2d9-55dd-46fc-ad00-706891dfbc48%2F3fefa488aac46898a25464ca96009cf05a6426e3
|
||||
|
||||
JsonPatchDocument patchDocument = new JsonPatchDocument();
|
||||
|
||||
patchDocument.Add(
|
||||
new JsonPatchOperation()
|
||||
{
|
||||
Operation = Operation.Test,
|
||||
Path = "/rev",
|
||||
Value = "3"
|
||||
}
|
||||
);
|
||||
|
||||
patchDocument.Add(
|
||||
new JsonPatchOperation()
|
||||
{
|
||||
Operation = Operation.Add,
|
||||
Path = "/relations/-",
|
||||
Value = new
|
||||
{
|
||||
rel = "ArtifactLink",
|
||||
url = commitUri,
|
||||
attributes = new { comment = "Fixed in Commit" }
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
VssConnection connection = Context.Connection;
|
||||
WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient<WorkItemTrackingHttpClient>();
|
||||
|
||||
WorkItem result = workItemTrackingClient.UpdateWorkItemAsync(patchDocument, id).Result;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
[ClientSampleMethod]
|
||||
public void UpdateWorkItemsByQueryResults(WorkItemQueryResult workItemQueryResult, string changedBy)
|
||||
{
|
||||
JsonPatchDocument patchDocument = new JsonPatchDocument();
|
||||
|
|
Загрузка…
Ссылка в новой задаче