示例#1
0
        public CronTestModel TestCron([FromBody] CronViewModelBody body)
        {
            var model = new CronTestModel();

            try
            {
                var time   = DateTime.UtcNow;
                var result = CrontabSchedule.TryParse(body.Expression);
                for (int i = 0; i < 10; i++)
                {
                    var next = result.GetNextOccurrence(time);
                    model.Schedule.Add(next);
                    time = next;
                }
                model.Success = true;
                return(model);
            }
            catch (Exception)
            {
                return(new CronTestModel
                {
                    Message = $"CRON Expression {body.Expression} is not valid"
                });
            }
        }
示例#2
0
        public CronTestModel TestCron([FromBody] CronViewModelBody body)
        {
            var model = new CronTestModel();

            try
            {
                var isValid = CronExpression.IsValidExpression(body.Expression);
                if (!isValid)
                {
                    return(new CronTestModel
                    {
                        Message = $"CRON Expression {body.Expression} is not valid"
                    });
                }

                model.Success = true;
                return(model);
            }
            catch (Exception)
            {
                return(new CronTestModel
                {
                    Message = $"CRON Expression {body.Expression} is not valid"
                });
            }
        }