public StartupViewModel(IAccountsService accountsService, ILoginService loginService) { _accountsService = accountsService; _loginService = loginService; GoToMainCommand = ReactiveCommand.Create(); GoToAccountsCommand = ReactiveCommand.Create(); GoToNewUserCommand = ReactiveCommand.Create(); BecomeActiveWindowCommand = ReactiveCommand.Create(); GoToAccountsCommand.Subscribe(_ => ShowViewModel(CreateViewModel <AccountsViewModel>())); GoToNewUserCommand.Subscribe(_ => ShowViewModel(CreateViewModel <NewAccountViewModel>())); GoToMainCommand.Subscribe(_ => ShowViewModel(CreateViewModel <MenuViewModel>())); LoadCommand = ReactiveCommand.CreateAsyncTask(x => Load()); }
private async Task Load() { var account = _accountsService.GetDefault(); // Account no longer exists if (account == null) { GoToAccountsOrNewUser(); } else { try { Status = string.Format("Logging in {0}", account.Username); Uri avatarUri; if (Uri.TryCreate(account.AvatarUrl, UriKind.Absolute, out avatarUri)) { ImageUrl = avatarUri; } IsLoggingIn = true; await _loginService.LoginAccount(account); _accountsService.ActiveAccount = account; GoToMainCommand.ExecuteIfCan(); } catch { GoToAccountsCommand.ExecuteIfCan(); } finally { IsLoggingIn = false; } } }