public SelectedCallsScreenViewModel(ISelectionService selectionService, IConcurrencyService concurrencyService, IObservablesList observablesListViewModel) { ObservablesList = observablesListViewModel; DisplayName = "IObservable instances"; observablesListViewModel.Observables = selectionService.WhenSelectionChanges .ObserveOn(concurrencyService.TaskPoolRxScheduler) .Select(selection => selection.SelectedInstrumentedCalls) .DistinctUntilChanged() .Select(calls => calls .Select(c => c.ObservableInstances) .Merge() .ToObservableChangeSet(obs => obs.ObservableId)) .SwitchFixed(); this.WhenActivated((CompositeDisposable disposables) => { observablesListViewModel.WhenSelectionChanges .OnItemAdded(obs => selectionService.ChangeSelection(s => s.AddObservableInstance(obs))) .OnItemRemoved(obs => selectionService.ChangeSelection(s => s.RemoveObservableInstance(obs))) .Subscribe() .DisposeWith(disposables); observablesListViewModel.Activator.Activate() .DisposeWith(disposables); }); }
public MonitoringConfigurationScreenViewModel(IConcurrencyService concurrencyService, ISelectionService selectionService) { var methodItems = new ObservableCollectionExtended <MethodItem>(); Methods = new ReadOnlyObservableCollection <MethodItem>(methodItems); this.WhenActivated((CompositeDisposable disposables) => { methodItems.Clear(); var monitoredCalls = Workspace.MonitoredCalls .TakeUntilDisposed(disposables) .Transform(c => c.Call) .AddKey(c => c.InstrumentedCallId) .SubscribeOn(concurrencyService.TaskPoolRxScheduler) .AsObservableCache(); Workspace.Methods .Transform(method => new MethodItem(method, monitoredCalls, concurrencyService, Workspace)) .SubscribeOn(concurrencyService.TaskPoolRxScheduler) .ObserveOn(concurrencyService.DispatcherRxScheduler) .Bind(methodItems) .DisposeMany() .Subscribe() .DisposeWith(disposables); this.WhenValueChanged(x => x.SelectedItem) .ObserveOn(concurrencyService.TaskPoolRxScheduler) .Subscribe(item => { if (item is CallItem c) { selectionService.ChangeSelection(s => s.SetCall(c.InstrumentedCall)); } else { selectionService.ChangeSelection(s => s.ClearCall()); } }); }); }
public ShellViewModel(IConnectionService connectionService, IScreenFactory screenFactory, IDialogService dialogService, IConcurrencyService concurrencyService, IWorkspaceFactory workspaceFactory, ISelectionService selectionService) { DisplayName = "Reactivity Monitor"; var concreteDialogService = (DialogService)dialogService; WhenActivated(disposables => { connectionService.WhenConnectionChanges .ObserveOnDispatcher() .Select(GetViewModelForConnection) .Subscribe(ActivateItem) .DisposeWith(disposables); this.ObservableForProperty(x => x.ActiveItem).Value() .Select(item => item.WhenAnyValue(x => x.DisplayName)) .Switch() .Select(itemTitle => $"{itemTitle} - Reactivity Monitor") .Subscribe(title => DisplayName = title) .DisposeWith(disposables); this.WhenAnyValue(x => x.ActiveItem) .Subscribe(item => selectionService.ChangeSelection(s => s.SetWorkspace((item as IHomeScreen)?.Workspace))) .DisposeWith(disposables); Disposable.Create(connectionService.Close).DisposeWith(disposables); concreteDialogService.WhenDialogViewModelChanges .ObserveOn(concurrencyService.DispatcherRxScheduler) .Subscribe(vm => DialogViewModel = vm) .DisposeWith(disposables); }); CancelDialogCommand = ReactiveCommand.Create(concreteDialogService.CancelActiveDialog); IScreen GetViewModelForConnection(IConnectionModel conn) { if (conn == null) { return(screenFactory.CreateConnectionScreen()); } else { var workspace = workspaceFactory.CreateWorkspace(conn); var homeScreen = screenFactory.CreateHomeScreen(workspace); return(homeScreen); } } }