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

Commit d2db591

Browse files
authored
Merge pull request #514 from github/fixes/496-track-vs-version-properly
Record Visual Studio version properly
2 parents f9f22eb + ff35699 commit d2db591

19 files changed

+166
-85
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

+1-6
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,7 @@ 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);
8+
string VSVersion { get; }
149

1510
void ActivityLogMessage(string message);
1611
void ActivityLogWarning(string message);

src/GitHub.Exports/Services/Services.cs

-2
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,6 @@ public static IVsOutputWindowPane OutputWindowPane
8484

8585
public static IVsUIShell UIShell => GetGlobalService<SVsUIShell, IVsUIShell>();
8686

87-
public static string VisualStudioVersion => Dte.Version;
88-
8987
public static IVsActivityLog GetActivityLog(this IServiceProvider provider)
9088
{
9189
return GetGlobalService<SVsActivityLog, IVsActivityLog>(provider);

src/GitHub.Exports/Services/UsageTracker.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public class UsageTracker : IUsageTracker
2424
readonly IMetricsService client;
2525
readonly IConnectionManager connectionManager;
2626
readonly IPackageSettings userSettings;
27+
readonly IVSServices vsservices;
2728
readonly DispatcherTimer timer;
2829
readonly string storePath;
2930

@@ -37,6 +38,7 @@ public UsageTracker(
3738
IProgram program,
3839
IConnectionManager connectionManager,
3940
IPackageSettings userSettings,
41+
IVSServices vsservices,
4042
[Import(typeof(SVsServiceProvider))] IServiceProvider serviceProvider)
4143
{
4244
fileExists = (path) => System.IO.File.Exists(path);
@@ -46,6 +48,7 @@ public UsageTracker(
4648

4749
this.connectionManager = connectionManager;
4850
this.userSettings = userSettings;
51+
this.vsservices = vsservices;
4952
this.client = serviceProvider.GetExportedValue<IMetricsService>();
5053
this.timer = new DispatcherTimer(
5154
TimeSpan.FromMinutes(1),
@@ -141,7 +144,7 @@ UsageStore LoadUsage()
141144

142145
result.Model.Lang = CultureInfo.InstalledUICulture.IetfLanguageTag;
143146
result.Model.AppVersion = AssemblyVersionInformation.Version;
144-
result.Model.VSVersion = GitHub.VisualStudio.Services.VisualStudioVersion;
147+
result.Model.VSVersion = vsservices.VSVersion;
145148

146149
return result;
147150
}
+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
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+
using System.Linq;
10+
11+
namespace GitHub.Services
12+
{
13+
[Export(typeof(IVSServices))]
14+
[PartCreationPolicy(CreationPolicy.Shared)]
15+
public class VSServices : IVSServices
16+
{
17+
readonly IUIProvider serviceProvider;
18+
19+
[ImportingConstructor]
20+
public VSServices(IUIProvider serviceProvider)
21+
{
22+
this.serviceProvider = serviceProvider;
23+
}
24+
25+
string vsVersion;
26+
public string VSVersion
27+
{
28+
get
29+
{
30+
if (vsVersion == null)
31+
vsVersion = GetVSVersion();
32+
return vsVersion;
33+
}
34+
}
35+
36+
37+
public void ActivityLogMessage(string message)
38+
{
39+
var log = serviceProvider.GetActivityLog();
40+
if (log != null)
41+
{
42+
if (!ErrorHandler.Succeeded(log.LogEntry((UInt32)__ACTIVITYLOG_ENTRYTYPE.ALE_INFORMATION,
43+
Info.ApplicationInfo.ApplicationSafeName, message)))
44+
Console.WriteLine(string.Format(CultureInfo.CurrentCulture, "Could not log message to activity log: {0}", message));
45+
}
46+
}
47+
48+
public void ActivityLogError(string message)
49+
{
50+
var log = serviceProvider.GetActivityLog();
51+
if (log != null)
52+
{
53+
54+
if (!ErrorHandler.Succeeded(log.LogEntry((UInt32)__ACTIVITYLOG_ENTRYTYPE.ALE_ERROR,
55+
Info.ApplicationInfo.ApplicationSafeName, message)))
56+
Console.WriteLine(string.Format(CultureInfo.CurrentCulture, "Could not log error to activity log: {0}", message));
57+
}
58+
}
59+
60+
public void ActivityLogWarning(string message)
61+
{
62+
var log = serviceProvider.GetActivityLog();
63+
if (log != null)
64+
{
65+
if (!ErrorHandler.Succeeded(log.LogEntry((UInt32)__ACTIVITYLOG_ENTRYTYPE.ALE_WARNING,
66+
Info.ApplicationInfo.ApplicationSafeName, message)))
67+
Console.WriteLine(string.Format(CultureInfo.CurrentCulture, "Could not log warning to activity log: {0}", message));
68+
}
69+
}
70+
71+
const string RegistryRootKey = @"Software\Microsoft\VisualStudio";
72+
const string EnvVersionKey = "EnvVersion";
73+
string GetVSVersion()
74+
{
75+
var version = VisualStudio.Services.Dte.Version;
76+
var keyPath = String.Format(CultureInfo.InvariantCulture, "{0}\\{1}_Config\\SplashInfo", RegistryRootKey, version);
77+
try
78+
{
79+
using (var key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(keyPath))
80+
{
81+
var value = (string)key.GetValue(EnvVersionKey, String.Empty);
82+
if (!String.IsNullOrEmpty(value))
83+
return value;
84+
}
85+
var asm = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(a => a.FullName.StartsWith("Microsoft.VisualStudio.CommonIDE", StringComparison.OrdinalIgnoreCase));
86+
if (asm != null)
87+
return asm.GetName().Version.ToString();
88+
}
89+
catch(Exception ex)
90+
{
91+
VsOutputLogger.WriteLine(string.Format(CultureInfo.CurrentCulture, "Error getting the Visual Studio version '{0}'", ex));
92+
}
93+
return version;
94+
}
95+
}
96+
}

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 =>

0 commit comments

Comments
 (0)