11using System ;
2- using System . Runtime . InteropServices ;
32using System . Threading ;
43using System . Threading . Tasks ;
5- using GitHub . Models ;
6- using GitHub . Services ;
4+ using System . Runtime . InteropServices ;
75using GitHub . VisualStudio ;
8- using GitHubCore ;
9- using Microsoft ;
106using Microsoft . VisualStudio . Shell ;
117using Microsoft . VisualStudio . Shell . CodeContainerManagement ;
12- using Microsoft . VisualStudio . ComponentModelHost ;
138using CodeContainer = Microsoft . VisualStudio . Shell . CodeContainerManagement . CodeContainer ;
149using ICodeContainerProvider = Microsoft . VisualStudio . Shell . CodeContainerManagement . ICodeContainerProvider ;
1510
@@ -25,67 +20,30 @@ public sealed class StartPagePackage : ExtensionPointPackage
2520 [ Guid ( Guids . CodeContainerProviderId ) ]
2621 public class GitHubContainerProvider : ICodeContainerProvider
2722 {
28- public async Task < CodeContainer > AcquireCodeContainerAsync ( IProgress < ServiceProgressData > downloadProgress , CancellationToken cancellationToken )
29- {
30- return await RunAcquisitionAsync ( downloadProgress , cancellationToken , null ) ;
31- }
23+ readonly ICodeContainerProvider provider ;
3224
33- public async Task < CodeContainer > AcquireCodeContainerAsync ( RemoteCodeContainer onlineCodeContainer , IProgress < ServiceProgressData > downloadProgress , CancellationToken cancellationToken )
25+ public GitHubContainerProvider ( ) : this ( null )
3426 {
35- var url = onlineCodeContainer . DisplayUrl . ToString ( ) ;
36- return await RunAcquisitionAsync ( downloadProgress , cancellationToken , url ) ;
3727 }
3828
39- async Task < CodeContainer > RunAcquisitionAsync ( IProgress < ServiceProgressData > downloadProgress , CancellationToken cancellationToken , string url = null )
29+ public GitHubContainerProvider ( IServiceProvider serviceProvider )
4030 {
41- await ThreadHelper . JoinableTaskFactory . SwitchToMainThreadAsync ( ) ;
42-
43- var componentModel = await ServiceProvider . GetGlobalServiceAsync < SComponentModel , IComponentModel > ( ) ;
44- Assumes . Present ( componentModel ) ;
45-
46- var result = await ShowCloneDialogAsync ( componentModel , downloadProgress , cancellationToken , url ) ;
47- if ( result == null )
48- {
49- return null ;
50- }
31+ ThreadHelper . ThrowIfNotOnUIThread ( ) ;
5132
52- var repositoryName = result . Url . RepositoryName ;
53- var repositoryRootFullPath = result . Path ;
54- var sccProvider = new Guid ( Guids . GitSccProviderId ) ;
55- var codeContainerProvider = new Guid ( Guids . CodeContainerProviderId ) ;
56- var displayUrl = result . Url . ToRepositoryUrl ( ) ;
57- var browseOnlineUrl = new Uri ( displayUrl . ToString ( ) . TrimSuffix ( ".git" ) ) ;
58- var lastAccessed = DateTimeOffset . UtcNow ;
59-
60- var codeContainer = new CodeContainer (
61- localProperties : new CodeContainerLocalProperties ( repositoryRootFullPath , CodeContainerType . Folder ,
62- new CodeContainerSourceControlProperties ( repositoryName , repositoryRootFullPath , sccProvider ) ) ,
63- remote : new RemoteCodeContainer ( repositoryName , codeContainerProvider , displayUrl , browseOnlineUrl , lastAccessed ) ,
64- isFavorite : false ,
65- lastAccessed : lastAccessed ) ;
66-
67- // Report all steps complete before returning a CodeContainer
68- downloadProgress . Report ( new ServiceProgressData ( string . Empty , string . Empty , 1 , 1 ) ) ;
69-
70- return codeContainer ;
33+ serviceProvider = serviceProvider ?? ServiceProvider . GlobalProvider ;
34+ var factory = new ExtensionServicesFactory ( serviceProvider ) ;
35+ var services = factory . Create ( ) ;
36+ provider = services . GetGitHubContainerProvider ( ) ;
7137 }
7238
73- static async Task < CloneDialogResult > ShowCloneDialogAsync ( IComponentModel componentModel ,
74- IProgress < ServiceProgressData > downloadProgress , CancellationToken cancellationToken , string url = null )
39+ public Task < CodeContainer > AcquireCodeContainerAsync ( IProgress < ServiceProgressData > downloadProgress , CancellationToken cancellationToken )
7540 {
76- var compositionServices = new CompositionServices ( ) ;
77- var compositionContainer = compositionServices . CreateCompositionContainer ( componentModel . DefaultExportProvider ) ;
78-
79- var dialogService = compositionContainer . GetExportedValue < IDialogService > ( ) ;
80- var cloneDialogResult = await dialogService . ShowCloneDialog ( null , url ) ;
81- if ( cloneDialogResult != null )
82- {
83- var repositoryCloneService = compositionContainer . GetExportedValue < IRepositoryCloneService > ( ) ;
84- await repositoryCloneService . CloneOrOpenRepository ( cloneDialogResult , downloadProgress , cancellationToken ) ;
85- return cloneDialogResult ;
86- }
41+ return provider . AcquireCodeContainerAsync ( downloadProgress , cancellationToken ) ;
42+ }
8743
88- return null ;
44+ public Task < CodeContainer > AcquireCodeContainerAsync ( RemoteCodeContainer onlineCodeContainer , IProgress < ServiceProgressData > downloadProgress , CancellationToken cancellationToken )
45+ {
46+ return provider . AcquireCodeContainerAsync ( onlineCodeContainer , downloadProgress , cancellationToken ) ;
8947 }
9048 }
9149}
0 commit comments