TFS API BranchObjectCreated 事件不会触发 [英] TFS API BranchObjectCreated Event does not fire

查看:22
本文介绍了TFS API BranchObjectCreated 事件不会触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些代码可以在 TFS 中自动创建构建定义.

I have some code to automate the creation of build definitions in TFS.

现在我想在创建分支时调用此代码.

Now I'd like to have this code invoked whenever a branch is created.

查看 API,我看到 BranchObjectCreatedEventMicrosoft.TeamFoundation.VersionControl.Client.VersionControlServer 中有一个 BranchObjectCreatedEvent.

Looking at the API, I see that there is a BranchObjectCreatedEvent in Microsoft.TeamFoundation.VersionControl.Client.VersionControlServer.

所以我在控制台应用程序中添加了一些代码来处理事件.

So I've added some code to a console app to handle the event.

    private static void MonitorBranchCreated()
    {
        try
        {
            TfsTeamProjectCollection tfs = InitialiseTfs();

            var vcs = tfs.GetService<VersionControlServer>();

            var projects = vcs.GetAllTeamProjects(true);

            foreach (var project in projects)
            {
                project.VersionControlServer.BranchObjectCreated += BranchObjectCreated;
            }

            Console.WriteLine("Subscribed to TFS BranchObjectCreated Event - Awaiting Notification...");
            Console.ReadLine();
        }
        catch (Exception exception)
        {
            DisplayError(exception);
        }
    }

    private static void BranchObjectCreated(object sender, BranchObjectCreatedEventArgs e)
    {
        // Create the Build
    }

问题在于,当我在 Visual Studio 中从源代码管理资源管理器创建分支时,该事件永远不会触发.

The trouble is that the event never fires when I create a branch from Source Control Explorer in Visual Studio.

MSDN 文档有限,我找不到任何其他使用示例,所以我希望有人能够告诉我这是否是正确的方法.

The MSDN documentation is limited and I can't find any other examples of usage so I'm hoping somebody might be able to tell me if this is the correct approach.

如果是这样,为什么事件可能不会触发?如果没有,是否有另一种方法可以连接到 TFS,以便我可以处理与创建分支相关的事件?

If so, why might the event not be firing? If not, is there another way I can hook into TFS so that I can handle events related to creation of branches?

推荐答案

当您将事件连接到客户端 API 时,您只能获得由该客户端创建的事件.如果您要连接一个 BranchObjectCreated 侦听器,则调用 VersionControlServer.CreateBranch()然后 将调用您的分支对象创建的侦听器.

When you hook up events to the client API, you only get events that were created by that client. If you were to hook up a BranchObjectCreated listener, then call VersionControlServer.CreateBranch(), then your branch object created listener would be called.

如果你想监听服务器上的事件(比如当其他人创建了一个分支,或者你从不同的客户端创建了一个分支),那么你需要绑定到服务器的项目警报系统.

If you want to listen to events on the server (such as when somebody else creates a branch, or you create a branch from a different client), then you need to tie into the server's project alert system.

您可以在 Team Foundation Server Power Tools 允许您配置细粒度警报在将向您发送电子邮件或调用网络方法的项目上.此时,您可以创建一个引用此新分支的新构建.

You can install the Alerts Explorer in the Team Foundation Server Power Tools that will allow you to configure fine-grained alerts on projects that will send you email or call a web method. At this point, you can create a new build that references this new branch.

这篇关于TFS API BranchObjectCreated 事件不会触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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