public AddExcludedDate ( System.DateTime excludedDateUtc ) : void | ||
excludedDateUtc | System.DateTime | |
return | void |
/// <summary> /// Get the object to serialize when generating serialized file for future /// tests, and against which to validate deserialized object. /// </summary> /// <returns></returns> protected override object GetTargetObject() { HolidayCalendar c = new HolidayCalendar(); c.Description = "description"; DateTime date = new DateTime(2005, 1, 20, 10, 5, 15); c.AddExcludedDate(date); return c; }
public override ICalendar GetCalendar() { var cal = new HolidayCalendar(); cal.TimeZone = TimeZoneInfo.Local; foreach (var d in this.Dates) { cal.AddExcludedDate(d); } return cal; }
public void TestTimeZone() { TimeZoneInfo tz = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time"); HolidayCalendar c = new HolidayCalendar(); c.TimeZone = tz; DateTimeOffset excludedDay = new DateTimeOffset(2012, 11, 4, 0,0,0, TimeSpan.Zero); c.AddExcludedDate(excludedDay.DateTime); // 11/5/2012 12:00:00 AM -04:00 translate into 11/4/2012 11:00:00 PM -05:00 (EST) DateTimeOffset date = new DateTimeOffset(2012, 11, 5, 0, 0, 0, TimeSpan.FromHours(-4)); Assert.IsFalse(c.IsTimeIncluded(date), "date was expected to not be included."); Assert.IsTrue(c.IsTimeIncluded(date.AddDays(1))); DateTimeOffset expectedNextAvailable = new DateTimeOffset(2012, 11, 5, 0, 0, 0, TimeSpan.FromHours(-5)); DateTimeOffset actualNextAvailable = c.GetNextIncludedTimeUtc(date); Assert.AreEqual(expectedNextAvailable, actualNextAvailable); }
public void ShouldGetArrayOfFutureFireDateTimesForCronStringExcludingCalendarDates() { // Arrange const string calName = "TestCal1"; var cal = new HolidayCalendar(); cal.AddExcludedDate(new DateTime(2016, 1, 4, 12, 0, 0)); _mockScheduler.Setup(i => i.GetCalendar(calName)).Returns(cal); var csu = new CronExpressionEx("0 0 12 ? * MON-FRI *", _mockScheduler.Object); var dateTimeAfter = new DateTime(2016, 1, 1, 12, 0, 0); // Act var result = csu.GetFutureFireDateTimesUtcAfter(dateTimeAfter, 10, calName); // Assert Assert.Equal(10, result.Count); Assert.Equal(new DateTime(2016, 1, 5, 0, 0, 0), result[0].Date); Assert.Equal(new DateTime(2016, 1, 18, 0, 0, 0), result[9].Date); }
protected override void OnStart(string[] args) { logger.Log(LogLevel.Info, String.Format("Starting NACHA File Processor")); // construct a scheduler factory ISchedulerFactory schedFact = new StdSchedulerFactory(); IScheduler sched = schedFact.GetScheduler(); Context ctx = new Context(); //Get Holiday Calendar Days to Not Generate NACHA File HolidayCalendar cal = new HolidayCalendar(); var calendar = ctx.Calendars.FirstOrDefault(c => c.CalendarCode == "NACHAHolidayCalendar"); foreach (var calendarDate in calendar.CalendarDates) { cal.AddExcludedDate(calendarDate.SelectedDate); } sched.AddCalendar("myHolidays", cal, true, true); JobDetail jobDetail = new JobDetail("myJob", null, typeof(CreateNachaFileJob)); //Setup trigger for NACHA file generation at 8:00 PM //Trigger trigger = TriggerUtils.MakeImmediateTrigger(100, new TimeSpan(0, 20, 0)); Trigger trigger = TriggerUtils.MakeDailyTrigger(22, 00); trigger.StartTimeUtc = DateTime.UtcNow; trigger.Name = "myTrigger2"; //trigger.CalendarName = "myHolidays"; sched.ScheduleJob(jobDetail, trigger); try { logger.Log(LogLevel.Info, String.Format("Starting Scheduler")); sched.Start(); } catch(Exception ex) { logger.Log(LogLevel.Info, String.Format("Exception Starting Scheduler {0}", ex.Message)); throw; } }
public void ShouldAddExclusionDatesToExistingHolidayCalendar() { // Arrange Guid calId = Guid.NewGuid(); const string calName = "TestHolCal"; var exclusionDate1 = new DateTime(2016, 01, 01); var exclusionDate2 = new DateTime(2016, 01, 02); _mockPersistanceStore.Setup(m => m.GetCalendarName(calId)).Returns(calName); var registeredCalendar = new HolidayCalendar(); registeredCalendar.AddExcludedDate(exclusionDate1); _mockScheduler.Setup(i => i.GetCalendar(calName)).Returns(registeredCalendar); ISchedulerCore schedulerCore = new SchedulerCore(_mockScheduler.Object, _mockPersistanceStore.Object); // Act schedulerCore.AddHolidayCalendarExclusionDates(calId, new List<DateTime> { exclusionDate1, exclusionDate2 }); // Assert _mockScheduler.Verify( x => x.AddCalendar(calName, It.Is<HolidayCalendar>( c => c.ExcludedDates.Contains(exclusionDate1) && c.ExcludedDates.Contains(exclusionDate2) && c.ExcludedDates.Count == 2), true, true), Times.Once); }
/// <summary> /// Register new <see cref="HolidayCalendar"/> and optionally provide an initital set of dates to exclude. /// </summary> /// <param name="name"></param> /// <param name="description"></param> /// <param name="daysExcludedUtc"></param> public Guid AddHolidayCalendar(string name, string description, IList<DateTime> daysExcludedUtc = null) { var holidays = new HolidayCalendar {Description = description}; if (null != daysExcludedUtc && daysExcludedUtc.Count > 0) { foreach (var dateTime in daysExcludedUtc) { holidays.AddExcludedDate(dateTime); } } Guid id; using (var tran = new TransactionScope()) { id = _persistanceStore.UpsertCalendarIdMap(name); _scheduler.AddCalendar(name, holidays, true, true); tran.Complete(); } return id; }
public void StartScheduler() { StdSchedulerFactory factory = new StdSchedulerFactory(); IScheduler scheduler = factory.GetScheduler(); string myJobName = "MyFirstJob"; string myGroupName="MyGroup"; JobKeySet jobNames = scheduler.GetJobKeys(GroupMatcher<JobKey>.GroupEquals(myGroupName)); if (!scheduler.CheckExists(JobKey.Create(myJobName, myGroupName))) { IJobDetail job = JobBuilder.Create<ConsoleJob1>() .WithIdentity(myJobName, myGroupName) .UsingJobData("ExtraText", "Plinko") .Build(); ITrigger trigger = TriggerBuilder.Create() .WithIdentity("myFirstTrigger", myGroupName) .StartNow() .WithSimpleSchedule(x => x .WithIntervalInMinutes(2) .RepeatForever()) .Build(); scheduler.ScheduleJob(job, trigger); } if (!jobNames.Any(k => k.Name == "HelloWorld1")) { IJobDetail job = JobBuilder.Create<NoOpJob>() .WithIdentity("HelloWorld1", myGroupName) .Build(); ITrigger trigger = TriggerBuilder.Create() .WithIdentity("HelloWorld1Trigger", myGroupName) .StartNow() .WithSimpleSchedule(x => x .WithIntervalInMinutes(15) .RepeatForever()) .Build(); scheduler.ScheduleJob(job, trigger); } if (!scheduler.CheckExists(JobKey.Create("HelloWorld2", myGroupName))) { HolidayCalendar calendar = new HolidayCalendar(); calendar.AddExcludedDate(DateTime.Now.ToUniversalTime()); calendar.AddExcludedDate(DateTime.Now.AddDays(4).ToUniversalTime()); scheduler.AddCalendar("randomHolidays", calendar, true, true); IJobDetail job = JobBuilder.Create<NoOpJob>() .WithIdentity("HelloWorld2", myGroupName) .Build(); ITrigger trigger = TriggerBuilder.Create() .WithIdentity("HelloWorld2Trigger", myGroupName) .StartNow() .WithDailyTimeIntervalSchedule(x => x .StartingDailyAt(TimeOfDay.HourAndMinuteOfDay(15, 0))) .ModifiedByCalendar("randomHolidays") .Build(); scheduler.ScheduleJob(job, trigger); } if (!scheduler.CheckExists(JobKey.Create("TimeTrackerReminder", myGroupName))) { IJobDetail job = JobBuilder.Create<NoOpJob>() .WithIdentity("TimeTrackerReminder", myGroupName) .Build(); ITrigger trigger = TriggerBuilder.Create() .WithIdentity("EveryMondayAtEight", myGroupName) .StartNow() .WithDailyTimeIntervalSchedule(x => x .OnDaysOfTheWeek(DayOfWeek.Monday) .StartingDailyAt(TimeOfDay.HourAndMinuteOfDay(8, 0))) .Build(); scheduler.ScheduleJob(job, trigger); } //if (!scheduler.CheckExists(JobKey.Create("UnscheduledJob", myGroupName))) //{ // IJobDetail job = JobBuilder.Create<NoOpJob>() // .WithIdentity("UnscheduledJob", myGroupName) // .Build(); // scheduler.AddJob(job, true); //} if (!scheduler.CheckExists(JobKey.Create("TwoAliens", myGroupName))) { IJobDetail job = JobBuilder.Create<TwoAlienJob>() .WithIdentity("TwoAliens", myGroupName) .Build(); ITrigger trigger = TriggerBuilder.Create() .WithIdentity("EveryFullMoon", myGroupName) .StartNow() .WithCronSchedule("0 59 23 28 1/1 ? *") .Build(); scheduler.ScheduleJob(job, trigger); } scheduler.Start(); }