This provider uses the VSTS Rest API to query the workitem repository. The provider uses the standard nuget client package
The provider works like extensions to the WorkItemTrackingHttpClient
class:
The provider support queries on the standard WorkItem class. Use the Field extention method to target specific workitem fields:
var assignedToMe = from workitem in Client.All()
where workitem.Field<string>("System.AssignedTo") == QueryConstant.Me
select workitem;
The provider contains a specific GenericWorkItem class. This class has the following purposes:
- base class for types workitems
- typed fields
- to hide the complexity of the update api
var projectWiQuery = from bug in Client.SetOf<GenericWorkItem>()
where bug.CreatedBy == bug.ChangedBy
select bug;
You can inherits from the Generic WorkItem class and create typed version of workitems. When used, the provider automaticaly add a filter on the workitem type
Bug definition:
[WorkItemType("Bug")]
public class Bug : GenericWorkItem
{
[Field("Microsoft.VSTS.Common.Priority")]
public virtual int? Priority
{
get => GetStructField<int>("Microsoft.VSTS.Common.Priority");
set => SetStructField("Microsoft.VSTS.Common.Priority", value);
}
}
Query on bugs:
var projectWiQuery = from bug in Client.SetOf<Bug>()
where bug.CreatedBy == bug.ChangedBy && bug.Priority == 2
select bug;
You can register a set of typed workitems and let the provider instanciate the right version:
public class ScrumTemplate : ProcessTemplate
{
public ScrumTemplate()
{
AddWorkItemType<Epic>();
AddWorkItemType<Feature>();
AddWorkItemType<ProductBacklogItem>();
AddWorkItemType<Bug>();
AddWorkItemType<Task>();
// ...
}
}
var q = from workitem in Client.FromTemplate<ScrumTemplate>()
select workitem;
As any linq provider, sync queries are supported. You can also use a specific extension method to retrieve the data as an async query:
var projectWiQuery = from bug in Client.SetOf<Bug>(Project)
where bug.IsUnderIteration(iteration)
select bug;
var result = await projectWiQuery.ToListAsync();
Typed workitems can be created and saved by using the New<> and Save<> methods:
var bug = Project.New<Bug>();
bug.Title = "New bug created";
await Client.Save(bug);
bug.Title = "Title Changed";
bug.Priority = 2;
await Client.Save(bug);