public FFmpegDownloadViewModel(FFmpegSettings FFmpegSettings,
                                       FFmpegDownloadModel DownloadModel,
                                       IFFmpegViewsProvider FFmpegViewsProvider,
                                       IMessageProvider MessageProvider)
        {
            this.FFmpegSettings = FFmpegSettings;
            _downloadModel      = DownloadModel;
            _messageProvider    = MessageProvider;

            StartCommand = _downloaderProgress
                           .Select(M => M.State)
                           .Select(M => M == FFmpegDownloaderState.Ready)
                           .ToReactiveCommand()
                           .WithSubscribe(async() =>
            {
                var progress = new Progress <FFmpegDownloaderProgress>(M => _downloaderProgress.Value = M);

                _downloadTask = DownloadModel.Start(progress, _cancellationTokenSource.Token);

                var result = await _downloadTask;

                AfterDownload?.Invoke(result);
            });

            CanCancel = _downloaderProgress
                        .Select(M => M.State)
                        .Select(M => M == FFmpegDownloaderState.Downloading)
                        .ToReadOnlyReactivePropertySlim();

            SelectFolderCommand = _downloaderProgress
                                  .Select(M => M.State)
                                  .Select(M => M == FFmpegDownloaderState.Ready)
                                  .ToReactiveCommand()
                                  .WithSubscribe(FFmpegViewsProvider.PickFolder);

            OpenFolderCommand = new ReactiveCommand()
                                .WithSubscribe(() =>
            {
                var path = FFmpegSettings.GetFolderPath();

                if (Directory.Exists(path))
                {
                    Process.Start(path);
                }
            });

            Status = _downloaderProgress
                     .Select(M =>
            {
                switch (M.State)
                {
                case FFmpegDownloaderState.Error:
                    return(M.ErrorMessage);

                case FFmpegDownloaderState.Downloading:
                    return($"{FFmpegDownloaderState.Downloading} ({M.DownloadProgress}%)");

                default:
                    return(M.State.ToString());
                }
            })
                     .ToReadOnlyReactivePropertySlim();

            Progress = _downloaderProgress
                       .Where(M => M.State == FFmpegDownloaderState.Downloading)
                       .Select(M => M.DownloadProgress)
                       .ToReadOnlyReactivePropertySlim();

            Progress.Subscribe(M => ProgressChanged?.Invoke(M));

            InProgress = _downloaderProgress
                         .Select(M => M.State)
                         .Select(M => M == FFmpegDownloaderState.Downloading || M == FFmpegDownloaderState.Extracting)
                         .ToReadOnlyReactivePropertySlim();

            IsDone = _downloaderProgress
                     .Select(M => M.State)
                     .Select(M => M == FFmpegDownloaderState.Done || M == FFmpegDownloaderState.Cancelled || M == FFmpegDownloaderState.Error)
                     .ToReadOnlyReactivePropertySlim();
        }
Exemplo n.º 2
0
 public FFmpegConsoleManager(FFmpegDownloadModel DownloadModel,
                             FFmpegSettings FfmpegSettings)
 {
     _downloadModel  = DownloadModel;
     _ffmpegSettings = FfmpegSettings;
 }