示例#1
0
 /// <summary>
 /// Shows the errors found during compilation and execution in the Error Page view.
 /// This function is called by <see cref="CompileButton_Click(object, RoutedEventArgs)"/> when
 /// errors are found.
 /// </summary>
 private void SetErrorsInUI()
 {
     Utilities.errorsInLines.Clear();
     foreach (UserControl element in BlocksWithErrorsInOrder)
     {
         Utilities.SetUserControlWithError(element, Utilities.BlockToLineErrors[element].Item2);
         var errorTemplate = new ErrorTemplate();
         errorTemplate.FillTemplate(element, Utilities.BlockToLineErrors[element].Item1, Utilities.BlockToLineErrors[element].Item2);
         Utilities.errorsInLines.Add(errorTemplate);
     }
 }
示例#2
0
        /// <summary>
        /// This event is invoked when the user clicks the Run button.
        /// Saves the original state of the Canvas, signals the Virtual Machine to start execution,
        /// handles errors that arise on execution, prints and resets memory when execution completes,
        /// and returns the Canvas back to its original state.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void Run_Button_Click(object sender, RoutedEventArgs e)
        {
            List <Tuple <int, int, int, int, int, int, string> > assetValues = new List <Tuple <int, int, int, int, int, int, string> >();

            foreach (UIElement child in MainCanvas.Children)
            {
                Asset c = child as Asset;
                assetValues.Add(new Tuple <int, int, int, int, int, int, string>(
                                    c.GetX(), c.GetY(), c.GetWidth(), c.GetHeight(), c.GetRotation(), c.GetNumber(), c.GetLabel()));
            }

            try {
                Utilities.DisableRunAndCompileButtons();
                Run_Button.IsEnabled = Utilities.RunButtonEnabled;
                await VirtualMachine.Execute();
            }
            catch (Exception ex)
            {
                var           errorTemplate = new ErrorTemplate();
                List <string> pseudoList    = new List <string>();
                pseudoList.Add(ex.Message);

                // add error to error list
                errorTemplate.FillTemplate(null, pseudoList, Utilities.GetRandomBrushForErrors());

                Utilities.errorsInLines.Add(errorTemplate);

                Utilities.vmExecuting = false;
                Utilities.BlueCompile();

                // restart instruction pointer
                VirtualMachine.currentInstruction = 0;

                Utilities.ChangePageHeader("Errors");
                this.Frame.Navigate((typeof(ErrorView)));
            }

            MemoryManager.PrintMemory(); // Print memory with all of its values set
            MemoryManager.RunReset();    // Reset memory to its original state before execution

            int attrCount = Enum.GetNames(typeof(MemoryManager.AssetAttributes)).Length;

            // Return assets in canvas to their original state before execution
            for (int i = 0; i < MainCanvas.Children.ToList().Count; i++)
            {
                Asset c = MainCanvas.Children[i] as Asset;

                MemoryManager.SetMemory((int)MemoryManager.AssetAttributes.x + (i * attrCount), assetValues[i].Item1);
                MemoryManager.SetMemory((int)MemoryManager.AssetAttributes.y + (i * attrCount), assetValues[i].Item2);
                c.SetPositionNoAwait(assetValues[i].Item1, assetValues[i].Item2);

                MemoryManager.SetMemory((int)MemoryManager.AssetAttributes.width + (i * attrCount), assetValues[i].Item3);
                MemoryManager.SetMemory((int)MemoryManager.AssetAttributes.height + (i * attrCount), assetValues[i].Item4);
                c.SetWidthNoAnimation(assetValues[i].Item3);
                c.SetHeightNoAnimation(assetValues[i].Item4);

                MemoryManager.SetMemory((int)MemoryManager.AssetAttributes.rotation + (i * attrCount), 0);
                c.SetRotationNoAnimation(0);

                MemoryManager.SetMemory((int)MemoryManager.AssetAttributes.number + (i * attrCount), assetValues[i].Item6);
                c.SetNumberNoWait(assetValues[i].Item6);

                MemoryManager.SetMemory((int)MemoryManager.AssetAttributes.label + (i * attrCount), assetValues[i].Item7);
                c.SetLabelNoWait(assetValues[i].Item7);
            }

            System.Threading.Thread.Sleep(500);

            Utilities.EnableRunAndCompileButtons();
            Run_Button.IsEnabled = Utilities.RunButtonEnabled;
        }