private void OnApplicationStateChanged(ApplicationState applicationState) { if (applicationState == ApplicationState.DisconnectedFromServer) { Application.Current.Dispatcher.Invoke(() => { AvailableUsers.Clear(); AreConnectionSettingsVisible = true; SelectedUser = null; IsUserListAvailable = false; }); } if (applicationState == ApplicationState.ConnectedButNotLoggedIn) { AreConnectionSettingsVisible = false; session.RequestUserList( userList => { Application.Current.Dispatcher.Invoke(async() => { AvailableUsers.Clear(); userList.Do(userData => AvailableUsers.Add(userData)); IsUserListAvailable = true; if (AvailableUsers.Count > 0) { SelectedUser = AvailableUsers.Any(user => user.Id == localSettingsRepository.LastLoggedInUserId) ? AvailableUsers.First(user => user.Id == localSettingsRepository.LastLoggedInUserId) : AvailableUsers.First(); } else { var dialog = new UserDialogBox("", "Es sind keine verfügbaren User vorhanden\n" + "Die Verbindung wird getrennt!", MessageBoxButton.OK); await dialog.ShowMahAppsDialog(); Disconnect.Execute(null); } }); }, errorMessage => { Application.Current.Dispatcher.Invoke(async() => { var dialog = new UserDialogBox("", "Die Userliste kann nicht vom Server abgefragt werden:\n" + $">> {errorMessage} <<\n" + "Die Verbindung wird getrennt - versuchen Sie es erneut", MessageBoxButton.OK); await dialog.ShowMahAppsDialog(); Disconnect.Execute(null); }); } ); } Application.Current.Dispatcher.Invoke(() => { ((ParameterrizedCommand <PasswordBox>)Login).RaiseCanExecuteChanged(); ((Command)Connect).RaiseCanExecuteChanged(); ((Command)DebugConnect).RaiseCanExecuteChanged(); ((Command)Disconnect).RaiseCanExecuteChanged(); }); }
private GlobalStatusStore() { Test = ReactiveCommand.CreateFromTask(TestImpl); var canOperate = this.WhenAnyValue(x => x.ConnectStatus) .Select(p => { if (p == ConnectStatus.Checking && p == ConnectStatus.Connecting && p == ConnectStatus.Disconnecting) { return(false); } else { return(true); } }); _canConnect = canOperate.ToProperty(this, x => x.CanOperate, false); Connect = ReactiveCommand.CreateFromTask(async() => { ConnectStatus = ConnectStatus.Connecting; if (await Locator.Current.GetService <IUserStorageService>().CheckUserPinExist(CurrentUser.Username)) { throw new ConnectionException(ConnectionError.LostPin); } else { await DoConnect.Execute(""); } }, canOperate); Connect.ThrownExceptions.Subscribe(ex => { }); DoConnect = ReactiveCommand.CreateFromTask <string, bool>(async(pin) => { string password; try { password = await Locator.Current.GetService <IUserStorageService>().DecryptedUserPassword(CurrentUser.Username, pin); } catch { throw new ConnectionException(ConnectionError.InvalidPin); } return(await Locator.Current.GetService <IInternetGatewayService>().Connect(CurrentUser.Username, password)); }, canOperate); DoConnect.ThrownExceptions.Subscribe(ex => { }); DoConnect.Where(u => u).Subscribe(p => { ConnectStatus = ConnectStatus.Connected; }); Disconnect = ReactiveCommand.CreateFromTask(async() => { ConnectStatus = ConnectStatus.Disconnecting; return(await Locator.Current.GetService <IInternetGatewayService>().Disconnect()); }, canOperate); Disconnect.Where(u => u).Subscribe(_ => { ConnectStatus = ConnectStatus.Disconnected; }); Disconnect.ThrownExceptions.Subscribe(ex => { }); Toggle = ReactiveCommand.CreateFromTask(async() => { if (ConnectStatus == ConnectStatus.Disconnected) { await Connect.Execute(); } else if (ConnectStatus == ConnectStatus.Connected) { await Disconnect.Execute(); } }, canOperate); Toggle.ThrownExceptions.Subscribe(_ => { }); }