11using System ;
2- using System . Linq ;
3- using System . Reactive . Linq ;
4- using System . Reactive . Threading . Tasks ;
52using System . Threading . Tasks ;
63using GitHub . Factories ;
74using GitHub . Models ;
8- using GitHub . Primitives ;
95using GitHub . Services ;
106
117namespace GitHub . Extensions
128{
139 public static class ConnectionManagerExtensions
1410 {
15- public static IObservable < bool > IsLoggedIn ( this IConnectionManager cm )
16- {
17- Guard . ArgumentNotNull ( cm , nameof ( cm ) ) ;
18-
19- return Observable . FromAsync ( async ( ) =>
20- {
21- var connections = await cm . GetLoadedConnections ( ) ;
22- return connections . Any ( x => x . ConnectionError == null ) ;
23- } ) ;
24- }
25-
26- public static IObservable < bool > IsLoggedIn ( this IConnectionManager cm , HostAddress address )
27- {
28- Guard . ArgumentNotNull ( cm , nameof ( cm ) ) ;
29- Guard . ArgumentNotNull ( address , nameof ( address ) ) ;
30-
31- return Observable . FromAsync ( async ( ) =>
32- {
33- var connections = await cm . GetLoadedConnections ( ) ;
34- return connections . Any ( x => x . HostAddress == address && x . ConnectionError == null ) ;
35- } ) ;
36- }
37-
38- public static IObservable < bool > IsLoggedIn ( this IConnection connection )
39- {
40- Guard . ArgumentNotNull ( connection , nameof ( connection ) ) ;
41-
42- return Observable . Return ( connection ? . IsLoggedIn ?? false ) ;
43- }
44-
45- public static IObservable < IConnection > GetConnection ( this IConnectionManager cm , HostAddress address )
46- {
47- Guard . ArgumentNotNull ( cm , nameof ( cm ) ) ;
48- Guard . ArgumentNotNull ( address , nameof ( address ) ) ;
49-
50- return cm . GetLoadedConnections ( )
51- . ToObservable ( )
52- . Select ( x => x . FirstOrDefault ( y => y . HostAddress == address ) ) ;
53- }
54-
55- public static IObservable < IConnection > GetLoggedInConnections ( this IConnectionManager cm )
56- {
57- Guard . ArgumentNotNull ( cm , nameof ( cm ) ) ;
58-
59- return cm . GetLoadedConnections ( )
60- . ToObservable ( )
61- . Select ( x => x . FirstOrDefault ( y => y . IsLoggedIn ) ) ;
62- }
63-
6411 public static async Task < IModelService > GetModelService (
6512 this IConnectionManager cm ,
6613 ILocalRepositoryModel repository ,
@@ -69,12 +16,5 @@ public static async Task<IModelService> GetModelService(
6916 var connection = await cm . LookupConnection ( repository ) ;
7017 return connection != null ? await factory . CreateAsync ( connection ) : null ;
7118 }
72-
73- public static IObservable < IConnection > LookupConnection ( this IConnectionManager cm , ILocalRepositoryModel repository )
74- {
75- return Observable . Return ( repository ? . CloneUrl != null
76- ? cm . Connections . FirstOrDefault ( c => c . HostAddress . Equals ( HostAddress . Create ( repository . CloneUrl ) ) )
77- : null ) ;
78- }
7919 }
8020}
0 commit comments