Пример #1
0
        private void SourceChanged(string code)
        {
            var result = _scriptingEngine.Compile(code);

            BuildErrors.Clear();
            if (result.CompilerErrors.Any())
            {
                BuildErrors.AddRange(result.CompilerErrors);
                Status.SetStatus(result.CompilerErrors.First().Text, StatusType.Error);
            }
            else
            {
                Status.SetReady();
            }
        }
Пример #2
0
        private async Task ExecuteInternalAsync(string code)
        {
            if (IsExecuting)
            {
                return;
            }
            IsExecuting = true;

            ExecutionResult = new ExecutionResultViewModel();

            try
            {
                ConsoleOutput.Output.Clear();

                if (string.IsNullOrWhiteSpace(code))
                {
                    ExecutionResult = new ExecutionResultViewModel
                    {
                        Message = "Nothing to execute",
                        Type    = ExecutionResultType.Warning
                    };
                    Status.SetReady();

                    return;
                }

                Status.SetInfo("Executing...");

                _cancellationToken = new CancellationTokenSource();
                var result = await _scriptingEngine.ExecuteAsync(code);

                if (result.CompilerErrors.Any())
                {
                    BuildErrors.Clear();
                    BuildErrors.AddRange(result.CompilerErrors);
                    Status.SetStatus(result.CompilerErrors.First().Text, StatusType.Error);
                }
                else
                {
                    var message = ConsoleOutput.Output.ToString();
                    message += result.ReturnValue == null ? "** no results from the execution **" : result.ReturnValue.ToString();

                    Status.SetInfo("Executed");
                    ExecutionResult = new ExecutionResultViewModel
                    {
                        Message = message,
                        Type    = ExecutionResultType.Success
                    };
                }
            }
            catch (OperationCanceledException)
            {
                _cancellationToken = null;
                ExecutionResult    = new ExecutionResultViewModel
                {
                    Message = "...",
                    Type    = ExecutionResultType.Warning
                };
                Status.SetStatus("Execution stopped", StatusType.Error);
            }
            catch (Exception e)
            {
                _cancellationToken = null;
                ExecutionResult    = new ExecutionResultViewModel
                {
                    Message = e.ToString(),
                    Type    = ExecutionResultType.Error
                };
                Status.SetStatus("Failed", StatusType.Error);
            }
            finally
            {
                IsExecuting        = false;
                _cancellationToken = null;
            }
        }