使用 TFS 2010 API 订阅工作区事件 [英] Using the TFS 2010 API to subscribe to Workspace Events

查看:21
本文介绍了使用 TFS 2010 API 订阅工作区事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

VS2010、TFS 2010、WinXP SP3

使用系统;使用 System.Collections.Generic;使用 System.Collections.ObjectModel;使用 System.Linq;使用 System.Net;使用 System.Text;使用 Microsoft.TeamFoundation.Client;使用 Microsoft.TeamFoundation.Framework.Client;使用 Microsoft.TeamFoundation.Framework.Common;使用 Microsoft.TeamFoundation.VersionControl.Client;命名空间 TestEventHanling{课程计划{static void Main(string[] args){Uri serverUri = new Uri(@"http://TfsServer:8080/tfs/collection");使用 (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("按\'q\'退出.");while (Console.Read() != 'q') ;}}内部静态无效 OnUpdatedWorkspace(对象发送者,WorkspaceEventArgs e){foreach(e.Workspace.Folders 中的工作文件夹 wf){Console.WriteLine("工作区更新{0}", wf.ServerItem);}}内部静态 void OnGetting(Object sender, GettingEventArgs e){Console.WriteLine("Getting: {0}, status: {1}", e.TargetLocalItem, e.Status);}}}

解决方案

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

例如,如果您在代码的其他地方更新了工作区,则 UpdatedWorkspace 处理程序将触发.

您可以订阅服务器端的一小部分事件(签入、构建等),但我不确定您是否可以通过 VersionControlServer 类监控服务器上发生的情况.

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);
        }


    }
}

解决方案

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.

这篇关于使用 TFS 2010 API 订阅工作区事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆