// on download button click private void ePaperDlButton_Click(object sender, RoutedEventArgs e) { // on download button click get chosen epaper and the date string ePaperName = ePaperChooser.Text; // ?? is a Null coalescing operator, if not null use selectedDate if null use currentDate DateTime ePaperDate = ePaperDatePicker.SelectedDate ?? DateTime.Now; // incase user selects a dir and later deletes the dir, create one for them DirectoryInfo dir = new DirectoryInfo(downloadDirTextbox.Text); if (!dir.Exists) { dir.Create(); } string downloadDir = downloadDirTextbox.Text; epaper = new Epaper(ePaperName, ePaperDate, downloadDir); // checks for the validity of input date, sets the download Link based on the paper chosen epaper.PaperDownloadInfo(); if (epaper.IsIssueDateValid) { // clone the ePaper.DownloadLinkAndFileName property List // _dlLinkAndFileName will be chnaged but we want to save the original DownloadLinkAndFileName as well // hence the copy instead of assignment _dlLinkAndFileName = new List <Dictionary <string, string> >(epaper.DownloadLinkAndFileName); //System.Threading.Thread thread = new System.Threading.Thread(() => //{ // downloader.DownloadFileAsync(new Uri(url), epaper.PathWithFileName); //}); //thread.Start(); // This application does not allow multi threading, so can't download two papers at the same time // download the first link on the List, once this is done if more Links are available it is downloaded // in onDownloadComplete Event Handler // since webclient doesn't support concurrent I/O operations a loop is not used to download multiple files // instead it is downloaded one after another upon download complete if (_dlLinkAndFileName.Count > 0) { downloader.DownloadFileAsync(new Uri(_dlLinkAndFileName[0]["dlLink"]), _dlLinkAndFileName[0]["filePathName"]); // deactivate the download button to prevent user from attempted download while one download is in progress ePaperDlButton.IsEnabled = false; } else { MessageBox.Show(epaper.InvalidDateMsg); // shown if dates without the links are chosen for daily papers } } else { MessageBox.Show(epaper.InvalidDateMsg); // shown if incorrect day of week is chosen for weekly, monthly or bimonthly papers } }
public ImagesToPdf(List <string> inpImagePaths, Epaper epaper) { ImageFilePath = inpImagePaths; EpaperInstance = epaper; }