Add more ClientSampleMethod
This commit is contained in:
Родитель
d26bfc762b
Коммит
fbd3f73e13
|
@ -1,4 +1,5 @@
|
|||
using Microsoft.TeamFoundation.Build.WebApi;
|
||||
using Microsoft.TeamServices.Samples.Client.Build;
|
||||
using Microsoft.VisualStudio.Services.WebApi;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
@ -12,7 +13,6 @@ namespace Microsoft.TeamServices.Samples.Client.Build
|
|||
public class BuildsSample : ClientSample
|
||||
{
|
||||
[ClientSampleMethod]
|
||||
|
||||
public IEnumerable<BuildDefinitionReference> ListBuildDefinitions()
|
||||
{
|
||||
string projectName = ClientSampleHelpers.FindAnyProject(this.Context).Name;
|
||||
|
@ -44,5 +44,98 @@ namespace Microsoft.TeamServices.Samples.Client.Build
|
|||
|
||||
return buildDefinitions;
|
||||
}
|
||||
|
||||
[ClientSampleMethod]
|
||||
public BuildArtifact CreateArtifact()
|
||||
{
|
||||
BuildArtifact result = new BuildArtifact();
|
||||
// Get a build client instance
|
||||
VssConnection connection = Context.Connection;
|
||||
BuildHttpClient buildClient = connection.GetClient<BuildHttpClient>();
|
||||
|
||||
ArtifactResource newArtifactResource = new ArtifactResource()
|
||||
{
|
||||
Type = "new ArtifactResource type",
|
||||
Data = "new ArtifactResource Data",
|
||||
Properties = null,
|
||||
Url = "new Url",
|
||||
DownloadUrl = "new DownloadUrl",
|
||||
DownloadTicket = "new downloadticket"
|
||||
};
|
||||
|
||||
|
||||
BuildArtifact newArtifact = new BuildArtifact()
|
||||
{
|
||||
Id = 900,
|
||||
Name = "New test artifact",
|
||||
Resource = newArtifactResource
|
||||
};
|
||||
|
||||
BuildArtifact newArtifact2 = new BuildArtifact()
|
||||
{
|
||||
Id = 901,
|
||||
Name = "New test artifact 2",
|
||||
Resource = newArtifactResource
|
||||
};
|
||||
|
||||
try
|
||||
{
|
||||
result = buildClient.CreateArtifactAsync(newArtifact, 1).Result;
|
||||
result = buildClient.CreateArtifactAsync(newArtifact2, 1).Result;
|
||||
|
||||
Console.WriteLine("success");
|
||||
Console.WriteLine("{0}", newArtifact.Name);
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine("failed");
|
||||
Console.WriteLine("Error creating artifact: " + ex.InnerException.Message);
|
||||
}
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
[ClientSampleMethod]
|
||||
public List<BuildArtifact> GetAllArtifacts()
|
||||
{
|
||||
// Get a build client instance
|
||||
VssConnection connection = Context.Connection;
|
||||
BuildHttpClient buildClient = connection.GetClient<BuildHttpClient>();
|
||||
|
||||
List<BuildArtifact> artifactsList = buildClient.GetArtifactsAsync(1).Result;
|
||||
|
||||
return artifactsList;
|
||||
}
|
||||
|
||||
[ClientSampleMethod]
|
||||
public BuildArtifact GetArtifact()
|
||||
{
|
||||
VssConnection connection = Context.Connection;
|
||||
BuildHttpClient buildClient = connection.GetClient<BuildHttpClient>();
|
||||
|
||||
BuildArtifact result = buildClient.GetArtifactAsync("Test Project", 1, "New test artifact").Result;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
[ClientSampleMethod]
|
||||
public void GetFile()
|
||||
{
|
||||
System.Diagnostics.Debugger.Launch();
|
||||
VssConnection connection = Context.Connection;
|
||||
BuildHttpClient buildClient = connection.GetClient<BuildHttpClient>();
|
||||
|
||||
//int buildId, string artifactName, string fileId, string fileName
|
||||
try
|
||||
{
|
||||
var result = buildClient.GetFileAsync(1, "New test artifact", "1", "test file").Result;
|
||||
Console.WriteLine("Get file successed");
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
Console.WriteLine("Get File failed: " + e.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,6 +18,46 @@ namespace Microsoft.TeamServices.Samples.Client.WorkItemTracking
|
|||
[ClientSample(WitConstants.WorkItemTrackingWebConstants.RestAreaName, WitConstants.WorkItemTrackingRestResources.Fields)]
|
||||
public class FieldsSample : ClientSample
|
||||
{
|
||||
[ClientSampleMethod]
|
||||
public WorkItemField CreateWorkItemField()
|
||||
{
|
||||
WorkItemField result = new WorkItemField();
|
||||
|
||||
WorkItemField newWorkItemField = new WorkItemField()
|
||||
{
|
||||
Name = "New Work Item Field",
|
||||
ReferenceName = "SupportedOperations.GreaterThanEquals",
|
||||
Description = null,
|
||||
Type = FieldType.String,
|
||||
Usage = FieldUsage.WorkItem,
|
||||
ReadOnly = false,
|
||||
CanSortBy = true,
|
||||
IsQueryable = true,
|
||||
SupportedOperations = new List<WorkItemFieldOperation>()
|
||||
{
|
||||
new WorkItemFieldOperation(){ ReferenceName="SupportedOperations.Equals", Name="="}
|
||||
},
|
||||
IsIdentity = true,
|
||||
IsPicklist = false,
|
||||
IsPicklistSuggested = false
|
||||
|
||||
};
|
||||
|
||||
VssConnection connection = Context.Connection;
|
||||
WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient<WorkItemTrackingHttpClient>();
|
||||
|
||||
try
|
||||
{
|
||||
result = workItemTrackingClient.CreateFieldAsync(newWorkItemField).Result;
|
||||
Console.WriteLine("Work Item Field Created.");
|
||||
}
|
||||
catch
|
||||
{
|
||||
Console.WriteLine("Work Item Field Failed.");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
[ClientSampleMethod]
|
||||
public WorkItemField GetFieldDetails()
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using Microsoft.TeamFoundation.Core.WebApi;
|
||||
using Microsoft.TeamFoundation.Core.WebApi.Types;
|
||||
using Microsoft.TeamFoundation.SourceControl.WebApi;
|
||||
using Microsoft.TeamFoundation.WorkItemTracking.WebApi;
|
||||
using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models;
|
||||
|
@ -998,5 +999,110 @@ namespace Microsoft.TeamServices.Samples.Client.WorkItemTracking
|
|||
}
|
||||
}
|
||||
|
||||
[ClientSampleMethod]
|
||||
public WorkItem GetWorkItemTemplate()
|
||||
{
|
||||
VssConnection connection = Context.Connection;
|
||||
WorkItemTrackingHttpClient client = connection.GetClient<WorkItemTrackingHttpClient>();
|
||||
|
||||
WorkItem result = client.GetWorkItemTemplateAsync("Test Project", "Bug").Result;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
[ClientSampleMethod]
|
||||
public WorkItemTemplate CreateTemplate()
|
||||
{
|
||||
VssConnection connection = Context.Connection;
|
||||
WorkItemTrackingHttpClient client = connection.GetClient<WorkItemTrackingHttpClient>();
|
||||
|
||||
Dictionary<string, string> field = new Dictionary<string, string>
|
||||
{
|
||||
{ "System.State", "New" }
|
||||
};
|
||||
|
||||
WorkItemTemplate template = new WorkItemTemplate()
|
||||
{
|
||||
Name = "Test Template",
|
||||
Description = "",
|
||||
WorkItemTypeName = "Feature",
|
||||
Fields = field
|
||||
};
|
||||
TeamContext teamContext = new TeamContext("Test Project", "Test Project Team");
|
||||
WorkItemTemplate result = null;
|
||||
|
||||
try
|
||||
{
|
||||
result = client.CreateTemplateAsync(template, teamContext).Result;
|
||||
Console.WriteLine("Create Work Item Template Successed.");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine("Create Work Item Template Failed:" + e.Message);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
[ClientSampleMethod]
|
||||
public List<WorkItemTemplateReference> ListTemplates()
|
||||
{
|
||||
TeamContext teamContext = new TeamContext("Test Project", "Test Project Team");
|
||||
VssConnection connection = Context.Connection;
|
||||
WorkItemTrackingHttpClient client = connection.GetClient<WorkItemTrackingHttpClient>();
|
||||
|
||||
List<WorkItemTemplateReference> result = client.GetTemplatesAsync(teamContext).Result;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
[ClientSampleMethod]
|
||||
public WorkItem GetTemplate()
|
||||
{
|
||||
VssConnection connection = Context.Connection;
|
||||
WorkItemTrackingHttpClient client = connection.GetClient<WorkItemTrackingHttpClient>();
|
||||
|
||||
WorkItem result = client.GetWorkItemTemplateAsync("Test Project", "Feature").Result;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/*To make this work, first run create template. Then comment out create template and replace the templateID*/
|
||||
[ClientSampleMethod]
|
||||
public WorkItemTemplate ReplaceTemplate()
|
||||
{
|
||||
VssConnection connection = Context.Connection;
|
||||
WorkItemTrackingHttpClient client = connection.GetClient<WorkItemTrackingHttpClient>();
|
||||
|
||||
Guid templateID = new Guid("d35d406c-32fa-4316-ba6e-76bb564beaaa"); /*Replace template ID from get template*/
|
||||
Dictionary<string, string> field = new Dictionary<string, string>
|
||||
{
|
||||
{ "System.State", "Old" }
|
||||
};
|
||||
|
||||
WorkItemTemplate template = new WorkItemTemplate()
|
||||
{
|
||||
Name = "Test Template",
|
||||
Description = "",
|
||||
WorkItemTypeName = "Feature",
|
||||
Fields = field
|
||||
};
|
||||
TeamContext teamContext = new TeamContext("Test Project", "Test Project Team");
|
||||
WorkItemTemplate result = null;
|
||||
|
||||
try
|
||||
{
|
||||
result = client.ReplaceTemplateAsync(template, teamContext, templateID).Result;
|
||||
Console.WriteLine("Replace template successed.");
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
result = null;
|
||||
Console.WriteLine("Replace template failed: " + e.Message);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,4 +37,10 @@ namespace Microsoft.TeamServices.Samples.Client.WorkItemTrackingProcess
|
|||
return group;
|
||||
}
|
||||
}
|
||||
static class OutOfBoxProcessTemplateTypeIds
|
||||
{
|
||||
public static readonly Guid Agile = new Guid("ADCC42AB-9882-485E-A3ED-7678F01F66BC");
|
||||
public static readonly Guid Scrum = new Guid("6B724908-EF14-45CF-84F8-768B5384DA45");
|
||||
public static readonly Guid Cmmi = new Guid("27450541-8E31-4150-9947-DC59F998FC01");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -130,6 +130,20 @@ namespace Microsoft.TeamServices.Samples.Client.WorkItemTrackingProcess
|
|||
return processInfo;
|
||||
}
|
||||
|
||||
[ClientSampleMethod]
|
||||
public ProcessInfo Process_GetById()
|
||||
{
|
||||
|
||||
VssConnection connection = Context.Connection;
|
||||
WorkItemTrackingProcessHttpClient client = connection.GetClient<WorkItemTrackingProcessHttpClient>();
|
||||
|
||||
//extra step to get the process by name
|
||||
//you should not have to do this
|
||||
var processInfo = client.GetProcessByItsIdAsync(OutOfBoxProcessTemplateTypeIds.Agile).Result;
|
||||
|
||||
return processInfo;
|
||||
}
|
||||
|
||||
[ClientSampleMethod]
|
||||
public List<ProcessWorkItemType> WorkItemTypes_List()
|
||||
{
|
||||
|
@ -151,6 +165,69 @@ namespace Microsoft.TeamServices.Samples.Client.WorkItemTrackingProcess
|
|||
return list;
|
||||
}
|
||||
|
||||
[ClientSampleMethod]
|
||||
public List<ProcessWorkItemType> WorkItemTypes_List_Expand_State()
|
||||
{
|
||||
//get process id stored in cache so we don't have to load it each time
|
||||
System.Guid processId = Context.GetValue<Guid>("$processId");
|
||||
|
||||
VssConnection connection = Context.Connection;
|
||||
WorkItemTrackingProcessHttpClient client = connection.GetClient<WorkItemTrackingProcessHttpClient>();
|
||||
|
||||
Console.Write("Getting list of work item types for '" + processId.ToString() + "'...");
|
||||
List<ProcessWorkItemType> list = client.GetProcessWorkItemTypesAsync(processId, expand:GetWorkItemTypeExpand.States).Result;
|
||||
Console.WriteLine("success");
|
||||
|
||||
foreach (var item in list)
|
||||
{
|
||||
Console.WriteLine("{0} : {1}", item.Name, item.ReferenceName);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
[ClientSampleMethod]
|
||||
public List<ProcessWorkItemType> WorkItemTypes_List_Expand_Behaviors()
|
||||
{
|
||||
//get process id stored in cache so we don't have to load it each time
|
||||
System.Guid processId = Context.GetValue<Guid>("$processId");
|
||||
|
||||
VssConnection connection = Context.Connection;
|
||||
WorkItemTrackingProcessHttpClient client = connection.GetClient<WorkItemTrackingProcessHttpClient>();
|
||||
|
||||
Console.Write("Getting list of work item types for '" + processId.ToString() + "'...");
|
||||
List<ProcessWorkItemType> list = client.GetProcessWorkItemTypesAsync(processId, expand: GetWorkItemTypeExpand.Behaviors).Result;
|
||||
Console.WriteLine("success");
|
||||
|
||||
foreach (var item in list)
|
||||
{
|
||||
Console.WriteLine("{0} : {1}", item.Name, item.ReferenceName);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
[ClientSampleMethod]
|
||||
public List<ProcessWorkItemType> WorkItemTypes_List_Expand_Layout()
|
||||
{
|
||||
//get process id stored in cache so we don't have to load it each time
|
||||
System.Guid processId = Context.GetValue<Guid>("$processId");
|
||||
|
||||
VssConnection connection = Context.Connection;
|
||||
WorkItemTrackingProcessHttpClient client = connection.GetClient<WorkItemTrackingProcessHttpClient>();
|
||||
|
||||
Console.Write("Getting list of work item types for '" + processId.ToString() + "'...");
|
||||
List<ProcessWorkItemType> list = client.GetProcessWorkItemTypesAsync(processId, expand: GetWorkItemTypeExpand.Layout).Result;
|
||||
Console.WriteLine("success");
|
||||
|
||||
foreach (var item in list)
|
||||
{
|
||||
Console.WriteLine("{0} : {1}", item.Name, item.ReferenceName);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
[ClientSampleMethod]
|
||||
public ProcessWorkItemType WorkItemTypes_Create()
|
||||
{
|
||||
|
@ -158,6 +235,7 @@ namespace Microsoft.TeamServices.Samples.Client.WorkItemTrackingProcess
|
|||
System.Guid processId = Context.GetValue<Guid>("$processId");
|
||||
|
||||
ProcessWorkItemType processWorkItemType = null;
|
||||
ProcessWorkItemType creatProcessWorkItemTypeResult = null;
|
||||
|
||||
CreateProcessWorkItemTypeRequest createWorkItemType = new CreateProcessWorkItemTypeRequest()
|
||||
{
|
||||
|
@ -186,7 +264,7 @@ namespace Microsoft.TeamServices.Samples.Client.WorkItemTrackingProcess
|
|||
try
|
||||
{
|
||||
//create new work item type
|
||||
processWorkItemType = client.CreateProcessWorkItemTypeAsync(createWorkItemType, processId).Result;
|
||||
creatProcessWorkItemTypeResult = client.CreateProcessWorkItemTypeAsync(createWorkItemType, processId).Result;
|
||||
|
||||
Console.WriteLine("success");
|
||||
Console.WriteLine("{0} : {1}", processWorkItemType.Name, processWorkItemType.ReferenceName);
|
||||
|
@ -205,6 +283,25 @@ namespace Microsoft.TeamServices.Samples.Client.WorkItemTrackingProcess
|
|||
|
||||
Context.SetValue<ProcessWorkItemType>("$newWorkItemType", processWorkItemType);
|
||||
|
||||
return creatProcessWorkItemTypeResult;
|
||||
}
|
||||
|
||||
[ClientSampleMethod]
|
||||
public ProcessWorkItemType WorkItemType_Get()
|
||||
{
|
||||
ProcessWorkItemType processWorkItemType = null;
|
||||
|
||||
//get process id stored in cache so we don't have to load it each time
|
||||
System.Guid processId = Context.GetValue<Guid>("$processId");
|
||||
|
||||
VssConnection connection = Context.Connection;
|
||||
WorkItemTrackingProcessHttpClient client = connection.GetClient<WorkItemTrackingProcessHttpClient>();
|
||||
|
||||
//load the process by id
|
||||
processWorkItemType = client.GetProcessWorkItemTypeAsync(processId, _witRefName).Result;
|
||||
|
||||
Console.WriteLine("Getting work item type for " + _refName);
|
||||
|
||||
return processWorkItemType;
|
||||
}
|
||||
|
||||
|
@ -415,6 +512,7 @@ namespace Microsoft.TeamServices.Samples.Client.WorkItemTrackingProcess
|
|||
return field;
|
||||
}
|
||||
|
||||
|
||||
[ClientSampleMethod]
|
||||
public ProcessWorkItemTypeField Field_AddFieldToWorkItemType()
|
||||
{
|
||||
|
@ -460,5 +558,56 @@ namespace Microsoft.TeamServices.Samples.Client.WorkItemTrackingProcess
|
|||
return processWorkItemTypeField;
|
||||
}
|
||||
}
|
||||
|
||||
[ClientSampleMethod]
|
||||
public List<ProcessWorkItemTypeField> Field_GetAllWorkItemTypeFieldsAsync()
|
||||
{
|
||||
System.Guid processId = Context.GetValue<Guid>("$processId");
|
||||
|
||||
VssConnection connection = Context.Connection;
|
||||
WorkItemTrackingProcessHttpClient client = connection.GetClient<WorkItemTrackingProcessHttpClient>();
|
||||
|
||||
//get the list of fields on the work item item
|
||||
Console.Write("Loading list of fields on the work item and checking to see if field '{0}' already exists...", _fieldRefName);
|
||||
|
||||
List<ProcessWorkItemTypeField> list = client.GetAllWorkItemTypeFieldsAsync(processId, _witRefName).Result;
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
[ClientSampleMethod]
|
||||
public ProcessWorkItemTypeField Field_GetWorkItemTypeField()
|
||||
{
|
||||
ProcessWorkItemTypeField processWorkItemTypeField = null;
|
||||
System.Guid processId = Context.GetValue<Guid>("$processId");
|
||||
|
||||
VssConnection connection = Context.Connection;
|
||||
WorkItemTrackingProcessHttpClient client = connection.GetClient<WorkItemTrackingProcessHttpClient>();
|
||||
|
||||
processWorkItemTypeField = client.GetWorkItemTypeFieldAsync(processId, _witRefName, _fieldRefName).Result;
|
||||
|
||||
return processWorkItemTypeField;
|
||||
}
|
||||
|
||||
[ClientSampleMethod]
|
||||
public ProcessWorkItemTypeField Field_UpdateWorkItemTypeField()
|
||||
{
|
||||
UpdateProcessWorkItemTypeFieldRequest newfieldRequest = new UpdateProcessWorkItemTypeFieldRequest()
|
||||
{
|
||||
ReadOnly = false,
|
||||
Required = false,
|
||||
DefaultValue = "Blue",
|
||||
AllowGroups = false
|
||||
};
|
||||
|
||||
System.Guid processId = Context.GetValue<Guid>("$processId");
|
||||
|
||||
VssConnection connection = Context.Connection;
|
||||
WorkItemTrackingProcessHttpClient client = connection.GetClient<WorkItemTrackingProcessHttpClient>();
|
||||
|
||||
ProcessWorkItemTypeField processWorkItemTypeField = client.UpdateWorkItemTypeFieldAsync(newfieldRequest, processId, _witRefName, _fieldRefName).Result;
|
||||
|
||||
return processWorkItemTypeField;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче