Example #1
0
        static void WorkIt()
        {
            if (_targetPath == null)
            {
                throw new Exception("Error: Unspecified PSE report file path.");
            }

            if (_targetPath.Contains("http:"))
            {
                var downloadParams = new DownloadParams();
                downloadParams.BaseURL  = _targetPath;
                downloadParams.FileName = "stockQuotes_%mm%dd%yyyy";
                downloadParams.FromDate = Convert.ToDateTime(_dateFrom);
                downloadParams.ToDate   = Convert.ToDateTime(_dateTo);

                var downloader = new ReportDownloader(downloadParams, _reportsDir, null);
                downloader.AsyncMode = false;
                downloader.Download();

                foreach (DownloadFileInfo reportFile in downloader.DownloadedFiles)
                {
                    if (reportFile.Success)
                    {
                        ConvertIt(reportFile.Filename);
                    }
                }
            }
            else
            {
                ConvertIt(_targetPath);
            }
        }
        public void And_download_times_out_Then_exception_should_be_thrown()
        {
            const int ZeroMilliseconds = 0;
            var downloader = new ReportDownloader(TomatoDailyBandwidthUri, TomatoUsername, TomatoPassword, ZeroMilliseconds);

            Assert.Catch<Exception>(() => downloader.DownloadMonthly());
        }
Example #3
0
    private void DoDownloadAndConvert()
    {
        DownloadParams param = new DownloadParams();

        param.BaseURL  = edtDownloadLink.Text;
        param.FileName = "stockQuotes_%mm%dd%yyyy";
        param.FromDate = Convert.ToDateTime(edtFrom.Text);
        param.ToDate   = Convert.ToDateTime(edtTo.Text);
        string           savePath   = System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + "/Reports";
        ReportDownloader downloader = new ReportDownloader(param, savePath, ProcessDownloadedFile);

        downloader.OnReportDownloadCompletedEvent += (s, o) =>
        {
        };
        downloader.OnDownloadAllCompletedEvent += (s, e) =>
        {
        };
        downloader.OnDownloadAllCompletedEvent += (s, e) => {
            //MonoPSEGetDataService dataService = new MonoPSEGetDataService();
            //dataService.
        };

        downloader.OnStartDownloadProcess += (s, o) => {
            labelStatus.Text = "Trying...";
        };
        downloader.OnDownloadProgressEvent += (s, o) => {
        };
        downloader.Download();
    }
Example #4
0
        static void WorkIt()
        {
            if (_targetPath == null)
            {
                throw new Exception("Error: Unspecified PSE report file path.");
            }

            if (_targetPath.Contains("https:"))
            {
                if (!_useLocal)
                {
                    var downloadParams = new DownloadParams();
                    downloadParams.BaseURL  = _targetPath;
                    downloadParams.FileName = "stockQuotes_%mm%dd%yyyy";
                    downloadParams.FromDate = Convert.ToDateTime(_dateFrom);
                    downloadParams.ToDate   = Convert.ToDateTime(_dateTo);

                    var downloader = new ReportDownloader(downloadParams, _reportsDir, null);
                    downloader.AsyncMode = false;
                    downloader.Download();

                    Console.WriteLine("---");

                    int count = 0;
                    int len   = downloader.DownloadedFiles.Count;
                    foreach (DownloadFileInfo reportFile in downloader.DownloadedFiles)
                    {
                        count++;
                        float progress = count > 0 ? ((float)count / (float)len) * 100f : 0f;
                        Console.Write($"Converting {Path.GetFileNameWithoutExtension(reportFile.Filename)} [{count}/{len}] ({progress.ToString("0")}%) ... ");
                        if (reportFile.Success)
                        {
                            ConvertIt(reportFile.Filename);
                            Console.WriteLine("SUCCESS!");
                        }
                        else
                        {
                            Console.WriteLine("FAILED!");
                        }
                    }
                }
                else
                {
                    int count = 0;
                    int len   = Directory.GetFiles(_reportsDir).Length;
                    foreach (string file in Directory.GetFiles(_reportsDir))
                    {
                        count++;
                        float progress = count > 0 ? ((float)count / (float)len) * 100f : 0f;
                        Console.Write($"Converting {Path.GetFileNameWithoutExtension(file)} [{count}/{len}] ({progress.ToString("0")}%) ... ");
                        ConvertIt(file);
                        Console.WriteLine("SUCCESS!");
                    }
                }
            }
            else
            {
                ConvertIt(_targetPath);
            }
        }
        public void Then_operation_should_return_results()
        {
            var downloader = new ReportDownloader(TomatoDailyBandwidthUri, TomatoUsername, TomatoPassword);

            var result = downloader.DownloadDaily();

            Assert.AreNotEqual(0, result.Daily.ToList());
        }
        public void Then_async_operation_should_return_results()
        {
            var downloader = new ReportDownloader(TomatoDailyBandwidthUri, TomatoUsername, TomatoPassword);

            downloader.BeginDownload();
            var result = downloader.EndDownload();

            Assert.AreNotEqual(0, result.Monthly.ToList(), "Monthly report should not be empty");
            Assert.AreNotEqual(0, result.Daily.ToList(), "Daily report should not be empty");
        }
Example #7
0
    private void ProcessDownloadedFile(object sender, AsyncCompletedEventArgs e)
    {
        ReportDownloader downloader = sender as ReportDownloader;

        if (e.Error != null)
        {
            File.Delete(downloader.CurrentDownloadFile);
            throw new Exception(e.Error.Message);
        }
        else
        {
//			PSEDocument document = Helpers.ConvertReportFile(downloader.CurrentDownloadFile, this.csvOutputSettings);
//			MonoPSEGetDataService dataService = new MonoPSEGetDataService();
//			dataService.SaveTradeData(document);
        }
    }
        public void And_DownloadDailyAsync_fails_it_should_raise_event_which_includes_the_exception()
        {
            var downloader = new ReportDownloader(TomatoDailyBandwidthUri, TomatoUsername, TomatoInvalidPassword);

            var waitHandle = new AutoResetEvent(false);
            DownloadCompletedEventArgs args = null;
            downloader.DownloadDailyCompleted += (sender, eventArgs) =>
            {
                args = eventArgs;
                waitHandle.Set();
            };

            downloader.DownloadDailyAsync();

            waitHandle.ThrowIfWaitHandleTimesOut(TimeSpan.FromSeconds(5));

            Assert.IsNotNull(args.Error);
            Assert.IsNull(args.Report);
        }
        public void Then_DownloadDailyAsync_should_raise_event_with_results()
        {
            var downloader = new ReportDownloader(TomatoDailyBandwidthUri, TomatoUsername, TomatoPassword);

            var waitHandle = new AutoResetEvent(false);
            DownloadCompletedEventArgs args = null;
            downloader.DownloadDailyCompleted += (sender, eventArgs) =>
            {
                args = eventArgs;
                waitHandle.Set();
            };

            downloader.DownloadDailyAsync();

            waitHandle.ThrowIfWaitHandleTimesOut(TimeSpan.FromSeconds(5));

            var result = args.Report;
            Assert.IsNull(args.Error);
            Assert.AreEqual(0, result.Monthly.Count(), "Monthly report should be empty");
            Assert.AreNotEqual(0, result.Daily.ToList(), "Daily report should not be empty");
        }
        public void And_uri_points_to_non_existing_page_Then_exception_should_be_thrown()
        {
            var downloader = new ReportDownloader(UriToNonExistentPage, TomatoUsername, TomatoPassword);

            Assert.Catch<Exception>(() => downloader.DownloadDaily());
        }
Example #11
0
 public void Calling_dispose_multiple_times_should_succeed()
 {
     var downloader = new ReportDownloader();
     downloader.Dispose();
     downloader.Dispose();
 }
Example #12
0
        void symbolDownloader_OnLoadDataComplete(SymbolDownloader symbolDownloader, List<Symbol> symbolList)
        {
            try
            {
                IEnumerable<string> symbolNameEnumerable = from symbol in symbolList select symbol.SymbolName;

                // Consider only those symbols that are in major market indexes
                IEnumerable<Symbol> symbolEnumerable = _entities.SymbolSet.Where(symbol => symbolNameEnumerable.Contains(symbol.SymbolName));

                // Set the next report date
                foreach (Symbol symbol in symbolEnumerable)
                {
                    symbol.ReportDate = _reportDate;
                }

                _entities.SaveChanges();

                // Keep track of progress on the list of symbols
                _symbolNameList = (from s in symbolEnumerable select s.SymbolName).ToList<string>();
                _symbolNameListReport = (from s in symbolEnumerable select s.SymbolName).ToList<string>();
                _symbolNameListDayPrice = (from s in symbolEnumerable select s.SymbolName).ToList<string>();

                // Load the price history for the market indexes
                dayPriceDownloader_Enqueue("^DJI",3000);
                dayPriceDownloader_Enqueue("^IXIC",3000);
                dayPriceDownloader_Enqueue("^GSPC",3000);
                System.Threading.Thread.Sleep(10000);

                // Retrieve the report history
                foreach (String symbolName in _symbolNameList)
                {
                    ReportDownloader reportDownloader = new ReportDownloader(symbolName);
                    reportDownloader.OnLoadDataComplete += new ReportDownloader.LoadDataCompleted(reportDownloader_OnLoadDataComplete);
                    ReportDownloaderQueue reportDownloaderQueue = ReportDownloaderQueue.Instance(5000);
                    reportDownloaderQueue.Enqueue(reportDownloader);
                }

                if (_symbolNameList.Count() == 0)
                {
                    if (OnCompleted != null) OnCompleted();
                    this.Dispose();
                }
            }
            catch (Exception ex)
            {
                LogOps.LogException(ex);
            }
        }
Example #13
0
        void reportDownloader_OnLoadDataComplete(ReportDownloader reportDownloader, List<Report> reportList)
        {
            try
            {
                // Check for existing reports
                List<DateTime> reportDateList = (from r in _entities.ReportSet where r.SymbolName.Equals(reportDownloader.SymbolName) select r.ReportDate).ToList<DateTime>();

                // Insert new reports
                foreach (Report report in reportList)
                {
                    if (!reportDateList.Contains(report.ReportDate))
                    {
                        System.Threading.Thread.Sleep(5); // Don't go too fast, or GUIDs are not unique.
                        _entities.ReportSet.AddObject(report);
                    }
                }

                //_entities.SaveChanges();

                // Check for process completion
                if (_symbolNameListReport.Contains(reportDownloader.SymbolName)) _symbolNameListReport.Remove(reportDownloader.SymbolName);
                if (_symbolNameListReport.Count < 1)
                {
                    // Get the DayPrice history
                    foreach (String symbolName in _symbolNameList)
                    {
                        dayPriceDownloader_Enqueue(symbolName, 6000);
                    }
                }
            }
            catch (Exception ex)
            {
                LogOps.LogException(ex);
            }
        }
        public void And_password_id_invalid_Then_exception_should_be_thrown()
        {
            var downloader = new ReportDownloader(TomatoDailyBandwidthUri, TomatoUsername, TomatoInvalidPassword);

            Assert.Catch<Exception>(() => downloader.DownloadMonthly());
        }