Ejemplo n.º 1
0
        static public bool TryParse(string s, out DayOfWeekExpressionSection result)
        {
            result = default(DayOfWeekExpressionSection);

            int dayOfWeek;

            if (int.TryParse(s, out dayOfWeek))
            {
                if (!ValidateValue(ExpressionSectionType.DayOfWeek, dayOfWeek))
                {
                    return(false);
                }
            }
            else if (string.Equals("SUN", s, StringComparison.OrdinalIgnoreCase))
            {
                dayOfWeek = 0;
            }
            else if (string.Equals("MON", s, StringComparison.OrdinalIgnoreCase))
            {
                dayOfWeek = 1;
            }
            else if (string.Equals("TUE", s, StringComparison.OrdinalIgnoreCase))
            {
                dayOfWeek = 2;
            }
            else if (string.Equals("WED", s, StringComparison.OrdinalIgnoreCase))
            {
                dayOfWeek = 3;
            }
            else if (string.Equals("THU", s, StringComparison.OrdinalIgnoreCase))
            {
                dayOfWeek = 4;
            }
            else if (string.Equals("FRI", s, StringComparison.OrdinalIgnoreCase))
            {
                dayOfWeek = 5;
            }
            else if (string.Equals("SAT", s, StringComparison.OrdinalIgnoreCase))
            {
                dayOfWeek = 6;
            }
            else if (string.Equals("L", s, StringComparison.OrdinalIgnoreCase))
            {
                dayOfWeek = 6;
            }
            else
            {
                return(false);
            }

            result       = new DayOfWeekExpressionSection();
            result.Type  = ExpressionSectionType.DayOfWeek;
            result.Value = dayOfWeek;
            return(true);
        }
        static public bool TryParse(string s, out DayOfWeekExpressionSection result)
        {
            result = default(DayOfWeekExpressionSection);

            int dayOfWeek;

            if (int.TryParse(s, out dayOfWeek))
            {
                if (!ValidateValue(ExpressionSectionType.DayOfWeek, dayOfWeek)) return false;
            }
            else if (string.Equals("SUN", s, StringComparison.OrdinalIgnoreCase))
            {
                dayOfWeek = 0;
            }
            else if (string.Equals("MON", s, StringComparison.OrdinalIgnoreCase))
            {
                dayOfWeek = 1;
            }
            else if (string.Equals("TUE", s, StringComparison.OrdinalIgnoreCase))
            {
                dayOfWeek = 2;
            }
            else if (string.Equals("WED", s, StringComparison.OrdinalIgnoreCase))
            {
                dayOfWeek = 3;
            }
            else if (string.Equals("THU", s, StringComparison.OrdinalIgnoreCase))
            {
                dayOfWeek = 4;
            }
            else if (string.Equals("FRI", s, StringComparison.OrdinalIgnoreCase))
            {
                dayOfWeek = 5;
            }
            else if (string.Equals("SAT", s, StringComparison.OrdinalIgnoreCase))
            {
                dayOfWeek = 6;
            }
            else if (string.Equals("L", s, StringComparison.OrdinalIgnoreCase))
            {
                dayOfWeek = 6;
            }
            else
            {
                return false;
            }

            result = new DayOfWeekExpressionSection();
            result.Type = ExpressionSectionType.DayOfWeek;
            result.Value = dayOfWeek;
            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);
            }
        }