使用 TFS 2010 API 订阅工作区事件
我正在尝试编写一些代码来监视本地工作站上的 TFS 工作区,但目前我在触发事件时遇到问题。
例如,如果我在工作区中映射一个新文件夹,我想订阅 versionControl.UpdatedWorkspace 事件,如果我执行“get”操作,我想映射到 versionControl.Getting 事件。下面的代码是一个控制台应用程序,我认为应该可以工作,但是当我执行 get 时什么也没有发生。有谁知道如何成功订阅这些活动?
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);
}
}
}
I'm trying to write some code that monitors the TFS workspace(s) on my local workstation but at the moment I'm having problems getting the events to fire.
For example if I map a new folder in my workspace I want to subscribe to the versionControl.UpdatedWorkspace event, and if I do a “get” I want to map to the versionControl.Getting event. The code below is a console application that I think should work, but when I do a get nothing happens. Does anyone know how to successfully subscribe to these events?
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);
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的理解是,这些事件发生在您的 VersionControlServer 本地实例上。也就是说,当您对代码中的该实例进行操作时,它们就会触发。
例如,如果在代码中的其他位置更新了工作区,则
UpdatedWorkspace
处理程序将触发。您可以订阅服务器端的一小部分事件(签入、构建等),但我不确定您是否可以通过 VersionControlServer 类监视服务器上发生的情况。
My understanding are that these are events that are on your local instance of VersionControlServer. That is to say, they will fire when you act on that instance in your code.
For example, if, somewhere else in your code, you updated a workspace, then the
UpdatedWorkspace
handler would fire.There's a smaller set of events that you can subscribe to server-side (check-in, builds, etc.), but I'm not sure that you can monitor what's happening on the server through the VersionControlServer class.