Skip to main content
 首页 » 编程设计

c#之TFS 集成

2024年02月06日12JeffreyZhao

我正在尝试将 TFS 集成与 tfs 自动同步到我的数据库.. 我正在做的所有窗口服务...... 为此,我编码如下......

DataRow dr = dstSyncWorkItem.Tables["Workitems"].Rows[i]; 
String uri = ConfigurationManager.AppSettings["TfsUri"] + dr["ProCollectionName"]; 
Uri collectionUri = new Uri(uri); 
NetworkCredential myNetCredentials = new NetworkCredential(ConfigurationManager.AppSettings["TfsUsername"], ConfigurationManager.AppSettings["TfsPassword"]); 
ICredentials myCredentials = (ICredentials)myNetCredentials; 
 
TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(collectionUri, myCredentials); 
WorkItemStore workItemStore = tpc.GetService<WorkItemStore>(); 
Project teamProject = workItemStore.Projects[dr["Project"].ToString()]; 
WorkItemType workItemType = teamProject.WorkItemTypes[dr["Type"].ToString()]; 
 
WorkItem workItem = new WorkItem(workItemType); 
workItem.Title = dr["Title"].ToString(); 
workItem.Description = dr["Desc"].ToString(); 
workItem.Save(); 

这将给出以下错误...

TF237124: Work Item is not ready to save.

请您参考如下方法:

您需要先验证工作项,然后才能保存它。调用:

ArrayList validation = workItem.Validate(); 

这将确保您所做的任何更改都是适当的,并根据您的更改进行工作项规则定义的任何其他状态更改。

如果存在验证失败,您必须妥善处理它们。否则,您可以调用:

workItem.Save();