예제 #1
0
        public void EnsureWeCanTellWhenTorontoViewsAreReady()
        {
            var Tminus1 = new DateUtils().PreviousWorkDay(DateTime.Now.Date);
            var m       = new TorontoViewManager();

            Assert.IsTrue(m.DataIsReadyInViewForDate("ve_BloombergDescription", Tminus1));

            Assert.IsTrue(m.DataIsReadyInViewForDate("ve_BloombergPerSecurityPull", Tminus1)); //different logic for ve_BloombergPerSecurityPull

            Assert.IsTrue(m.DataIsReadyInViewForDate("ve_BloombergCreditRisk", Tminus1));      //historic not kept for credit risk - too big.

            var res = Utils.DbController.GetScalar <DateTime>("select top 1 FileDate from helium.bloombergdatalicense.dbo.BloombergPerSecurityfiledate where 1=2");

            //looking for reasons to fail - null, or the date is wrong.
            Assert.AreEqual(DateTime.MinValue, res);
        }
예제 #2
0
파일: Program.cs 프로젝트: colinnaylor/CN
        private static void Main(string[] args)
        {
            Utils.Logger.Info("Starting process");
            Utils.Logger.Info("Database connection string: {0} ", ConfigurationManager.ConnectionStrings["BloombergConnectionString"].ToString());


            try
            {
                var mgr = new DatawarehouseManager();
                Utils.SetLoggerClassName(args[0]);

                if (args[0].ToUpper() == "PM")
                {
                    var T = DateTime.Now.Date;

                    if (args.Length == 2)
                    {
                        T = DateTime.Parse(args[1]);
                    }

                    Utils.Logger.Info("Running EOD for: {0}", T.ToString(CultureInfo.InvariantCulture));

                    //fill with tickers from T positions
                    Utils.Logger.Info(string.Format("{0}: GetLiveTickersUsingBergConsumerSqls", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")));
                    var tickers = mgr.GetLiveTickersUsingBergConsumerSqls(T);

                    Utils.Logger.Info(string.Format("{0}: InsertTickersIntoDatawarehouse", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")));
                    mgr.InsertTickersIntoDatawarehouse(tickers, T);

                    //recreate datawarehouse - categorise tor long types for all tickers in datawarehouse
                    Utils.Logger.Info(string.Format("{0}: CategoriseBergTickersIntoTorontoAssetTypes", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")));
                    mgr.CategoriseBergTickersIntoTorontoAssetTypes(T);

                    //upload tickers to toronto
                    Utils.Logger.Info(string.Format("{0}: UploadTickersToToronto", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")));
                    Utils.DbController.ExecuteNonQuery(File.ReadAllText("Sql\\UploadTickersToToronto.sql").Replace("{Position_Date}", T.ToString("ddMMMyyyy")));
                }
                else if (args[0].ToUpper() == "AM")
                {
                    var tminus1 = new DateUtils().PreviousWorkDay(DateTime.Now.Date);

                    //download from tor for T-1
                    Utils.Logger.Info(string.Format("{0}: DownloadDataFromToronto", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")));
                    Utils.DbController.ExecuteNonQuery(File.ReadAllText("Sql\\DownloadDataFromToronto.sql").Replace("{Position_Date}", tminus1.ToString("ddMMMyyyy")));

                    //enrich datawarehouse entries for T-1
                    Utils.Logger.Info(string.Format("{0}: EnrichDatawarehouse", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")));
                    Utils.DbController.ExecuteNonQuery(File.ReadAllText("sql\\EnrichDatawarehouse.sql").Replace("{Position_Date}", tminus1.ToString("ddMMMyyyy")));

                    //ready for use!
                }
                else if (args[0].ToUpper() == "ENRICH")
                {
                    var tminus1 = new DateUtils().PreviousWorkDay(DateTime.Now.Date);
                    if (args.Length == 2)
                    {
                        tminus1 = DateTime.Parse(args[1]);
                    }
                    var dw = new DatawarehouseManager();
                    if (dw.HasBeenEnrichedForDate(tminus1))
                    {
                        Utils.Logger.Info("EnrichDatawarehouse - doing nothing - already enriched: {0:ddMMMyyyy}", tminus1);
                    }
                    else
                    {
                        if (dw.DataAvailableInAllPricingViews(tminus1))
                        {
                            Utils.Logger.Info("EnrichDatawarehouse - starting: {0:ddMMMyyyy}", tminus1);
                            Utils.DbController.ExecuteNonQuery(File.ReadAllText("sql\\EnrichDatawarehouse.sql").Replace("{Position_Date}", tminus1.ToString("ddMMMyyyy")));
                            Utils.Logger.Info("EnrichDatawarehouse - completed: {0:ddMMMyyyy}", tminus1);

                            Utils.Logger.Info("Calculating usage costs - writing to table CostReportActual - starting: {0:ddMMMyyyy}", tminus1);
                            mgr.RunCostReportActual(tminus1);
                            Utils.Logger.Info("Calculating usage costs - writing to table CostReportActual - completed: {0:ddMMMyyyy}", tminus1);

                            CheckData(tminus1);
                        }
                        else
                        {
                            Utils.Logger.Info("EnrichDatawarehouse - doing nothing - not all required data is ready: {0:ddMMMyyyy}", tminus1);
                        }
                    }
                }
                else if (args[0].ToUpper() == "COSTS")
                {
                    var tminus1 = new DateUtils().PreviousWorkDay(DateTime.Now.Date);
                    if (args.Length == 2)
                    {
                        tminus1 = DateTime.Parse(args[1]);
                    }
                    mgr.RunCostReportActual(tminus1);
                }
                else if (args[0].ToUpper() == "DOWNLOAD")
                {
                    var tminus1 = new DateUtils().PreviousWorkDay(DateTime.Now.Date);
                    if (args.Length == 2)
                    {
                        tminus1 = DateTime.Parse(args[1]);
                    }

                    //download from tor for T-1
                    var dw = new DatawarehouseManager(); var toronto = new TorontoViewManager();

                    foreach (var torView in toronto.ListOfTorontoViews())
                    {
                        Utils.Logger.Info("Checking for work to be done on {0} for date {1:ddMMMyyyy}", torView, tminus1);
                        if (!dw.HasDataInWarehouseTableForDate(torView.Replace("ve_", "TorView"), tminus1) &&
                            toronto.DataIsReadyInViewForDate(torView, tminus1))
                        {
                            Utils.Logger.Info("DOWNLOAD starting ... {0} for date {1:ddMMMyyyy}", torView, tminus1);
                            Utils.DbController.ExecuteNonQuery(
                                File.ReadAllText(string.Format("Sql\\DownloadDataFromToronto.{0}.sql", torView.Replace("ve_", "TorView")))
                                .Replace("{Position_Date}", tminus1.ToString("ddMMMyyyy")));
                            Utils.Logger.Info("DOWNLOAD completed ... {0} for date {1:ddMMMyyyy}", torView, tminus1);
                        }
                        else
                        {
                            Utils.Logger.Info("Doing nothing - already have data or data not yet available ... {0} for date {1:ddMMMyyyy}", torView, tminus1);
                        }
                    }
                }
                else if (args[0].ToUpper() == "GETTICKERS")
                {
                    var T = DateTime.Now.Date;
                    if (args.Length == 2)
                    {
                        T = DateTime.Parse(args[1]);
                    }
                    //fill with tickers from T positions
                    Utils.Logger.Info(string.Format("{0}: GetLiveTickersUsingBergConsumerSqls", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")));
                    var tickers = mgr.GetLiveTickersUsingBergConsumerSqls(T);

                    Utils.Logger.Info(string.Format("{0}: InsertTickersIntoDatawarehouse", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")));
                    mgr.InsertTickersIntoDatawarehouse(tickers, T);
                }
                else if (args[0].ToUpper() == "UPLOAD")
                {
                    var T = DateTime.Now.Date;

                    //upload tickers to toronto
                    Utils.Logger.Info(string.Format("{0}: UploadTickersToToronto", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")));
                    Utils.DbController.ExecuteNonQuery(File.ReadAllText("Sql\\UploadTickersToToronto.sql").Replace("{Position_Date}", T.ToString("ddMMMyyyy")));
                }
                else if (args[0].ToUpper() == "CATEGORISE")
                {
                    var T = DateTime.Now.Date;
                    if (args.Length == 2)
                    {
                        T = DateTime.Parse(args[1]);
                    }
                    //recreate datawarehouse - categorise tor long types for all tickers in datawarehouse
                    Utils.Logger.Info(string.Format("{0}: CategoriseBergTickersIntoTorontoAssetTypes", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")));
                    mgr.CategoriseBergTickersIntoTorontoAssetTypes(T);
                }
                else if (args[0].ToUpper() == "CHECK")
                {
                    var tminus1 = new DateUtils().PreviousWorkDay(DateTime.Now.Date);
                    if (args.Length == 2)
                    {
                        tminus1 = DateTime.Parse(args[1]);
                    }

                    CheckData(tminus1);
                }
            }
            catch (Exception ex)
            {
                Utils.Logger.Error("Stopping process with error: {0}", ex.ToString());
            }
            finally
            {
                Utils.Logger.Info("Process end.");
            }
        }