Exemplo n.º 1
0
 public CrontabValueMonthDayGroup(CronDayValue day, CronMonthValue month)
 {
     this.day   = day;
     this.month = month;
 }
Exemplo n.º 2
0
        public static bool TryParse(string value, out CronMonthValue crontabValue)
        {
            crontabValue = null;
            var list  = new List <CronNodeBase>();
            var array = value.Split(Separator, StringSplitOptions.RemoveEmptyEntries);

            foreach (var item in array)
            {
                if (item == "*" || item == "*/1")
                {
                    crontabValue = new CronMonthValue(null);
                    return(true);
                }
                if (int.TryParse(item, out int data))
                {
                    if (data >= min && data <= max)
                    {
                        list.Add(new SingleCrontabValueNode(data));
                        continue;
                    }
                    else
                    {
                        return(false);
                    }
                }
                var aftmatch = AllFromToRegex.Match(item);
                if (aftmatch.Success)
                {
                    var interval = Convert.ToInt32(aftmatch.Groups["interval"].Value);
                    if (interval > 0)
                    {
                        list.Add(new RangeCrontabValueNode(min, max, min, max, interval));
                        continue;
                    }
                    else
                    {
                        return(false);
                    }
                }
                var ftmatch = FromToRegex.Match(item);
                if (ftmatch.Success)
                {
                    var start    = Convert.ToInt32(ftmatch.Groups["start"].Value);
                    var end      = Convert.ToInt32(ftmatch.Groups["end"].Value);
                    var interval = 1;
                    if (ftmatch.Groups["interval"].Success)
                    {
                        interval = Convert.ToInt32(ftmatch.Groups["interval"].Value);
                    }
                    if (start >= min && start <= max && end >= min && end <= max && interval > 0)
                    {
                        list.Add(new RangeCrontabValueNode(min, max, start, end, interval));
                        continue;
                    }
                    else
                    {
                        return(false);
                    }
                }
                return(false);
            }
            if (list.Count == 0)
            {
                return(false);
            }
            else
            {
                crontabValue = new CronMonthValue(list);
                return(true);
            }
        }