99using Microsoft . VisualStudio . ComponentModelHost ;
1010using CodeContainer = Microsoft . VisualStudio . Shell . CodeContainerManagement . CodeContainer ;
1111using ICodeContainerProvider = Microsoft . VisualStudio . Shell . CodeContainerManagement . ICodeContainerProvider ;
12+ using System . Runtime . InteropServices ;
1213
1314namespace GitHub . VisualStudio
1415{
@@ -18,71 +19,72 @@ public ICodeContainerProvider GetGitHubContainerProvider()
1819 {
1920 return new InBoxGitHubContainerProvider ( ) ;
2021 }
22+ }
2123
22- class InBoxGitHubContainerProvider : ICodeContainerProvider
24+ [ Guid ( Guids . CodeContainerProviderId ) ]
25+ public class InBoxGitHubContainerProvider : ICodeContainerProvider
26+ {
27+ public async Task < CodeContainer > AcquireCodeContainerAsync ( IProgress < ServiceProgressData > downloadProgress , CancellationToken cancellationToken )
2328 {
24- public async Task < CodeContainer > AcquireCodeContainerAsync ( IProgress < ServiceProgressData > downloadProgress , CancellationToken cancellationToken )
25- {
26- return await RunAcquisitionAsync ( downloadProgress , cancellationToken , null ) ;
27- }
28-
29- public async Task < CodeContainer > AcquireCodeContainerAsync ( RemoteCodeContainer onlineCodeContainer , IProgress < ServiceProgressData > downloadProgress , CancellationToken cancellationToken )
30- {
31- var url = onlineCodeContainer . DisplayUrl . ToString ( ) ;
32- return await RunAcquisitionAsync ( downloadProgress , cancellationToken , url ) ;
33- }
29+ return await RunAcquisitionAsync ( downloadProgress , cancellationToken , null ) ;
30+ }
3431
35- async Task < CodeContainer > RunAcquisitionAsync ( IProgress < ServiceProgressData > downloadProgress , CancellationToken cancellationToken , string url = null )
36- {
37- await ThreadHelper . JoinableTaskFactory . SwitchToMainThreadAsync ( ) ;
32+ public async Task < CodeContainer > AcquireCodeContainerAsync ( RemoteCodeContainer onlineCodeContainer , IProgress < ServiceProgressData > downloadProgress , CancellationToken cancellationToken )
33+ {
34+ var url = onlineCodeContainer . DisplayUrl . ToString ( ) ;
35+ return await RunAcquisitionAsync ( downloadProgress , cancellationToken , url ) ;
36+ }
3837
39- var componentModel = await ServiceProvider . GetGlobalServiceAsync < SComponentModel , IComponentModel > ( ) ;
40- Assumes . Present ( componentModel ) ;
38+ async Task < CodeContainer > RunAcquisitionAsync ( IProgress < ServiceProgressData > downloadProgress , CancellationToken cancellationToken , string url = null )
39+ {
40+ await ThreadHelper . JoinableTaskFactory . SwitchToMainThreadAsync ( ) ;
4141
42- var result = await ShowCloneDialogAsync ( componentModel , downloadProgress , cancellationToken , url ) ;
43- if ( result == null )
44- {
45- return null ;
46- }
42+ var componentModel = await ServiceProvider . GetGlobalServiceAsync < SComponentModel , IComponentModel > ( ) ;
43+ Assumes . Present ( componentModel ) ;
4744
48- var repositoryName = result . Url . RepositoryName ;
49- var repositoryRootFullPath = result . Path ;
50- var sccProvider = new Guid ( Guids . GitSccProviderId ) ;
51- var codeContainerProvider = new Guid ( Guids . CodeContainerProviderId ) ;
52- var displayUrl = result . Url . ToRepositoryUrl ( ) ;
53- var browseOnlineUrl = new Uri ( displayUrl . ToString ( ) . TrimSuffix ( ".git" ) ) ;
54- var lastAccessed = DateTimeOffset . UtcNow ;
45+ var result = await ShowCloneDialogAsync ( componentModel , downloadProgress , cancellationToken , url ) ;
46+ if ( result == null )
47+ {
48+ return null ;
49+ }
5550
56- var codeContainer = new CodeContainer (
57- localProperties : new CodeContainerLocalProperties ( repositoryRootFullPath , CodeContainerType . Folder ,
58- new CodeContainerSourceControlProperties ( repositoryName , repositoryRootFullPath , sccProvider ) ) ,
59- remote : new RemoteCodeContainer ( repositoryName , codeContainerProvider , displayUrl , browseOnlineUrl , lastAccessed ) ,
60- isFavorite : false ,
61- lastAccessed : lastAccessed ) ;
51+ var repositoryName = result . Url . RepositoryName ;
52+ var repositoryRootFullPath = result . Path ;
53+ var sccProvider = new Guid ( Guids . GitSccProviderId ) ;
54+ var codeContainerProvider = new Guid ( Guids . CodeContainerProviderId ) ;
55+ var displayUrl = result . Url . ToRepositoryUrl ( ) ;
56+ var browseOnlineUrl = new Uri ( displayUrl . ToString ( ) . TrimSuffix ( ".git" ) ) ;
57+ var lastAccessed = DateTimeOffset . UtcNow ;
6258
63- // Report all steps complete before returning a CodeContainer
64- downloadProgress . Report ( new ServiceProgressData ( string . Empty , string . Empty , 1 , 1 ) ) ;
59+ var codeContainer = new CodeContainer (
60+ localProperties : new CodeContainerLocalProperties ( repositoryRootFullPath , CodeContainerType . Folder ,
61+ new CodeContainerSourceControlProperties ( repositoryName , repositoryRootFullPath , sccProvider ) ) ,
62+ remote : new RemoteCodeContainer ( repositoryName , codeContainerProvider , displayUrl , browseOnlineUrl , lastAccessed ) ,
63+ isFavorite : false ,
64+ lastAccessed : lastAccessed ) ;
6565
66- return codeContainer ;
67- }
66+ // Report all steps complete before returning a CodeContainer
67+ downloadProgress . Report ( new ServiceProgressData ( string . Empty , string . Empty , 1 , 1 ) ) ;
6868
69- static async Task < CloneDialogResult > ShowCloneDialogAsync ( IComponentModel componentModel ,
70- IProgress < ServiceProgressData > downloadProgress , CancellationToken cancellationToken , string url = null )
71- {
72- var compositionServices = new CompositionServices ( ) ;
73- var compositionContainer = compositionServices . CreateVisualStudioCompositionContainer ( componentModel . DefaultExportProvider ) ;
69+ return codeContainer ;
70+ }
7471
75- var dialogService = compositionContainer . GetExportedValue < IDialogService > ( ) ;
76- var cloneDialogResult = await dialogService . ShowCloneDialog ( null , url ) ;
77- if ( cloneDialogResult != null )
78- {
79- var repositoryCloneService = compositionContainer . GetExportedValue < IRepositoryCloneService > ( ) ;
80- await repositoryCloneService . CloneOrOpenRepository ( cloneDialogResult , downloadProgress , cancellationToken ) ;
81- return cloneDialogResult ;
82- }
72+ static async Task < CloneDialogResult > ShowCloneDialogAsync ( IComponentModel componentModel ,
73+ IProgress < ServiceProgressData > downloadProgress , CancellationToken cancellationToken , string url = null )
74+ {
75+ var compositionServices = new CompositionServices ( ) ;
76+ var compositionContainer = compositionServices . CreateVisualStudioCompositionContainer ( componentModel . DefaultExportProvider ) ;
8377
84- return null ;
78+ var dialogService = compositionContainer . GetExportedValue < IDialogService > ( ) ;
79+ var cloneDialogResult = await dialogService . ShowCloneDialog ( null , url ) ;
80+ if ( cloneDialogResult != null )
81+ {
82+ var repositoryCloneService = compositionContainer . GetExportedValue < IRepositoryCloneService > ( ) ;
83+ await repositoryCloneService . CloneOrOpenRepository ( cloneDialogResult , downloadProgress , cancellationToken ) ;
84+ return cloneDialogResult ;
8585 }
86+
87+ return null ;
8688 }
8789 }
8890}
0 commit comments