如何以编程方式确定待签到中包含哪些项目? [英] how do I determine what items are included pending check-ins programatically?

查看:24
本文介绍了如何以编程方式确定待签到中包含哪些项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以查询 PendingSets 和候选 PendingSets,似乎无法区分包含的待处理更改和排除的待处理更改.

I can query PendingSets and candidate PendingSets, and there appears to be no way to tell between included pending changes, and excluded pending changes.

我在包含的更改中包含了一个文件以通过 Visual Studio Team Explorer 签入.

I have one file included in the included changes to check in via Visual Studio Team Explorer.

使用 Tfs dll 查询我得到有 112 个待处理和 145 个 CandidatePending:

Using Tfs dlls to query I get that there are 112 pending, and 145 CandidatePending:

var tfsServer = Macros.TfsModule.GetTfsServerFromEnvironment();

var tfs =new Macros.TFS(tfsServer,"Development", null);
var vcs= tfs.Tfs.GetService<Microsoft.TeamFoundation.VersionControl.Client.VersionControlServer>();
var searchBase=vcs.GetItem("$/");
//vcs.Dump();
var workspace = vcs.GetWorkspace(Environment.ExpandEnvironmentVariables("%devroot%"));

// vcs.QueryWorkspaces(null,null,null).Dump("workspaces");
var itemSpecs = new []{new ItemSpec(searchBase.ServerItem,RecursionType.Full)};

vcs.QueryPendingSets(itemSpecs, workspace.Name, workspace.OwnerName, false, true)
    .Select(ps=>new {Pending=ps.PendingChanges.Select(pc=>new{ pc.LocalOrServerItem,PendingChange=Util.OnDemand("PendingChange",()=> pc)}), ps.CandidatePendingChanges})
    .First()
    .Dump();

workspace.Dump();

112 值确实与包含+排除对齐.465 值与 Detected add(s) 值一致.

The 112 value does line up with included+excluded. The 465 value lines up with the Detected add(s) value.

但是,我完全无法弄清楚当前包含哪些更改.我已经尝试了 Tfs dll 查询和 EnvDte 几个小时.

However I've been completely unable to figure out which changes are currently included. I've tried Tfs dll querying, and EnvDte for hours.

我能否以编程方式获取当前包含的更改列表(甚至更好,更改包含/排除列表)?

Can I programatically get the list of included changes currently (and even better, change the include/exclude list) ?

推荐答案

在我看来,您请求的功能(获取/修改包含和排除的更改)是待定更改"窗口本身的一部分,而不是TFS API 的一部分.请参阅 这篇文章 是如何与Pending Changes"窗口交互的示例(部分通过反射).也许这是进一步探索的一个重要起点.

It seems to me that the functionality you are requesting (getting/modifying the set included and excluded changes) is part of the "Pending Changes" window itself, not part of the TFS API. See this post for an example of how to interact with the "Pending Changes" window (partially via reflection). Maybe that is a considerable starting point for further exploration.

编辑

我只是进一步探索了这一点,并提出了以下代码.它主要利用 Microsoft.TeamFoundation.VersionControl.Controls.PendingChanges.IPendingChangesDataProvider 接口,这是程序集 Microsoft.TeamFoundation.VersionControl.Controls.dll 的内部接口.

I just explored this further and came up with the following code. It primarily utilizes the interface Microsoft.TeamFoundation.VersionControl.Controls.PendingChanges.IPendingChangesDataProvider, which is internal to the assembly Microsoft.TeamFoundation.VersionControl.Controls.dll.

using System;
using System.Collections.Generic;
using System.Reflection;
using Microsoft.TeamFoundation.Controls;
using Microsoft.TeamFoundation.Controls.WPF.TeamExplorer;
using Microsoft.TeamFoundation.VersionControl.Client;

namespace PrettyFlyForANamespace
{
    public class PendingChangesInclusion
    {
        private readonly Action<IList<PendingChange>> _includeChanges;
        private readonly Action<IList<PendingChange>> _excludeChanges;
        private readonly Func<IList<PendingChange>> _getIncludedChanges;
        private readonly Func<IList<PendingChange>> _getExcludedChanges;

        public IList<PendingChange> IncludedChanges
        {
            get
            {
                return _getIncludedChanges();
            }
        }

        public IList<PendingChange> ExcludedChanges
        {
            get
            {
                return _getExcludedChanges();
            }
        }

        public PendingChangesInclusion(ITeamExplorer teamExplorer)
        {
            var pendingChangesPage = (TeamExplorerPageBase)teamExplorer.NavigateToPage(new Guid(TeamExplorerPageIds.PendingChanges), null);

            var model = pendingChangesPage.Model;
            var p = model.GetType().GetProperty("DataProvider", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.FlattenHierarchy);

            var dataProvider = p.GetValue(model); // IPendingChangesDataProvider is internal;
            var dataProviderType = dataProvider.GetType();

            p = dataProviderType.GetProperty("IncludedChanges", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.FlattenHierarchy);
            var m = p.GetMethod;
            _getIncludedChanges = (Func<IList<PendingChange>>)m.CreateDelegate(typeof(Func<IList<PendingChange>>), dataProvider);

            p = dataProviderType.GetProperty("ExcludedChanges", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.FlattenHierarchy);
            m = p.GetMethod;
            _getExcludedChanges = (Func<IList<PendingChange>>)m.CreateDelegate(typeof(Func<IList<PendingChange>>), dataProvider);

            m = dataProviderType.GetMethod("IncludeChanges", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.FlattenHierarchy);
            _includeChanges = (Action<IList<PendingChange>>)m.CreateDelegate(typeof(Action<IList<PendingChange>>), dataProvider);

            m = dataProviderType.GetMethod("ExcludeChanges", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.FlattenHierarchy);
            _excludeChanges = (Action<IList<PendingChange>>)m.CreateDelegate(typeof(Action<IList<PendingChange>>), dataProvider);
        }

        public void IncludeChanges(IList<PendingChange> changes)
        {
            _includeChanges(changes);
        }

        public void ExcludeChanges(IList<PendingChange> changes)
        {
            _excludeChanges(changes);
        }
    }
}

如果要从 VS Package 对象中调用上面的代码,可以使用以下代码:

If you want to call the code above from within a VS Package object, you can use the following code:

var teamExplorer = (ITeamExplorer)GetService(typeof(ITeamExplorer));
var psi = new PendingChangesInclusion(teamExplorer);

// To see if this works, include all excluded pending changes.
psi.IncludeChanges(psi.ExcludedChanges);

您需要使用浏览"对话框包含以下程序集:

You will need to include the following assemblies using the "browse" dialog:

  • C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\ReferenceAssemblies\v2.0\Microsoft.TeamFoundation.Client.dll
  • C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\ReferenceAssemblies\v4.5\Microsoft.TeamFoundation.Controls.dll
  • C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\ReferenceAssemblies\v2.0\Microsoft.TeamFoundation.VersionControl.Client.dll

这篇关于如何以编程方式确定待签到中包含哪些项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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