@@ -62,40 +62,48 @@ public void Start(IDialogContentViewModel viewModel)
62
62
public async Task StartWithConnection < T > ( T viewModel )
63
63
where T : IDialogContentViewModel , IConnectionInitializedViewModel
64
64
{
65
- var connections = await connectionManager . Value . GetLoadedConnections ( ) ;
65
+ var connections = await connectionManager . Value . GetLoadedConnections ( ) . ConfigureAwait ( true ) ;
66
66
var connection = connections . FirstOrDefault ( x => x . IsLoggedIn ) ;
67
67
68
68
if ( connection == null )
69
69
{
70
- var login = CreateLoginViewModel ( ) ;
71
-
72
- subscription = login . Done . Take ( 1 ) . Subscribe ( async x =>
73
- {
74
- var newConnection = ( IConnection ) x ;
75
-
76
- if ( newConnection != null )
77
- {
78
- await viewModel . InitializeAsync ( newConnection ) ;
79
- Start ( viewModel ) ;
80
- }
81
- else
82
- {
83
- done . OnNext ( null ) ;
84
- }
85
- } ) ;
86
-
87
- Content = login ;
70
+ connection = await ShowLogin ( ) . ConfigureAwait ( true ) ;
88
71
}
89
- else
72
+
73
+ if ( connection != null )
90
74
{
91
- await viewModel . InitializeAsync ( connection ) ;
75
+ await viewModel . InitializeAsync ( connection ) . ConfigureAwait ( true ) ;
92
76
Start ( viewModel ) ;
93
77
}
94
78
}
95
79
96
- ILoginViewModel CreateLoginViewModel ( )
80
+ public async Task StartWithLogout < T > ( T viewModel , IConnection connection )
81
+ where T : IDialogContentViewModel , IConnectionInitializedViewModel
82
+ {
83
+ var logout = factory . CreateViewModel < ILogOutRequiredViewModel > ( ) ;
84
+
85
+ subscription ? . Dispose ( ) ;
86
+ subscription = logout . Done . Take ( 1 ) . Subscribe ( async _ =>
87
+ {
88
+ await connectionManager . Value . LogOut ( connection . HostAddress ) . ConfigureAwait ( true ) ;
89
+
90
+ connection = await ShowLogin ( ) . ConfigureAwait ( true ) ;
91
+
92
+ if ( connection != null )
93
+ {
94
+ await viewModel . InitializeAsync ( connection ) . ConfigureAwait ( true ) ;
95
+ Start ( viewModel ) ;
96
+ }
97
+ } ) ;
98
+
99
+ Content = logout ;
100
+ }
101
+
102
+ async Task < IConnection > ShowLogin ( )
97
103
{
98
- return factory . CreateViewModel < ILoginViewModel > ( ) ;
104
+ var login = factory . CreateViewModel < ILoginViewModel > ( ) ;
105
+ Content = login ;
106
+ return ( IConnection ) await login . Done . Take ( 1 ) ;
99
107
}
100
108
}
101
109
}
0 commit comments