Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit f651b19

Browse files
committed
Clean up and xmldoc the AnnotateFile method
1 parent 81b6d8a commit f651b19

File tree

1 file changed

+34
-10
lines changed

1 file changed

+34
-10
lines changed

src/GitHub.App/Services/GitHubContextService.cs

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -360,23 +360,47 @@ IVsTextView FindActiveView()
360360
return textView;
361361
}
362362

363+
/// <summary>
364+
/// Call AnnotateFile of the IGitExt2 service if it can be found.
365+
/// </summary>
366+
/// <remarks>
367+
/// The IGitExt2 interface was introduced in an update of Visual Studio 2017.
368+
/// The <see cref="branchName"/> must exist but doesn't appear to be used in the UI.
369+
/// </remarks>
370+
/// <param name="repositoryPath">Path of the target repository</param>
371+
/// <param name="branchName">A branch of the target repository</param>
372+
/// <param name="relativePath">A path the the target blob</param>
373+
/// <param name="versionSha">The commit version of the blob</param>
374+
/// <returns></returns>
363375
bool AnnotateFile(string repositoryPath, string branchName, string relativePath, string versionSha)
364376
{
365-
var gitExt2Type = Type.GetType("Microsoft.VisualStudio.TeamFoundation.Git.Extensibility.IGitExt2, Microsoft.TeamFoundation.Git.Provider", false);
366-
if (gitExt2Type == null)
377+
var serviceType = Type.GetType("Microsoft.VisualStudio.TeamFoundation.Git.Extensibility.IGitExt2, Microsoft.TeamFoundation.Git.Provider", false);
378+
if (serviceType == null)
367379
{
368380
return false;
369381
}
370382

371-
InvokeService(gitExt2Type, "AnnotateFile", repositoryPath, branchName, relativePath, versionSha);
372-
return true;
373-
}
374-
375-
void InvokeService<T1, T2, T3, T4>(Type serviceType, string method, T1 arg1, T2 arg2, T3 arg3, T4 arg4)
376-
{
377383
var service = serviceProvider.GetService(serviceType);
378-
var action = (Action<T1, T2, T3, T4>)Delegate.CreateDelegate(typeof(Action<T1, T2, T3, T4>), service, method);
379-
action.Invoke(arg1, arg2, arg3, arg4);
384+
if (service == null)
385+
{
386+
return false;
387+
}
388+
389+
try
390+
{
391+
Invoke(service, "AnnotateFile", repositoryPath, branchName, relativePath, versionSha);
392+
return true;
393+
}
394+
catch (Exception)
395+
{
396+
return false;
397+
}
398+
399+
void Invoke<T1, T2, T3, T4>(object target, string method, T1 arg1, T2 arg2, T3 arg3, T4 arg4)
400+
{
401+
var action = (Action<T1, T2, T3, T4>)Delegate.CreateDelegate(typeof(Action<T1, T2, T3, T4>), target, method);
402+
action.Invoke(arg1, arg2, arg3, arg4);
403+
}
380404
}
381405

382406
static void SetSelection(IVsTextView textView, GitHubContext context)

0 commit comments

Comments
 (0)