WorkItemStore:表示跟蹤與運行 Team Foundation Server的服務器的工做項客戶端鏈接。服務器
A.添加工做項spa
1.首先得到某服務器的WorkItemStore。code
WorkItemStore workstore = server.GetService<WorkItemStore>();server
2.而後經過對上面WorkItemStore得到Project項目。對象
Project project = workstore.Projects["Calueng"];blog
3.根據Project得到工做項類型WorkItemType,能夠是Bug,任務等。ip
WorkItemType itemtype = project.WorkItemTypes["Bug"];開發
4.根據WorkItemType新建一個工做項WorkItemstring
WorkItem bug = new WorkItem(itemtype);it
B.修改工做項和保存工做項
1.另外能夠經過WorkItemStore得到指定ID的WorkItem進行修改
WorkItem workitem = workstore.GetWorkItem(1);
2.workitem.Fields["指派給"].Value = "*****";設置指派人是誰
static void Main(string[] args) { Uri tfsUri = new Uri("http://pc-20130113jkun:8080/tfs"); TfsTeamProjectCollection server = new TfsTeamProjectCollection(tfsUri); WorkItemStore workstore = server.GetService<WorkItemStore>(); //取得Calueng這個團隊項目 Project project = workstore.Projects["Calueng"]; //新建一個「bug」類型的工做項,也能夠新建「任務」等 WorkItemType itemtype = project.WorkItemTypes["Bug"]; WorkItem bug = new WorkItem(itemtype); //制定bug工做項的標題、描述和狀態等 bug.Title = "第一個bug"; bug.Description = "二次開發添加的第一個bug!"; //設置bug的指派對象爲zhangyuchun bug.Fields["指派給"].Value = "zhangyuchun"; bug.State = "新建"; bug.Save(); Console.WriteLine("第一個bug已經保存成功!"); //取得ID爲1的工做項,在這裏經過GetWorkItem方法取得 WorkItem workitem = workstore.GetWorkItem(1); //取得原有指派人,修改ID爲1工做項的指派對象 string oldAssignedTo = (string)workitem.Fields["指派給"].Value; workitem.Fields["指派給"].Value = "laijingsi"; //查看工做項是否有效,而且保存工做項 if (workitem.IsValid()) { workitem.Save(); Console.WriteLine("原來指派的對象爲:"+oldAssignedTo); Console.WriteLine("Work Item已經保存成功。"); } Console.ReadLine(); }