Пример #1
0
        public ImportViewModel(MediaFileWatcher mediaFileWatcher)
        {
            Title = "Import Media";

            OkCommand = new Command(async() =>
            {
                CancellableOperationProgressView progress = new CancellableOperationProgressView();
                ImportProgressViewModel vm = new ImportProgressViewModel(mediaFileWatcher.MediaFileState);
                progress.DataContext       = vm;
                progress.Show();
                Task t = vm.importAsync(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();
            }));
        }
Пример #2
0
        public ImportViewModel(MediaFileWatcher mediaFileWatcher)
        {
            Title = "Import Media";
            
            OkCommand = new Command(async () =>
            {
                CancellableOperationProgressView progress = new CancellableOperationProgressView();
                ImportProgressViewModel vm = new ImportProgressViewModel(mediaFileWatcher.MediaFileState);
                progress.DataContext = vm;
                progress.Show();
                Task t = vm.importAsync(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();             
            }));
        }