同时在 TFS 服务器中保存工作项
本文关键字:保存 工作 服务器 TFS | 更新日期: 2023-09-27 18:33:04
根据我们的要求,需要在父级别分配工作项,并在其树级别分配工作项,如子工作项。
foreach (WorkItem ari in queryResultsARI)
{
if(ari.Fields["Assigned To"].Value.Equals(""))
{
ari.Open();
ari.Fields["Assigned To"].Value = Name;
ari.Fields["Lab"].Value = Location;
ari.Save(SaveFlags.MergeAll);
Thread.Sleep(2000); //give delay for 3 sec to get assigned name, lab location updated in TFS DB
foreach (WorkItemLink varient in ari.Links.WorkItem.WorkItemLinks)
{
WorkItem vri = workItemStore.GetWorkItem(varient.TargetId);
vri.Open();
vri.Fields["Assigned To"].Value = Name;
vri.Fields["Lab"].Value = Location;
vri.Save(SaveFlags.MergeAll);
Thread.Sleep(2000);
foreach (WorkItemLink workorder in vri.Links.WorkItem.WorkItemLinks)
{
if (workorder.LinkTypeEnd.Name == "Child")
{
WorkItem wri = workItemStore.GetWorkItem(workorder.TargetId);
wri.Open();
wri.Fields["Assigned To"].Value = Name;
wri.Fields["Lab"].Value = Location;
wri.Save(SaveFlags.MergeAll);
Thread.Sleep(2000);
但分配给工作项字段正在为尝试保存的多个实例保存。甚至SaveFlags.MergeAll也没有帮助。
有人可以在同一个问题上帮助我们。我们怀疑TFS的计时问题,我们需要找到解决方案。
您可以使用代码片段获取链接到特定工作项的所有工作项的 ID:
TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(new Uri("URL"));
WorkItemStore workitemstores = tfs.GetService<WorkItemStore>();
WorkItem workitem = workitemstores.GetWorkItem(ID);
if(workitem.Links.Count!=0)
{
foreach (Link link in workitem.Links)
{
RelatedLink relatedLink = link as RelatedLink;
if (relatedLink != null)
{
Console.WriteLine(relatedLink.RelatedWorkItemId);
}
}
}
然后将所有这些工作项放在一个数组中,并逐个修改"分配给"字段。