public void MonthlyOvernightTest() { JobScheduleMonthly schedule = (JobScheduleMonthly)monthlyOvernightSchedule.ScheduleConfig; DateTime dt = startTestTime.AddMonths(-2); System.Collections.Generic.Dictionary <DateTime, DateTime> validRanges = new System.Collections.Generic.Dictionary <DateTime, DateTime>(); while (dt <= endTestTime) { dt = dt.AddMonths(1); if (DateTime.DaysInMonth(dt.Year, dt.Month) < schedule.Day.Day) { continue; } DateTime s = new DateTime(dt.Year, dt.Month, schedule.Day.Day); DateTime e = s.AddDays(1); s = s.Add(schedule.Day.Time.StartTime.TimeOfDay); e = e.Add(schedule.Day.Time.EndTime.TimeOfDay); validRanges.Add(s, e); } RunTests(monthlyOvernightSchedule, validRanges); }
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()); } }
private static void SetupMonthlyRunOnce() { monthlyRunOnceJob.JobName = "Test_MonthlyRunOnce"; monthlyRunOnceJob.ExecuteTimes = 1; JobScheduleMonthly monthly = new JobScheduleMonthly(); monthly.Day = new JobScheduleMonthlyDay(); monthly.Day.Day = 20; monthly.Day.Time = new Time(); monthly.Day.Time.StartTime = new DateTime(1, 1, 1, 2, 0, 0); AddJobToEngine(monthlyRunOnceJob, monthly); }
public void MonthlyRunOnce() { List <DateTime> expectedDates = new List <DateTime>(); JobScheduleMonthly monthly = ((JobScheduleMonthly)monthlyRunOnceJob.Schedules[0].ScheduleConfig); DateTime s = t.StartTime.Add(monthly.Day.Time.StartTime.TimeOfDay); while (s.Day != monthly.Day.Day) { s = s.AddDays(1); } while (s <= t.EndTime) { expectedDates.Add(s); s = s.AddMonths(1); } VerifyRun(monthlyRunOnceJob.JobName, expectedDates); }
private static Time GetMonthlyTime(JobScheduleMonthly monthly, DateTime NOW) { if (monthly.Day.Time.StartTime.TimeOfDay > monthly.Day.Time.EndTime.TimeOfDay) { //has overnight, if we are running for next day, set now one day back if (NOW.TimeOfDay <= monthly.Day.Time.EndTime.TimeOfDay) { NOW = NOW.AddDays(-1); } } if (DateTime.DaysInMonth(NOW.Year, NOW.Month) < monthly.Day.Day) { return(null); } monthly.Day.Time.StartTime = new DateTime(NOW.Year, NOW.Month, monthly.Day.Day).Add(monthly.Day.Time.StartTime.TimeOfDay); monthly.Day.Time.EndTime = new DateTime(NOW.Year, NOW.Month, monthly.Day.Day).Add(monthly.Day.Time.EndTime.TimeOfDay); return(AdjustIfOvernight(monthly.Day.Time)); }
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; }