使用 TFS SDK 显示项目历史记录窗口

发布于 2024-12-18 03:51:23 字数 523 浏览 2 评论 0原文

我正在编写一个通过官方 SDK 与 TFS 集成的应用程序,以自动化并支持各种常见操作。尽管大部分都是自动化,并且 TFS API 公开了我需要的几乎所有内容,但某些操作需要用户干预,因此我需要向用户显示信息。

我找到了诸如 Difference.VisualDiffItems 使我能够使用 Visual Studio 使用的相同 UI 轻松直观地比较文件。我还需要显示项目的历史记录(包括分支、重命名等),并且我希望使用内置 UI,而不必编写自己的 UI。项目历史UI实际上相当复杂,我以为MS会在SDK中提供它,但我似乎找不到它。

谁能确认 TFS SDK 没有提供可视化项目历史记录的必要方法,或者如果提供了,请为我指明正确的方向?

I'm writing an app that integrates with TFS via the official SDKs to automate and support various common actions. Although most of it is automation and the TFS API exposes pretty much everything I need, some of the actions need user intervention so I need to display information to the user.

I've found methods such as Difference.VisualDiffItems that allow me to easily compare files visually using the same UI that Visual Studio uses. I also need to display an item's history (including branches, renames, etc.) and I would love to use a built-in UI instead of having to write my own. The item history UI is actually quite complex and I'd thought that MS would've provided it in the SDK, but I can't seem to find it.

Can anyone confirm that the TFS SDK does not provide the necessary methods to visualize an item's history or point me in the right direction if it does?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

风尘浪孓 2024-12-25 03:51:23

在 TF.exe 实用程序上使用 ILSpy,您可以看到用于查看历史记录的 UI 控件是 Microsoft.TeamFoundation.VersionControl.Controls.DialogHistory。该类是内部类,因此除非您喜欢使用反射,否则您将无法自己实例化该对象。

实际上,搜索该类名会出现这个social.msdn页面:
http://social.msdn.microsoft.com/Forums/ar/tfsversioncontrol/thread/9a10473e-d381-4e83-bde9-dd423f430feb

可能与您的问题最相关的一行来自巴克·霍奇斯:
“您确实可以选择通过反射来获取它们。由于它们不是公开的,我们可能会在不同版本(包括服务包)之间更改它们,因此您接受被破坏的风险”

另一种方法是直接使用命令行调用 TF(通过直接引用 TF.exe 并将其加载到同一进程中,或者使用所需的命令行启动一个新进程)。在任何一种情况下,您可能都必须处理传递到标准输出的错误消息,您可能需要也可能不需要它们。

希望这有帮助。

Using ILSpy on the TF.exe utility you can see that the UI control being used for viewing history is Microsoft.TeamFoundation.VersionControl.Controls.DialogHistory. This class is internal so unless you are happy with using reflection you won't be able to instantiate this object yourself.

Actually, searching for that class name brought up this social.msdn page:
http://social.msdn.microsoft.com/Forums/ar/tfsversioncontrol/thread/9a10473e-d381-4e83-bde9-dd423f430feb

The one line that may be most relevant to your question is from Buck Hodges:
"You do have the option to get to them through reflection. Since they aren't public, we may change them from release to release (including service packs), so you accept the risk of being broken"

The alternative would be to call TF with a command line directly (by referencing TF.exe directly and loading it in the same process OR by starting a new process with the command line required). In either case you will probably have to work with the error messages being delivered to stdout where you may or may not want them.

Hope this helps.

岁月打碎记忆 2024-12-25 03:51:23

乔诺的回答非常有帮助,而且很准确。我继续创建了一个使用反射调用对话框的代码片段(在 TFS 2010 SP1 中适用于我)。希望它对其有同样问题的其他人有用。如前所述,不保证此方法在任何未来版本中无需更改即可工作。

public class TfsHistoryDialogWrapper
{
    private readonly Type _dialogHistoryType;
    private readonly object _historyDialogInstance;

    public TfsHistoryDialogWrapper(VersionControlServer versionControl, string historyItem, VersionSpec itemVersion, int itemDeletionId, RecursionType recursionType, VersionSpec versionFrom, VersionSpec versionTo, string userFilter, int maxVersions, bool? slotMode)
    {
        Assembly tfsAssembly = typeof(Microsoft.TeamFoundation.VersionControl.Controls.LocalPathLinkBox).Assembly;
        _dialogHistoryType = tfsAssembly.GetType("Microsoft.TeamFoundation.VersionControl.Controls.DialogHistory");

        _historyDialogInstance = _dialogHistoryType.GetConstructor(
                                BindingFlags.NonPublic | BindingFlags.Instance,
                                null, 
                                new Type[]{typeof(VersionControlServer), typeof(string), typeof(VersionSpec), typeof(int), typeof(RecursionType), typeof(VersionSpec), typeof(VersionSpec), typeof(string), typeof(int), typeof(bool?)},
                                null).Invoke(new object[]{ versionControl, historyItem, itemVersion, itemDeletionId, recursionType, versionFrom, versionTo, userFilter, maxVersions, slotMode });
    }

    public void ShowDialog()
    {
        _dialogHistoryType.GetMethod("ShowDialog", new Type[]{}).Invoke(_historyDialogInstance, new object[]{});
    }

}

Jonno's answer is very helpful and spot-on. I went ahead and created a code snippet for using reflection to invoke the dialog (works for me in TFS 2010 SP1). Hopefully it will be of use to someone else with the same question. As previously stated, this method is not guaranteed to work without changes in any future version.

public class TfsHistoryDialogWrapper
{
    private readonly Type _dialogHistoryType;
    private readonly object _historyDialogInstance;

    public TfsHistoryDialogWrapper(VersionControlServer versionControl, string historyItem, VersionSpec itemVersion, int itemDeletionId, RecursionType recursionType, VersionSpec versionFrom, VersionSpec versionTo, string userFilter, int maxVersions, bool? slotMode)
    {
        Assembly tfsAssembly = typeof(Microsoft.TeamFoundation.VersionControl.Controls.LocalPathLinkBox).Assembly;
        _dialogHistoryType = tfsAssembly.GetType("Microsoft.TeamFoundation.VersionControl.Controls.DialogHistory");

        _historyDialogInstance = _dialogHistoryType.GetConstructor(
                                BindingFlags.NonPublic | BindingFlags.Instance,
                                null, 
                                new Type[]{typeof(VersionControlServer), typeof(string), typeof(VersionSpec), typeof(int), typeof(RecursionType), typeof(VersionSpec), typeof(VersionSpec), typeof(string), typeof(int), typeof(bool?)},
                                null).Invoke(new object[]{ versionControl, historyItem, itemVersion, itemDeletionId, recursionType, versionFrom, versionTo, userFilter, maxVersions, slotMode });
    }

    public void ShowDialog()
    {
        _dialogHistoryType.GetMethod("ShowDialog", new Type[]{}).Invoke(_historyDialogInstance, new object[]{});
    }

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文