使用TFS 2010 API订阅Workspace Events

我正在尝试编写一些代码来监视本地工作站上的TFS工作区,但目前我遇到了触发事件的问题。

例如,如果我在我的工作区中映射一个新文件夹,我想订阅versionControl.UpdatedWorkspace事件,如果我执行“get”,我想映射到versionControl.Getting事件。 下面的代码是一个控制台应用程序,我认为应该可以工作,但是当我这样做时,什么也没发生。 有谁知道如何成功订阅这些活动?

VS2010,TFS 2010,WinXP SP3

using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Net; using System.Text; using Microsoft.TeamFoundation.Client; using Microsoft.TeamFoundation.Framework.Client; using Microsoft.TeamFoundation.Framework.Common; using Microsoft.TeamFoundation.VersionControl.Client; namespace TestEventHanling { class Program { static void Main(string[] args) { Uri serverUri = new Uri(@"http://TfsServer:8080/tfs/collection"); using (TfsTeamProjectCollection collection = new TfsTeamProjectCollection(serverUri, CredentialCache.DefaultCredentials)) { VersionControlServer versionControl = (VersionControlServer)collection.GetService(typeof(VersionControlServer)); versionControl.UpdatedWorkspace += new WorkspaceEventHandler(OnUpdatedWorkspace); versionControl.Getting += new GettingEventHandler(OnGetting); Console.WriteLine("Press \'q\' to quit."); while (Console.Read() != 'q') ; } } internal static void OnUpdatedWorkspace(object sender, WorkspaceEventArgs e) { foreach (WorkingFolder wf in e.Workspace.Folders) { Console.WriteLine("Workspace updated {0}", wf.ServerItem); } } internal static void OnGetting(Object sender, GettingEventArgs e) { Console.WriteLine("Getting: {0}, status: {1}", e.TargetLocalItem, e.Status); } } } 

我的理解是这些是本地VersionControlServer实例上的事件。 也就是说,当您在代码中对该实例执行操作时,它们将触发。

例如,如果在代码中的其他位置更新了工作区,则会UpdatedWorkspace处理程序。

可以订阅服务器端(签入,构建等)的事件较少,但我不确定您是否可以通过VersionControlServer类监视服务器上发生的事情。