static public bool TryParse(string s, ExpressionSectionType type, out IgnoreExpressionSection result) { result = default(IgnoreExpressionSection); if (string.IsNullOrEmpty(s)) return false; if (!string.Equals("?", s, StringComparison.OrdinalIgnoreCase)) return false; switch (type) { case ExpressionSectionType.DayOfMonth: result = _dayOfMonthInstance; break; case ExpressionSectionType.DayOfWeek: result = _dayOfWeekInstance; break; case ExpressionSectionType.Hour: result = _hourInstance; break; case ExpressionSectionType.Minute: result = _minuteInstance; break; case ExpressionSectionType.Month: result = _monthInstance; break; default: throw new InvalidOperationException(string.Format("Unexpected {0} {1}", typeof(ExpressionSectionType).Name, type)); } return true; }
static public bool TryParse(string s, ExpressionSectionType type, out EveryOccurenceExpressionSection result) { result = null; if (!string.Equals("*", s, StringComparison.OrdinalIgnoreCase)) { return(false); } switch (type) { case ExpressionSectionType.DayOfMonth: result = _dayOfMonthInstance; break; case ExpressionSectionType.DayOfWeek: result = _dayOfWeekInstance; break; case ExpressionSectionType.Hour: result = _hourInstance; break; case ExpressionSectionType.Minute: result = _minuteInstance; break; default: result = _monthInstance; break; } return(true); }
static public bool TryParse(string s, ExpressionSectionType type, out RangeExpressionSection result) { result = default(RangeExpressionSection); if (string.IsNullOrEmpty(s)) return false; string[] parts = s.Split('-'); if (parts.Length != 2) return false; if (string.IsNullOrEmpty(parts[0])) return false; if (parts[0].Contains(",")) return false; if (parts[0].Contains("/")) return false; if (parts[0].Contains("-")) return false; if (parts[0].Contains("?")) return false; ExpressionSectionBase startValue; if (!TryParse(parts[0], type, out startValue)) return false; if (!(startValue is SimpleExpressionSection)) return false; if (string.IsNullOrEmpty(parts[1])) return false; if (parts[1].Contains(",")) return false; if (parts[1].Contains("/")) return false; if (parts[1].Contains("-")) return false; if (parts[1].Contains("?")) return false; ExpressionSectionBase endValue; if (!TryParse(parts[1], type, out endValue)) return false; result = new RangeExpressionSection(); result.Type = type; result.StartValue = startValue as SimpleExpressionSection; result.EndValue = endValue as SimpleExpressionSection; return true; }
static public bool TryParse(string s, ExpressionSectionType type, out ListExpressionSection result) { result = default(ListExpressionSection); if (string.IsNullOrEmpty(s)) return false; string[] parts = s.Split(','); if (parts.Length <= 1) return false; var sections = new List<ExpressionSectionBase>(); foreach (string part in parts) { if (string.IsNullOrEmpty(part)) return false; if (part.Contains(",")) return false; if (part.Contains("/")) return false; if (part.Contains("-")) return false; if (part.Contains("?")) return false; ExpressionSectionBase section; if (!TryParse(part, type, out section)) return false; sections.Add(section); } result = new ListExpressionSection(); result.Type = type; result._sections.AddRange(sections); return true; }
static public bool TryParse(string s, ExpressionSectionType type, out ListExpressionSection result) { result = default(ListExpressionSection); if (string.IsNullOrEmpty(s)) return false; string[] parts = s.Split(','); if (parts.Length <= 1) return false; var sections = new List<ExpressionSectionBase>(); foreach (string part in parts) { if (string.IsNullOrEmpty(part)) return false; if (part.Contains(",")) return false; if (part.Contains("/")) return false; if (part.Contains("-")) return false; if (part.Contains("?")) return false; ExpressionSectionBase section; if (!TryParse(part, type, out section)) return false; sections.Add(section); } result = new ListExpressionSection(); result.Type = type; result._sections.AddRange(sections); return true; }
static public bool TryParse(string s, ExpressionSectionType type, out EveryOccurenceExpressionSection result) { result = null; if (!string.Equals("*", s, StringComparison.OrdinalIgnoreCase)) return false; switch (type) { case ExpressionSectionType.DayOfMonth: result = _dayOfMonthInstance; break; case ExpressionSectionType.DayOfWeek: result = _dayOfWeekInstance; break; case ExpressionSectionType.Hour: result = _hourInstance; break; case ExpressionSectionType.Minute: result = _minuteInstance; break; default: result = _monthInstance; break; } return true; }
static public bool TryParse(string s, ExpressionSectionType type, out RepeatingExpressionSection result) { result = default(RepeatingExpressionSection); if (string.IsNullOrEmpty(s)) return false; string[] parts = s.Split('/'); if (parts.Length != 2) return false; if (string.IsNullOrEmpty(parts[0])) return false; if (parts[0].Contains(",")) return false; if (parts[0].Contains("/")) return false; if (parts[0].Contains("-")) return false; ExpressionSectionBase startValue; if (!TryParse(parts[0], type, out startValue)) return false; if (startValue is EveryOccurenceExpressionSection) { if (!(TryParse("0", type, out startValue))) TryParse("1", type, out startValue); } else if (!(startValue is SimpleExpressionSection)) return false; if (string.IsNullOrEmpty(parts[1])) return false; if (parts[1].Contains(",")) return false; if (parts[1].Contains("/")) return false; if (parts[1].Contains("-")) return false; ExpressionSectionBase frequency; if (!TryParse(parts[1], type, out frequency)) return false; if (!(frequency is SimpleExpressionSection)) return false; result = new RepeatingExpressionSection(); result.Type = type; result.StartValue = startValue as SimpleExpressionSection; result.Frequency = frequency as SimpleExpressionSection; return true; }
static public bool TryParse(string s, ExpressionSectionType type, out SimpleExpressionSection result) { result = default(SimpleExpressionSection); if (string.IsNullOrEmpty(s)) return false; int value; if (!int.TryParse(s, out value)) return false; if (!ValidateValue(type, value)) return false; result = new SimpleExpressionSection(); result.Type = type; result.Value = value; return true; }
static public bool ValidateValue(ExpressionSectionType type, int value) { switch (type) { case ExpressionSectionType.Minute: return value >= 0 && value <= 59; case ExpressionSectionType.Hour: return value >= 0 && value <= 23; case ExpressionSectionType.DayOfMonth: return value >= 1 && value <= 31; case ExpressionSectionType.Month: return value >= 1 && value <= 12; default: return value >= 0 && value <= 7; } }
static public bool TryParse(string s, ExpressionSectionType type, out IgnoreExpressionSection result) { result = default(IgnoreExpressionSection); if (string.IsNullOrEmpty(s)) { return(false); } if (!string.Equals("?", s, StringComparison.OrdinalIgnoreCase)) { return(false); } switch (type) { case ExpressionSectionType.DayOfMonth: result = _dayOfMonthInstance; break; case ExpressionSectionType.DayOfWeek: result = _dayOfWeekInstance; break; case ExpressionSectionType.Hour: result = _hourInstance; break; case ExpressionSectionType.Minute: result = _minuteInstance; break; case ExpressionSectionType.Month: result = _monthInstance; break; default: throw new InvalidOperationException(string.Format("Unexpected {0} {1}", typeof(ExpressionSectionType).Name, type)); } return(true); }
static public bool ValidateValue(ExpressionSectionType type, int value) { switch (type) { case ExpressionSectionType.Minute: return(value >= 0 && value <= 59); case ExpressionSectionType.Hour: return(value >= 0 && value <= 23); case ExpressionSectionType.DayOfMonth: return(value >= 1 && value <= 31); case ExpressionSectionType.Month: return(value >= 1 && value <= 12); default: return(value >= 0 && value <= 7); } }
static public bool TryParse(string s, ExpressionSectionType type, out SimpleExpressionSection result) { result = default(SimpleExpressionSection); if (string.IsNullOrEmpty(s)) { return(false); } int value; if (!int.TryParse(s, out value)) { return(false); } if (!ValidateValue(type, value)) { return(false); } result = new SimpleExpressionSection(); result.Type = type; result.Value = value; return(true); }
static public bool TryParse(string s, ExpressionSectionType type, out RepeatingExpressionSection result) { result = default(RepeatingExpressionSection); if (string.IsNullOrEmpty(s)) { return(false); } string[] parts = s.Split('/'); if (parts.Length != 2) { return(false); } if (string.IsNullOrEmpty(parts[0])) { return(false); } if (parts[0].Contains(",")) { return(false); } if (parts[0].Contains("/")) { return(false); } if (parts[0].Contains("-")) { return(false); } ExpressionSectionBase startValue; if (!TryParse(parts[0], type, out startValue)) { return(false); } if (startValue is EveryOccurenceExpressionSection) { if (!(TryParse("0", type, out startValue))) { TryParse("1", type, out startValue); } } else if (!(startValue is SimpleExpressionSection)) { return(false); } if (string.IsNullOrEmpty(parts[1])) { return(false); } if (parts[1].Contains(",")) { return(false); } if (parts[1].Contains("/")) { return(false); } if (parts[1].Contains("-")) { return(false); } ExpressionSectionBase frequency; if (!TryParse(parts[1], type, out frequency)) { return(false); } if (!(frequency is SimpleExpressionSection)) { return(false); } result = new RepeatingExpressionSection(); result.Type = type; result.StartValue = startValue as SimpleExpressionSection; result.Frequency = frequency as SimpleExpressionSection; return(true); }
static public bool TryParse(string s, ExpressionSectionType type, out RangeExpressionSection result) { result = default(RangeExpressionSection); if (string.IsNullOrEmpty(s)) { return(false); } string[] parts = s.Split('-'); if (parts.Length != 2) { return(false); } if (string.IsNullOrEmpty(parts[0])) { return(false); } if (parts[0].Contains(",")) { return(false); } if (parts[0].Contains("/")) { return(false); } if (parts[0].Contains("-")) { return(false); } if (parts[0].Contains("?")) { return(false); } ExpressionSectionBase startValue; if (!TryParse(parts[0], type, out startValue)) { return(false); } if (!(startValue is SimpleExpressionSection)) { return(false); } if (string.IsNullOrEmpty(parts[1])) { return(false); } if (parts[1].Contains(",")) { return(false); } if (parts[1].Contains("/")) { return(false); } if (parts[1].Contains("-")) { return(false); } if (parts[1].Contains("?")) { return(false); } ExpressionSectionBase endValue; if (!TryParse(parts[1], type, out endValue)) { return(false); } result = new RangeExpressionSection(); result.Type = type; result.StartValue = startValue as SimpleExpressionSection; result.EndValue = endValue as SimpleExpressionSection; 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; } }
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); } }