Beispiel #1
0
        public void TestMethod1()
        {
            string retValue;
            string retTime;

            ScreenScraper.GetRate("http://www.bloomberg.com/markets/stocks/world-indexes/", out retValue, out retTime);
            Console.WriteLine(retValue);
            Console.WriteLine(retTime);
        }
Beispiel #2
0
        public static void ProcessRates()
        {
            holidays = ConfigurationManager.GetSection("Holidays") as NameValueCollection;
            string url          = ConfigurationManager.AppSettings["url"] as string;
            string workArea     = ConfigurationManager.AppSettings["lifePROWorkarea"] as string;
            string emailAddress = ConfigurationManager.AppSettings["emailNotifcations"] as string;
            string retrivalTime = ConfigurationManager.AppSettings["retrivalTime"] as string;
            string outputFile   = ConfigurationManager.AppSettings["outputFile"] as string;
            string goodFile     = ConfigurationManager.AppSettings["goodFile"] as string;
            string cmdPath      = ConfigurationManager.AppSettings["cmdPath"] as string;
            string cmd          = ConfigurationManager.AppSettings["cmd"] as string;
            string args         = ConfigurationManager.AppSettings["args"] as string;

            string retVal;
            string retTime;

            DateTime startTime = Convert.ToDateTime(retrivalTime);

            double millisecondsToWait = (startTime - DateTime.Now).TotalMilliseconds;

            try
            {
                var stopwatch = new Stopwatch();
                stopwatch.Start();

                while (stopwatch.Elapsed < TimeSpan.FromMilliseconds(millisecondsToWait))
                {
                    // Do nothing until stopwatch stops...
                    //log.Debug("Waiting..");
                }
                stopwatch.Stop();
            }
            catch (Exception e)
            {
                log.Error(e);
                SendMail(emailAddress, "*****@*****.**", "Error getting Standard and Poors closing index",
                         "Error while wiating for closing time of " + retrivalTime);
                return;
            }


            if (!IsHoliday())
            {
                if (File.Exists(Path.Combine(workArea, goodFile)))
                {
                    File.Delete(Path.Combine(workArea, goodFile));
                }
                if (ScreenScraper.GetRate(url, out retVal, out retTime))
                {
                    WriteOutputFile(Path.Combine(workArea, outputFile), retVal);
                    RunResults result = CallLifepro(Path.Combine(cmdPath, cmd), args, Path.Combine(workArea, goodFile));
                    switch (result)
                    {
                    case RunResults.Success:
                        SendMail(emailAddress, "*****@*****.**", "Successful call to get Standard and Poors closing index",
                                 "Standard and Poors Closing index value sucessfully retrieved and LifePRO program called at: " + DateTime.Now.ToShortDateString() + "  " + DateTime.Now.ToShortTimeString());
                        break;

                    case RunResults.BadDate:
                        log.Error("SANDP.GOOD was present but had the wrong date present. This indicates that the LifePRO program  did not run. Rates will need to be entered manually.");
                        SendMail(emailAddress, "*****@*****.**", "Error getting Standard and Poors closing index",
                                 "SANDP.GOOD was present but had the wrong date present. This indicates that the LifePRO program  did not run. Rates will need to be entered manually.");
                        break;

                    case RunResults.NoFile:
                        log.Error("No SANDP.GOOD FILE Found. The LifePRO program must not have run. Rates need to be entered manually.");
                        SendMail(emailAddress, "*****@*****.**", "Error getting Standard and Poors closing index",
                                 "No SANDP.GOOD FILE Found. The LifePRO program must not have run. Rates need to be entered manually.");
                        break;

                    default:
                        break;
                    }
                }
                else
                {
                    log.Error(retVal);
                    SendMail(emailAddress, "*****@*****.**", "Error getting Standard and Poors closing index",
                             "There was an error scraping the screen for S & P index rates. The error is " + retVal);
                }
            }
        }