Exemplo n.º 1
0
 public void Init()
 {
     BundleLogic = new BundleLogic();
     Date = new DateTime(2014, 05, 02);
     var creationResult = BundleLogic.CreateBundle(Date);
     TestBundle = creationResult.ReturnObject;
 }
Exemplo n.º 2
0
        public Fill()
        {
            BundleLogic = new BundleLogic();
            InstantGagnantLogic = new InstantGagnantLogic();
            Date = new DateTime(2014, 05, 02);
            List<Bundle> list = BundleLogic.ListBundles();

            foreach (Bundle bundle in list)
            {
                BundleLogic.DeleteBundles();
            }
        }
Exemplo n.º 3
0
 public void Init()
 {
     BundleLogic = new BundleLogic();
     CleanUp();
     Date = new DateTime(2014, 05, 02);
 }
Exemplo n.º 4
0
        public void TestCreationForService()
        {
            BundleLogic bundleLogic = new BundleLogic();
            DateTime mockNowDate = new DateTime(2014, 05, 02);
            int DailyExecutionHour = 0;
            int DailyExecutionMinute = 0;
            var bundleGet = bundleLogic.GetBundleByDate(mockNowDate.AddDays(-1));
            bool goCsvCreate = false;
            if (mockNowDate.Hour == DailyExecutionHour
                && mockNowDate.Minute == DailyExecutionMinute
                &&
                    (
                        !bundleGet.Result
                        ||
                        (
                            bundleGet.Result
                            && bundleGet.ReturnObject.Status == BundleStatus.NoFileCreated
                        )
                    )
                )
                goCsvCreate = true;

            Assert.AreEqual<bool>(true, goCsvCreate);
        }
Exemplo n.º 5
0
        private void OnElapsedTime(object source, ElapsedEventArgs e)
        {
            if (DateTime.Now.DayOfWeek.Equals(DayOfWeek.Saturday) || DateTime.Now.DayOfWeek.Equals(DayOfWeek.Sunday))
                return;
            timer.Stop();
            bool hasTriggeredTodayYet = LastBundleModifiedDate == BundleLogic.GetToday();
            if (hasTriggeredTodayYet)
            {
                timer.Start();
                return;
            }

            bool rightTime = (DateTime.Now.Hour == DailyExecutionHour && DateTime.Now.Minute == DailyExecutionMinute) || WebConfig.Get.forceRightTime == "true";
            if (!rightTime)
            {
                timer.Start();
                return;
            }
            Program.log("It's business time !");
            BundleLogic bundleLogic = new BundleLogic();
            DateTime Today0h = BundleLogic.GetToday();
            var bundleGet = bundleLogic.GetBundleByDate(Today0h);
            if (!bundleGet.Result && bundleGet.Message == "Probleme de connexion à la base.")
            {
                Program.log(bundleGet.Message);
                Stop();
            }

            Program.log("Bundle déjà créé ? " + bundleGet.Result +"("+ bundleGet.Message+")");

            // predicates
            bool csvNotYetCreated = !bundleGet.Result || (bundleGet.Result && bundleGet.ReturnObject.Status == BundleStatus.NoFileCreated);
            bool featureCsvCreationActivated = WebConfig.Get.createCsv == "true";
            Program.log("yesterdayCsvNotYetCreated : " + csvNotYetCreated);
            Program.log("rightTime : " + rightTime);
            Program.log("featureCsvCreationActivated : " + featureCsvCreationActivated);

            if (csvNotYetCreated && featureCsvCreationActivated)
            {

                Program.log(string.Format("It's time ! ({0}h{1}) {2}", DateTime.Now.Hour, DateTime.Now.Minute, WebConfig.Get.forceRightTime == "true" ? "(Forced)" : ""));

                var bResult = bundleLogic.CreateBundle(Today0h); Program.log("Bundle créé : " + Today0h);

                ServiceProcess service = new ServiceProcess(); Program.log("Retrieving users since " + BundleLogic.GetPreviousDayOrSo0h().ToString("dd/MM/yyyy"));
                List<User> listNewUserDay = service.RetrieveNewUsersSince(BundleLogic.GetPreviousDayOrSo0h()); Program.log("User List : " + listNewUserDay.Count);
                bundleLogic.SetBundleTotalSubs(Today0h, listNewUserDay.Count);
                UserDataService uDal = new UserDataService();
                string csvInPath = ConfigurationManager.AppSettings["localCsvFilesDirectory"];
                string localfilePath = uDal.CreateCsvContentForCanal(csvInPath, listNewUserDay, 1);
                if (File.Exists(localfilePath))
                {
                    Program.log("File CSVIN créé : " + localfilePath);

                    var bfResult = bundleLogic.AttachFileToBundle(Today0h, localfilePath, BundleFileType.CsvIn);
                    if (bfResult.Result)
                        bundleLogic.SetBundleStatus(Today0h, BundleStatus.CsvInCreated);

                    if (ConfigurationManager.AppSettings["sendCsvToCanal"] == "true")
                    {
                        var ftpResult = service.CanalPushFileFTP(localfilePath);
                        if (ftpResult.Result)
                            bundleLogic.SetBundleStatus(Today0h, BundleStatus.CsvInSentToCanal);
                    }
                }

                if (!_canTriggerSeveralTimesADay)
                {
                    LastBundleModifiedDate = Today0h;
                }
            }
            else if (!_canTriggerSeveralTimesADay)
            {
                LastBundleModifiedDate = Today0h;
            }
            timer.Start();
        }