我寫了一個自定義的窗體窗體應用程序,允許我運行自己的動態查詢,並創建新的或更新現有的工作項目。
下面是我用於連接到我們的TFS 2010服務器的一段代碼的簡化版本,運行查詢並返回結果。
Imports Microsoft.TeamFoundation.Client
Imports Microsoft.TeamFoundation.WorkItemTracking.Client
Imports System.Net
Imports System.Text.RegularExpressions
Imports System.Data.SqlTypes
Public Class DNATFSProxy
Private _teamProjectCollection As TfsTeamProjectCollection
Private _workItemStore As WorkItemStore
Private _projectName As String
Private _project As Project
Public Sub Connect()
_teamProjectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(New Uri(_uri))
_workItemStore = New WorkItemStore(_teamProjectCollection)
_project = _workItemStore.Projects(_projectName)
End Sub
Public Sub GetWorkItems(ByVal whereClause As String)
If _workItemStore IsNot Nothing Then
'Attempt to get the work items
Dim query As String = String.Format("SELECT * FROM WorkItems WHERE {0}", whereClause)
Dim workItemCollection As WorkItemCollection = _workItemStore.Query(query)
'Iterate through each work item
For Each workItem As WorkItem In workItemCollection
'Insert your custom code here
Dim title As String = workItem.Title.ToString()
'You can also update the work item in TFS
workItem.Title = "New title"
workItem.Save()
Next
End If
End Sub
Public Property URI() As String
Get
Return _uri
End Get
Set(ByVal value As String)
_uri = value
End Set
End Property
Public Property Project() As String
Get
Return _projectName
End Get
Set(ByVal value As String)
_projectName = value
End Set
End Property
End Class
然後,您可以調用這個代理如下:
Dim proxy As New DNATFSProxy()
proxy.URI = "http://tfs:8080/tfs/DefaultCollection"
proxy.Project = "Your Project Name"
proxy.Connect()
proxy.GetWorkItems("Insert your query here")
我希望這有助於!