查询从TFS获取数据:
SELECT * FROM WorkItems WHERE [System.WorkItemType] = 'Task' AND [Assigned to] = 'name'
ORDER BY [System.WorkItemType], [System.Id]
这是获取字段的代码
public void getDataFromTfs()
{
Console.WriteLine("Getting data from TFS to Store");
Console.WriteLine("*********************");
setQuery();
Console.WriteLine("Query" + byTasksModified.ToString());
Console.WriteLine("*********************");
Console.ReadLine();
credentials = new System.Net.NetworkCredential("xxxxx", "xxxxxx", "xxxxx");
TfsTeamProjectCollection teamProjectCollection =
new TfsTeamProjectCollection(new Uri(@"LINK HERE"), credentials);
teamProjectCollection.EnsureAuthenticated();
Store = (WorkItemStore) teamProjectCollection.GetService(typeof(WorkItemStore));
WIC = Store.Query(byTasksAssignedTo);
Console.WriteLine("Data fetched into Store");
foreach (WorkItem workItem in WIC)
{
Console.WriteLine("ID: {0}", workItem.Id);
Console.WriteLine("Title: {0}", workItem.Title);
}
}
这里我通过特定查询得到了我需要的所有任务,然后我有了拉取特定任务的方法
public void getSpecificWorkItemData()
{
workItem = Store.GetWorkItem(64);
Console.WriteLine("ID: {0}", workItem.Id);
Console.WriteLine("Title: {0}", workItem.Title);
workItem.Open();
Console.ReadLine();
}
然后我有任务的更新方法
public void updateWorkItem()
{
workItem.Fields["Assigned to"].Value = "NAME";
if (workItem.IsValid() == false)
{
Console.WriteLine("Item is not valid");
}
else
{
try
{
workItem.Save();
}
catch (ValidationException exception)
{
Console.WriteLine("Error saving work item!");
Console.WriteLine(exception.Message);
}
Console.WriteLine("Item Saved");
workItem.Close();
Console.ReadLine();
}
}
答案 0 :(得分:6)
这取决于您的流程模板哪些字段可用。现在您正在查询“任务”工作项,默认情况下“工作”组中包含以下字段。请注意,任务没有“努力”字段,还有其他:
Process Template | Field (s)
Scrum | Remaining Work
MSF Agile | Remaining Work, Completed Work, Original estimate
MSF CMMI | Remaining Work, Completed Work, Original estimate
您所使用的Effort字段在Scrum流程模板中定义,并且由需求类别中的所有工作项使用(默认情况下为Product Backlog Item和Bug):
Process Template | Field (s)
Scrum | Effort
MSF Agile | Story Point
MSF CMMI | Size
如果要更新Scrum Process模板中工作项的Effort字段,最好查询工作项类型类别“Requirement Category”中的工作项:
SELECT *
FROM WorkItems
WHERE [System.TeamProject] = @project
AND [System.WorkItemType] IN GROUP 'Requirement Category'
ORDER BY [System.Id]
如果要更新剩余工作,已完成工时或原始估算字段,则需要使用任务:
SELECT id, Microsoft.VSTS.Scheduling.CompletedWork, Microsoft.VSTS.Scheduling.RemainingWork, Microsoft.VSTS.Scheduling.OriginalEstimate
FROM WorkItems
WHERE [System.TeamProject] = @project
AND [System.WorkItemType] IN GROUP 'Task Category'
ORDER BY [System.Id]
然后根据TFS Field Reference中定义的Ref名称更新它们是最安全的方法:
workItem.Fields["Microsoft.VSTS.Scheduling.CompletedWork"].Value = 123;
workItem.Fields["Microsoft.VSTS.Scheduling.RemainingWork"].Value = 123;
workItem.Fields["Microsoft.VSTS.Scheduling.OriginalEstimate"].Value = 123;