Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show item history windows with TFS SDK

Tags:

.net

tfs

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?

like image 251
madd0 Avatar asked Nov 25 '11 10:11

madd0


2 Answers

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.

like image 194
Jonno Avatar answered Nov 09 '22 09:11

Jonno


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

}
like image 4
Joe Skeen Avatar answered Nov 09 '22 11:11

Joe Skeen