Skip to content

Instantly share code, notes, and snippets.

@postromantic
Created October 6, 2014 07:49
Show Gist options
  • Save postromantic/959c02344a0480a46bea to your computer and use it in GitHub Desktop.
Save postromantic/959c02344a0480a46bea to your computer and use it in GitHub Desktop.
Helper class to show TFS history dialog
public class TfsHistoryDialogWrapper
{
private Type _dialogHistoryType;
private object _historyDialogInstance;
public TfsHistoryDialogWrapper(string tfsHistoryItem, string tfsServerUri)
{
var fullyQualifiedUriForName = TfsTeamProjectCollection.GetFullyQualifiedUriForName(tfsServerUri);
var tfsClientCredentials = TfsClientCredentials.LoadCachedCredentials(fullyQualifiedUriForName, false, false);
var tfs = new TfsTeamProjectCollection(fullyQualifiedUriForName, tfsClientCredentials);
tfs.EnsureAuthenticated();
var vcs = (VersionControlServer)tfs.GetService(typeof(VersionControlServer));
Init(vcs, tfsHistoryItem, VersionSpec.Latest, 0, RecursionType.None, null, VersionSpec.Latest, null, int.MaxValue, null);
}
public void Init(VersionControlServer versionControl, string historyItem, VersionSpec itemVersion, int itemDeletionId, RecursionType recursionType, VersionSpec versionFrom, VersionSpec versionTo, string userFilter, int maxVersions, bool? slotMode)
{
var tfsAssembly = typeof(Microsoft.TeamFoundation.VersionControl.Controls.ExplorerNodeType).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[] { });
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment