Ejemplo n.º 1
0
        static public bool TryParse(string s, out Expression result)
        {
            result = default(Expression);
            if (string.IsNullOrEmpty(s))
            {
                return(false);
            }

            string[] parts = s.Split(' ');
            if (parts.Length != 5L)
            {
                return(false);
            }

            ExpressionSectionBase minuteSection;
            ExpressionSectionBase hourSection;
            ExpressionSectionBase dayOfMonthSection;
            ExpressionSectionBase monthSection;
            ExpressionSectionBase dayOfWeekSection;

            if (!ExpressionSectionBase.TryParse(parts[0],
                                                ExpressionSectionType.Minute,
                                                out minuteSection))
            {
                return(false);
            }
            if (!ExpressionSectionBase.TryParse(parts[1],
                                                ExpressionSectionType.Hour,
                                                out hourSection))
            {
                return(false);
            }
            if (!ExpressionSectionBase.TryParse(parts[2],
                                                ExpressionSectionType.DayOfMonth,
                                                out dayOfMonthSection))
            {
                return(false);
            }
            if (!ExpressionSectionBase.TryParse(parts[3],
                                                ExpressionSectionType.Month,
                                                out monthSection))
            {
                return(false);
            }
            if (!ExpressionSectionBase.TryParse(parts[4],
                                                ExpressionSectionType.DayOfWeek,
                                                out dayOfWeekSection))
            {
                return(false);
            }

            if (DaySectionsConflict(dayOfWeekSection, dayOfMonthSection))
            {
                return(false);
            }

            result = new Expression(minuteSection, hourSection, dayOfMonthSection, monthSection, dayOfWeekSection);
            return(true);
        }
Ejemplo n.º 2
0
 static private bool DaySectionsConflict(ExpressionSectionBase dayOfWeek, ExpressionSectionBase dayOfMonth)
 {
     if (dayOfWeek is IgnoreExpressionSection)
     {
         return(dayOfMonth is IgnoreExpressionSection);
     }
     if (dayOfMonth is IgnoreExpressionSection)
     {
         return(dayOfWeek is IgnoreExpressionSection);
     }
     return(!(dayOfWeek is EveryOccurenceExpressionSection && dayOfMonth is EveryOccurenceExpressionSection));
 }
Ejemplo n.º 3
0
 private Expression(ExpressionSectionBase minuteSection,
                    ExpressionSectionBase hourSection,
                    ExpressionSectionBase dayOfMonthSection,
                    ExpressionSectionBase monthSection,
                    ExpressionSectionBase dayOfWeekSection
                    )
 {
     if (minuteSection.Type != ExpressionSectionType.Minute ||
         hourSection.Type != ExpressionSectionType.Hour ||
         dayOfMonthSection.Type != ExpressionSectionType.DayOfMonth ||
         dayOfWeekSection.Type != ExpressionSectionType.DayOfWeek ||
         monthSection.Type != ExpressionSectionType.Month)
     {
         throw new ArgumentException("Invalid constructor call.");
     }
     _minuteSection     = minuteSection;
     _hourSection       = hourSection;
     _dayOfMonthSection = dayOfMonthSection;
     _monthSection      = monthSection;
     _dayOfWeekSection  = dayOfWeekSection;
 }
Ejemplo n.º 4
0
 private Expression(ExpressionSectionBase minuteSection,
                    ExpressionSectionBase hourSection,
                    ExpressionSectionBase dayOfMonthSection,
                    ExpressionSectionBase monthSection,
                    ExpressionSectionBase dayOfWeekSection
     )
 {
     if (minuteSection.Type != ExpressionSectionType.Minute
         || hourSection.Type != ExpressionSectionType.Hour
         || dayOfMonthSection.Type != ExpressionSectionType.DayOfMonth
         || dayOfWeekSection.Type != ExpressionSectionType.DayOfWeek
         || monthSection.Type != ExpressionSectionType.Month)
     {
         throw new ArgumentException("Invalid constructor call.");
     }
     _minuteSection = minuteSection;
     _hourSection = hourSection;
     _dayOfMonthSection = dayOfMonthSection;
     _monthSection = monthSection;
     _dayOfWeekSection = dayOfWeekSection;
 }
Ejemplo n.º 5
0
        static public bool TryParse(string s, ExpressionSectionType type, out ExpressionSectionBase result)
        {
            result = default(ExpressionSectionBase);

            if (string.IsNullOrEmpty(s)) return false;

            EveryOccurenceExpressionSection every;
            if (EveryOccurenceExpressionSection.TryParse(s, type, out every))
            {
                result = every;
                return true;
            }
            IgnoreExpressionSection ignore;
            if (IgnoreExpressionSection.TryParse(s, type, out ignore))
            {
                if (type != ExpressionSectionType.DayOfMonth && type != ExpressionSectionType.DayOfWeek) return false;
                result = ignore;
                return true;
            }

            RangeExpressionSection range;
            if (RangeExpressionSection.TryParse(s, type, out range))
            {
                result = range;
                return true;
            }

            RepeatingExpressionSection repeating;
            if (RepeatingExpressionSection.TryParse(s, type, out repeating))
            {
                result = repeating;
                return true;
            }

            ListExpressionSection list;
            if (ListExpressionSection.TryParse(s, type, out list))
            {
                result = list;
                return true;
            }

            switch (type)
            {
                case ExpressionSectionType.Month:
                    MonthExpressionSection month;
                    if (!MonthExpressionSection.TryParse(s, out month)) return false;
                    result = month;
                    return true;
                case ExpressionSectionType.DayOfWeek:
                    DayOfWeekExpressionSection dayOfWeek;
                    if (DayOfWeekExpressionSection.TryParse(s, out dayOfWeek))
                    {
                        result = dayOfWeek;
                        return true;
                    }
                    SpecifiedWeekAndWeekDayExpressionSection specifiedDayAndWeekDay;
                    if (SpecifiedWeekAndWeekDayExpressionSection.TryParse(s, out specifiedDayAndWeekDay))
                    {
                        result = specifiedDayAndWeekDay;
                        return true;
                    }
                    goto default;
                case ExpressionSectionType.DayOfMonth:
                    LastDayOfMonthExpressionSection lastDayOfMonth;
                    if (LastDayOfMonthExpressionSection.TryParse(s, out lastDayOfMonth))
                    {
                        result = lastDayOfMonth;
                        return true;
                    }
                    NearestWeekdayExpressionSection nearestWeekDay;
                    if (NearestWeekdayExpressionSection.TryParse(s, out nearestWeekDay))
                    {
                        result = nearestWeekDay;
                        return true;
                    }
                    LastWeekDayOfMonthExpressionSection lastWeekDay;
                    if (LastWeekDayOfMonthExpressionSection.TryParse(s, out lastWeekDay))
                    {
                        result = lastWeekDay;
                        return true;
                    }
                    goto default;
                default:
                    SimpleExpressionSection simple;
                    if (!SimpleExpressionSection.TryParse(s, type, out simple)) return false;
                    result = simple;
                    return true;
            }
        }
        static public bool TryParse(string s, ExpressionSectionType type, out ExpressionSectionBase result)
        {
            result = default(ExpressionSectionBase);

            if (string.IsNullOrEmpty(s))
            {
                return(false);
            }

            EveryOccurenceExpressionSection every;

            if (EveryOccurenceExpressionSection.TryParse(s, type, out every))
            {
                result = every;
                return(true);
            }
            IgnoreExpressionSection ignore;

            if (IgnoreExpressionSection.TryParse(s, type, out ignore))
            {
                if (type != ExpressionSectionType.DayOfMonth && type != ExpressionSectionType.DayOfWeek)
                {
                    return(false);
                }
                result = ignore;
                return(true);
            }

            RangeExpressionSection range;

            if (RangeExpressionSection.TryParse(s, type, out range))
            {
                result = range;
                return(true);
            }

            RepeatingExpressionSection repeating;

            if (RepeatingExpressionSection.TryParse(s, type, out repeating))
            {
                result = repeating;
                return(true);
            }

            ListExpressionSection list;

            if (ListExpressionSection.TryParse(s, type, out list))
            {
                result = list;
                return(true);
            }

            switch (type)
            {
            case ExpressionSectionType.Month:
                MonthExpressionSection month;
                if (!MonthExpressionSection.TryParse(s, out month))
                {
                    return(false);
                }
                result = month;
                return(true);

            case ExpressionSectionType.DayOfWeek:
                DayOfWeekExpressionSection dayOfWeek;
                if (DayOfWeekExpressionSection.TryParse(s, out dayOfWeek))
                {
                    result = dayOfWeek;
                    return(true);
                }
                SpecifiedWeekAndWeekDayExpressionSection specifiedDayAndWeekDay;
                if (SpecifiedWeekAndWeekDayExpressionSection.TryParse(s, out specifiedDayAndWeekDay))
                {
                    result = specifiedDayAndWeekDay;
                    return(true);
                }
                goto default;

            case ExpressionSectionType.DayOfMonth:
                LastDayOfMonthExpressionSection lastDayOfMonth;
                if (LastDayOfMonthExpressionSection.TryParse(s, out lastDayOfMonth))
                {
                    result = lastDayOfMonth;
                    return(true);
                }
                NearestWeekdayExpressionSection nearestWeekDay;
                if (NearestWeekdayExpressionSection.TryParse(s, out nearestWeekDay))
                {
                    result = nearestWeekDay;
                    return(true);
                }
                LastWeekDayOfMonthExpressionSection lastWeekDay;
                if (LastWeekDayOfMonthExpressionSection.TryParse(s, out lastWeekDay))
                {
                    result = lastWeekDay;
                    return(true);
                }
                goto default;

            default:
                SimpleExpressionSection simple;
                if (!SimpleExpressionSection.TryParse(s, type, out simple))
                {
                    return(false);
                }
                result = simple;
                return(true);
            }
        }
Ejemplo n.º 7
0
 static private bool DaySectionsConflict(ExpressionSectionBase dayOfWeek, ExpressionSectionBase dayOfMonth)
 {
     if (dayOfWeek is IgnoreExpressionSection) return dayOfMonth is IgnoreExpressionSection;
     if (dayOfMonth is IgnoreExpressionSection) return dayOfWeek is IgnoreExpressionSection;
     return !(dayOfWeek is EveryOccurenceExpressionSection && dayOfMonth is EveryOccurenceExpressionSection);
 }