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 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(); })); }
private async Task clearMedia() { MessageBoxResult result = MessageBox.Show("Are you sure you want to clear all Media from the database?", "Clear All Media", MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.No); if (result == MessageBoxResult.No) return; List<BaseMetadata> media; using (MetadataDbCommands mediaCommands = new MetadataDbCommands()) { media = mediaCommands.getAllMetadata(); } List<MediaFileItem> items = new List<MediaFileItem>(); foreach (BaseMetadata m in media) { items.Add(MediaFileItem.Factory.create(m.Location)); } ExportProgressViewModel export = new ExportProgressViewModel(MediaFileWatcher.Instance.MediaFileState); CancellableOperationProgressView exportView = new CancellableOperationProgressView(); exportView.DataContext = export; exportView.ShowDialog(); await export.exportAsync(items); NrMedia = 0; }