Show item history windows with TFS SDK

核能气质少年 提交于 2019-12-05 13:08:35
Jonno

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.

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[]{});
    }

}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!