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

Commit decd642

Browse files
committed
Split VS version-specific methods from general ones
1 parent 3bfc81e commit decd642

File tree

16 files changed

+118
-78
lines changed

16 files changed

+118
-78
lines changed

src/GitHub.App/Services/RepositoryCloneService.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ public class RepositoryCloneService : IRepositoryCloneService
2222

2323
readonly IOperatingSystem operatingSystem;
2424
readonly string defaultClonePath;
25-
readonly IVSServices vsservices;
25+
readonly IVSGitServices vsGitServices;
2626

2727
[ImportingConstructor]
28-
public RepositoryCloneService(IOperatingSystem operatingSystem, IVSServices vsservices)
28+
public RepositoryCloneService(IOperatingSystem operatingSystem, IVSGitServices vsGitServices)
2929
{
3030
this.operatingSystem = operatingSystem;
31-
this.vsservices = vsservices;
31+
this.vsGitServices = vsGitServices;
3232

3333
defaultClonePath = GetLocalClonePathFromGitProvider(operatingSystem.Environment.GetUserRepositoriesPath());
3434
}
@@ -48,7 +48,7 @@ public IObservable<Unit> CloneRepository(string cloneUrl, string repositoryName,
4848
try
4949
{
5050
// this will throw if it can't find it
51-
vsservices.Clone(cloneUrl, path, true);
51+
vsGitServices.Clone(cloneUrl, path, true);
5252
}
5353
catch (Exception ex)
5454
{
@@ -62,7 +62,7 @@ public IObservable<Unit> CloneRepository(string cloneUrl, string repositoryName,
6262

6363
string GetLocalClonePathFromGitProvider(string fallbackPath)
6464
{
65-
var ret = vsservices.GetLocalClonePathFromGitProvider();
65+
var ret = vsGitServices.GetLocalClonePathFromGitProvider();
6666
return !string.IsNullOrEmpty(ret)
6767
? operatingSystem.Environment.ExpandEnvironmentVariables(ret)
6868
: fallbackPath;

src/GitHub.App/Services/RepositoryPublishService.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ public class RepositoryPublishService : IRepositoryPublishService
1616
readonly IRepository activeRepository;
1717

1818
[ImportingConstructor]
19-
public RepositoryPublishService(IGitClient gitClient, IVSServices services)
19+
public RepositoryPublishService(IGitClient gitClient, IVSGitServices vsGitServices)
2020
{
2121
this.gitClient = gitClient;
22-
this.activeRepository = services.GetActiveRepo();
22+
this.activeRepository = vsGitServices.GetActiveRepo();
2323
}
2424

2525
public string LocalRepositoryName

src/GitHub.Exports/GitHub.Exports.csproj

+2
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@
130130
<Compile Include="Services\ITeamExplorerServiceHolder.cs" />
131131
<Compile Include="Services\INotificationService.cs" />
132132
<Compile Include="Services\IUsageTracker.cs" />
133+
<Compile Include="Services\IVSGitServices.cs" />
133134
<Compile Include="Services\IVSServices.cs" />
134135
<Compile Include="Services\Logger.cs" />
135136
<Compile Include="Services\Services.cs" />
@@ -145,6 +146,7 @@
145146
<Compile Include="Authentication\AuthenticationResultExtensions.cs" />
146147
<Compile Include="Extensions\ServiceProviderExtensions.cs" />
147148
<Compile Include="Services\UsageTracker.cs" />
149+
<Compile Include="Services\VSServices.cs" />
148150
<Compile Include="Settings\generated\IPackageSettings.cs">
149151
<AutoGen>True</AutoGen>
150152
<DesignTime>True</DesignTime>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System.Collections.Generic;
2+
using GitHub.Models;
3+
4+
namespace GitHub.Services
5+
{
6+
public interface IVSGitServices
7+
{
8+
string GetLocalClonePathFromGitProvider();
9+
void Clone(string cloneUrl, string clonePath, bool recurseSubmodules);
10+
string GetActiveRepoPath();
11+
LibGit2Sharp.IRepository GetActiveRepo();
12+
IEnumerable<ISimpleRepositoryModel> GetKnownRepositories();
13+
string SetDefaultProjectPath(string path);
14+
}
15+
}

src/GitHub.Exports/Services/IVSServices.cs

-7
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,6 @@ namespace GitHub.Services
55
{
66
public interface IVSServices
77
{
8-
string GetLocalClonePathFromGitProvider();
9-
void Clone(string cloneUrl, string clonePath, bool recurseSubmodules);
10-
string GetActiveRepoPath();
11-
LibGit2Sharp.IRepository GetActiveRepo();
12-
IEnumerable<ISimpleRepositoryModel> GetKnownRepositories();
13-
string SetDefaultProjectPath(string path);
14-
158
void ActivityLogMessage(string message);
169
void ActivityLogWarning(string message);
1710
void ActivityLogError(string message);
+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
using System;
2+
using System.Collections;
3+
using System.Collections.Generic;
4+
using System.ComponentModel.Composition;
5+
using System.Globalization;
6+
using GitHub.VisualStudio;
7+
using Microsoft.VisualStudio;
8+
using Microsoft.VisualStudio.Shell.Interop;
9+
10+
namespace GitHub.Services
11+
{
12+
[Export(typeof(IVSServices))]
13+
[PartCreationPolicy(CreationPolicy.Shared)]
14+
public class VSServices : IVSServices
15+
{
16+
readonly IUIProvider serviceProvider;
17+
18+
[ImportingConstructor]
19+
public VSServices(IUIProvider serviceProvider)
20+
{
21+
this.serviceProvider = serviceProvider;
22+
}
23+
24+
25+
public void ActivityLogMessage(string message)
26+
{
27+
var log = serviceProvider.GetActivityLog();
28+
if (log != null)
29+
{
30+
if (!ErrorHandler.Succeeded(log.LogEntry((UInt32)__ACTIVITYLOG_ENTRYTYPE.ALE_INFORMATION,
31+
Info.ApplicationInfo.ApplicationSafeName, message)))
32+
Console.WriteLine(string.Format(CultureInfo.CurrentCulture, "Could not log message to activity log: {0}", message));
33+
}
34+
}
35+
36+
public void ActivityLogError(string message)
37+
{
38+
var log = serviceProvider.GetActivityLog();
39+
if (log != null)
40+
{
41+
42+
if (!ErrorHandler.Succeeded(log.LogEntry((UInt32)__ACTIVITYLOG_ENTRYTYPE.ALE_ERROR,
43+
Info.ApplicationInfo.ApplicationSafeName, message)))
44+
Console.WriteLine(string.Format(CultureInfo.CurrentCulture, "Could not log error to activity log: {0}", message));
45+
}
46+
}
47+
48+
public void ActivityLogWarning(string message)
49+
{
50+
var log = serviceProvider.GetActivityLog();
51+
if (log != null)
52+
{
53+
if (!ErrorHandler.Succeeded(log.LogEntry((UInt32)__ACTIVITYLOG_ENTRYTYPE.ALE_WARNING,
54+
Info.ApplicationInfo.ApplicationSafeName, message)))
55+
Console.WriteLine(string.Format(CultureInfo.CurrentCulture, "Could not log warning to activity log: {0}", message));
56+
}
57+
}
58+
}
59+
}

src/GitHub.TeamFoundation.14/Connect/GitHubConnectSection.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,8 @@ void ShowNotification(ISimpleRepositoryModel newrepo, string msg)
277277
}
278278
else if (prefix == "c:")
279279
{
280-
var vsservices = ServiceProvider.GetExportedValue<IVSServices>();
281-
vsservices.SetDefaultProjectPath(newrepo.LocalPath);
280+
var vsGitServices = ServiceProvider.GetExportedValue<IVSGitServices>();
281+
vsGitServices.SetDefaultProjectPath(newrepo.LocalPath);
282282
if (ErrorHandler.Succeeded(ServiceProvider.GetSolution().CreateNewProjectViaDlg(null, null, 0)))
283283
ServiceProvider.TryGetService<ITeamExplorer>()?.NavigateToPage(new Guid(TeamExplorerPageIds.Home), null);
284284
}

src/GitHub.TeamFoundation.14/GitHub.TeamFoundation.14.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@
107107
</ItemGroup>
108108
<ItemGroup>
109109
<Compile Include="RegistryHelper.cs" />
110-
<Compile Include="Services\VSServices.cs" />
110+
<Compile Include="Services\VSGitServices.cs" />
111111
<Compile Include="Settings.cs" />
112112
<Compile Include="Base\EnsureLoggedInSection.cs" />
113113
<Compile Include="Base\TeamExplorerInvitationBase.cs" />

src/GitHub.TeamFoundation.14/Services/VSServices.cs renamed to src/GitHub.TeamFoundation.14/Services/VSGitServices.cs

+3-39
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,15 @@
99
using GitHub.VisualStudio;
1010
using Microsoft.VisualStudio;
1111
using Microsoft.VisualStudio.Shell.Interop;
12-
using Microsoft.Win32;
13-
using System.Diagnostics;
1412
using GitHub.TeamFoundation;
1513
using Microsoft.TeamFoundation.Git.Controls.Extensibility;
1614
using Microsoft.VisualStudio.TeamFoundation.Git.Extensibility;
1715

1816
namespace GitHub.Services
1917
{
20-
[Export(typeof(IVSServices))]
18+
[Export(typeof(IVSGitServices))]
2119
[PartCreationPolicy(CreationPolicy.Shared)]
22-
public class VSServices : IVSServices
20+
public class VSGitServices : IVSGitServices
2321
{
2422
readonly IUIProvider serviceProvider;
2523

@@ -32,7 +30,7 @@ public class VSServices : IVSServices
3230
IGitExt gitExtService;
3331

3432
[ImportingConstructor]
35-
public VSServices(IUIProvider serviceProvider)
33+
public VSGitServices(IUIProvider serviceProvider)
3634
{
3735
this.serviceProvider = serviceProvider;
3836
}
@@ -104,39 +102,5 @@ public string SetDefaultProjectPath(string path)
104102
{
105103
return RegistryHelper.SetDefaultProjectPath(path);
106104
}
107-
108-
public void ActivityLogMessage(string message)
109-
{
110-
var log = serviceProvider.GetActivityLog();
111-
if (log != null)
112-
{
113-
if (!ErrorHandler.Succeeded(log.LogEntry((UInt32)__ACTIVITYLOG_ENTRYTYPE.ALE_INFORMATION,
114-
Info.ApplicationInfo.ApplicationSafeName, message)))
115-
Console.WriteLine(string.Format(CultureInfo.CurrentCulture, "Could not log message to activity log: {0}", message));
116-
}
117-
}
118-
119-
public void ActivityLogError(string message)
120-
{
121-
var log = serviceProvider.GetActivityLog();
122-
if (log != null)
123-
{
124-
125-
if (!ErrorHandler.Succeeded(log.LogEntry((UInt32)__ACTIVITYLOG_ENTRYTYPE.ALE_ERROR,
126-
Info.ApplicationInfo.ApplicationSafeName, message)))
127-
Console.WriteLine(string.Format(CultureInfo.CurrentCulture, "Could not log error to activity log: {0}", message));
128-
}
129-
}
130-
131-
public void ActivityLogWarning(string message)
132-
{
133-
var log = serviceProvider.GetActivityLog();
134-
if (log != null)
135-
{
136-
if (!ErrorHandler.Succeeded(log.LogEntry((UInt32)__ACTIVITYLOG_ENTRYTYPE.ALE_WARNING,
137-
Info.ApplicationInfo.ApplicationSafeName, message)))
138-
Console.WriteLine(string.Format(CultureInfo.CurrentCulture, "Could not log warning to activity log: {0}", message));
139-
}
140-
}
141105
}
142106
}

src/GitHub.TeamFoundation.15/GitHub.TeamFoundation.15.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,8 @@
163163
<Compile Include="..\GitHub.TeamFoundation.14\Services\TeamExplorerServices.cs">
164164
<Link>Services\TeamExplorerServices.cs</Link>
165165
</Compile>
166-
<Compile Include="..\GitHub.TeamFoundation.14\Services\VSServices.cs">
167-
<Link>Services\VSServices.cs</Link>
166+
<Compile Include="..\GitHub.TeamFoundation.14\Services\VSGitServices.cs">
167+
<Link>Services\VSGitServices.cs</Link>
168168
</Compile>
169169
<Compile Include="RegistryHelper.cs" />
170170
<None Include="..\..\script\Key.snk" Condition="$(Buildtype) == 'Internal'">

src/GitHub.VisualStudio/Base/MenuBase.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ protected ISimpleRepositoryModel GetActiveRepo()
6060
// activeRepo can be null at this point because it is set elsewhere as the result of async operation that may not have completed yet.
6161
if (activeRepo == null)
6262
{
63-
var path = ServiceProvider.GetExportedValue<IVSServices>()?.GetActiveRepoPath() ?? String.Empty;
63+
var path = ServiceProvider.GetExportedValue<IVSGitServices>()?.GetActiveRepoPath() ?? String.Empty;
6464
try
6565
{
6666
activeRepo = !string.IsNullOrEmpty(path) ? new SimpleRepositoryModel(path) : null;
@@ -96,8 +96,8 @@ void RefreshRepo()
9696

9797
if (ActiveRepo == null)
9898
{
99-
var vsservices = ServiceProvider.GetExportedValue<IVSServices>();
100-
string path = vsservices?.GetActiveRepoPath() ?? String.Empty;
99+
var vsGitServices = ServiceProvider.GetExportedValue<IVSGitServices>();
100+
string path = vsGitServices?.GetActiveRepoPath() ?? String.Empty;
101101
try
102102
{
103103
ActiveRepo = !String.IsNullOrEmpty(path) ? new SimpleRepositoryModel(path) : null;

src/GitHub.VisualStudio/Services/ConnectionManager.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class ConnectionCacheItem
2828
public class ConnectionManager : IConnectionManager
2929
{
3030
readonly string cachePath;
31-
readonly IVSServices vsServices;
31+
readonly IVSGitServices vsGitServices;
3232
const string cacheFile = "ghfvs.connections";
3333

3434
public event Func<IConnection, IObservable<IConnection>> DoLogin;
@@ -41,9 +41,9 @@ public class ConnectionManager : IConnectionManager
4141
Action<string> dirCreate;
4242

4343
[ImportingConstructor]
44-
public ConnectionManager(IProgram program, IVSServices services)
44+
public ConnectionManager(IProgram program, IVSGitServices vsGitServices)
4545
{
46-
vsServices = services;
46+
this.vsGitServices = vsGitServices;
4747
fileExists = (path) => System.IO.File.Exists(path);
4848
readAllText = (path, encoding) => System.IO.File.ReadAllText(path, encoding);
4949
writeAllText = (path, content) => System.IO.File.WriteAllText(path, content);
@@ -62,9 +62,9 @@ public ConnectionManager(IProgram program, IVSServices services)
6262
Connections.CollectionChanged += RefreshConnections;
6363
}
6464

65-
public ConnectionManager(IProgram program, Rothko.IOperatingSystem os, IVSServices services)
65+
public ConnectionManager(IProgram program, Rothko.IOperatingSystem os, IVSGitServices vsGitServices)
6666
{
67-
vsServices = services;
67+
this.vsGitServices = vsGitServices;
6868
fileExists = (path) => os.File.Exists(path);
6969
readAllText = (path, encoding) => os.File.ReadAllText(path, encoding);
7070
writeAllText = (path, content) => os.File.WriteAllText(path, content);
@@ -129,7 +129,7 @@ public void RequestLogout(IConnection connection)
129129

130130
public async Task RefreshRepositories()
131131
{
132-
var list = await Task.Run(() => vsServices.GetKnownRepositories());
132+
var list = await Task.Run(() => vsGitServices.GetKnownRepositories());
133133
list.GroupBy(r => Connections.FirstOrDefault(c => r.CloneUrl != null && c.HostAddress.Equals(HostAddress.Create(r.CloneUrl))))
134134
.Where(g => g.Key != null)
135135
.ForEach(g =>

src/UnitTests/GitHub.App/Services/RepositoryCloneServiceTests.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ public async Task ClonesToRepositoryPath()
1313
{
1414
var serviceProvider = Substitutes.ServiceProvider;
1515
var operatingSystem = serviceProvider.GetOperatingSystem();
16-
var vsservices = serviceProvider.GetVSServices();
16+
var vsGitServices = serviceProvider.GetVSGitServices();
1717
var cloneService = serviceProvider.GetRepositoryCloneService();
1818

1919
await cloneService.CloneRepository("https://github.com/foo/bar", "bar", @"c:\dev");
2020

2121
operatingSystem.Directory.Received().CreateDirectory(@"c:\dev\bar");
22-
vsservices.Received().Clone("https://github.com/foo/bar", @"c:\dev\bar", true);
22+
vsGitServices.Received().Clone("https://github.com/foo/bar", @"c:\dev\bar", true);
2323
}
2424
}
2525
}

src/UnitTests/GitHub.VisualStudio/Services/ConnectionManagerTests.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public void IsLoadedFromCache()
2424
.Returns(@"c:\fake");
2525
operatingSystem.File.Exists(@"c:\fake\GHfVS\ghfvs.connections").Returns(true);
2626
operatingSystem.File.ReadAllText(@"c:\fake\GHfVS\ghfvs.connections", Encoding.UTF8).Returns(cacheData);
27-
var manager = new ConnectionManager(program, operatingSystem, Substitutes.IVSServices);
27+
var manager = new ConnectionManager(program, operatingSystem, Substitutes.IVSGitServices);
2828

2929
var connections = manager.Connections;
3030

@@ -49,7 +49,7 @@ public void IsEmptyWhenCacheCorrupt(string cacheJson)
4949
.Returns(@"c:\fake");
5050
operatingSystem.File.Exists(@"c:\fake\GHfVS\ghfvs.connections").Returns(true);
5151
operatingSystem.File.ReadAllText(@"c:\fake\GHfVS\ghfvs.connections", Encoding.UTF8).Returns(cacheJson);
52-
var manager = new ConnectionManager(program, operatingSystem, Substitutes.IVSServices);
52+
var manager = new ConnectionManager(program, operatingSystem, Substitutes.IVSGitServices);
5353

5454
var connections = manager.Connections;
5555

@@ -67,7 +67,7 @@ public void IsSavedToDiskWhenConnectionAdded()
6767
.Returns(@"c:\fake");
6868
operatingSystem.File.Exists(@"c:\fake\GHfVS\ghfvs.connections").Returns(true);
6969
operatingSystem.File.ReadAllText(@"c:\fake\GHfVS\ghfvs.connections", Encoding.UTF8).Returns("");
70-
var manager = new ConnectionManager(program, operatingSystem, Substitutes.IVSServices);
70+
var manager = new ConnectionManager(program, operatingSystem, Substitutes.IVSGitServices);
7171

7272
manager.Connections.Add(new Connection(manager, HostAddress.GitHubDotComHostAddress, "coolio"));
7373

src/UnitTests/GitHub.VisualStudio/Services/RepositoryPublishServiceTests.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using Microsoft.VisualStudio.Shell.Interop;
88
using NSubstitute;
99
using Xunit;
10+
using UnitTests;
1011

1112
public class RepositoryPublishServiceTests
1213
{
@@ -17,7 +18,7 @@ public async Task CreatesRepositoryAndPushesLocalToIt()
1718
{
1819
var solution = Substitute.For<IVsSolution>();
1920
var gitClient = Substitute.For<IGitClient>();
20-
var service = new RepositoryPublishService(gitClient, Substitute.For<IVSServices>());
21+
var service = new RepositoryPublishService(gitClient, Substitutes.IVSGitServices);
2122
var newRepository = new Octokit.NewRepository("test");
2223
var account = Substitute.For<IAccount>();
2324
account.Login.Returns("monalisa");

0 commit comments

Comments
 (0)