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;
                                                                     
                });
        }
Пример #2
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;
            });
        }