首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> .NET 網頁程式設計 >> 關於.NET

Team System:TFS 事件服務完整指南——訂閱管理、自定義 Web Service 聽眾與 SOAP 通知

     編輯:關於.NET

事件服務定位

TFS 服務集合中的支援服務,觸發事件後可發送 Email 或呼叫 SOAP Web Service。適用 TFS 2005/2008。

Visual Studio 內建「專案警示」

四大事件:簽入、建置完成、建置狀態變更、指派工作項目變更。可設多 Email、HTML/純文字格式。

專案警示對話框

Email 格式控制:XSLT 轉換

C:\Program Files\Microsoft Visual Studio 2008 Team Foundation Server\Web Services\Services\v1.0\Transforms 目錄下 28 個檔案:eMailTemplate、plaintextXsl、XSD、XSL。修改 XSL 即可客製化 Email 版面,修改後下次事件自動生效。

所有可用事件清單

服務事件註冊服務列出
工作項目追蹤WorkItemChangedEvent否
版本控制CheckinEvent是
團隊專案建置BuildCompletionEvent2是
團隊專案建置BuildStatusChangeEvent是
團隊專案建置BuildCompletionEvent是 (升級相容)
公共結構服務ProjectCreatedEvent / ProjectDeletedEvent是
GSS/授權/CSSDataChangedEvent (子類型:結構/安全性/身分)否

註冊服務列舉代碼:

Dim rs As IRegistration = mtfs.GetService(GetType(IRegistration))
For Each re In rs.GetRegistrationEntries(String.Empty)
    Debug.WriteLine(re.Type)
    For Each et In re.EventTypes : Debug.WriteLine("-->" & et.Name) : Next
Next

建立訂閱兩大管道

1. BisSubscribe.exe 命令列

bissubscribe /eventType CheckinEvent /address user@domain /deliveryType EmailHtml /server tfs08
bissubscribe /eventType CheckinEvent /address https://host/Service.asmx /deliveryType Soap /server tfs08
bissubscribe unsubscribe /id 7 /server tfs08

支援篩選器(如 /filter "'Artifacts/Artifact[@TeamProject = MSFAgile]' <> null")。

2. 程式碼建立訂閱

Dim es As IEventService = mtfs.GetService(GetType(IEventService))
Dim userSubs = es.EventSubscriptions(Environment.UserDomainName & "\" & Environment.UserName)
' 列舉/刪除 userSubs(i).ID

Dim dp As New DeliveryPreference()
dp.Address = $"https://{mtfs.Uri.Authority}/MSDNMagTFSEvents/ProcessEvents.asmx"
dp.Schedule = DeliverySchedule.Immediate
dp.Type = DeliveryType.Soap
Dim filter = If(chkProject.Checked, $"PortfolioProject = '{cboProject.Text}'", Nothing)
Dim subId = es.SubscribeEvent(mtfs.AuthenticatedUserName, "WorkItemChangedEvent", filter, dp)

自定義事件聽眾:ASMX Web Service

  1. 建立 Web Service 專案,部署至 TFS 應用層(需在 Team Foundation Server 應用程式集區)。
  2. 實作 Notify 方法:
<SoapDocumentMethod("https://schemas.microsoft.com/TeamFoundation/2005/06/Services/Notification/03/Notify", ...)>
<WebMethod()>
Public Sub Notify(ByVal eventXml As String, ByVal tfsIdentityXml As String)
    ' eventXml 含事件完整資料,可用 LINQ to XML 解析
    ' 範例:偵測 Title 變更並寫入 Windows 事件日誌
End Sub

關鍵部署細節

  • 服務以 tfsservice 帳戶執行,具備存取其他 TFS 特權服務能力。
  • 建立 SOAP 訂閱需 TFS 管理員或 TFS 服務安全群組成員權限。
  • 篩選器語法可參考 CodePlex 社群專案 tfseventsubscription。

總結

EventService 提供強大彈性,配合 Email/XSLT 或自定義 Web Service 可滿足各式整合與通知需求。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved