/// <summary> /// Do nothing in this method as functions are not directly executed. /// </summary> public override bool Execute(ICanceller canceller) { if (canceller.ShouldCancel()) { return false; } return true; }
/// <summary> /// If commands are conditionally executed. /// </summary> public override bool Execute(ICanceller canceller) { if (canceller.ShouldCancel()) { return false; } var shouldContinue = true; if (ExpressionComparerHelper.CheckCondition(Lhs, Operator, Rhs)) { shouldContinue = base.Execute(canceller); } return shouldContinue; }
/// <summary> /// Repeat commands are executed a fixed number of time. /// </summary> public override bool Execute(ICanceller canceller) { if (canceller.ShouldCancel()) { return false; } var shouldContinue = true; for (var iteration = 0; iteration < IterationCount; iteration++) { if (shouldContinue) { shouldContinue = base.Execute(canceller); } else { break; } } return shouldContinue; }
/// <summary> /// Executes the turtle graphics command and all nested commands, overridden in subclasses /// to implemente execution behavior. For example loops and function will behave differently /// </summary> public virtual bool Execute(ICanceller canceller) { if(canceller.ShouldCancel()) { return false; } var shouldContinue = true; if (Attribute != null && Attribute.Type == typeof(TurtleGraphicsCommand)) { ImplementingFunction.Invoke(ExecutionContext, ArgumentValues.Count == 0 ? null : GetTypedArgumentValues()); } else if (Attribute != null && Attribute.Type == typeof(TurtleGraphicsDoFunctionCommand)) { // Do function takes a param array so arguments need to be repackaged. var argumentList = GetTypedArgumentValues(); var invokeList = new object[2]; invokeList[0] = argumentList[0]; var destinationArray = new float[argumentList.Length - 1]; Array.Copy(argumentList, 1, destinationArray, 0, argumentList.Length - 1); invokeList[1] = destinationArray; ImplementingFunction.Invoke(ExecutionContext, invokeList); } foreach (var innerCommand in Commands) { if (shouldContinue) { shouldContinue = innerCommand.Execute(canceller); } else { break; } } return shouldContinue; }