简体   繁体   English

使用TFS 2010 API订阅工作区事件

[英]Using the TFS 2010 API to subscribe to Workspace Events

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. 我正在尝试编写一些代码来监视本地工作站上的TFS工作区,但此刻我在触发事件方面遇到了问题。

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. 例如,如果我在工作区中映射一个新文件夹,我想订阅versionControl.UpdatedWorkspace事件,如果我执行“获取”,我想映射到versionControl.Getting事件。 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 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);
        }


    }
}

My understanding are that these are events that are on your local instance of VersionControlServer. 我的理解是,这些是您的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. 例如,如果您在代码中的其他位置更新了工作空间,则将UpdatedWorkspace处理程序。

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. 您可以预订服务器端事件的数量较少(签入,构建等),但是我不确定您是否可以通过VersionControlServer类监视服务器上发生的事件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM