Domanda

I want to get the hours I have submitted to work items in TFS programatically. How can I do that?

For example if I add 4 hours to User Story 2222 and Task 1111, I want to be able to extract the hours, userstory number and task number. Is that possible?

È stato utile?

Soluzione

I'd start by looking at the Microsoft.TeamFoundation.WorkItemTracking.Client Namespace and specifically at the WorkItemCollection Class.

You can query for a collection of work items:

TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(new Uri("http://server:8080/tfs/DefaultCollection"));
WorkItemStore workItemStore = (WorkItemStore)tpc.GetService(typeof(WorkItemStore)); 
WorkItemCollection queryResults = workItemStore.Query("
   Select [State], [Title] 
   From WorkItems
   Where [Work Item Type] = 'User Story'
   Order By [State] Asc, [Changed Date] Desc");

or get a specific WorkItem by ID:

WorkItem workItem = workItemStore.GetWorkItem(62);

After you have a specific work item (or a collection of them) and the hours field's name, you can do: WorkItem["field-name"] or WorkItem.Fields["field-name"].Value to get/set the value of the field.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top