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

Commit e517687

Browse files
committed
Move CreateVSGitExt into VSGitExtFactory
1 parent cc6a112 commit e517687

File tree

3 files changed

+35
-22
lines changed

3 files changed

+35
-22
lines changed

src/GitHub.VisualStudio/GitHub.VisualStudio.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@
328328
<Compile Include="Services\UsageTracker.cs" />
329329
<Compile Include="Services\LoginManagerDispatcher.cs" />
330330
<Compile Include="Services\UsageTrackerDispatcher.cs" />
331+
<Compile Include="Services\VSGitExtFactory.cs" />
331332
<Compile Include="Services\VSGitExtDispatcher.cs" />
332333
<Compile Include="Settings\Constants.cs" />
333334
<Compile Include="Services\ConnectionManager.cs" />

src/GitHub.VisualStudio/GitHubPackage.cs

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
extern alias TF14;
2-
extern alias TF15;
3-
4-
using System;
1+
using System;
52
using System.ComponentModel.Composition;
63
using System.Diagnostics;
74
using System.Runtime.InteropServices;
@@ -25,8 +22,6 @@
2522
using Octokit;
2623
using Serilog;
2724
using Task = System.Threading.Tasks.Task;
28-
using VSGitExt14 = TF14.GitHub.VisualStudio.Base.VSGitExt;
29-
using VSGitExt15 = TF15.GitHub.VisualStudio.Base.VSGitExt;
3025

3126
namespace GitHub.VisualStudio
3227
{
@@ -268,7 +263,7 @@ async Task<object> CreateService(IAsyncServiceContainer container, CancellationT
268263
else if (serviceType == typeof(IVSGitExt))
269264
{
270265
var dte = await GetServiceAsync(typeof(DTE)) as DTE;
271-
return CreateVSGitExt(dte.Version);
266+
return VSGitExtFactory.Create(dte.Version, this);
272267
}
273268
else if (serviceType == typeof(IGitHubToolWindowManager))
274269
{
@@ -281,20 +276,5 @@ async Task<object> CreateService(IAsyncServiceContainer container, CancellationT
281276
return sp.TryGetService(serviceType);
282277
}
283278
}
284-
285-
IVSGitExt CreateVSGitExt(string dteVersion)
286-
{
287-
// DTE.Version always ends with ".0" even for later minor versions.
288-
switch (dteVersion)
289-
{
290-
case "14.0":
291-
return new Lazy<IVSGitExt>(() => new VSGitExt14(GetServiceAsync)).Value;
292-
case "15.0":
293-
return new Lazy<IVSGitExt>(() => new VSGitExt15(GetServiceAsync)).Value;
294-
default:
295-
log.Error("There is no IVSGitExt implementation for DTE version {Version}", dteVersion);
296-
return null;
297-
}
298-
}
299279
}
300280
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
extern alias TF14;
2+
extern alias TF15;
3+
4+
using System;
5+
using GitHub.Logging;
6+
using Serilog;
7+
using VSGitExt14 = TF14.GitHub.VisualStudio.Base.VSGitExt;
8+
using VSGitExt15 = TF15.GitHub.VisualStudio.Base.VSGitExt;
9+
using Microsoft.VisualStudio.Shell;
10+
11+
namespace GitHub.Services
12+
{
13+
public class VSGitExtFactory
14+
{
15+
static readonly ILogger log = LogManager.ForContext<VSGitExtFactory>();
16+
17+
public static IVSGitExt Create(string dteVersion, IAsyncServiceProvider sp)
18+
{
19+
// DTE.Version always ends with ".0" even for later minor versions.
20+
switch (dteVersion)
21+
{
22+
case "14.0":
23+
return new Lazy<IVSGitExt>(() => new VSGitExt14(sp.GetServiceAsync)).Value;
24+
case "15.0":
25+
return new Lazy<IVSGitExt>(() => new VSGitExt15(sp.GetServiceAsync)).Value;
26+
default:
27+
log.Error("There is no IVSGitExt implementation for DTE version {Version}", dteVersion);
28+
return null;
29+
}
30+
}
31+
}
32+
}

0 commit comments

Comments
 (0)