1+ using System ;
2+ using System . Reactive . Linq ;
3+ using GitHub . Api ;
4+ using GitHub . Extensions ;
5+ using GitHub . Models ;
6+ using GitHub . Services ;
7+ using GitHub . UI ;
8+ using GitHub . VisualStudio . Base ;
9+ using Microsoft . TeamFoundation . MVVM ;
10+ using System . Globalization ;
11+ using GitHub . Primitives ;
12+ using System . Threading . Tasks ;
13+
14+ namespace GitHub . VisualStudio . TeamExplorer . Sync
15+ {
16+ public class EnsureLoggedInSection : TeamExplorerSectionBase
17+ {
18+ readonly IRepositoryHosts hosts ;
19+ readonly IVSServices vsServices ;
20+
21+ public EnsureLoggedInSection ( ISimpleApiClientFactory apiFactory , ITeamExplorerServiceHolder holder ,
22+ IConnectionManager cm , IRepositoryHosts hosts , IVSServices vsServices )
23+ : base ( apiFactory , holder , cm )
24+ {
25+ IsVisible = false ;
26+ this . hosts = hosts ;
27+ this . vsServices = vsServices ;
28+ }
29+
30+ public override void Initialize ( IServiceProvider serviceProvider )
31+ {
32+ base . Initialize ( serviceProvider ) ;
33+ CheckLogin ( ) . Forget ( ) ;
34+ }
35+
36+ protected override void RepoChanged ( )
37+ {
38+ base . RepoChanged ( ) ;
39+ CheckLogin ( ) . Forget ( ) ;
40+ }
41+
42+ async Task CheckLogin ( )
43+ {
44+ // this is not a github repo, or it hasn't been published yet
45+ if ( ActiveRepo == null || ActiveRepoUri == null )
46+ return ;
47+
48+ var isgithub = await IsAGitHubRepo ( ) ;
49+ if ( ! isgithub )
50+ return ;
51+
52+ vsServices . ClearNotifications ( ) ;
53+ var add = HostAddress . Create ( ActiveRepoUri ) ;
54+ bool loggedIn = await connectionManager . IsLoggedIn ( hosts , add ) ;
55+ if ( ! loggedIn )
56+ {
57+ var msg = string . Format ( CultureInfo . CurrentUICulture , Resources . NotLoggedInMessage , add . Title , add . Title ) ;
58+ vsServices . ShowMessage (
59+ msg ,
60+ new RelayCommand ( ( ) => StartFlow ( UIControllerFlow . Authentication ) )
61+ ) ;
62+ }
63+ }
64+
65+ void StartFlow ( UIControllerFlow controllerFlow )
66+ {
67+ var uiProvider = ServiceProvider . GetExportedValue < IUIProvider > ( ) ;
68+ var ret = uiProvider . SetupUI ( controllerFlow , null ) ;
69+ ret . Subscribe ( c => { } , ( ) => CheckLogin ( ) . Forget ( ) ) ;
70+ uiProvider . RunUI ( ) ;
71+ }
72+ }
73+ }
0 commit comments