public static void DownloadAndConvertAsync(DownloadAndConvertParams downloadAndConvertParams) { var param = new DownloadParams(); document = null; param.BaseURL = downloadAndConvertParams.DownloadUri.ToString(); param.FileName = "stockQuotes_%mm%dd%yyyy"; param.FromDate = downloadAndConvertParams.FromDate; param.ToDate = downloadAndConvertParams.ToDate; DownloadAndConvertHelper._outputSettings = downloadAndConvertParams.OutputSettings; ConvertCompleteCallback = downloadAndConvertParams.ConvertCompleteCallback; BeforeConvertCallback = downloadAndConvertParams.BeforeConvertCallback; ProcessCompletedCallback = downloadAndConvertParams.ProcessCompletedCallback; ConvertErrorHandler = downloadAndConvertParams.ConvertErrorHandler; var downloader = new ReportDownloader(param, downloadAndConvertParams.SavePath, ProcessDownloadedFile); downloader.OnReportDownloadCompletedEvent += downloadAndConvertParams.ReportDownloadedHandler; downloader.OnDownloadAllCompletedEvent += downloadAndConvertParams.DownloadAllCompletedHandler; downloader.OnDownloadAllCompletedEvent += (s, e) => { downloadAndConvertParams.ProcessCompletedCallback(document); }; downloader.OnStartDownloadProcess += downloadAndConvertParams.OnStartDownloadProcess; downloader.OnDownloadProgressEvent += downloadAndConvertParams.DownloadProgressHandler; downloader.Download(); }
public ReportDownloader(DownloadParams downloadParams, string savePath, Action <object, string> progressCallback, Action <Exception> exceptionCallback, Action downloadCompleteCallback) { DownloadParams = downloadParams; SavePath = savePath; OnProgressEvent = progressCallback; OnExceptionEvent = exceptionCallback; OnDownloadCompleteEvent = downloadCompleteCallback; }
public ReportDownloader(DownloadParams downloadParams, string savePath, AsyncCompletedEventHandler downloadCompletedEvent) : this() { DownloadParams = downloadParams; SavePath = savePath; OnReportDownloadCompletedEvent = downloadCompletedEvent; wc.DownloadFileCompleted += wc_DownloadFileCompleted; wc.DownloadProgressChanged += wc_DownloadProgressChange; }
public object Clone() { DownloadParams downloadParams = new DownloadParams(); downloadParams.BaseURL = baseURL; downloadParams.FromDate = fromDate; downloadParams.ToDate = toDate; downloadParams.FileName = FileName; return(downloadParams); }
public void Download() { try { if (DownloadParams.ToDate < DownloadParams.FromDate) { throw new PSEGetException("Invalid date range."); } DownloadedFiles.Clear(); //this.FailedDownloadFiles.Clear(); DateTime reportDate = DownloadParams.FromDate; do { var downloadParams = (DownloadParams)DownloadParams.Clone(); downloadParams.FileName = downloadParams.FileName.Replace("%dd", String.Format("{0:00}", reportDate.Day)); downloadParams.FileName = downloadParams.FileName.Replace("%mm", String.Format("{0:00}", reportDate.Month)); downloadParams.FileName = downloadParams.FileName.Replace("%yyyy", String.Format("{0:00}", reportDate.Year)); if (reportDate.DayOfWeek == DayOfWeek.Saturday || reportDate.DayOfWeek == DayOfWeek.Sunday) { reportDate = reportDate.AddDays(1); continue; } downloadQueue.Enqueue(downloadParams); reportDate = reportDate.AddDays(1); } while (reportDate <= DownloadParams.ToDate); if (downloadQueue.Count > 0) { if (OnStartDownloadProcess != null) { OnStartDownloadProcess(this, null); } } else { throw new PSEGetException("There were no pse reports found in the dates you specified."); } ProcessQueue(); } catch (Exception e) { OnReportDownloadCompletedEvent(this, new AsyncCompletedEventArgs(e, false, null)); if (downloadQueue.Count == 0) { OnDownloadAllCompletedEvent(this, new EventArgs()); } } }
public void Download() { if (DownloadParams.ToDate < DownloadParams.FromDate) { throw new PSEGetException("Invalid date range."); } DownloadedFiles.Clear(); downloadQueue.Clear(); DateTime reportDate = DownloadParams.FromDate; do { var downloadParams = (DownloadParams)DownloadParams.Clone(); downloadParams.FileName = downloadParams.FileName.Replace("%dd", String.Format("{0:00}", reportDate.Day)); downloadParams.FileName = downloadParams.FileName.Replace("%mm", String.Format("{0:00}", reportDate.Month)); downloadParams.FileName = downloadParams.FileName.Replace("%yyyy", String.Format("{0:00}", reportDate.Year)); if (reportDate.DayOfWeek == DayOfWeek.Saturday || reportDate.DayOfWeek == DayOfWeek.Sunday) { reportDate = reportDate.AddDays(1); continue; } downloadQueue.Enqueue(downloadParams); reportDate = reportDate.AddDays(1); } while (reportDate <= DownloadParams.ToDate); if (downloadQueue.Count > 0) { } else { throw new PSEGetException("Nothing to download"); } ProcessQueue(); }
public ReportDownloaderAsync(DownloadParams downloadParams) : base() { DownloadParams = downloadParams; }
public void Download(DownloadParams downloadParams) { DownloadParams = downloadParams; Download(); }