2
我正在尝试编写一些代码来监视我的本地工作站上的TFS工作区,但此刻我遇到问题需要触发事件。使用TFS 2010 API来订阅工作区事件
例如,如果我在我的工作区中映射一个新文件夹,我想订阅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);
}
}
}
不够公平,我认为他们会在我操纵工作空间或在运行代码之外(例如从VS)获取时触发,类似于FileSystemWatcher中的事件行为方式。我会仔细研究并查找服务器端事件,看看它们是否符合我的要求。 – 2011-03-04 16:49:51
我已经看了一下API,我不认为有什么会做我想做的。呵呵,回到画板 – 2011-03-05 02:23:43
行。我已经使用这个代码示例,它的工作方式和描述一样。 但是,我需要更新我的应用程序的数据库中的某些信息,其中ServerSide发生任何更改(TeamWebAccess或WorkItem在应用程序中以.net更新)。谢谢你的建议。 – 2011-10-03 17:55:13