Inheritance: Blacker.MangaScraper.ViewModel.BaseViewModel
        public DownloadManagerViewModel()
        {
            _downloadsSemaphore = new FifoSemaphore(Properties.Settings.Default.MaxParallelDownloads);

            var olderDownloads = new List<DownloadViewModel>();

            ServiceLocator.Instance.GetService<ILibraryManager>().UpdateScrapersList(ScraperLoader.Instance.AllScrapers);

            foreach (DownloadedChapterInfo chapterInfo in ServiceLocator.Instance.GetService<ILibraryManager>().GetDownloads())
            {
                var downloadViewModel = new DownloadViewModel(chapterInfo, _downloadsSemaphore);

                downloadViewModel.RemoveFromCollection += DownloadViewModel_RemoveFromCollection;
                downloadViewModel.DownloadStarted += DownloadViewModel_DownloadStarted;

                olderDownloads.Add(downloadViewModel);
            }

            Downloads = new AsyncObservableCollection<DownloadViewModel>(olderDownloads);
            _downloadsCollectionView = (ListCollectionView) CollectionViewSource.GetDefaultView(Downloads);
            _downloadsCollectionView.CustomSort = new DownloadAgeComparer();

            // init filter
            SelectedTabIndex = Properties.Settings.Default.SelectedDownloadsTab;
        }
Exemple #2
0
        public void Download(IChapterRecord chapter, string outputPath, IDownloadFormatProvider formatProvider)
        {
            var downloadViewModel = new DownloadViewModel(new DownloadedChapterInfo(chapter), _downloadsSemaphore);

            downloadViewModel.RemoveFromCollection += DownloadViewModel_RemoveFromCollection;
            downloadViewModel.DownloadStarted      += DownloadViewModel_DownloadStarted;

            Downloads.Add(downloadViewModel);

            downloadViewModel.DownloadChapter(outputPath, formatProvider);

            OnPropertyChanged(() => HasActiveDownloads);
        }
        public void SaveClicked(object parameter)
        {
            if (string.IsNullOrEmpty(OutputPath))
            {
                MessageBox.Show("Output folder must be selected.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            if (SelectedChapters.Count == 0)
            {
                MessageBox.Show("Chapter must be selected.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            if (!Directory.Exists(OutputPath))
            {
                if (MessageBox.Show("The output folder doesn't exist. Would you like to create it?", "Output folder",
                    MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
                {
                    try
                    {
                        Directory.CreateDirectory(OutputPath);
                    }
                    catch (Exception ex)
                    {
                        _log.Error("Unable to create output folder.", ex);
                        MessageBox.Show("Unable to create output folder", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                        return;
                    }
                }
                else
                {
                    // if user don't want us to create the output folder, we will simply don't start the download
                    return;
                }
            }

            // save output path to recent list
            Properties.Settings.Default.RecentFolders.Add(OutputPath);
            InvokePropertyChanged("RecentFolders");

            foreach (var selectedChapter in SelectedChapters)
            {
                var downloadViewModel = new DownloadViewModel(CurrentScraper.GetDownloader(), selectedChapter);
                downloadViewModel.RemoveFromCollection += DownloadViewModel_RemoveFromCollection;
                Downloads.Add(downloadViewModel);

                downloadViewModel.DownloadChapter(OutputPath, ZipFile, _downloadsSemaphore);
            }
        }
        public void Download(IChapterRecord chapter, string outputPath, IDownloadFormatProvider formatProvider)
        {
            var downloadViewModel = new DownloadViewModel(new DownloadedChapterInfo(chapter), _downloadsSemaphore);

            downloadViewModel.RemoveFromCollection += DownloadViewModel_RemoveFromCollection;
            downloadViewModel.DownloadStarted += DownloadViewModel_DownloadStarted;

            Downloads.Add(downloadViewModel);

            downloadViewModel.DownloadChapter(outputPath, formatProvider);

            OnPropertyChanged(() => HasActiveDownloads);
        }