Ejemplo n.º 1
0
        public static bool TryParse(string value, out CrontabValueTimeRange timeRange)
        {
            timeRange = null;
            if (string.IsNullOrEmpty(value))
            {
                return(false);
            }
            string[] rangearr = value.Split(separator, StringSplitOptions.RemoveEmptyEntries);
            if (rangearr.Length == 0)
            {
                return(false);
            }

            List <TimeRange> list = new List <TimeRange>();

            foreach (var item in rangearr)
            {
                var match = regex.Match(item);
                if (match.Success)
                {
                    var fromHour   = Convert.ToInt32(match.Groups["fromHour"].Value);
                    var fromMinute = Convert.ToInt32(match.Groups["fromMinute"].Value);
                    var toHour     = Convert.ToInt32(match.Groups["toHour"].Value);
                    var toMinute   = Convert.ToInt32(match.Groups["toMinute"].Value);
                    var interval   = 1;
                    if (match.Groups["interval"].Success)
                    {
                        interval = Convert.ToInt32(match.Groups["interval"].Value);
                    }
                    var timerange = new TimeRange(fromHour, fromMinute, toHour, toMinute, interval);
                    list.Add(timerange);
                }
                else
                {
                    return(false);
                }
            }

            timeRange = new CrontabValueTimeRange(list);
            return(true);
        }
Ejemplo n.º 2
0
 public CrontabValueTimeRangeGroup(CrontabValueTimeRange timeRange)
 {
     this.timeRange = timeRange;
 }
Ejemplo n.º 3
0
        /// <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);
            }
        }