private async Task WrapBrowserJob(IUserIntervention intervention, Func <WebBrowserVM, CancellationTokenSource, Task> toDo) { var cancel = new CancellationTokenSource(); var oldPane = MainWindow.ActivePane; using var vm = await WebBrowserVM.GetNew(); MainWindow.NavigateTo(vm); vm.BackCommand = ReactiveCommand.Create(() => { cancel.Cancel(); MainWindow.NavigateTo(oldPane); intervention.Cancel(); }); try { await toDo(vm, cancel); } catch (TaskCanceledException) { intervention.Cancel(); } catch (Exception ex) { Utils.Error(ex); intervention.Cancel(); } MainWindow.NavigateTo(oldPane); }
public async Task Handle(IUserIntervention msg) { switch (msg) { case RequestNexusAuthorization c: await WrapBrowserJob(msg, async (vm, cancel) => { var key = await NexusApiClient.SetupNexusLogin(vm.Browser, m => vm.Instructions = m, cancel.Token); c.Resume(key); }); break; case RequestLoversLabLogin c: await WrapBrowserJob(msg, async (vm, cancel) => { var data = await LoversLabDownloader.GetAndCacheLoversLabCookies(vm.Browser, m => vm.Instructions = m, cancel.Token); c.Resume(data); }); break; case ConfirmationIntervention c: break; default: throw new NotImplementedException($"No handler for {msg}"); } }
public async Task Handle(IUserIntervention msg) { switch (msg) { case RequestNexusAuthorization c: await WrapBrowserJob(msg, async (vm, cancel) => { await vm.Driver.WaitForInitialized(); var key = await NexusApiClient.SetupNexusLogin(new CefSharpWrapper(vm.Browser), m => vm.Instructions = m, cancel.Token); c.Resume(key); }); break; case RequestBethesdaNetLogin c: var data = await BethesdaNetDownloader.Login(); c.Resume(data); break; case AbstractNeedsLoginDownloader.RequestSiteLogin c: await WrapBrowserJob(msg, async (vm, cancel) => { await vm.Driver.WaitForInitialized(); var data = await c.Downloader.GetAndCacheCookies(new CefSharpWrapper(vm.Browser), m => vm.Instructions = m, cancel.Token); c.Resume(data); }); break; case YesNoIntervention c: var result = MessageBox.Show(c.ExtendedDescription, c.ShortDescription, MessageBoxButton.YesNo, MessageBoxImage.Question); if (result == MessageBoxResult.Yes) { c.Confirm(); } else { c.Cancel(); } break; case CriticalFailureIntervention c: MessageBox.Show(c.ExtendedDescription, c.ShortDescription, MessageBoxButton.OK, MessageBoxImage.Error); c.Cancel(); break; case ConfirmationIntervention c: break; default: throw new NotImplementedException($"No handler for {msg}"); } }
public IUserIntervention InterventionConverter(IUserIntervention intervention) { switch (intervention) { case ConfirmUpdateOfExistingInstall confirm: return(new ConfirmUpdateOfExistingInstallVM(this, confirm)); default: return(intervention); } }
private async Task WrapBethesdaNetLogin(IUserIntervention intervention) { CancellationTokenSource cancel = new CancellationTokenSource(); var oldPane = MainWindow.ActivePane; var vm = await BethesdaNetLoginVM.GetNew(); MainWindow.NavigateTo(vm); vm.BackCommand = ReactiveCommand.Create(() => { cancel.Cancel(); MainWindow.NavigateTo(oldPane); intervention.Cancel(); }); }
public IUserIntervention InterventionConverter(IUserIntervention intervention) => intervention;