/// <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;
        }
 public TurtleGraphicsExecutionEngine(ITurtleGraphicsLexicalAnalyser textParser,
     ITurtleGraphicsSyntaxAnalyser turtleGraphicsSyntaxAnalyser, ICanceller canceller,
     ITurtleGraphicsRuntime turtleGraphicsRuntime)
 {
     _textParser = textParser;
     _turtleGraphicsSyntaxAnalyser = turtleGraphicsSyntaxAnalyser;
     _canceller = canceller;
     _turtleGraphicsRuntime = turtleGraphicsRuntime;
 }
        /// <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;
        }
        public SilverlightTurtleGraphicsRuntime(ICanceller canceller, Panel drawingSurface, Image turtlePointer, Color[] colors,
            int startForeColorIdx, int startBackColorIdx, TextBox debugWindow, int initialPenWidth, ITurtleViewModel turtleViewModel,
            ScrollViewer screenScroller)
        {
            _canceller = canceller;
            _drawingSurface = drawingSurface;
            _defaultTurtlePointer = turtlePointer;
            _colors = colors;
            _startForeColorIdx = startForeColorIdx;
            _startBackColorIdx = startBackColorIdx;
            _debugWindow = debugWindow;
            _initialPenWidth = initialPenWidth;
            _turtleViewModel = turtleViewModel;
            _screenScroller = screenScroller;
            _drawingSurface.Background = new SolidColorBrush();

            InitialiseStructures();

            SetInitialState();

            SetUpColorConstants();

            SetUpTurtleImageConstants();
        }
 /// <summary>
 /// Halt execution or exit a function.
 /// </summary>
 public override bool Execute(ICanceller canceller)
 {
     return false;
 }
        /// <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;
        }