public LoginViewModel(ILoginService loginFactory, IAccountsService accountsService) { _loginFactory = loginFactory; WebDomain = "https://github.com"; GoToOldLoginWaysCommand = ReactiveCommand.Create(); GoToOldLoginWaysCommand.Subscribe(_ => ShowViewModel(CreateViewModel <AddAccountViewModel>())); var loginCommand = ReactiveCommand.CreateAsyncTask( this.WhenAnyValue(x => x.Code).Select(x => !string.IsNullOrEmpty(x)), _ => Login(Code)); loginCommand.Subscribe(x => accountsService.ActiveAccount = x); LoginCommand = loginCommand; }
public LoginViewModel(ILoginService loginFactory, IAccountsService accountsService, IActionMenuService actionMenuService, IStatusIndicatorService statusIndicatorService, IAlertDialogService alertDialogService) { _loginFactory = loginFactory; Title = "Login"; GoToOldLoginWaysCommand = ReactiveCommand.Create(); GoToOldLoginWaysCommand.Subscribe(_ => ShowViewModel(CreateViewModel <AddAccountViewModel>())); var loginCommand = ReactiveCommand.CreateAsyncTask( this.WhenAnyValue(x => x.Code).Select(x => !string.IsNullOrEmpty(x)), _ => Login(Code)); loginCommand.Subscribe(x => accountsService.ActiveAccount = x); loginCommand.Subscribe(x => MessageBus.Current.SendMessage(new LogoutMessage())); LoginCommand = loginCommand; ShowLoginOptionsCommand = ReactiveCommand.CreateAsyncTask(t => { var actionMenu = actionMenuService.Create(Title); actionMenu.AddButton("Login via BASIC", GoToOldLoginWaysCommand); return(actionMenu.Show()); }); LoginCommand.IsExecuting.Skip(1).Subscribe(x => { if (x) { statusIndicatorService.Show("Logging in..."); } else { statusIndicatorService.Hide(); } }); _loginUrl = this.WhenAnyValue(x => x.WebDomain) .IsNotNull() .Select(x => x.TrimEnd('/')) .Select(x => string.Format(x + "/login/oauth/authorize?client_id={0}&redirect_uri={1}&scope={2}", ClientId, Uri.EscapeDataString(RedirectUri), Uri.EscapeDataString("user,repo,notifications,gist"))) .ToProperty(this, x => x.LoginUrl); LoadCommand = ReactiveCommand.CreateAsyncTask(async t => { if (IsEnterprise && string.IsNullOrEmpty(WebDomain)) { var response = await alertDialogService.PromptTextBox("Enterprise URL", "Please enter the webpage address for the GitHub Enterprise installation", DefaultWebDomain, "Ok"); WebDomain = response; } else { WebDomain = DefaultWebDomain; } }); LoadCommand.ThrownExceptions.Take(1).Subscribe(x => DismissCommand.ExecuteIfCan()); }