/// <summary> /// This method returns the Repeat Type /// </summary> public static RepeatTypeEnum SetRepeatType(string text) { // initial value RepeatTypeEnum repeatType = RepeatTypeEnum.NoRepeat; // determine the repeat type by the text if (text.Contains("repeat left")) { // Set the RepeatType repeatType = RepeatTypeEnum.Left; } else if (text.Contains("repeat up")) { // Set the RepeatType repeatType = RepeatTypeEnum.Up; } else if (text.Contains("repeat right")) { // Set the RepeatType repeatType = RepeatTypeEnum.Right; } else if (text.Contains("repeat down")) { // Set the RepeatType repeatType = RepeatTypeEnum.Down; } // return value return(repeatType); }
/// <summary> /// This method returns the text after Repeat Left, Repeat Right, etc. /// </summary> public static string GetRepeatText(string text, RepeatTypeEnum repeatType) { // initial value string repeatText = ""; // local string lineStart = "repeat "; // If the strings text and repeatType both exist if ((TextHelper.Exists(text)) && (repeatType != RepeatTypeEnum.NoRepeat)) { // set the lineStart text lineStart += repeatType.ToString().ToLower(); // if the text was found if (text.Contains(lineStart)) { // get the repeatText repeatText = text.Substring(lineStart.Length).Trim(); } } // return value return(repeatText); }
/// <summary> /// Repeats the provided traversal until the provided condition is met /// </summary> /// <returns>The repeat.</returns> /// <param name="traversal">The sub query to repeat</param> /// <param name="condition">The condition that must be met to end the loop</param> /// <param name="type">Specifies a do-while or while-do loop</param> public Query Repeat <TOutput>(ITraversalQuery <T, TOutput> traversal, ITraversalQuery <T> condition, RepeatTypeEnum type) { if (traversal.Steps.Count < 1) { throw new ArgumentException("Provided traversal must contain at least one step"); } if (condition.Steps.Count < 1) { throw new ArgumentException("Provided condition must have at least one step"); } string until = "until(" + condition.ToString() + ")"; string repeat = "repeat(" + traversal.ToString() + ")"; switch (type) { case RepeatTypeEnum.DoWhile: Steps.Add(repeat + "." + until); break; case RepeatTypeEnum.WhileDo: Steps.Add(until + "." + repeat); break; } return(this as Query); }