Inheritance: Quartz.Impl.Calendar.BaseCalendar, ICalendar
        /// <summary>
        /// Creates a new object that is a copy of the current instance.
        /// </summary>
        /// <returns>A new object that is a copy of this instance.</returns>
        public override object Clone()
        {
            HolidayCalendar clone = (HolidayCalendar)base.Clone();

            clone.dates = new TreeSet <DateTime>(dates);
            return(clone);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a new object that is a copy of the current instance.
        /// </summary>
        /// <returns>A new object that is a copy of this instance.</returns>
        public override ICalendar Clone()
        {
            HolidayCalendar clone = new HolidayCalendar();

            CloneFields(clone);
            clone.dates = new SortedSet <DateTime>(dates);
            return(clone);
        }
Exemplo n.º 3
0
 /// <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;
 }
Exemplo n.º 4
0
        public override ICalendar GetCalendar() {
            var cal = new HolidayCalendar();
            cal.TimeZone = TimeZoneInfo.Local;

            foreach (var d in this.Dates) {
                cal.AddExcludedDate(d);
            }
            return cal;
        }
        public bool Equals(HolidayCalendar obj)
        {
            if (obj == null)
            {
                return(false);
            }

            bool baseEqual = GetBaseCalendar() == null || GetBaseCalendar().Equals(obj.GetBaseCalendar());

            return(baseEqual && (ExcludedDates.Equals(obj.ExcludedDates)));
        }
Exemplo n.º 6
0
        public bool Equals(HolidayCalendar obj)
        {
            if (obj == null)
            {
                return(false);
            }
            var baseEqual = GetBaseCalendar() != null?
                            GetBaseCalendar().Equals(obj.GetBaseCalendar()) : true;

            return(baseEqual && (ExcludedDates.Equals(obj.ExcludedDates)));
        }
        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);
        }
Exemplo n.º 8
0
        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);
        }
Exemplo n.º 9
0
        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;
            }
        }
Exemplo n.º 10
0
        /// <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;
        }
Exemplo n.º 11
0
        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);
        }
Exemplo n.º 12
0
        public bool Equals(HolidayCalendar obj)
        {
            if (obj == null)
            {
                return false;
            }

            bool baseEqual = GetBaseCalendar() != null ?
                             GetBaseCalendar().Equals(obj.GetBaseCalendar()) : true;

            return baseEqual && (ExcludedDates.Equals(obj.ExcludedDates));

        }
Exemplo n.º 13
0
 public HolidayCalendarDto(HolidayCalendar calendar) : base(calendar)
 {
     ExcludedDates = calendar.ExcludedDates.ToList();
     TimeZone = new TimeZoneDto(calendar.TimeZone);
 }
Exemplo n.º 14
0
 static void InitializeHoliday(HolidayCalendar holidayCalendar, IHolidayCalendar calendar) {
     holidayCalendar.TimeZone = TimeZoneInfo.FindSystemTimeZoneById(Persistent.Base.General.RegistryTimeZoneProvider.GetRegistryKeyNameByTimeZoneId(calendar.TimeZone));
     calendar.DatesExcluded.ForEach(holidayCalendar.AddExcludedDate);
 }
 public void Setup()
 {
     cal = new HolidayCalendar();
 }
Exemplo n.º 16
0
        public void Test(IScheduler scheduler, bool clearJobs, bool scheduleJobs)
        {
            try
               {
               if (clearJobs)
               {
                   scheduler.Clear();
               }

               if (scheduleJobs)
               {
                   ICalendar cronCalendar = new CronCalendar("0/5 * * * * ?");
                   ICalendar holidayCalendar = new HolidayCalendar();

                   // QRTZNET-86
                   ITrigger t = scheduler.GetTrigger(new TriggerKey("NonExistingTrigger", "NonExistingGroup"));
                   Assert.IsNull(t);

                   AnnualCalendar cal = new AnnualCalendar();
                   scheduler.AddCalendar("annualCalendar", cal, false, true);

                   IOperableTrigger calendarsTrigger = new SimpleTriggerImpl("calendarsTrigger", "test", 20, TimeSpan.FromMilliseconds(5));
                   calendarsTrigger.CalendarName = "annualCalendar";

                   JobDetailImpl jd = new JobDetailImpl("testJob", "test", typeof(NoOpJob));
                   scheduler.ScheduleJob(jd, calendarsTrigger);

                   // QRTZNET-93
                   scheduler.AddCalendar("annualCalendar", cal, true, true);

                   scheduler.AddCalendar("baseCalendar", new BaseCalendar(), false, true);
                   scheduler.AddCalendar("cronCalendar", cronCalendar, false, true);
                   scheduler.AddCalendar("dailyCalendar", new DailyCalendar(DateTime.Now.Date, DateTime.Now.AddMinutes(1)), false, true);
                   scheduler.AddCalendar("holidayCalendar", holidayCalendar, false, true);
                   scheduler.AddCalendar("monthlyCalendar", new MonthlyCalendar(), false, true);
                   scheduler.AddCalendar("weeklyCalendar", new WeeklyCalendar(), false, true);

                   scheduler.AddCalendar("cronCalendar", cronCalendar, true, true);
                   scheduler.AddCalendar("holidayCalendar", holidayCalendar, true, true);

                   Assert.IsNotNull(scheduler.GetCalendar("annualCalendar"));

                   JobDetailImpl lonelyJob = new JobDetailImpl("lonelyJob", "lonelyGroup", typeof(SimpleRecoveryJob));
                   lonelyJob.Durable = true;
                   lonelyJob.RequestsRecovery = true;
                   scheduler.AddJob(lonelyJob, false);
                   scheduler.AddJob(lonelyJob, true);

                   string schedId = scheduler.SchedulerInstanceId;

                   int count = 1;

                   JobDetailImpl job = new JobDetailImpl("job_" + count, schedId, typeof(SimpleRecoveryJob));

                   // ask scheduler to re-Execute this job if it was in progress when
                   // the scheduler went down...
                   job.RequestsRecovery = true;
                   IOperableTrigger trigger = new SimpleTriggerImpl("trig_" + count, schedId, 20, TimeSpan.FromSeconds(5));
                   trigger.JobDataMap.Add("key", "value");
                   trigger.EndTimeUtc = DateTime.UtcNow.AddYears(10);

                   trigger.StartTimeUtc = DateTime.Now.AddMilliseconds(1000L);
                   scheduler.ScheduleJob(job, trigger);

                   // check that trigger was stored
                   ITrigger persisted = scheduler.GetTrigger(new TriggerKey("trig_" + count, schedId));
                   Assert.IsNotNull(persisted);
                   Assert.IsTrue(persisted is SimpleTriggerImpl);

                   count++;
                   job = new JobDetailImpl("job_" + count, schedId, typeof(SimpleRecoveryJob));
                   // ask scheduler to re-Execute this job if it was in progress when
                   // the scheduler went down...
                   job.RequestsRecovery = (true);
                   trigger = new SimpleTriggerImpl("trig_" + count, schedId, 20, TimeSpan.FromSeconds(5));

                   trigger.StartTimeUtc = (DateTime.Now.AddMilliseconds(2000L));
                   scheduler.ScheduleJob(job, trigger);

                   count++;
                   job = new JobDetailImpl("job_" + count, schedId, typeof(SimpleRecoveryStatefulJob));
                   // ask scheduler to re-Execute this job if it was in progress when
                   // the scheduler went down...
                   job.RequestsRecovery = (true);
                   trigger = new SimpleTriggerImpl("trig_" + count, schedId, 20, TimeSpan.FromSeconds(3));

                   trigger.StartTimeUtc = (DateTime.Now.AddMilliseconds(1000L));
                   scheduler.ScheduleJob(job, trigger);

                   count++;
                   job = new JobDetailImpl("job_" + count, schedId, typeof(SimpleRecoveryJob));
                   // ask scheduler to re-Execute this job if it was in progress when
                   // the scheduler went down...
                   job.RequestsRecovery = (true);
                   trigger = new SimpleTriggerImpl("trig_" + count, schedId, 20, TimeSpan.FromSeconds(4));

                   trigger.StartTimeUtc = (DateTime.Now.AddMilliseconds(1000L));
                   scheduler.ScheduleJob(job, trigger);

                   count++;
                   job = new JobDetailImpl("job_" + count, schedId, typeof(SimpleRecoveryJob));
                   // ask scheduler to re-Execute this job if it was in progress when
                   // the scheduler went down...
                   job.RequestsRecovery = (true);
                   trigger = new SimpleTriggerImpl("trig_" + count, schedId, 20, TimeSpan.FromMilliseconds(4500));
                   scheduler.ScheduleJob(job, trigger);

                   count++;
                   job = new JobDetailImpl("job_" + count, schedId, typeof(SimpleRecoveryJob));
                   // ask scheduler to re-Execute this job if it was in progress when
                   // the scheduler went down...
                   job.RequestsRecovery = (true);
                   IOperableTrigger ct = new CronTriggerImpl("cron_trig_" + count, schedId, "0/10 * * * * ?");
                   ct.JobDataMap.Add("key", "value");
                   ct.StartTimeUtc = DateTime.Now.AddMilliseconds(1000);

                   scheduler.ScheduleJob(job, ct);

                   count++;
                   job = new JobDetailImpl("job_" + count, schedId, typeof(SimpleRecoveryJob));
                   // ask scheduler to re-Execute this job if it was in progress when
                   // the scheduler went down...
                   job.RequestsRecovery = (true);
                   DailyTimeIntervalTriggerImpl nt = new DailyTimeIntervalTriggerImpl("nth_trig_" + count, schedId, new TimeOfDay(1, 1, 1), new TimeOfDay(23, 30, 0), IntervalUnit.Hour, 1);
                   nt.StartTimeUtc = DateTime.Now.Date.AddMilliseconds(1000);

                   scheduler.ScheduleJob(job, nt);

                   DailyTimeIntervalTriggerImpl nt2 = new DailyTimeIntervalTriggerImpl();
                   nt2.Key = new TriggerKey("nth_trig2_" + count, schedId);
                   nt2.StartTimeUtc = DateTime.Now.Date.AddMilliseconds(1000);
                   nt2.JobKey = job.Key;
                   scheduler.ScheduleJob(nt2);

                   // GitHub issue #92
                   scheduler.GetTrigger(nt2.Key);

                   // GitHub issue #98
                   nt2.StartTimeOfDay = new TimeOfDay(1, 2, 3);
                   nt2.EndTimeOfDay = new TimeOfDay(2, 3, 4);

                   scheduler.UnscheduleJob(nt2.Key);
                   scheduler.ScheduleJob(nt2);

                   var triggerFromDb = (IDailyTimeIntervalTrigger) scheduler.GetTrigger(nt2.Key);
                   Assert.That(triggerFromDb.StartTimeOfDay.Hour, Is.EqualTo(1));
                   Assert.That(triggerFromDb.StartTimeOfDay.Minute, Is.EqualTo(2));
                   Assert.That(triggerFromDb.StartTimeOfDay.Second, Is.EqualTo(3));

                   Assert.That(triggerFromDb.EndTimeOfDay.Hour, Is.EqualTo(2));
                   Assert.That(triggerFromDb.EndTimeOfDay.Minute, Is.EqualTo(3));
                   Assert.That(triggerFromDb.EndTimeOfDay.Second, Is.EqualTo(4));

                   job.RequestsRecovery = (true);
                   CalendarIntervalTriggerImpl intervalTrigger = new CalendarIntervalTriggerImpl(
                       "calint_trig_" + count,
                       schedId,
                       DateTime.UtcNow.AddMilliseconds(300),
                       DateTime.UtcNow.AddMinutes(1),
                       IntervalUnit.Second,
                       8);
                   intervalTrigger.JobKey = job.Key;

                   scheduler.ScheduleJob(intervalTrigger);

                   // bulk operations
                   var info = new Dictionary<IJobDetail, Collection.ISet<ITrigger>>();
                   IJobDetail detail = new JobDetailImpl("job_" + count, schedId, typeof(SimpleRecoveryJob));
                   ITrigger simple = new SimpleTriggerImpl("trig_" + count, schedId, 20, TimeSpan.FromMilliseconds(4500));
                   var triggers = new Collection.HashSet<ITrigger>();
                   triggers.Add(simple);
                   info[detail] = triggers;

                   scheduler.ScheduleJobs(info, true);

                   Assert.IsTrue(scheduler.CheckExists(detail.Key));
                   Assert.IsTrue(scheduler.CheckExists(simple.Key));

                   // QRTZNET-243
                   scheduler.GetJobKeys(GroupMatcher<JobKey>.GroupContains("a").DeepClone());
                   scheduler.GetJobKeys(GroupMatcher<JobKey>.GroupEndsWith("a").DeepClone());
                   scheduler.GetJobKeys(GroupMatcher<JobKey>.GroupStartsWith("a").DeepClone());
                   scheduler.GetJobKeys(GroupMatcher<JobKey>.GroupEquals("a").DeepClone());

                   scheduler.GetTriggerKeys(GroupMatcher<TriggerKey>.GroupContains("a").DeepClone());
                   scheduler.GetTriggerKeys(GroupMatcher<TriggerKey>.GroupEndsWith("a").DeepClone());
                   scheduler.GetTriggerKeys(GroupMatcher<TriggerKey>.GroupStartsWith("a").DeepClone());
                   scheduler.GetTriggerKeys(GroupMatcher<TriggerKey>.GroupEquals("a").DeepClone());

                   scheduler.Start();

                   Thread.Sleep(TimeSpan.FromSeconds(3));

                   scheduler.PauseAll();

                   scheduler.ResumeAll();

                   scheduler.PauseJob(new JobKey("job_1", schedId));

                   scheduler.ResumeJob(new JobKey("job_1", schedId));

                   scheduler.PauseJobs(GroupMatcher<JobKey>.GroupEquals(schedId));

                   Thread.Sleep(TimeSpan.FromSeconds(1));

                   scheduler.ResumeJobs(GroupMatcher<JobKey>.GroupEquals(schedId));

                   scheduler.PauseTrigger(new TriggerKey("trig_2", schedId));
                   scheduler.ResumeTrigger(new TriggerKey("trig_2", schedId));

                   scheduler.PauseTriggers(GroupMatcher<TriggerKey>.GroupEquals(schedId));

                   Assert.AreEqual(1, scheduler.GetPausedTriggerGroups().Count);

                   Thread.Sleep(TimeSpan.FromSeconds(3));
                   scheduler.ResumeTriggers(GroupMatcher<TriggerKey>.GroupEquals(schedId));

                   Assert.IsNotNull(scheduler.GetTrigger(new TriggerKey("trig_2", schedId)));
                   Assert.IsNotNull(scheduler.GetJobDetail(new JobKey("job_1", schedId)));
                   Assert.IsNotNull(scheduler.GetMetaData());
                   Assert.IsNotNull(scheduler.GetCalendar("weeklyCalendar"));

                   Thread.Sleep(TimeSpan.FromSeconds(20));

                   scheduler.Standby();

                   CollectionAssert.IsNotEmpty(scheduler.GetCalendarNames());
                   CollectionAssert.IsNotEmpty(scheduler.GetJobKeys(GroupMatcher<JobKey>.GroupEquals(schedId)));

                   CollectionAssert.IsNotEmpty(scheduler.GetTriggersOfJob(new JobKey("job_2", schedId)));
                   Assert.IsNotNull(scheduler.GetJobDetail(new JobKey("job_2", schedId)));

                   scheduler.DeleteCalendar("cronCalendar");
                   scheduler.DeleteCalendar("holidayCalendar");
                   scheduler.DeleteJob(new JobKey("lonelyJob", "lonelyGroup"));
                   scheduler.DeleteJob(job.Key);

                   scheduler.GetJobGroupNames();
                   scheduler.GetCalendarNames();
                   scheduler.GetTriggerGroupNames();
               }
               }
               finally
               {
               scheduler.Shutdown(false);
               }
        }
Exemplo n.º 17
0
        public void TestSqlServerStress()
        {
            NameValueCollection properties = new NameValueCollection();

            properties["quartz.scheduler.instanceName"] = "TestScheduler";
            properties["quartz.scheduler.instanceId"] = "instance_one";
            properties["quartz.threadPool.type"] = "Quartz.Simpl.SimpleThreadPool, Quartz";
            properties["quartz.threadPool.threadCount"] = "10";
            properties["quartz.threadPool.threadPriority"] = "Normal";
            properties["quartz.jobStore.misfireThreshold"] = "60000";
            properties["quartz.jobStore.type"] = "Quartz.Impl.AdoJobStore.JobStoreTX, Quartz";
            properties["quartz.jobStore.driverDelegateType"] = "Quartz.Impl.AdoJobStore.StdAdoDelegate, Quartz";
            properties["quartz.jobStore.useProperties"] = "false";
            properties["quartz.jobStore.dataSource"] = "default";
            properties["quartz.jobStore.tablePrefix"] = "QRTZ_";
            properties["quartz.jobStore.clustered"] = clustered.ToString();

            properties["quartz.jobStore.driverDelegateType"] = "Quartz.Impl.AdoJobStore.SqlServerDelegate, Quartz";
            RunAdoJobStoreTest("SqlServer-20", "SQLServer", properties);

            string connectionString;
            if (!dbConnectionStrings.TryGetValue("SQLServer", out connectionString))
            {
                throw new Exception("Unknown connection string id: " + "SQLServer");
            }
            properties["quartz.dataSource.default.connectionString"] = connectionString;
            properties["quartz.dataSource.default.provider"] = "SqlServer-20";

            // First we must get a reference to a scheduler
            ISchedulerFactory sf = new StdSchedulerFactory(properties);
            IScheduler sched = sf.GetScheduler();

            try
            {
                sched.Clear();

                if (scheduleJobs)
                {
                    ICalendar cronCalendar = new CronCalendar("0/5 * * * * ?");
                    ICalendar holidayCalendar = new HolidayCalendar();

                    for (int i = 0; i < 100000; ++i)
                    {
                        ITrigger trigger = new SimpleTriggerImpl("calendarsTrigger", "test", SimpleTriggerImpl.RepeatIndefinitely, TimeSpan.FromSeconds(1));
                        JobDetailImpl jd = new JobDetailImpl("testJob", "test", typeof(NoOpJob));
                        sched.ScheduleJob(jd, trigger);
                    }
                }
                sched.Start();
                Thread.Sleep(TimeSpan.FromSeconds(30));
            }
            finally
            {
                sched.Shutdown(false);
            }
        }
 public void CanAddCalendar()
 {
     ICalendar calendar = new HolidayCalendar();
     calendar.Description = "This is my holiday calendar";
     scheduler.AddCalendar("Holiday calendar", calendar, false, false);
 }
Exemplo n.º 19
0
        private void RunAdoJobStoreTest(string dbProvider, string connectionStringId,
                                        NameValueCollection extraProperties)
        {
            NameValueCollection properties = new NameValueCollection();

            properties["quartz.scheduler.instanceName"] = "TestScheduler";
            properties["quartz.scheduler.instanceId"] = "instance_one";
            properties["quartz.threadPool.type"] = "Quartz.Simpl.SimpleThreadPool, Quartz";
            properties["quartz.threadPool.threadCount"] = "10";
            properties["quartz.threadPool.threadPriority"] = "Normal";
            properties["quartz.jobStore.misfireThreshold"] = "60000";
            properties["quartz.jobStore.type"] = "Quartz.Impl.AdoJobStore.JobStoreTX, Quartz";
            properties["quartz.jobStore.driverDelegateType"] = "Quartz.Impl.AdoJobStore.StdAdoDelegate, Quartz";
            properties["quartz.jobStore.useProperties"] = "false";
            properties["quartz.jobStore.dataSource"] = "default";
            properties["quartz.jobStore.tablePrefix"] = "QRTZ_";
            properties["quartz.jobStore.clustered"] = clustered.ToString();

            if (extraProperties != null)
            {
                foreach (string key in extraProperties.Keys)
                {
                    properties[key] = extraProperties[key];
                }
            }

            if (connectionStringId == "SQLServer" || connectionStringId == "SQLite")
            {
                // if running MS SQL Server we need this
                properties["quartz.jobStore.lockHandler.type"] =
                    "Quartz.Impl.AdoJobStore.UpdateLockRowSemaphore, Quartz";
            }

            string connectionString;
            if (!dbConnectionStrings.TryGetValue(connectionStringId, out connectionString))
            {
                throw new Exception("Unknown connection string id: " + connectionStringId);
            }
            properties["quartz.dataSource.default.connectionString"] = connectionString;
            properties["quartz.dataSource.default.provider"] = dbProvider;

            // First we must get a reference to a scheduler
            ISchedulerFactory sf = new StdSchedulerFactory(properties);
            IScheduler sched = sf.GetScheduler();

            try
            {
                if (clearJobs)
                {
                    CleanUp(sched);
                }

                if (scheduleJobs)
                {
                    ICalendar cronCalendar = new CronCalendar("0/5 * * * * ?");
                    ICalendar holidayCalendar = new HolidayCalendar();

                    // QRTZNET-86
                    ITrigger t = sched.GetTrigger(new TriggerKey("NonExistingTrigger", "NonExistingGroup"));
                    Assert.IsNull(t);

                    AnnualCalendar cal = new AnnualCalendar();
                    sched.AddCalendar("annualCalendar", cal, false, true);

                    IOperableTrigger calendarsTrigger = new SimpleTriggerImpl("calendarsTrigger", "test", 20, TimeSpan.FromMilliseconds(5));
                    calendarsTrigger.CalendarName = "annualCalendar";

                    JobDetailImpl jd = new JobDetailImpl("testJob", "test", typeof(NoOpJob));
                    sched.ScheduleJob(jd, calendarsTrigger);

                    // QRTZNET-93
                    sched.AddCalendar("annualCalendar", cal, true, true);

                    sched.AddCalendar("baseCalendar", new BaseCalendar(), false, true);
                    sched.AddCalendar("cronCalendar", cronCalendar, false, true);
                    sched.AddCalendar("dailyCalendar", new DailyCalendar(DateTime.Now.Date, DateTime.Now.AddMinutes(1)), false, true);
                    sched.AddCalendar("holidayCalendar", holidayCalendar, false, true);
                    sched.AddCalendar("monthlyCalendar", new MonthlyCalendar(), false, true);
                    sched.AddCalendar("weeklyCalendar", new WeeklyCalendar(), false, true);

                    sched.AddCalendar("cronCalendar", cronCalendar, true, true);
                    sched.AddCalendar("holidayCalendar", holidayCalendar, true, true);

                    Assert.IsNotNull(sched.GetCalendar("annualCalendar"));

                    JobDetailImpl lonelyJob = new JobDetailImpl("lonelyJob", "lonelyGroup", typeof(SimpleRecoveryJob));
                    lonelyJob.Durable = true;
                    lonelyJob.RequestsRecovery = true;
                    sched.AddJob(lonelyJob, false);
                    sched.AddJob(lonelyJob, true);

                    string schedId = sched.SchedulerInstanceId;

                    int count = 1;

                    JobDetailImpl job = new JobDetailImpl("job_" + count, schedId, typeof (SimpleRecoveryJob));

                    // ask scheduler to re-Execute this job if it was in progress when
                    // the scheduler went down...
                    job.RequestsRecovery = true;
                    IOperableTrigger trigger = new SimpleTriggerImpl("trig_" + count, schedId, 20, TimeSpan.FromSeconds(5));

                    trigger.StartTimeUtc = DateTime.Now.AddMilliseconds(1000L);
                    sched.ScheduleJob(job, trigger);

                    // check that trigger was stored
                    ITrigger persisted = sched.GetTrigger(new TriggerKey("trig_" + count, schedId));
                    Assert.IsNotNull(persisted);
                    Assert.IsTrue(persisted is SimpleTriggerImpl);

                    count++;
                    job = new JobDetailImpl("job_" + count, schedId, typeof (SimpleRecoveryJob));
                    // ask scheduler to re-Execute this job if it was in progress when
                    // the scheduler went down...
                    job.RequestsRecovery = (true);
                    trigger = new SimpleTriggerImpl("trig_" + count, schedId, 20, TimeSpan.FromSeconds(5));

                    trigger.StartTimeUtc = (DateTime.Now.AddMilliseconds(2000L));
                    sched.ScheduleJob(job, trigger);

                    count++;
                    job = new JobDetailImpl("job_" + count, schedId, typeof (SimpleRecoveryStatefulJob));
                    // ask scheduler to re-Execute this job if it was in progress when
                    // the scheduler went down...
                    job.RequestsRecovery = (true);
                    trigger = new SimpleTriggerImpl("trig_" + count, schedId, 20, TimeSpan.FromSeconds(3));

                    trigger.StartTimeUtc = (DateTime.Now.AddMilliseconds(1000L));
                    sched.ScheduleJob(job, trigger);

                    count++;
                    job = new JobDetailImpl("job_" + count, schedId, typeof (SimpleRecoveryJob));
                    // ask scheduler to re-Execute this job if it was in progress when
                    // the scheduler went down...
                    job.RequestsRecovery = (true);
                    trigger = new SimpleTriggerImpl("trig_" + count, schedId, 20, TimeSpan.FromSeconds(4));

                    trigger.StartTimeUtc = (DateTime.Now.AddMilliseconds(1000L));
                    sched.ScheduleJob(job, trigger);

                    count++;
                    job = new JobDetailImpl("job_" + count, schedId, typeof (SimpleRecoveryJob));
                    // ask scheduler to re-Execute this job if it was in progress when
                    // the scheduler went down...
                    job.RequestsRecovery = (true);
                    trigger = new SimpleTriggerImpl("trig_" + count, schedId, 20, TimeSpan.FromMilliseconds(4500));
                    sched.ScheduleJob(job, trigger);

                    count++;
                    job = new JobDetailImpl("job_" + count, schedId, typeof (SimpleRecoveryJob));
                    // ask scheduler to re-Execute this job if it was in progress when
                    // the scheduler went down...
                    job.RequestsRecovery = (true);
                    IOperableTrigger ct = new CronTriggerImpl("cron_trig_" + count, schedId, "0/10 * * * * ?");
                    ct.StartTimeUtc = DateTime.Now.AddMilliseconds(1000);

                    sched.ScheduleJob(job, ct);

                    count++;
                    job = new JobDetailImpl("job_" + count, schedId, typeof (SimpleRecoveryJob));
                    // ask scheduler to re-Execute this job if it was in progress when
                    // the scheduler went down...
                    job.RequestsRecovery = (true);
                    NthIncludedDayTrigger nt = new NthIncludedDayTrigger("cron_trig_" + count, schedId);
                    nt.StartTimeUtc = DateTime.Now.Date.AddMilliseconds(1000);
                    nt.N = 1;

                    sched.ScheduleJob(job, nt);

                    sched.Start();

                    sched.PauseAll();

                    sched.ResumeAll();

                    sched.PauseJob(new JobKey("job_1", schedId));

                    sched.ResumeJob(new JobKey("job_1", schedId));

                    sched.PauseJobs(GroupMatcher<JobKey>.GroupEquals(schedId));

                    Thread.Sleep(1000);

                    sched.ResumeJobs(GroupMatcher<JobKey>.GroupEquals(schedId));

                    sched.PauseTrigger(new TriggerKey("trig_2", schedId));
                    sched.ResumeTrigger(new TriggerKey("trig_2", schedId));

                    sched.PauseTriggers(GroupMatcher<TriggerKey>.GroupEquals(schedId));

                    Assert.AreEqual(1, sched.GetPausedTriggerGroups().Count);

                    Thread.Sleep(1000);
                    sched.ResumeTriggers(GroupMatcher<TriggerKey>.GroupEquals(schedId));

                    Thread.Sleep(TimeSpan.FromSeconds(20));

                    sched.Standby();

                    CollectionAssert.IsNotEmpty(sched.GetCalendarNames());
                    CollectionAssert.IsNotEmpty(sched.GetJobKeys(GroupMatcher<JobKey>.GroupEquals(schedId)));

                    CollectionAssert.IsNotEmpty(sched.GetTriggersOfJob(new JobKey("job_2", schedId)));
                    Assert.IsNotNull(sched.GetJobDetail(new JobKey("job_2", schedId)));

                    sched.DeleteCalendar("cronCalendar");
                    sched.DeleteCalendar("holidayCalendar");
                    sched.DeleteJob(new JobKey("lonelyJob", "lonelyGroup"));

                }
            }
            finally
            {
                sched.Shutdown(false);
            }
        }
Exemplo n.º 20
0
        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();
        }
Exemplo n.º 21
0
	    /// <summary>
	    /// Creates a new object that is a copy of the current instance.
	    /// </summary>
	    /// <returns>A new object that is a copy of this instance.</returns>
        public override ICalendar Clone()
	    {
            HolidayCalendar clone = new HolidayCalendar();
            CloneFields(clone);
            clone.dates = new SortedSet<DateTime>(dates);
            return clone;
	    }
Exemplo n.º 22
0
        public bool Equals(HolidayCalendar obj)
        {
            if (obj == null)
            {
                return false;
            }

            bool baseEqual = GetBaseCalendar() == null || GetBaseCalendar().Equals(obj.GetBaseCalendar());

            return baseEqual && ExcludedDates.SequenceEqual(obj.ExcludedDates);
        }