Ejemplo n.º 1
0
        public RecordingViewModel(RecordingModel recordingModel,
                                  Settings settings,
                                  TimerModel timerModel,
                                  VideoSourcesViewModel videoSourcesViewModel)
        {
            _recordingModel = recordingModel;

            RecordCommand = new[]
            {
                settings.Audio
                .ObserveProperty(audioSettings => audioSettings.Enabled),
                videoSourcesViewModel
                .ObserveProperty(sourcesViewModel => sourcesViewModel.SelectedVideoSourceKind)
                .Select(videoSourceProvider => !(videoSourceProvider is NoVideoSourceProvider))
            }
            .CombineLatest(bools => bools[0] || bools[1])
            .ToReactiveCommand()
            .WithSubscribe(recordingModel.OnRecordExecute);

            PauseCommand = new[]
            {
                timerModel
                .ObserveProperty(model => model.Waiting),
                recordingModel
                .ObserveProperty(model => model.RecorderState)
                .Select(recorderState => recorderState != RecorderState.NotRecording)
            }
            .CombineLatest(bools => !bools[0] && bools[1])
            .ToReactiveCommand()
            .WithSubscribe(recordingModel.OnPauseExecute);

            recordingModel.PropertyChanged += (sender, e) =>
            {
                switch (e.PropertyName)
                {
                case "":
                case null:
                case nameof(RecorderState):
                    RaisePropertyChanged(nameof(RecorderState));
                    break;
                }
            };
        }