コード例 #1
0
        internal OutputsSelectedSampleViewModel(IAppState appState, IAppService appService, ModuleState moduleState)
        {
            _appState    = appState;
            _moduleState = moduleState;
            _simulation  = appState.Target.AssertSome();

            ShareParameterValues = ReactiveCommand.Create(
                HandleShareParameterValues,
                this.ObservableForProperty(
                    vm => vm.SelectedSample,
                    _ => SelectedSample != NOT_FOUND
                    )
                );

            _reactiveSafeInvoke = appService.GetReactiveSafeInvoke();

            _subscriptions = new CompositeDisposable(

                this
                .ObservableForProperty(vm => vm.SelectedSample)
                .Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <object>(
                        ObserveSelectedSample
                        )
                    )

                );
        }
コード例 #2
0
        internal static void Save(ModuleState instance, Simulation simulation)
        {
            simulation.SavePrivateData(
                new _ModuleStateDTO
            {
                ParametersState = new _ParametersStateDTO
                {
                    SelectedParameter = instance.ParametersState.SelectedParameter
                },

                SamplesState = new _SamplesStateDTO
                {
                    NumberOfSamples       = instance.SamplesState.NumberOfSamples,
                    Seed                  = instance.SamplesState.Seed,
                    LatinHypercubeDesign  = instance.SamplesState.LatinHypercubeDesign.ToDTO(),
                    RankCorrelationDesign = instance.SamplesState.RankCorrelationDesign.ToDTO()
                },

                OutputsState = new _OutputsStateDTO
                {
                    SelectedOutputName     = instance.OutputsState.SelectedOutputName,
                    IsSeriesTypeLine       = instance.OutputsState.IsSeriesTypeLine,
                    ObservationsReferences = instance.OutputsState.ObservationsReferences.ToArray()
                },

                FilteredSamplesStateDTO = new _FilteredSamplesStateDTO
                {
                    IsEnabled = instance.FilteredSamplesState.IsEnabled,
                    IsUnion   = instance.FilteredSamplesState.IsUnion
                },

                ParameterStates = instance.ParameterStates
                                  .Map(ps => new _ParameterStateDTO
                {
                    Name               = ps.Name,
                    DistributionType   = ps.DistributionType.ToString(),
                    DistributionStates = Distribution.SerializeDistributions(ps.Distributions),
                    IsSelected         = ps.IsSelected
                })
                                  .OrderBy(ps => ps.Name !.ToUpperInvariant())
                                  .ToArray(),

                SamplingDesign = instance.SamplingDesign?.CreatedOn.ToDirectoryName(),

                RootExportDirectory = instance.RootExportDirectory,
                OpenAfterExport     = instance.OpenAfterExport,

                AutoApplyParameterSharedState    = instance.AutoApplyParameterSharedState,
                AutoShareParameterSharedState    = instance.AutoShareParameterSharedState,
                AutoApplyElementSharedState      = instance.AutoApplyElementSharedState,
                AutoShareElementSharedState      = instance.AutoShareElementSharedState,
                AutoApplyObservationsSharedState = instance.AutoApplyObservationsSharedState,
                AutoShareObservationsSharedState = instance.AutoShareObservationsSharedState
            },
コード例 #3
0
        internal ParameterSamplingViewModel(SimParameter parameter, ModuleState moduleState)
        {
            RequireNotNull(parameter);

            Parameter = parameter;
            SortKey   = parameter.Name.ToUpperInvariant();

            _moduleState = moduleState;

            var histogram = new PlotModel
            {
                TitleFontSize = 10
            };

            var linearAxis = new LinearAxis
            {
                Title = "Frequency"
            };

            histogram.Axes.Add(linearAxis);

            linearAxis = new LinearAxis
            {
                Position = AxisPosition.Bottom,
                Title    = parameter.Name,
                Unit     = parameter.Unit
            };

            histogram.Axes.Add(linearAxis);

            Histogram = histogram;

            this
            .ObservableForProperty(vm => vm.Distribution)
            .Subscribe(ObserveDistribution);

            this
            .ObservableForProperty(vm => vm.Samples)
            .Subscribe(ObserveSamples);
        }
コード例 #4
0
        internal OutputsEvidenceViewModel(IAppState appState, IAppService appService, ModuleState moduleState)
        {
            _moduleState = moduleState;
            _evidence    = appState.SimEvidence;

            _selectObservations = ReactiveCommand.Create <ISelectableItemViewModel>(HandleSelectObservations);

            PopulateObservations();

            _reactiveSafeInvoke = appService.GetReactiveSafeInvoke();

            _subscriptions = new CompositeDisposable(

                _evidence.ObservationsChanges.Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <(Arr <SimObservations>, ObservableQualifier)>(
                        ObserveEvidenceObservationChange
                        )
                    ),

                _moduleState.OutputsState
                .ObservableForProperty(os => os.SelectedOutputName)
                .Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <object>(
                        ObserveOutputsStateSelectedOutputName
                        )
                    ),

                _moduleState.OutputsState
                .ObservableForProperty(os => os.ObservationsReferences)
                .Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <object>(
                        ObserveOutputsStateObservationsReferences
                        )
                    )

                );
        }
コード例 #5
0
ファイル: OutputsViewModel.cs プロジェクト: thehoglet/RVis
        internal OutputsViewModel(
            IAppState appState,
            IAppService appService,
            IAppSettings appSettings,
            ModuleState moduleState,
            SamplingDesigns samplingDesigns
            )
        {
            _appState    = appState;
            _appSettings = appSettings;
            _moduleState = moduleState;
            _simulation  = appState.Target.AssertSome();

            _outputsSelectedSampleViewModel  = new OutputsSelectedSampleViewModel(appState, appService, moduleState);
            _outputsFilteredSamplesViewModel = new OutputsFilteredSamplesViewModel(appState, appService, moduleState, samplingDesigns);
            _outputsEvidenceViewModel        = new OutputsEvidenceViewModel(appState, appService, moduleState);

            var output = _simulation.SimConfig.SimOutput;

            _outputNames = output.DependentVariables
                           .Map(e => e.Name)
                           .OrderBy(n => n.ToUpperInvariant())
                           .ToArr();

            _moduleState.OutputsState.SelectedOutputName ??= _outputNames.Head();

            _selectedOutputName = _outputNames.IndexOf(
                _moduleState.OutputsState.SelectedOutputName
                );

            PlotController = new();
            PlotController.Bind(
                new OxyMouseDownGesture(OxyMouseButton.Left),
                new DelegatePlotCommand <OxyMouseDownEventArgs>(HandleOutputsMouseDown)
                );
            PlotController.Bind(
                new OxyMouseDownGesture(OxyMouseButton.Left, OxyModifierKeys.Control),
                new DelegatePlotCommand <OxyMouseDownEventArgs>(HandleOutputsMouseDown)
                );

            Outputs = new();

            var horizontalAxis = new LinearAxis
            {
                Position = AxisPosition.Bottom,
                Title    = output.IndependentVariable.Name,
                Unit     = output.IndependentVariable.Unit
            };

            Outputs.Axes.Add(horizontalAxis);

            var verticalAxis = new LinearAxis
            {
                Position = AxisPosition.Left
            };

            Outputs.Axes.Add(verticalAxis);

            Outputs.ApplyThemeToPlotModelAndAxes();

            PopulateAll();

            ToggleSeriesType = ReactiveCommand.Create(HandleToggleSeriesType);
            ResetAxes        = ReactiveCommand.Create(HandleResetAxes);

            _reactiveSafeInvoke = appService.GetReactiveSafeInvoke();

            _subscriptions = new CompositeDisposable(

                appSettings
                .GetWhenPropertyChanged()
                .Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <string?>(
                        ObserveAppSettingsPropertyChange
                        )
                    ),

                moduleState.OutputsState
                .ObservableForProperty(os => os.SelectedOutputName)
                .Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <object>(
                        ObserveOutputsStateSelectedOutputName
                        )
                    ),

                moduleState.OutputsState
                .ObservableForProperty(os => os.ObservationsReferences)
                .Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <object>(
                        ObserveOutputsStateObservationsReferences
                        )
                    ),

                moduleState
                .ObservableForProperty(ms => ms.FilterConfig)
                .Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <object>(
                        ObserveModuleStateFilterConfig
                        )
                    ),

                moduleState
                .ObservableForProperty(ms => ms.Outputs)
                .Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <object>(
                        ObserveModuleStateOutputs
                        )
                    ),

                moduleState
                .ObservableForProperty(ms => ms.OutputFilters)
                .Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <object>(
                        ObserveModuleStateOutputFilters
                        )
                    ),

                this
                .ObservableForProperty(vm => vm.SelectedOutputName)
                .Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <object>(
                        ObserveSelectedOutputName
                        )
                    )

                );
        }
コード例 #6
0
        internal DesignViewModel(
            IAppState appState,
            IAppService appService,
            IAppSettings appSettings,
            ModuleState moduleState,
            SamplingDesigns samplingDesigns
            )
        {
            _appService      = appService;
            _appSettings     = appSettings;
            _moduleState     = moduleState;
            _samplingDesigns = samplingDesigns;

            _simulation = appState.Target.AssertSome();
            _simData    = appState.SimData;

            CreateDesign = ReactiveCommand.Create(
                HandleCreateDesign,
                this.WhenAny(vm => vm.CanCreateDesign, _ => CanCreateDesign)
                );

            UnloadDesign = ReactiveCommand.Create(
                HandleUnloadDesign,
                this.WhenAny(vm => vm.CanUnloadDesign, _ => CanUnloadDesign)
                );

            AcquireOutputs = ReactiveCommand.Create(
                HandleAcquireOutputs,
                this.WhenAny(vm => vm.CanAcquireOutputs, _ => CanAcquireOutputs)
                );

            CancelAcquireOutputs = ReactiveCommand.Create(
                HandleCancelAcquireOutputs,
                this.WhenAny(vm => vm.CanCancelAcquireOutputs, _ => CanCancelAcquireOutputs)
                );

            _reactiveSafeInvoke = appService.GetReactiveSafeInvoke();

            _subscriptions = new CompositeDisposable(

                moduleState
                .ObservableForProperty(vm => vm.Samples)
                .Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <object>(
                        ObserveModuleStateSamples
                        )
                    ),

                moduleState
                .ObservableForProperty(vm => vm.SamplingDesign)
                .Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <object>(
                        ObserveModuleStateSamplingDesign
                        )
                    )

                );

            using (_reactiveSafeInvoke.SuspendedReactivity)
            {
                Populate();

                if (_moduleState.SamplingDesign != default)
                {
                    ConfigureOutputsAcquisition();
                }

                UpdateEnable();
            }
        }
コード例 #7
0
ファイル: ParametersViewModel.cs プロジェクト: thehoglet/RVis
        internal ParametersViewModel(IAppState appState, IAppService appService, IAppSettings appSettings, ModuleState moduleState)
        {
            _simulation  = appState.Target.AssertSome("No simulation");
            _moduleState = moduleState;

            _toggleSelectParameter = ReactiveCommand.Create <IParameterViewModel>(HandleToggleSelectParameter);

            var parameters = _simulation.SimConfig.SimInput.SimParameters;

            AllParameterViewModels = parameters
                                     .Map(p => new ParameterViewModel(p.Name, _toggleSelectParameter))
                                     .OrderBy(vm => vm.SortKey)
                                     .ToArr <IParameterViewModel>();

            moduleState.ParameterStates.Iter(ps =>
            {
                var parameterViewModel = AllParameterViewModels
                                         .Find(vm => vm.Name == ps.Name)
                                         .AssertSome($"Unknown parameter in module state: {ps.Name}");

                parameterViewModel.IsSelected = ps.IsSelected;
            });

            SelectedParameterViewModels = new ObservableCollection <IParameterViewModel>(
                AllParameterViewModels.Where(vm => vm.IsSelected)
                );

            SelectedParameterViewModel = SelectedParameterViewModels.FindIndex(
                vm => vm.Name == moduleState.ParametersState.SelectedParameter
                );

            _parameterDistributionViewModel = new ParameterDistributionViewModel(appState, appService, appSettings, true);

            _reactiveSafeInvoke = appService.GetReactiveSafeInvoke();

            using (_reactiveSafeInvoke.SuspendedReactivity)
            {
                _subscriptions = new CompositeDisposable(

                    this
                    .WhenAny(vm => vm.SelectedParameterViewModel, _ => default(object))
                    .Subscribe(
                        _reactiveSafeInvoke.SuspendAndInvoke <object?>(
                            ObserveSelectedParameterViewModel
                            )
                        ),

                    _parameterDistributionViewModel
                    .ObservableForProperty(vm => vm.ParameterState)
                    .Subscribe(
                        _reactiveSafeInvoke.SuspendAndInvoke <object>(
                            ObserveParameterDistributionViewModelParameterState
                            )
                        ),

                    moduleState.ParameterStateChanges.Subscribe(
                        _reactiveSafeInvoke.SuspendAndInvoke <(Arr <ParameterState>, ObservableQualifier)>(
                            ObserveModuleStateParameterStateChange
                            )
                        )

                    );

                UpdateParameterViewModelDistributions(moduleState.ParameterStates);
                UpdateSelectedParameter();
            }
        }
コード例 #8
0
ファイル: ViewModel.cs プロジェクト: thehoglet/RVis
        internal ViewModel(IAppState appState, IAppService appService, IAppSettings appSettings)
        {
            _appState    = appState;
            _appService  = appService;
            _sharedState = appState.SimSharedState;
            _simulation  = appState.Target.AssertSome();
            _evidence    = appState.SimEvidence;

            var pathToSamplingDesignsDirectory = _simulation.GetPrivateDirectory(nameof(Sampling), nameof(SamplingDesigns));

            _samplingDesigns = new SamplingDesigns(pathToSamplingDesignsDirectory);

            _moduleState = ModuleState.LoadOrCreate(_simulation, _samplingDesigns);

            _parametersViewModel    = new ParametersViewModel(appState, appService, appSettings, _moduleState);
            _samplesViewModel       = new SamplesViewModel(appState, appService, appSettings, _moduleState);
            _designViewModel        = new DesignViewModel(appState, appService, appSettings, _moduleState, _samplingDesigns);
            _outputsViewModel       = new OutputsViewModel(appState, appService, appSettings, _moduleState, _samplingDesigns);
            _designDigestsViewModel = new DesignDigestsViewModel(appService, _moduleState, _samplingDesigns);

            _reactiveSafeInvoke = appService.GetReactiveSafeInvoke();

            _subscriptions = new CompositeDisposable(

                _moduleState.ParameterStateChanges.Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <(Arr <ParameterState>, ObservableQualifier)>(
                        ObserveParameterStateChange
                        )
                    ),

                _sharedState.ParameterSharedStateChanges.Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <(Arr <SimParameterSharedState>, ObservableQualifier)>(
                        ObserveSharedStateParameterChange
                        )
                    ),

                _sharedState.ObservationsSharedStateChanges.Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <(Arr <SimObservationsSharedState>, ObservableQualifier)>(
                        ObserveSharedStateObservationsChange
                        )
                    ),

                _designDigestsViewModel
                .ObservableForProperty(vm => vm.TargetSamplingDesign).Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <object>(
                        ObserveTargetSamplingDesign
                        )
                    ),

                _moduleState
                .ObservableForProperty(ms => ms.SamplingDesign)
                .Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <object>(
                        ObserveModuleStateSamplingDesign
                        )
                    ),

                _moduleState.OutputsState
                .ObservableForProperty(os => os.ObservationsReferences)
                .Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <object>(
                        ObserveOutputsStateObservationsReferences
                        )
                    ),

                _evidence.ObservationsChanges.Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <(Arr <SimObservations>, ObservableQualifier)>(
                        ObserveEvidenceObservationsChange
                        )
                    ),

                _samplingDesigns.SamplingDesignChanges.Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <(DesignDigest, ObservableQualifier)>(
                        ObserveSamplingDesignChange
                        )
                    )

                );

            SetActivities();

            if (_moduleState.SamplingDesign != default)
            {
                _designViewModel.IsSelected = true;
            }
        }
コード例 #9
0
        internal SamplesViewModel(
            IAppState appState,
            IAppService appService,
            IAppSettings appSettings,
            ModuleState moduleState
            )
        {
            _appState    = appState;
            _appService  = appService;
            _appSettings = appSettings;
            _moduleState = moduleState;

            _simulation = appState.Target.AssertSome();

            ShareParameters = ReactiveCommand.Create(
                HandleShareParameters,
                this.WhenAny(
                    vm => vm.Distributions,
                    _ => _moduleState.FilterConfig.IsEnabled &&
                    !_moduleState.FilterConfig.Filters.IsEmpty &&
                    !_moduleState.Outputs.IsEmpty &&
                    Distributions.Count > 0)
                );

            ConfigureLHS = ReactiveCommand.Create(
                HandleConfigureLHS,
                this.WhenAny(vm => vm.CanConfigureLHS, _ => CanConfigureLHS)
                );

            ConfigureRC = ReactiveCommand.Create(
                HandleConfigureRC,
                this.WhenAny(vm => vm.CanConfigureRC, _ => CanConfigureRC)
                );

            GenerateSamples = ReactiveCommand.Create(
                HandleGenerateSamplesAsync,
                this.WhenAny(vm => vm.CanGenerateSamples, _ => CanGenerateSamples)
                );

            ViewCorrelation = ReactiveCommand.Create(
                HandleViewCorrelation,
                this.WhenAny(vm => vm.CanViewCorrelation, _ => CanViewCorrelation)
                );

            _reactiveSafeInvoke = appService.GetReactiveSafeInvoke();

            _subscriptions = new CompositeDisposable(

                _moduleState.ParameterStateChanges.Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <(Arr <ParameterState>, ObservableQualifier)>(
                        ObserveParameterStateChange
                        )
                    ),

                _moduleState.SamplesState
                .ObservableForProperty(ms => ms.LatinHypercubeDesign)
                .Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <object>(
                        ObserveSamplesStateLatinHypercubeDesign
                        )
                    ),

                _moduleState
                .ObservableForProperty(ms => ms.FilterConfig)
                .Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <object>(
                        ObserveModuleStateFilterConfig
                        )
                    ),

                _moduleState
                .ObservableForProperty(ms => ms.OutputFilters)
                .Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <object>(
                        ObserveModuleStateOutputFilters
                        )
                    ),

                _moduleState
                .ObservableForProperty(ms => ms.SamplesState.RankCorrelationDesign)
                .Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <object>(
                        ObserveSamplesStateRankCorrelationDesign
                        )
                    ),

                _moduleState
                .ObservableForProperty(vm => vm.SamplingDesign)
                .Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <object>(
                        ObserveModuleStateSamplingDesign
                        )
                    ),

                _appSettings
                .GetWhenPropertyChanged()
                .Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <string?>(
                        ObserveAppSettingsPropertyChange
                        )
                    ),

                Observable
                .Merge(
                    this.ObservableForProperty(vm => vm.NSamples),
                    this.ObservableForProperty(vm => vm.Seed)
                    )
                .Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <object>(
                        ObserveInputs
                        )
                    ),

                this
                .ObservableForProperty(vm => vm.IsReadOnly)
                .Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <object>(
                        ObserveIsReadOnly
                        )
                    )

                );

            using (_reactiveSafeInvoke.SuspendedReactivity)
            {
                if (_moduleState.SamplingDesign == default)
                {
                    Populate(_moduleState.SamplesState, _moduleState.ParameterStates);
                }
                else
                {
                    Populate(_moduleState.SamplingDesign);
                }

                UpdateEnable();
            }
        }
コード例 #10
0
        internal OutputsFilteredSamplesViewModel(
            IAppState appState,
            IAppService appService,
            ModuleState moduleState,
            SamplingDesigns samplingDesigns
            )
        {
            _moduleState     = moduleState;
            _samplingDesigns = samplingDesigns;

            _simulation = appState.Target.AssertSome();

            _toggleEnable = ReactiveCommand.Create <OutputsFilterViewModel>(HandleToggleEnable);
            _delete       = ReactiveCommand.Create <OutputsFilterViewModel>(HandleDelete);

            var independentVariable = _simulation.SimConfig.SimOutput.IndependentVariable;

            IndependentVariableName = independentVariable.Name;
            IndependentVariableUnit = independentVariable.Unit;

            _outputName = moduleState.OutputsState.SelectedOutputName;

            AddNewFilter = ReactiveCommand.Create(
                HandleAddNewFilter,
                this.WhenAny(
                    vm => vm.FromN,
                    vm => vm.ToN,
                    (_, _) => FromN.HasValue && ToN.HasValue
                    )
                );

            IsUnion = moduleState.SamplingDesign is null
        ? moduleState.FilteredSamplesState.IsUnion
        : _moduleState.FilterConfig.IsUnion;
            IsEnabled = moduleState.SamplingDesign is null
        ? moduleState.FilteredSamplesState.IsEnabled
        : moduleState.FilterConfig.IsEnabled;

            PopulateOutputFilters();

            _reactiveSafeInvoke = appService.GetReactiveSafeInvoke();

            _subscriptions = new CompositeDisposable(

                moduleState
                .ObservableForProperty(ms => ms.Outputs)
                .Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <object>(
                        ObserveModuleStateOutputs
                        )
                    ),

                moduleState
                .ObservableForProperty(ms => ms.FilterConfig)
                .Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <object>(
                        ObserveModuleStateFilterConfig
                        )
                    ),

                moduleState
                .ObservableForProperty(ms => ms.OutputFilters)
                .Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <object>(
                        ObserveModuleStateOutputFilters
                        )
                    ),

                moduleState.OutputsState
                .ObservableForProperty(os => os.SelectedOutputName)
                .Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <object>(
                        ObserveOutputsStateSelectedOutputName
                        )
                    ),

                this
                .ObservableForProperty(vm => vm.FromT)
                .Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <object>(
                        ObserveFromT
                        )
                    ),

                this
                .ObservableForProperty(vm => vm.ToT)
                .Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <object>(
                        ObserveToT
                        )
                    ),

                this
                .ObservableForProperty(vm => vm.IsEnabled)
                .Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <object>(
                        ObserveIsEnabled
                        )
                    ),

                this
                .ObservableForProperty(vm => vm.IsUnion)
                .Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <object>(
                        ObserveIsUnion
                        )
                    )

                );
        }
コード例 #11
0
        internal DesignDigestsViewModel(
            IAppService appService,
            ModuleState moduleState,
            SamplingDesigns samplingDesigns
            )
        {
            _moduleState     = moduleState;
            _samplingDesigns = samplingDesigns;

            LoadSamplingDesign = ReactiveCommand.Create(
                HandleLoadSamplingDesign,
                this.WhenAny(
                    vm => vm.SelectedDesignDigestViewModel,
                    _ => SelectedDesignDigestViewModel != default
                    )
                );

            DeleteSamplingDesign = ReactiveCommand.Create(
                HandleDeleteSamplingDesign,
                this.WhenAny(
                    vm => vm.SelectedDesignDigestViewModel,
                    _ => SelectedDesignDigestViewModel != default
                    )
                );

            FollowKeyboardInDesignDigests = ReactiveCommand.Create <(Key Key, bool Control, bool Shift)>(
                HandleFollowKeyboardInDesignDigests
                );

            DesignDigestViewModels = new ObservableCollection <IDesignDigestViewModel>(
                samplingDesigns.DesignDigests.Map(
                    dd => new DesignDigestViewModel(dd.CreatedOn, dd.Description)
                    ));

            if (_moduleState.SamplingDesign != default)
            {
                TargetSamplingDesign = Some((_moduleState.SamplingDesign.CreatedOn, DateTime.Now));

                SelectedDesignDigestViewModel = DesignDigestViewModels
                                                .Find(vm => vm.CreatedOn == _moduleState.SamplingDesign.CreatedOn)
                                                .Match <IDesignDigestViewModel?>(vm => vm, () => default);
            }

            _reactiveSafeInvoke = appService.GetReactiveSafeInvoke();

            _subscriptions = new CompositeDisposable(

                moduleState
                .ObservableForProperty(ms => ms.SamplingDesign)
                .Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <object>(
                        ObserveModuleStateSamplingDesign
                        )
                    ),

                samplingDesigns.SamplingDesignChanges.Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <(DesignDigest, ObservableQualifier)>(
                        ObserveSamplingDesignChange
                        )
                    )

                );
        }