public void YearlyOvernightTest()
        {
            JobScheduleYearly schedule = (JobScheduleYearly)yearlyOvernightSchedule.ScheduleConfig;

            DateTime dt = startTestTime.AddYears(-2);

            System.Collections.Generic.Dictionary <DateTime, DateTime> validRanges = new System.Collections.Generic.Dictionary <DateTime, DateTime>();

            while (dt <= endTestTime)
            {
                dt = dt.AddYears(1);
                if (DateTime.DaysInMonth(dt.Year, dt.Month) < schedule.Month.Day)
                {
                    continue;
                }

                DateTime s = new DateTime(dt.Year, ((int)schedule.Month.MonthName) + 1, schedule.Month.Day);
                DateTime e = s.AddDays(1);

                s = s.Add(schedule.Month.Time.StartTime.TimeOfDay);
                e = e.Add(schedule.Month.Time.EndTime.TimeOfDay);
                validRanges.Add(s, e);
            }

            RunTests(yearlyOvernightSchedule, validRanges);
        }
Пример #2
0
        public static bool IsJobScheduledToRunNow(JobSchedule jobSchedule, DateTime NOW)
        {
            switch (jobSchedule.JobScheduleType)
            {
            case JobScheduleTypeEnum.JobScheduleDaily:
                JobScheduleDaily daily = JsonConvert.DeserializeObject <JobScheduleDaily>(jobSchedule.ScheduleConfig.ToString());
                return(IsTimeToRunNow(GetDailyTime(daily, NOW), NOW));

            case JobScheduleTypeEnum.JobScheduleWeekly:
                JobScheduleWeekly weekly = JsonConvert.DeserializeObject <JobScheduleWeekly>(jobSchedule.ScheduleConfig.ToString());
                return(DoWeeklyCheck(weekly, NOW));

            case JobScheduleTypeEnum.JobScheduleMonthly:
                JobScheduleMonthly monthly = JsonConvert.DeserializeObject <JobScheduleMonthly>(jobSchedule.ScheduleConfig.ToString());
                return(IsTimeToRunNow(GetMonthlyTime(monthly, NOW), NOW));

            case JobScheduleTypeEnum.JobScheduleYearly:
                JobScheduleYearly yearly = JsonConvert.DeserializeObject <JobScheduleYearly>(jobSchedule.ScheduleConfig.ToString());
                return(IsTimeToRunNow(GetYearlyTime(yearly, NOW), NOW));

            case JobScheduleTypeEnum.JobScheduleOneTimeOnly:
                JobScheduleOneTimeOnly oneTime = JsonConvert.DeserializeObject <JobScheduleOneTimeOnly>(jobSchedule.ScheduleConfig.ToString());
                return(DoOneTimeOnlyCheck(oneTime, NOW));

            default:
                throw new Exception("Unknown Schedule Type: " + jobSchedule.JobScheduleType.ToString());
            }
        }
Пример #3
0
        private static void SetupYearlyRunOnce()
        {
            yearlyRunOnceJob.JobName      = "Test_YearlyRunOnce";
            yearlyRunOnceJob.ExecuteTimes = 1;

            JobScheduleYearly yearly = new JobScheduleYearly();

            yearly.Month                = new JobScheduleYearlyMonth();
            yearly.Month.MonthName      = MonthName.January;
            yearly.Month.Day            = 23;
            yearly.Month.Time           = new Time();
            yearly.Month.Time.StartTime = new DateTime(1, 1, 1, 2, 0, 0);

            AddJobToEngine(yearlyRunOnceJob, yearly);
        }
Пример #4
0
        public void YearlyRunOnce()
        {
            List <DateTime>   expectedDates = new List <DateTime>();
            JobScheduleYearly yearly        = ((JobScheduleYearly)yearlyRunOnceJob.Schedules[0].ScheduleConfig);
            DateTime          s             = t.StartTime.Add(yearly.Month.Time.StartTime.TimeOfDay);

            while (true)
            {
                if (((s.Month - 1) == (int)yearly.Month.MonthName) && (s.Day == yearly.Month.Day))
                {
                    break;
                }

                s = s.AddDays(1);
            }

            while (s <= t.EndTime)
            {
                expectedDates.Add(s);
                s = s.AddYears(1);
            }
            VerifyRun(yearlyRunOnceJob.JobName, expectedDates);
        }
Пример #5
0
        private void Initialize(Engine engine)
        {
            try
            {
                SamayLogger.SetLogLevel(SamayLogger.SamayEngineLoggingGUID, engine.EngineConfig.LogLevel);
                LogInfo(JsonConvert.SerializeObject(engine, Formatting.Indented));

                AppDomain   ad = AppDomain.CreateDomain("SamayEnginedomain" + DateTime.Now.ToString());
                TaskFactory tf = (TaskFactory)ad.CreateInstanceAndUnwrap(
                    Assembly.GetExecutingAssembly().FullName,
                    "Technisient.TaskFactory");
                _TaskAssemblyDict = tf.Initialize();

                AppDomain.Unload(ad);
                //TaskFactory.Initialize();


                //at the Job level, we still use the Engine log level
                foreach (SamayConfig.Job job in engine.Jobs)
                {
                    SamayLogger.SetLogLevel(job.Id, engine.EngineConfig.LogLevel);

                    if ((job.TaskChain.Task == null) || (job.TaskChain.Task.Count() == 0))
                    {
                        continue;
                    }

                    foreach (SamayConfig.Task task in job.TaskChain.Task)
                    {
                        SamayLogger.SetLogLevel(task.Id, task.LogLevel);
                    }
                }

                //cache Global Exclude Dates
                _GlobalExcludeDates = new List <DateTime>();
                if (engine.EngineConfig.GlobalExcludeDates != null)
                {
                    foreach (GlobalExcludeDate dt in engine.EngineConfig.GlobalExcludeDates)
                    {
                        _GlobalExcludeDates.Add(dt.Date);
                    }
                }

                _jobExcludeDates = new Dictionary <string, List <DateTime> >();
                //cache JobExclude Dates
                foreach (Job job in engine.Jobs)
                {
                    List <DateTime> dtList = new List <DateTime>();
                    if (job.ExcludeDates != null)
                    {
                        foreach (JobExcludeDates exc in job.ExcludeDates)
                        {
                            dtList.Add(exc.Date);
                        }
                    }
                    _jobExcludeDates.Add(job.JobName, dtList);

                    // set endtime to really high number for jobs which do not run continously
                    if (job.ExecuteTimes != -1)
                    {
                        if (job.Schedules != null)
                        {
                            foreach (JobSchedule jobSchedule in job.Schedules)
                            {
                                Time t = new Time();
                                switch (jobSchedule.ScheduleConfig.GetType().Name)
                                {
                                case "EngineJobScheduleDaily":
                                    JobScheduleDaily daily = (JobScheduleDaily)jobSchedule.ScheduleConfig;
                                    t = daily.Time;
                                    break;

                                case "EngineJobScheduleWeekly":
                                    JobScheduleWeekly weekly = (JobScheduleWeekly)jobSchedule.ScheduleConfig;
                                    t = weekly.Day.Time;
                                    break;

                                case "EngineJobScheduleMonthly":
                                    JobScheduleMonthly monthly = (JobScheduleMonthly)jobSchedule.ScheduleConfig;
                                    t = monthly.Day.Time;
                                    break;

                                case "EngineJobScheduleYearly":
                                    JobScheduleYearly yearly = (JobScheduleYearly)jobSchedule.ScheduleConfig;
                                    t = yearly.Month.Time;
                                    break;

                                case "EngineJobScheduleOneTimeOnly":
                                    JobScheduleOneTimeOnly oneTime = (JobScheduleOneTimeOnly)jobSchedule.ScheduleConfig;
                                    if (!oneTime.EndDateTimeSpecified)
                                    {
                                        oneTime.EndDateTime          = oneTime.StartDateTime.AddYears(10);
                                        oneTime.EndDateTimeSpecified = true;
                                    }
                                    continue;

                                default:
                                    throw new Exception("Unknown Schedule Type: " + jobSchedule.ScheduleConfig.GetType().Name);
                                }
                                if (!t.EndTimeSpecified)
                                {
                                    if (job.ExecuteTimes == 1)
                                    {
                                        t.EndTime = t.StartTime.AddMinutes(1);
                                    }
                                    else if (job.Interval.ClockTime != null)
                                    {
                                        t.EndTime = t.StartTime;
                                        int count = 0;
                                        while (count < job.ExecuteTimes)
                                        {
                                            if (job.Interval.ClockTime.Contains(t.EndTime.Minute))
                                            {
                                                count++;
                                            }
                                            t.EndTime = t.EndTime.AddMinutes(1);
                                        }
                                    }
                                    else
                                    {
                                        int interval = (int)job.Interval.Interval_msec;
                                        t.EndTime = t.StartTime.AddMilliseconds(interval * job.ExecuteTimes).AddMinutes(1);
                                    }
                                    t.EndTimeSpecified = true;
                                }
                            }
                        }
                    }
                }

                LogInfo("Starting Up Engine");
            }
            catch (Exception ex)
            {
                string sSource = "Technisient Samay";
                string sLog    = "Samay Engine";

                if (!EventLog.SourceExists(sSource))
                {
                    EventLog.CreateEventSource(sSource, sLog);
                }
                EventLog.WriteEntry(sSource, ex.ToString());
            }
        }
        public static void MyClassInitialize(TestContext testContext)
        {
            //DAILY
            JobScheduleDaily d_d = new JobScheduleDaily();

            d_d.Time = GetDayTime();
            dailyDaySchedule.ScheduleConfig = d_d;

            JobScheduleDaily d_o = new JobScheduleDaily();

            d_o.Time = GetOvernightTime();
            dailyOvernightSchedule.ScheduleConfig = d_o;


            //MONTHLY
            //TODO: run from 0 to 40 days in a loop?
            JobScheduleMonthly m_d = new JobScheduleMonthly();

            m_d.Day      = new JobScheduleMonthlyDay();
            m_d.Day.Day  = 31;
            m_d.Day.Time = GetDayTime();
            monthlyDaySchedule.ScheduleConfig = m_d;

            JobScheduleMonthly m_o = new JobScheduleMonthly();

            m_o.Day      = new JobScheduleMonthlyDay();
            m_o.Day.Day  = 31;
            m_o.Day.Time = GetOvernightTime();
            monthlyOvernightSchedule.ScheduleConfig = m_o;


            //YEARLY
            JobScheduleYearly y_d = new JobScheduleYearly();

            y_d.Month           = new JobScheduleYearlyMonth();
            y_d.Month.MonthName = MonthName.March;
            y_d.Month.Day       = 31;
            y_d.Month.Time      = GetDayTime();
            yearlyDaySchedule.ScheduleConfig = y_d;

            JobScheduleYearly y_o = new JobScheduleYearly();

            y_o.Month           = new JobScheduleYearlyMonth();
            y_o.Month.MonthName = MonthName.March;
            y_o.Month.Day       = 31;
            y_o.Month.Time      = GetOvernightTime();
            yearlyOvernightSchedule.ScheduleConfig = y_o;


            //ONETIME
            //TODO: run for a year
            JobScheduleOneTimeOnly o_d = new JobScheduleOneTimeOnly();

            o_d.StartDateTime = new DateTime(2011, 1, 31, 6, 0, 0);
            o_d.EndDateTime   = new DateTime(2011, 1, 31, 14, 30, 0);
            OneTimeDaySchedule.ScheduleConfig = o_d;

            JobScheduleOneTimeOnly o_o = new JobScheduleOneTimeOnly();

            o_o.StartDateTime = new DateTime(2011, 12, 31, 6, 0, 0);
            o_o.EndDateTime   = new DateTime(2012, 1, 2, 14, 30, 0);
            OneTimeOvernightSchedule.ScheduleConfig = o_o;
        }
Пример #7
0
 private static Time GetYearlyTime(JobScheduleYearly yearly, DateTime NOW)
 {
     yearly.Month.Time.StartTime = new DateTime(NOW.Year, (int)yearly.Month.MonthName + 1, yearly.Month.Day).Add(yearly.Month.Time.StartTime.TimeOfDay);
     yearly.Month.Time.EndTime   = new DateTime(NOW.Year, (int)yearly.Month.MonthName + 1, yearly.Month.Day).Add(yearly.Month.Time.EndTime.TimeOfDay);
     return(AdjustIfOvernight(yearly.Month.Time));
 }