public CrontabValueMonthDayGroup(CrontabValueDay day, CrontabValueMonth month) { this.day = day; this.month = month; }
public static bool TryParse(string value, out CrontabValueMonth crontabValue) { crontabValue = null; var list = new List <CrontabValueNode>(); var array = value.Split(Separator, StringSplitOptions.RemoveEmptyEntries); foreach (var item in array) { if (item == "*" || item == "*/1") { crontabValue = new CrontabValueMonth(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 CrontabValueMonth(list); return(true); } }
/// <summary> /// Try to parse the value for the schedule /// </summary> /// <param name="value"></param> /// <param name="schedule"></param> /// <returns></returns> public static bool TryParse(string value, out CrontabSchedule schedule) { schedule = null; if (string.IsNullOrEmpty(value)) { return(false); } string[] array = value.Split(Separator, StringSplitOptions.RemoveEmptyEntries); if (array.Length == 0) { return(false); } var v1 = array[0]; if (CrontabValueMinute.TryParse(v1, out CrontabValueMinute minute)) { CrontabValueHour hour = null; CrontabValueDay day = null; CrontabValueMonth month = null; CrontabValueWeek week = null; if (array.Length >= 2) { if (!CrontabValueHour.TryParse(array[1], out hour)) { return(false); } } if (array.Length >= 3) { if (!CrontabValueDay.TryParse(array[2], out day)) { return(false); } } if (array.Length >= 4) { if (!CrontabValueMonth.TryParse(array[3], out month)) { return(false); } } if (array.Length >= 5) { if (!CrontabValueWeek.TryParse(array[4], out week)) { return(false); } } if (array.Length >= 6) { return(false); } var timeGroup = new CrontabValueHourMinuteGroup(minute, hour); var dateGroup = new CrontabValueMonthDayGroup(day, month); schedule = new CrontabSchedule(value, timeGroup, dateGroup, week); return(true); } else if (CrontabValueTimeRange.TryParse(v1, out CrontabValueTimeRange timeRange)) { CrontabValueDay day = null; CrontabValueMonth month = null; CrontabValueWeek week = null; if (array.Length >= 2) { if (!CrontabValueDay.TryParse(array[1], out day)) { return(false); } } if (array.Length >= 3) { if (!CrontabValueMonth.TryParse(array[2], out month)) { return(false); } } if (array.Length >= 4) { if (!CrontabValueWeek.TryParse(array[3], out week)) { return(false); } } if (array.Length >= 5) { return(false); } var timeGroup = new CrontabValueTimeRangeGroup(timeRange); var dateGroup = new CrontabValueMonthDayGroup(day, month); schedule = new CrontabSchedule(value, timeGroup, dateGroup, week); return(true); } else { return(false); } }