Exemplo n.º 1
0
        public static void AssertHasCronExpression(TextToScheduleResults results, string cronExpression)
        {
            bool foundCronTrigger = false;

            foreach (var g in results.RegisterGroups)
            {
                var trigger = g.TriggerBuilder.Build();

                if (trigger is ICronTrigger)
                {
                    ICronTrigger cronTrigger = (ICronTrigger)trigger;
                    if (cronExpression == cronTrigger.CronExpressionString)
                    {
                        foundCronTrigger = true;
                        break;
                    }
                }
            }

            if (!foundCronTrigger)
            {
                Assert.Fail(
                    string.Format("Could not find cron string of {0}, in the list of found cron expressions ({1}).",
                                  cronExpression,
                                  string.Join(", ", results.RegisterGroups.Select(x => x.TriggerBuilder.Build()).OfType <ICronTrigger>().Select(x => x.CronExpressionString).ToList())));
            }
        }
Exemplo n.º 2
0
        private static void InputChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            var m = (sender) as Model;

            m.Triggers.Clear();

            TextToScheduleResults results = null;

            TextToScheduleFactory parserFactory = new TextToScheduleFactory();
            var englishParser = parserFactory.CreateEnglishParser();
            var germanParser  = parserFactory.CreateGermanParser();
            var spanishParser = parserFactory.CreateSpanishParser();

            ITextToSchedule textToSchedule = new MultiTextToSchedule(
                parserFactory.CreateEnglishParser(),
                parserFactory.CreateGermanParser(),
                parserFactory.CreateSpanishParser(),
                parserFactory.CreateCronParser());

            string text = m.Input;

            results = textToSchedule.Parse(text, m.TimeZone);

            if (results != null)
            {
                List <DateTimeOffset> list = new List <DateTimeOffset>();

                foreach (var groups in results.RegisterGroups)
                {
                    var trigger = (IOperableTrigger)groups.TriggerBuilder.Build();

                    var dates = TriggerUtils.ComputeFireTimes(trigger, groups.Calendar, MaxResultsToReturn);

                    foreach (var d in dates)
                    {
                        list.Add(TimeZoneUtil.ConvertTime(d, m.TimeZone));
                    }
                }

                //sort the list
                list.Sort();

                foreach (var item in list.Take(MaxResultsToReturn))
                {
                    m.Triggers.Add(item.ToString("ddd, MM/dd/yyyy hh:mm:ss tt (zzz)"));
                }
            }
        }
        static void Main(string[] args)
        {
            //create and parse the text into a TextToScheduleResults
            string scheduleText = "every 2 seconds";

            Console.WriteLine("Running schedule of \"{0}\"", scheduleText);

            ITextToSchedule       parser  = TextToScheduleFactory.CreateEnglishParser();
            TextToScheduleResults results = parser.Parse(scheduleText);

            //create & start the scheduler
            ISchedulerFactory factory = new StdSchedulerFactory();
            IScheduler        sched   = factory.GetScheduler();

            sched.Start();

            //create a job detail
            IJobDetail job = JobBuilder.Create <SampleJob>().Build();

            //schedule job
            results.ScheduleWithJob(sched, job);
        }