Esempio n. 1
0
        public Task Execute(IJobExecutionContext context)
        {
            JobDataMap dataMap = context.JobDetail.JobDataMap;
            KidsNoteScheduleParameters param = (KidsNoteScheduleParameters)dataMap["param"];
            KidsNoteNotifierManager    owner = (KidsNoteNotifierManager)dataMap["owner"];

            Task task = Task.Run(() =>
            {
                owner.DoScheduledCheck(true);
            });

            return(task);
        }
Esempio n. 2
0
        public void AddJob(KidsNoteScheduleParameters param)
        {
            var schedulerTask = StdSchedulerFactory.GetDefaultScheduler();

            schedulerTask.Wait();
            IScheduler scheduler = schedulerTask.Result;

            string jobName = param.ToString();

            if (ActiveScheduleNames.Contains(jobName))
            {
                return;
            }

            /*
             * 1.Seconds
             * 2.Minutes
             * 3.Hours
             * 4.Day - of - Month
             * 5.Month
             * 6.Day - of - Week
             * 7.Year(optional field)
             */

#if DEBUG
            DateTime scheduled = DateTime.Now;
            scheduled += new TimeSpan(0, 0, 0, 30);
#endif

            string cronFormat = "";
            if (param.Days == KidsNoteScheduleParameters.DaysType.MON_FRI)
            {
#if DEBUG
                cronFormat = String.Format("{0} {1} {2} ? * MON-FRI", scheduled.Second, scheduled.Minute, scheduled.Hour);
#else
                cronFormat = "0 0 * ? * MON-FRI";
#endif
            }
            else
            {
#if DEBUG
                cronFormat = String.Format("{0} {1} {2} * * ?", scheduled.Second, scheduled.Minute, scheduled.Hour);
#else
                cronFormat = "0 0 * * * ?";
#endif
            }


            IJobDetail job = JobBuilder.Create <KidsNoteScheduledJob>().WithIdentity(jobName, Constants.KISNOTE_SCHEDULER_GROUP_NAME).Build();
            job.JobDataMap.Put("param", param);
            job.JobDataMap.Put("owner", this);

            ITrigger trigger =
                TriggerBuilder.Create()
                .WithIdentity(jobName, Constants.KISNOTE_SCHEDULER_GROUP_NAME)
                .WithCronSchedule(cronFormat)
                .ForJob(jobName, Constants.KISNOTE_SCHEDULER_GROUP_NAME)
                .Build();

            scheduler.ScheduleJob(job, trigger);

            ActiveScheduleNames.Add(jobName);
        }