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