コード例 #1
0
 public void Value_Works()
 {
     MonthExpressionSection value = new MonthExpressionSection();
     value.Value = 1;
     Assert.AreEqual(Month.January, value.Month);
     value.Value = 8;
     Assert.AreEqual(Month.August, value.Month);
     value.Month = Month.June;
     Assert.AreEqual(6, value.Value);
 }
コード例 #2
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);
            }
        }
コード例 #3
0
        static public bool TryParse(string s, out MonthExpressionSection result)
        {
            result = default(MonthExpressionSection);
            if (string.IsNullOrEmpty(s))
            {
                return(false);
            }

            int month;

            if (int.TryParse(s, out month))
            {
                if (!ValidateValue(ExpressionSectionType.Month, month))
                {
                    return(false);
                }
            }
            else if (string.Equals("JAN", s, StringComparison.OrdinalIgnoreCase))
            {
                month = 1;
            }
            else if (string.Equals("FEB", s, StringComparison.OrdinalIgnoreCase))
            {
                month = 2;
            }
            else if (string.Equals("MAR", s, StringComparison.OrdinalIgnoreCase))
            {
                month = 3;
            }
            else if (string.Equals("APR", s, StringComparison.OrdinalIgnoreCase))
            {
                month = 4;
            }
            else if (string.Equals("MAY", s, StringComparison.OrdinalIgnoreCase))
            {
                month = 5;
            }
            else if (string.Equals("JUN", s, StringComparison.OrdinalIgnoreCase))
            {
                month = 6;
            }
            else if (string.Equals("JUL", s, StringComparison.OrdinalIgnoreCase))
            {
                month = 7;
            }
            else if (string.Equals("AUG", s, StringComparison.OrdinalIgnoreCase))
            {
                month = 8;
            }
            else if (string.Equals("SEP", s, StringComparison.OrdinalIgnoreCase))
            {
                month = 9;
            }
            else if (string.Equals("OCT", s, StringComparison.OrdinalIgnoreCase))
            {
                month = 10;
            }
            else if (string.Equals("NOV", s, StringComparison.OrdinalIgnoreCase))
            {
                month = 11;
            }
            else if (string.Equals("DEC", s, StringComparison.OrdinalIgnoreCase))
            {
                month = 12;
            }
            else
            {
                return(false);
            }

            result       = new MonthExpressionSection();
            result.Type  = ExpressionSectionType.Month;
            result.Month = (Month)month;
            return(true);
        }
コード例 #4
0
        static public bool TryParse(string s, out MonthExpressionSection result)
        {
            result = default(MonthExpressionSection);
            if (string.IsNullOrEmpty(s)) return false;

            int month;

            if (int.TryParse(s, out month))
            {
                if (!ValidateValue(ExpressionSectionType.Month, month)) return false;
            }
            else if (string.Equals("JAN", s, StringComparison.OrdinalIgnoreCase))
            {
                month = 1;
            }
            else if (string.Equals("FEB", s, StringComparison.OrdinalIgnoreCase))
            {
                month = 2;
            }
            else if (string.Equals("MAR", s, StringComparison.OrdinalIgnoreCase))
            {
                month = 3;
            }
            else if (string.Equals("APR", s, StringComparison.OrdinalIgnoreCase))
            {
                month = 4;
            }
            else if (string.Equals("MAY", s, StringComparison.OrdinalIgnoreCase))
            {
                month = 5;
            }
            else if (string.Equals("JUN", s, StringComparison.OrdinalIgnoreCase))
            {
                month = 6;
            }
            else if (string.Equals("JUL", s, StringComparison.OrdinalIgnoreCase))
            {
                month = 7;
            }
            else if (string.Equals("AUG", s, StringComparison.OrdinalIgnoreCase))
            {
                month = 8;
            }
            else if (string.Equals("SEP", s, StringComparison.OrdinalIgnoreCase))
            {
                month = 9;
            }
            else if (string.Equals("OCT", s, StringComparison.OrdinalIgnoreCase))
            {
                month = 10;
            }
            else if (string.Equals("NOV", s, StringComparison.OrdinalIgnoreCase))
            {
                month = 11;
            }
            else if (string.Equals("DEC", s, StringComparison.OrdinalIgnoreCase))
            {
                month = 12;
            }
            else
            {
                return false;
            }

            result = new MonthExpressionSection();
            result.Type = ExpressionSectionType.Month;
            result.Month = (Month)month;
            return true;
        }