예제 #1
0
        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();
        }
예제 #2
0
 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;
 }
예제 #3
0
        public ReportDownloader(DownloadParams downloadParams, string savePath, AsyncCompletedEventHandler downloadCompletedEvent)
            : this()
        {
            DownloadParams = downloadParams;
            SavePath       = savePath;
            OnReportDownloadCompletedEvent = downloadCompletedEvent;

            wc.DownloadFileCompleted   += wc_DownloadFileCompleted;
            wc.DownloadProgressChanged += wc_DownloadProgressChange;
        }
예제 #4
0
        public object Clone()
        {
            DownloadParams downloadParams = new DownloadParams();

            downloadParams.BaseURL  = baseURL;
            downloadParams.FromDate = fromDate;
            downloadParams.ToDate   = toDate;
            downloadParams.FileName = FileName;

            return(downloadParams);
        }
예제 #5
0
        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());
                }
            }
        }
예제 #6
0
        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();
        }
예제 #7
0
 public ReportDownloaderAsync(DownloadParams downloadParams)
     : base()
 {
     DownloadParams = downloadParams;
 }
예제 #8
0
 public void Download(DownloadParams downloadParams)
 {
     DownloadParams = downloadParams;
     Download();
 }