5
5
using LibGit2Sharp ;
6
6
using Microsoft . VisualStudio ;
7
7
using Microsoft . VisualStudio . ComponentModelHost ;
8
- using Microsoft . VisualStudio . Shell ;
9
8
using Microsoft . VisualStudio . Shell . Interop ;
10
9
using GitHub . Info ;
11
10
using GitHub . Primitives ;
12
11
using GitHub . Extensions ;
13
12
14
13
namespace GitHub . VisualStudio
15
14
{
15
+
16
16
public static class Services
17
17
{
18
18
public static IServiceProvider PackageServiceProvider { get ; set ; }
19
19
20
20
/// <summary>
21
- /// Three ways of getting a service. First, trying the passed-in <paramref name="provider"/>,
22
- /// then <see cref="PackageServiceProvider"/>, then <see cref="T:Microsoft.VisualStudio.Shell.Package"/>
23
- /// If the passed-in provider returns null, try PackageServiceProvider or Package, returning the fetched value
24
- /// regardless of whether it's null or not. Package.GetGlobalService is never called if PackageServiceProvider is set.
25
- /// This is on purpose, to support easy unit testing outside VS.
21
+ /// Two ways of getting a service. First, trying the passed-in <paramref name="provider"/>,
22
+ /// then <see cref="PackageServiceProvider"/>
23
+ /// If the passed-in provider returns null, try PackageServiceProvider, returning the fetched value
24
+ /// regardless of whether it's null or not.
26
25
/// </summary>
27
26
/// <typeparam name="T"></typeparam>
28
27
/// <typeparam name="Ret"></typeparam>
@@ -35,9 +34,7 @@ static Ret GetGlobalService<T, Ret>(IServiceProvider provider = null) where T :
35
34
ret = provider . GetService ( typeof ( T ) ) as Ret ;
36
35
if ( ret != null )
37
36
return ret ;
38
- if ( PackageServiceProvider != null )
39
- return PackageServiceProvider . GetService ( typeof ( T ) ) as Ret ;
40
- return Package . GetGlobalService ( typeof ( T ) ) as Ret ;
37
+ return PackageServiceProvider . GetService ( typeof ( T ) ) as Ret ;
41
38
}
42
39
43
40
public static IComponentModel ComponentModel
@@ -101,18 +98,6 @@ public static IVsSolution GetSolution(this IServiceProvider provider)
101
98
return GetGlobalService < SVsSolution , IVsSolution > ( provider ) ;
102
99
}
103
100
104
- public static T GetExportedValue < T > ( this IServiceProvider serviceProvider )
105
- {
106
- var ui = serviceProvider as IUIProvider ;
107
- if ( ui != null )
108
- return ui . GetService < T > ( ) ;
109
- else
110
- {
111
- var componentModel = ( IComponentModel ) serviceProvider . GetService ( typeof ( SComponentModel ) ) ;
112
- return componentModel . DefaultExportProvider . GetExportedValue < T > ( ) ;
113
- }
114
- }
115
-
116
101
public static UriString GetRepoUrlFromSolution ( IVsSolution solution )
117
102
{
118
103
string solutionDir , solutionFile , userFile ;
@@ -125,11 +110,11 @@ public static UriString GetRepoUrlFromSolution(IVsSolution solution)
125
110
return null ;
126
111
using ( var repo = new Repository ( repoPath ) )
127
112
{
128
- return repo . GetUri ( ) ;
113
+ return GetUri ( repo ) ;
129
114
}
130
115
}
131
116
132
- public static Repository GetRepoFromSolution ( this IVsSolution solution )
117
+ public static IRepository GetRepoFromSolution ( this IVsSolution solution )
133
118
{
134
119
string solutionDir , solutionFile , userFile ;
135
120
if ( ! ErrorHandler . Succeeded ( solution . GetSolutionInfo ( out solutionDir , out solutionFile , out userFile ) ) )
@@ -141,5 +126,10 @@ public static Repository GetRepoFromSolution(this IVsSolution solution)
141
126
return null ;
142
127
return new Repository ( repoPath ) ;
143
128
}
129
+ static UriString GetUri ( IRepository repo )
130
+ {
131
+ return UriString . ToUriString ( GitService . GetUriFromRepository ( repo ) ? . ToRepositoryUrl ( ) ) ;
132
+ }
133
+ public static IGitService IGitService { get { return PackageServiceProvider . GetService < IGitService > ( ) ; } }
144
134
}
145
135
}
0 commit comments