상속: ViewModelBase
        public MainViewModel()
        {
            _timer          = new Timer(1000);
            _timer.Elapsed += TimerOnElapsed;

            #region Commands
            ScreenShotCommand = new DelegateCommand(CaptureScreenShot, () => _canScreenShot);

            RecordCommand = new DelegateCommand(() =>
            {
                if (ReadyToRecord)
                {
                    StartRecording();
                }
                else
                {
                    StopRecording();
                }
            }, () => _canRecord);

            RefreshCommand = new DelegateCommand(() =>
            {
                VideoViewModel.RefreshVideoSources();

                VideoViewModel.RefreshCodecs();

                AudioViewModel.RefreshAudioSources();

                Status = $"{VideoViewModel.AvailableCodecs.Count} Encoder(s) and " +
                         $"{AudioViewModel.AvailableRecordingSources.Count + AudioViewModel.AvailableLoopbackSources.Count - 2} AudioDevice(s) found";
            });

            OpenOutputFolderCommand = new DelegateCommand(() => Process.Start("explorer.exe", OutPath));

            PauseCommand = new DelegateCommand(() =>
            {
                if (IsPaused)
                {
                    _recorder.Start();
                    _timer.Start();

                    IsPaused = false;
                    Status   = "Recording...";
                }
                else
                {
                    _recorder.Pause();
                    _timer.Stop();

                    IsPaused = true;
                    Status   = "Paused";
                }
            }, () => !ReadyToRecord && _recorder != null);

            SelectOutputFolderCommand = new DelegateCommand(() =>
            {
                var dlg = new FolderBrowserDialog
                {
                    SelectedPath = OutPath,
                    Description  = "Select Output Folder"
                };

                if (dlg.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                OutPath = dlg.SelectedPath;
                Settings.Default.OutputPath = dlg.SelectedPath;
                Settings.Default.Save();
            });
            #endregion

            //Populate Available Codecs, Audio and Video Sources ComboBoxes
            RefreshCommand.Execute(null);

            AudioViewModel.PropertyChanged += (Sender, Args) =>
            {
                if (Args.PropertyName == nameof(AudioViewModel.SelectedRecordingSource) ||
                    Args.PropertyName == nameof(AudioViewModel.SelectedLoopbackSource))
                {
                    CheckFunctionalityAvailability();
                }
            };

            VideoViewModel.PropertyChanged += (Sender, Args) =>
            {
                if (Args.PropertyName == nameof(VideoViewModel.SelectedVideoSource))
                {
                    CheckFunctionalityAvailability();
                }
            };

            _cursor = new MouseCursor(OthersViewModel.Cursor);

            OthersViewModel.PropertyChanged += (Sender, Args) =>
            {
                switch (Args.PropertyName)
                {
                case nameof(OthersViewModel.RegionSelectorVisible):
                    VideoViewModel.RefreshVideoSources();
                    break;

                case nameof(OthersViewModel.Cursor):
                    _cursor.Include = OthersViewModel.Cursor;
                    break;
                }
            };

            // If Output Dircetory is not set. Set it to Documents\Captura\
            if (string.IsNullOrWhiteSpace(OutPath))
            {
                OutPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Captura\\");
            }

            // Create the Output Directory if it does not exist
            if (!Directory.Exists(OutPath))
            {
                Directory.CreateDirectory(OutPath);
            }

            Settings.Default.OutputPath = OutPath;
            Settings.Default.Save();
        }
예제 #2
0
        MainViewModel()
        {
            _timer          = new Timer(1000);
            _timer.Elapsed += TimerOnElapsed;

            #region Commands
            ScreenShotCommand = new DelegateCommand(CaptureScreenShot);

            RecordCommand = new DelegateCommand(() =>
            {
                if (RecorderState == RecorderState.NotRecording)
                {
                    StartRecording();
                }
                else
                {
                    StopRecording();
                }
            });

            RefreshCommand = new DelegateCommand(() =>
            {
                VideoViewModel.RefreshVideoSources();

                VideoViewModel.RefreshCodecs();

                AudioViewModel.AudioSource.Refresh();

                Status = "Refreshed";
            });

            OpenOutputFolderCommand = new DelegateCommand(() =>
            {
                EnsureOutPath();

                Process.Start(Settings.OutPath);
            });

            PauseCommand = new DelegateCommand(() =>
            {
                if (RecorderState == RecorderState.Paused)
                {
                    _recorder.Start();
                    _timer.Start();

                    RecorderState = RecorderState.Recording;
                    Status        = "Recording...";
                }
                else
                {
                    _recorder.Stop();
                    _timer.Stop();

                    RecorderState = RecorderState.Paused;
                    Status        = "Paused";

                    SystemTrayManager.ShowNotification("Recording Paused", " ", 500, null);
                }
            }, false);

            SelectOutputFolderCommand = new DelegateCommand(() =>
            {
                var dlg = new FolderBrowserDialog
                {
                    SelectedPath = Settings.OutPath,
                    Description  = "Select Output Folder"
                };

                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    Settings.OutPath = dlg.SelectedPath;
                }
            });
            #endregion

            //Populate Available Codecs, Audio and Video Sources ComboBoxes
            RefreshCommand.Execute(null);

            AudioViewModel.AudioSource.PropertyChanged += (Sender, Args) =>
            {
                if (Args.PropertyName == nameof(AudioViewModel.AudioSource.SelectedRecordingSource) ||
                    Args.PropertyName == nameof(AudioViewModel.AudioSource.SelectedLoopbackSource))
                {
                    CheckFunctionalityAvailability();
                }
            };

            VideoViewModel.PropertyChanged += (Sender, Args) =>
            {
                if (Args.PropertyName == nameof(VideoViewModel.SelectedVideoSource))
                {
                    CheckFunctionalityAvailability();
                }
            };

            _cursor = new MouseCursor(Settings.IncludeCursor);

            Settings.PropertyChanged += (Sender, Args) =>
            {
                switch (Args.PropertyName)
                {
                case nameof(Settings.IncludeCursor):
                    _cursor.Include = Settings.IncludeCursor;
                    break;
                }
            };

            // If Output Dircetory is not set. Set it to Documents\Captura\
            if (string.IsNullOrWhiteSpace(Settings.OutPath))
            {
                Settings.OutPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Captura\\");
            }

            // Create the Output Directory if it does not exist
            if (!Directory.Exists(Settings.OutPath))
            {
                Directory.CreateDirectory(Settings.OutPath);
            }

            HotKeyManager.RegisterAll();
            SystemTrayManager.Init();
        }