public void TryParse_NoMatch7() { RepeatingExpressionSection value; bool result = RepeatingExpressionSection.TryParse("1/9", ExpressionSectionType.DayOfWeek, out value); Assert.False(result); }
public void TryParse_NoMatch6() { RepeatingExpressionSection value; bool result = RepeatingExpressionSection.TryParse("?/1", ExpressionSectionType.DayOfMonth, out value); Assert.False(result); }
public void TryParse_NoMatch5() { RepeatingExpressionSection value; bool result = RepeatingExpressionSection.TryParse("123/1", ExpressionSectionType.Hour, out value); Assert.False(result); }
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; }
public void TryParse_Match1() { RepeatingExpressionSection value; bool result = RepeatingExpressionSection.TryParse("1/2", ExpressionSectionType.Hour, out value); Assert.True(result); var start = value.StartValue as SimpleExpressionSection; Assert.NotNull(start); Assert.AreEqual(1, start.Value); var frequency = value.Frequency as SimpleExpressionSection; Assert.NotNull(frequency); Assert.AreEqual(2, frequency.Value); }
public void TryParse_Match4() { RepeatingExpressionSection value; bool result = RepeatingExpressionSection.TryParse("*/9", ExpressionSectionType.Hour, out value); Assert.True(result); var start = value.StartValue; Assert.NotNull(start); Assert.AreEqual(0, start.Value); var frequency = value.Frequency; Assert.NotNull(frequency); Assert.AreEqual(9, frequency.Value); }
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); }