public DownloadViewModel(DownloadedChapterInfo downloadInfo, ISemaphore downloadSemaphore)
{
if (downloadInfo == null)
throw new ArgumentNullException("downloadInfo");
if (downloadSemaphore == null)
throw new ArgumentNullException("downloadSemaphore");
if (downloadInfo.ChapterRecord == null)
throw new ArgumentException("Chapter record is invalid.", "downloadInfo");
if (String.IsNullOrEmpty(downloadInfo.ChapterRecord.ChapterId))
throw new ArgumentException("Chapter record id is invalid.", "downloadInfo");
if (downloadInfo.ChapterRecord.MangaRecord == null)
throw new ArgumentException("Manga record is invalid.", "downloadInfo");
if (String.IsNullOrEmpty(downloadInfo.ChapterRecord.MangaRecord.MangaId))
throw new ArgumentException("Manga record id is invalid.", "downloadInfo");
_downloadInfo = downloadInfo;
_downloadSemaphore = downloadSemaphore;
_scraper = ScraperLoader.Instance.AllScrapers.FirstOrDefault(s => s.ScraperGuid == downloadInfo.ChapterRecord.Scraper);
if (_scraper != null)
{
_downloader = _scraper.GetDownloader();
// register downloader events
_downloader.DownloadProgress += _downloader_DownloadProgress;
_downloader.DownloadCompleted += _downloader_DownloadCompleted;
}
if (!String.IsNullOrEmpty(_downloadInfo.Path))
{
// file was already downloaded
State = DownloadState.Unknown;
Completed = true;
}
else
{
// we will be downloading the file now
State = DownloadState.Ok;
Completed = false;
}
CurrentActionText = String.Empty;
_cancelDownloadCommand = new RelayCommand(Cancel, x => !Completed);
_removeDownloadCommand = new RelayCommand(Remove);
_openDownloadCommand = new RelayCommand(Open, x => DownloadExists);
_retryDownloadCommand = new RelayCommand(RetryDownload, x => _downloader != null
&& Completed
&& !DownloadExists
&& !String.IsNullOrEmpty(_downloadInfo.DownloadFolder));
CancelText = ButtonCancelText;
}