public VideoSettingsViewModel() : base("Video", new Uri(typeof(VideoSettingsView).FullName, UriKind.Relative)) { DirectoryPickerCommand = new Command(() => { DirectoryPickerView directoryPicker = new DirectoryPickerView(); DirectoryPickerViewModel vm = (DirectoryPickerViewModel)directoryPicker.DataContext; vm.SelectedPath = VideoScreenShotLocation; vm.PathHistory = VideoScreenShotLocationHistory; if (directoryPicker.ShowDialog() == true) { VideoScreenShotLocation = vm.SelectedPath; } }); VideoScreenShotLocationHistory = Settings.Default.VideoScreenShotLocationHistory; if (String.IsNullOrEmpty(Settings.Default.VideoScreenShotLocation)) { Settings.Default.VideoScreenShotLocation = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures); } VideoScreenShotSaveMode = new ListCollectionView(Enum.GetValues(typeof(Infrastructure.Constants.SaveLocation))); VideoScreenShotSaveMode.MoveCurrentTo(Settings.Default.VideoScreenShotSaveMode); VideoScreenShotLocation = Settings.Default.VideoScreenShotLocation; VideoScreenShotTimeOffset = Settings.Default.VideoScreenShotTimeOffset; MinNrBufferedPackets = Settings.Default.VideoMinBufferedPackets; StepDurationSeconds = Settings.Default.VideoStepDurationSeconds; MaxNrBufferedPackets = 1000; }
public ImageSearchSettingsViewModel() : base("Image Search Plugin", new Uri(typeof(ImageSearchSettingsView).FullName, UriKind.Relative)) { DirectoryPickerCommand = new Command(() => { DirectoryPickerView directoryPicker = new DirectoryPickerView(); DirectoryPickerViewModel vm = (DirectoryPickerViewModel)directoryPicker.DataContext; vm.SelectedPath = FixedDownloadPath; if (directoryPicker.ShowDialog() == true) { FixedDownloadPath = vm.SelectedPath; MiscUtils.insertIntoHistoryCollection(FixedDownloadPathHistory, FixedDownloadPath); } }); ImageSaveMode = new ListCollectionView(Enum.GetValues(typeof(MediaViewer.Infrastructure.Constants.SaveLocation))); ImageSaveMode.MoveCurrentTo(ImageSearchPlugin.Properties.Settings.Default.ImageSaveMode); if (String.IsNullOrEmpty(ImageSearchPlugin.Properties.Settings.Default.FixedDownloadPath)) { FixedDownloadPath = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures); } else { FixedDownloadPath = ImageSearchPlugin.Properties.Settings.Default.FixedDownloadPath; } FixedDownloadPathHistory = ImageSearchPlugin.Properties.Settings.Default.FixedDownloadPathHistory; }
public DirectoryPickerControl() { InitializeComponent(); SingleTree = new DirectoryPickerViewModel(); this.DataContext = SingleTree; }
public VideoTranscodeViewModel() { OutputPathHistory = Settings.Default.TranscodeOutputDirectoryHistory; OkCommand = new Command(async() => { CancellableOperationProgressView progress = new CancellableOperationProgressView(); VideoTranscodeProgressViewModel vm = new VideoTranscodeProgressViewModel(this); progress.DataContext = vm; vm.WindowIcon = IconUri; Task task = vm.startTranscodeAsync(); progress.Show(); OnClosingRequest(); await task; MiscUtils.insertIntoHistoryCollection(Settings.Default.TranscodeOutputDirectoryHistory, OutputPath); }); DefaultsCommand = new Command(() => { setDefaults(); }); CancelCommand = new Command(() => { OnClosingRequest(); }); DirectoryPickerCommand = new Command(() => { DirectoryPickerView directoryPicker = new DirectoryPickerView(); DirectoryPickerViewModel vm = (DirectoryPickerViewModel)directoryPicker.DataContext; vm.InfoString = "Select Transcode Output Path"; vm.SelectedPath = OutputPath; vm.PathHistory = OutputPathHistory; if (directoryPicker.ShowDialog() == true) { OutputPath = vm.SelectedPath; } }); SupportedAudioEncoders = new ListCollectionView(Enum.GetValues(typeof(AudioEncoders))); SupportedAudioEncoders.Filter = supportedAudioEncodersFilter; SupportedVideoEncoders = new ListCollectionView(Enum.GetValues(typeof(VideoEncoders))); SupportedVideoEncoders.Filter = supportedVideoEncodersFilter; Items = new List <VideoAudioPair>(); Title = "Transcode Video(s)"; IconUri = "/MediaViewer;component/Resources/Icons/videofile.ico"; setDefaults(); IsTimeRangeEnabled = false; StartTimeRange = 0; EndTimeRange = 0; }
public override async Task <IScriptCommand> ExecuteAsync(ParameterDic pm) { IWindowManager wm = pm.GetValue <IWindowManager>(WindowManagerKey) ?? new WindowManager(); IEventAggregator events = pm.GetValue <IEventAggregator>(EventAggregatorKey) ?? new EventAggregator(); IExplorerInitializer initializer = new ScriptCommandInitializer() { StartupParameters = pm, WindowManager = wm, Events = events, OnModelCreated = ScriptCommands.Run(OnModelCreatedKey), OnViewAttached = ScriptCommands.Run(OnViewAttachedKey) }; ExplorerViewModel evm = null; switch (ExplorerMode) { case Script.ExplorerMode.Normal: evm = new ExplorerViewModel(wm, events) { Initializer = initializer }; break; case Script.ExplorerMode.FileOpen: evm = new FilePickerViewModel(wm, events) { Initializer = initializer, PickerMode = FilePickerMode.Open }; break; case Script.ExplorerMode.FileSave: evm = new FilePickerViewModel(wm, events) { Initializer = initializer, PickerMode = FilePickerMode.Save }; break; case Script.ExplorerMode.DirectoryOpen: evm = new DirectoryPickerViewModel(wm, events) { Initializer = initializer }; break; default: return(ResultCommand.Error(new NotSupportedException(ExplorerMode.ToString()))); } logger.Info(String.Format("Creating {0}", evm)); pm.SetValue(DestinationKey, evm, false); return(NextCommand); }
public override async Task <IScriptCommand> ExecuteAsync(ParameterDic pm) { IWindowManager wm = pm.GetValue <IWindowManager>(WindowManagerKey) ?? new WindowManager(); IExplorerViewModel evm = pm.GetValue <IExplorerViewModel>(ExplorerKey); if (evm == null) { return(ResultCommand.Error(new KeyNotFoundException(ExplorerKey))); } logger.Info(String.Format("Showing {0}", evm)); if (evm is DirectoryPickerViewModel) { DirectoryPickerViewModel dpvm = evm as DirectoryPickerViewModel; bool result = wm.ShowDialog(dpvm).Value; pm.SetValue(DialogResultKey, result); if (result) { pm.SetValue(SelectionPathsKey, dpvm.SelectedDirectory.FullPath); pm.SetValue(SelectionEntriesKey, dpvm.SelectedDirectory); } } else if (evm is FilePickerViewModel) { FilePickerViewModel fpvm = evm as FilePickerViewModel; bool result = wm.ShowDialog(fpvm).Value; pm.SetValue(DialogResultKey, result); if (result) { switch (fpvm.PickerMode) { case FilePickerMode.Save: pm.SetValue(SelectionPathsKey, fpvm.FileName); break; case FilePickerMode.Open: pm.SetValue(SelectionPathsKey, fpvm.SelectedFiles.Select(m => m.FullPath).ToArray()); pm.SetValue(SelectionEntriesKey, fpvm.SelectedFiles); break; } } } else { wm.ShowWindow(evm); } return(NextCommand); }
public ImageTranscodeViewModel() { OkCommand = new Command(async() => { CancellableOperationProgressView progress = new CancellableOperationProgressView(); ImageTranscodeProgressViewModel vm = new ImageTranscodeProgressViewModel(this); progress.DataContext = vm; Task task = vm.startTranscodeAsync(); progress.Show(); OnClosingRequest(); await task; MiscUtils.insertIntoHistoryCollection(Settings.Default.ImageTranscodeOutputDirectoryHistory, OutputPath); }); DefaultsCommand = new Command(() => { setDefaults(); }); CancelCommand = new Command(() => { OnClosingRequest(); }); DirectoryPickerCommand = new Command(() => { DirectoryPickerView directoryPicker = new DirectoryPickerView(); DirectoryPickerViewModel vm = (DirectoryPickerViewModel)directoryPicker.DataContext; vm.InfoString = "Select Transcode Output Path"; vm.SelectedPath = OutputPath; vm.PathHistory = OutputPathHistory; if (directoryPicker.ShowDialog() == true) { OutputPath = vm.SelectedPath; } }); OutputPathHistory = Settings.Default.ImageTranscodeOutputDirectoryHistory; OutputFormatCollectionView = new ListCollectionView(outFormats); JpegRotationCollectionView = new ListCollectionView(Enum.GetNames(typeof(Rotation))); PngInterlacingCollectionView = new ListCollectionView(Enum.GetNames(typeof(PngInterlaceOption))); TiffCompressionCollectionView = new ListCollectionView(Enum.GetNames(typeof(TiffCompressOption))); setDefaults(); }
public VideoPreviewImageViewModel(MediaFileWatcher mediaFileWatcher) { setDefaults(mediaFileWatcher); directoryPickerCommand = new Command(new Action(() => { DirectoryPickerView directoryPicker = new DirectoryPickerView(); DirectoryPickerViewModel vm = (DirectoryPickerViewModel)directoryPicker.DataContext; vm.SelectedPath = OutputPath; vm.PathHistory = OutputPathHistory; if (directoryPicker.ShowDialog() == true) { OutputPath = vm.SelectedPath; } })); OkCommand = new Command(async() => { CancellableOperationProgressView progress = new CancellableOperationProgressView(); using (VideoPreviewImageProgressViewModel vm = new VideoPreviewImageProgressViewModel()) { progress.DataContext = vm; vm.AsyncState = this; progress.Show(); Task task = vm.generatePreviews(); OnClosingRequest(); await task; MiscUtils.insertIntoHistoryCollection(OutputPathHistory, OutputPath); } }); CancelCommand = new Command(() => { OnClosingRequest(); }); DefaultsCommand = new Command(() => { setDefaults(mediaFileWatcher); }); }
public ExportViewModel(MediaFileWatcher mediaFileWatcher) { Title = "Export Media"; OkCommand = new Command(async() => { CancellableOperationProgressView progress = new CancellableOperationProgressView(); ExportProgressViewModel vm = new ExportProgressViewModel(mediaFileWatcher.MediaFileState); progress.DataContext = vm; progress.Show(); Task t = vm.exportAsync(IncludeLocations, ExcludeLocations); OnClosingRequest(); await t; }); CancelCommand = new Command(() => { OnClosingRequest(); }); IncludeLocations = new ObservableCollection <ScanLocation>(); IncludeLocations.Add(new ScanLocation(mediaFileWatcher.Path)); AddIncludeLocationCommand = new Command(new Action(() => { DirectoryPickerView directoryPicker = new DirectoryPickerView(); DirectoryPickerViewModel vm = (DirectoryPickerViewModel)directoryPicker.DataContext; if (SelectedIncludeLocation == null) { vm.SelectedPath = mediaFileWatcher.Path; } else { vm.SelectedPath = SelectedIncludeLocation.Location; } if (directoryPicker.ShowDialog() == true) { ScanLocation newLocation = new ScanLocation(vm.SelectedPath); if (!IncludeLocations.Contains(newLocation)) { IncludeLocations.Add(newLocation); } } if (IncludeLocations.Count > 0) { OkCommand.IsExecutable = true; } })); RemoveIncludeLocationCommand = new Command(new Action(() => { for (int i = IncludeLocations.Count() - 1; i >= 0; i--) { if (IncludeLocations[i].IsSelected == true) { IncludeLocations.RemoveAt(i); } } if (IncludeLocations.Count == 0) { OkCommand.IsExecutable = false; } })); ClearIncludeLocationsCommand = new Command(new Action(() => { IncludeLocations.Clear(); OkCommand.IsExecutable = false; })); ExcludeLocations = new ObservableCollection <ScanLocation>(); AddExcludeLocationCommand = new Command(new Action(() => { DirectoryPickerView directoryPicker = new DirectoryPickerView(); DirectoryPickerViewModel vm = (DirectoryPickerViewModel)directoryPicker.DataContext; if (SelectedExcludeLocation == null) { vm.SelectedPath = mediaFileWatcher.Path; } else { vm.SelectedPath = SelectedExcludeLocation.Location; } if (directoryPicker.ShowDialog() == true) { ScanLocation newLocation = new ScanLocation(vm.SelectedPath); if (!ExcludeLocations.Contains(newLocation)) { ExcludeLocations.Add(newLocation); } } })); RemoveExcludeLocationCommand = new Command(new Action(() => { for (int i = ExcludeLocations.Count() - 1; i >= 0; i--) { if (ExcludeLocations[i].IsSelected == true) { ExcludeLocations.RemoveAt(i); } } })); ClearExcludeLocationsCommand = new Command(new Action(() => { ExcludeLocations.Clear(); })); }
public MetaDataViewModel(MediaFileWatcher mediaFileWatcher, IEventAggregator eventAggregator) { //Items = new ObservableCollection<MediaFileItem>(); itemsLock = new Object(); DynamicProperties = new ObservableCollection <Tuple <string, string> >(); BindingOperations.EnableCollectionSynchronization(DynamicProperties, itemsLock); EventAggregator = eventAggregator; Tags = new ObservableCollection <Tag>(); tagsLock = new Object(); BindingOperations.EnableCollectionSynchronization(Tags, tagsLock); AddTags = new ObservableCollection <Tag>(); addTagsLock = new Object(); BindingOperations.EnableCollectionSynchronization(AddTags, addTagsLock); RemoveTags = new ObservableCollection <Tag>(); removeTagsLock = new Object(); BindingOperations.EnableCollectionSynchronization(RemoveTags, removeTagsLock); MetaDataPresets = new ObservableCollection <PresetMetadata>(); loadMetaDataPresets(); clear(); BatchMode = false; IsEnabled = false; IsReadOnly = true; WriteMetaDataCommand = new AsyncCommand(async() => { CancellableOperationProgressView metaDataUpdateView = new CancellableOperationProgressView(); MetaDataUpdateViewModel vm = new MetaDataUpdateViewModel(mediaFileWatcher, EventAggregator); metaDataUpdateView.DataContext = vm; metaDataUpdateView.Show(); await vm.writeMetaDataAsync(new MetaDataUpdateViewModelAsyncState(this)); }); FilenamePresetsCommand = new Command(() => { FilenameRegexView filenamePreset = new FilenameRegexView(); FilenameRegexViewModel vm = (FilenameRegexViewModel)filenamePreset.DataContext; if (filenamePreset.ShowDialog() == true) { if (!vm.SelectedRegex.IsEmpty) { Filename = vm.SelectedRegex.Regex; ReplaceFilename = vm.SelectedRegex.Replace; } } }); DirectoryPickerCommand = new Command(() => { DirectoryPickerView directoryPicker = new DirectoryPickerView(); DirectoryPickerViewModel vm = (DirectoryPickerViewModel)directoryPicker.DataContext; vm.SelectedPath = String.IsNullOrEmpty(Location) ? mediaFileWatcher.Path : Location; lock (Items) { vm.SelectedItems = new List <MediaFileItem>(Items); } vm.PathHistory = Settings.Default.MetaDataUpdateDirectoryHistory; if (directoryPicker.ShowDialog() == true) { Location = vm.SelectedPath; } }); MetaDataPresetsCommand = new Command(() => { MetaDataPresetsView metaDataPresets = new MetaDataPresetsView(); metaDataPresets.ShowDialog(); loadMetaDataPresets(); }); ClearRatingCommand = new Command(() => { Rating = null; }); mediaFileWatcher.MediaFileState.ItemPropertyChanged += MediaState_ItemPropertiesChanged; FilenameHistory = Settings.Default.FilenameHistory; ReplaceFilenameHistory = Settings.Default.ReplaceFilenameHistory; MovePathHistory = Settings.Default.MetaDataUpdateDirectoryHistory; FavoriteLocations = Settings.Default.FavoriteLocations; IsRegexEnabled = false; ReplaceFilename = ""; }
public VideoViewModel(IEventAggregator eventAggregator) { EventAggregator = eventAggregator; VideoSettings = ServiceLocator.Current.GetInstance(typeof(VideoSettingsViewModel)) as VideoSettingsViewModel; VideoSettings.SettingsChanged += VideoSettings_SettingsChanged; IsInitialized = false; isInitializedSignal = new SemaphoreSlim(0, 1); CurrentItem = new VideoAudioPair(null, null); OpenAndPlayCommand = new AsyncCommand <VideoAudioPair>(async item => { await isInitializedSignal.WaitAsync(); isInitializedSignal.Release(); try { CurrentItem = item; String videoLocation = null; String videoFormatName = null; if (item.Video != null) { videoLocation = item.Video.Location; if (item.Video is MediaStreamedItem) { if (item.Video.Metadata != null) { videoFormatName = MediaFormatConvert.mimeTypeToExtension(item.Video.Metadata.MimeType); } } } String audioLocation = null; String audioFormatName = null; if (item.Audio != null) { audioLocation = item.Audio.Location; if (item.Audio is MediaStreamedItem && item.Audio.Metadata != null) { audioFormatName = MediaFormatConvert.mimeTypeToExtension(item.Audio.Metadata.MimeType); } } CloseCommand.IsExecutable = true; IsLoading = true; await VideoPlayer.openAndPlay(videoLocation, videoFormatName, audioLocation, audioFormatName); } catch (OperationCanceledException) { CloseCommand.IsExecutable = false; throw; } catch (Exception e) { CloseCommand.IsExecutable = false; MessageBox.Show("Error opening " + item.Video.Location + "\n\n" + e.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); throw; } finally { IsLoading = false; } EventAggregator.GetEvent <TitleChangedEvent>().Publish(CurrentItem.IsEmpty ? null : CurrentItem.Name); }); PlayCommand = new AsyncCommand(async() => { if (VideoState == VideoPlayerControl.VideoState.CLOSED && !CurrentItem.IsEmpty) { await openAndPlay(CurrentItem); } else if (VideoState == VideoPlayerControl.VideoState.OPEN || VideoState == VideoPlayerControl.VideoState.PAUSED) { VideoPlayer.play(); } }, false); PauseCommand = new Command(() => { VideoPlayer.pause(); }, false); CloseCommand = new AsyncCommand(async() => { await VideoPlayer.close(); }, false); SeekCommand = new AsyncCommand <double>(async(pos) => { await VideoPlayer.seek(pos); }, false); StepForwardCommand = new AsyncCommand(async() => { StepForwardCommand.IsExecutable = false; double timeStamp = VideoPlayer.getFrameSeekTimeStamp() + Settings.Default.VideoStepDurationSeconds; await VideoPlayer.seek(timeStamp, VideoLib.VideoPlayer.SeekKeyframeMode.SEEK_FORWARDS); StepForwardCommand.IsExecutable = true; }, false); StepBackwardCommand = new AsyncCommand(async() => { StepBackwardCommand.IsExecutable = false; double timeStamp = VideoPlayer.getFrameSeekTimeStamp() - Settings.Default.VideoStepDurationSeconds; await VideoPlayer.seek(timeStamp, VideoLib.VideoPlayer.SeekKeyframeMode.SEEK_BACKWARDS); StepBackwardCommand.IsExecutable = true; }, false); FrameByFrameCommand = new Command(() => { VideoPlayer.displayNextFrame(); }, false); CutVideoCommand = new Command(() => { String outputPath; if (FileUtils.isUrl(VideoPlayer.VideoLocation)) { outputPath = MediaFileWatcher.Instance.Path; } else { outputPath = FileUtils.getPathWithoutFileName(VideoPlayer.VideoLocation); } VideoTranscodeView videoTranscode = new VideoTranscodeView(); videoTranscode.ViewModel.Items.Add(CurrentItem); videoTranscode.ViewModel.Title = "Cut Video"; videoTranscode.ViewModel.IconUri = "/MediaViewer;component/Resources/Icons/videocut.ico"; videoTranscode.ViewModel.OutputPath = outputPath; videoTranscode.ViewModel.IsTimeRangeEnabled = IsTimeRangeEnabled; videoTranscode.ViewModel.StartTimeRange = startTimeRangeTimeStamp; videoTranscode.ViewModel.EndTimeRange = endTimeRangeTimeStamp; String extension = Path.GetExtension(VideoPlayer.VideoLocation).ToLower().TrimStart('.'); foreach (ContainerFormats format in Enum.GetValues(typeof(ContainerFormats))) { if (format.ToString().ToLower().Equals(extension)) { videoTranscode.ViewModel.ContainerFormat = format; } } videoTranscode.ShowDialog(); }, false); ScreenShotCommand = new Command(() => { try { String screenShotName = FileUtils.removeIllegalCharsFromFileName(CurrentItem.Video.Name, " "); screenShotName += "." + "jpg"; String path = null; switch (Settings.Default.VideoScreenShotSaveMode) { case MediaViewer.Infrastructure.Constants.SaveLocation.Current: { path = MediaFileWatcher.Instance.Path; break; } case MediaViewer.Infrastructure.Constants.SaveLocation.Ask: { DirectoryPickerView directoryPicker = new DirectoryPickerView(); DirectoryPickerViewModel vm = (DirectoryPickerViewModel)directoryPicker.DataContext; directoryPicker.Title = "Screenshot Output Directory"; vm.SelectedPath = Settings.Default.VideoScreenShotLocation; vm.PathHistory = Settings.Default.VideoScreenShotLocationHistory; if (directoryPicker.ShowDialog() == true) { path = vm.SelectedPath; } else { return; } break; } case MediaViewer.Infrastructure.Constants.SaveLocation.Fixed: { path = Settings.Default.VideoScreenShotLocation; break; } default: break; } String fullPath = FileUtils.getUniqueFileName(path + "\\" + screenShotName); VideoPlayer.createScreenShot(fullPath, VideoSettings.VideoScreenShotTimeOffset); } catch (Exception e) { MessageBox.Show("Error creating screenshot.\n\n" + e.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }, false); SetLeftMarkerCommand = new Command(() => { if (IsTimeRangeEnabled == false) { IsTimeRangeEnabled = true; } // get the exact time of the current audio or video frame, positionseconds is potentially inaccurate StartTimeRange = VideoPlayer.PositionSeconds; startTimeRangeTimeStamp = VideoPlayer.getFrameSeekTimeStamp(); }, false); SetRightMarkerCommand = new Command(() => { if (IsTimeRangeEnabled == false) { IsTimeRangeEnabled = true; StartTimeRange = VideoPlayer.PositionSeconds; startTimeRangeTimeStamp = VideoPlayer.getFrameSeekTimeStamp(); } else { EndTimeRange = VideoPlayer.PositionSeconds; endTimeRangeTimeStamp = VideoPlayer.getFrameSeekTimeStamp(); } }, false); OpenLocationCommand = new Command(async() => { VideoOpenLocationView openLocation = new VideoOpenLocationView(); bool?success = openLocation.ShowDialog(); if (success == true) { MediaItem video = null; MediaItem audio = null; if (!String.IsNullOrWhiteSpace(openLocation.ViewModel.VideoLocation)) { video = MediaItemFactory.create(openLocation.ViewModel.VideoLocation); MiscUtils.insertIntoHistoryCollection(Settings.Default.VideoLocationHistory, openLocation.ViewModel.VideoLocation); } if (!String.IsNullOrWhiteSpace(openLocation.ViewModel.AudioLocation)) { audio = MediaItemFactory.create(openLocation.ViewModel.AudioLocation); MiscUtils.insertIntoHistoryCollection(Settings.Default.AudioLocationHistory, openLocation.ViewModel.AudioLocation); } await openAndPlay(new VideoAudioPair(video, audio)); } }); HasAudio = true; VideoState = VideoPlayerControl.VideoState.CLOSED; IsTimeRangeEnabled = false; StartTimeRange = 0; EndTimeRange = 0; startTimeRangeTimeStamp = 0; endTimeRangeTimeStamp = 0; }
public TorrentCreationViewModel() { IsPrivate = false; IsCommentEnabled = false; OutputPathHistory = new ObservableCollection <string>(); InputPathHistory = new ObservableCollection <string>(); AnnounceURLHistory = Settings.Default.TorrentAnnounceHistory; if (AnnounceURLHistory.Count > 0) { AnnounceURL = AnnounceURLHistory[0]; } InputDirectoryPickerCommand = new Command(new Action(async() => { DirectoryPickerView directoryPicker = new DirectoryPickerView(); DirectoryPickerViewModel vm = (DirectoryPickerViewModel)directoryPicker.DataContext; vm.SelectedPath = String.IsNullOrEmpty(InputPath) ? PathRoot : InputPath; vm.PathHistory = InputPathHistory; if (directoryPicker.ShowDialog() == true) { InputPath = vm.SelectedPath; TorrentName = Path.GetFileName(InputPath); ScanFilesViewModel scanFilesViewModel = new ScanFilesViewModel(); NonCancellableOperationProgressView progressView = new NonCancellableOperationProgressView(); progressView.DataContext = scanFilesViewModel; ObservableCollection <MediaFileItem> items = new ObservableCollection <MediaFileItem>(); await Task.Factory.StartNew(() => { App.Current.Dispatcher.BeginInvoke(new Action(() => { progressView.ShowDialog(); })); try { items = scanFilesViewModel.getInputMedia(InputPath); } catch (Exception e) { Logger.Log.Error("Error reading: " + inputPath, e); MessageBox.Show("Error reading: " + inputPath + "\n\n" + e.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } finally { Application.Current.Dispatcher.BeginInvoke(new Action(() => { progressView.Close(); })); } }); Media = items; } })); OutputDirectoryPickerCommand = new Command(new Action(() => { DirectoryPickerView directoryPicker = new DirectoryPickerView(); DirectoryPickerViewModel vm = (DirectoryPickerViewModel)directoryPicker.DataContext; vm.SelectedPath = OutputPath; vm.PathHistory = OutputPathHistory; if (directoryPicker.ShowDialog() == true) { OutputPath = vm.SelectedPath; } })); CancelCommand = new Command(() => { OnClosingRequest(); }); OkCommand = new Command(async() => { CancellableOperationProgressView progress = new CancellableOperationProgressView(); TorrentCreationProgressViewModel vm = new TorrentCreationProgressViewModel(); progress.DataContext = vm; Task task = vm.createTorrentAsync(this); progress.Show(); OnClosingRequest(); await task; }); }