async Task <IConnection> ShowLogin() { var login = factory.CreateViewModel <ILoginViewModel>(); Content = login; return((IConnection)await login.Done.Take(1)); }
/// <inheritdoc/> public async Task StartWithConnection <T>(T viewModel) where T : IDialogContentViewModel, IConnectionInitializedViewModel { var connections = await connectionManager.Value.GetLoadedConnections(); var connection = connections.FirstOrDefault(x => x.IsLoggedIn); if (connection == null) { var login = CreateLoginViewModel(); subscription = login.Done.Take(1).Subscribe(async x => { var newConnection = (IConnection)x; if (newConnection != null) { await viewModel.InitializeAsync(newConnection); Start(viewModel); } else { done.OnNext(null); } }); Content = login; } else { await viewModel.InitializeAsync(connection); Start(viewModel); } }
public Task <object> Show(IDialogContentViewModel viewModel) { var result = default(object); using (var dialogViewModel = CreateViewModel()) using (dialogViewModel.Done.Take(1).Subscribe(x => result = x)) { dialogViewModel.Start(viewModel); var window = new GitHubDialogWindow(dialogViewModel); window.ShowModal(); } return(Task.FromResult(result)); }
public WpfDialog(UserControl view) { if (!(view.DataContext is IDialogContentViewModel viewModel)) { var message = $"DataContext must implement {nameof(IDialogContentViewModel)}"; throw new ArgumentException(message); } dialogViewModel = viewModel; var context = new WpfDialogViewModel(dialogViewModel) { OkayCommand = new RelayCommand(ExecuteOkay, dialogViewModel.CanExecute), CancelCommand = new RelayCommand(ExecuteCancel) }; Content = new WpfDialogView(view) { DataContext = context }; SizeToContent = SizeToContent.WidthAndHeight; }
public async Task StartWithLogout <T>(T viewModel, IConnection connection) where T : IDialogContentViewModel, IConnectionInitializedViewModel { var logout = factory.CreateViewModel <ILogOutRequiredViewModel>(); subscription?.Dispose(); subscription = logout.Done.Take(1).Subscribe(async _ => { await connectionManager.Value.LogOut(connection.HostAddress).ConfigureAwait(true); connection = await ShowLogin().ConfigureAwait(true); if (connection != null) { await viewModel.InitializeAsync(connection).ConfigureAwait(true); Start(viewModel); } }); Content = logout; }
/// <inheritdoc/> public void Start(IDialogContentViewModel viewModel) { subscription?.Dispose(); Content = viewModel; subscription = viewModel.Done?.Subscribe(done); }
public WpfDialogViewModel(IDialogContentViewModel dialogContent) { contentModel = dialogContent; }