Exemple #1
0
        internal Task ExecuteAsync(IInteractiveWindow interactiveWindow, string title)
        {
            if (GetProjectProperties(out var references, out var referenceSearchPaths, out var sourceSearchPaths, out var projectNamespaces, out var projectDirectory, out var platform))
            {
                // Now, we're going to do a bunch of async operations.  So create a wait
                // indicator so the user knows something is happening, and also so they cancel.
                var waitIndicator = GetWaitIndicator();
                var waitContext   = waitIndicator.StartWait(title, InteractiveEditorFeaturesResources.Building_Project, allowCancel: true, showProgress: false);

                var resetInteractiveTask = ResetInteractiveAsync(
                    interactiveWindow,
                    references,
                    referenceSearchPaths,
                    sourceSearchPaths,
                    projectNamespaces,
                    projectDirectory,
                    platform,
                    waitContext);

                // Once we're done resetting, dismiss the wait indicator and focus the REPL window.
                return(resetInteractiveTask.SafeContinueWith(
                           _ =>
                {
                    waitContext.Dispose();
                    ExecutionCompleted?.Invoke(this, new EventArgs());
                },
                           TaskScheduler.FromCurrentSynchronizationContext()));
            }

            return(Task.CompletedTask);
        }
        private void RaiseExecutionCompleted(string file, uint[] lines, bool isStepping, BreakState breakState)
        {
            var args = new ExecutionCompletedEventArgs(file, lines, isStepping);

            ExecutionCompleted?.Invoke(this, args);
            _breakLineTagger.OnExecutionCompleted(args);
            BreakEntered(this, breakState);
        }
        public Completion Execute(Class m)
        {
            _current = m;
            if (_current == null)
            {
                return(null);
            }
            Completion c = Completion.Void;

            foreach (var func in _current.Functions)
            {
                if ("main".Equals(func.Format, StringComparison.OrdinalIgnoreCase))
                {
                    foreach (var v in _current.Variables)
                    {
                        RegisterValue(v.Name, v.Value);
                    }
                    var parameter = func.Params;
                    ExecutionEnvironment current = new ExecutionEnvironment(this);
                    ExecutionStarted?.Invoke(this, null);
                    foreach (var p in parameter)
                    {
                        current.RegisterValue(p.Name, null);
                    }
                    try
                    {
                        IsCompleted = false;
                        c           = func.Execute(current);
                        break;
                    }catch (Exception e)
                    {
                        IsCompleted = true;
                        Console.WriteLine(e.Message);
                        Console.WriteLine(e.StackTrace);
                        ExecutionAborted?.Invoke(this, new Completion(e.Message, CompletionType.Exception));
                        return(Completion.Void);
                    }
                }
            }
            IsCompleted = true;
            if (c.Type == CompletionType.Value)
            {
                ExecutionCompleted?.Invoke(this, c);
            }
            else if (c.Type == CompletionType.Exception)
            {
                ExecutionAborted?.Invoke(this, c);
            }
            else
            {
                ExecutionAborted?.Invoke(this, Completion.Exception("Unknown exception", null));
            }
            return(c);
        }
Exemple #4
0
        public void ExecuteScript(Node behaviorTree, Entity entity)
        {
            _currentTree       = behaviorTree;
            _currentTree.Owner = entity;

            _executionToken = new CancellationTokenSource();

            Task.Run(() =>
            {
                while (!_executionToken.IsCancellationRequested &&
                       _currentTree.Execute() == ExecutingStatus.Running)
                {
                }
            }, _executionToken.Token).ContinueWith((t) =>
            {
                if (t.IsFaulted)
                {
                    Exception ex = t.Exception;
                    while (ex is AggregateException && ex.InnerException != null)
                    {
                        ex = ex.InnerException;
                    }
                    Log.Write("The script execution failed: " + ex.Message);
                }
                else if (t.IsCanceled)
                {
                    Log.Write("The script execution cancelled !");
                }
                else
                {
                    Log.Write("The script is executed successfully !");
                }

                if (!t.IsFaulted)
                {
                    _currentTree.Deactivate();
                }
                ExecutionCompleted?.Invoke(_currentTree, EventArgs.Empty);
                _currentTree = null;
            }, TaskScheduler.FromCurrentSynchronizationContext());
        }
Exemple #5
0
 private TaskResult RunTask()
 {
     try
     {
         BeforeExecution?.Invoke(this, new JobEventArgs {
             Context = Context
         });
         Context.ExecutionStartedOn = DateTime.UtcNow;
         var result = Context.Task.Run(Context.JobName, Context.ScheduleName, Context.Parameters);
         Context.ExecutionFinishedOn = DateTime.UtcNow;
         ExecutionCompleted?.Invoke(this, new JobEventArgs {
             Context = Context
         });
         return(result);
     }
     catch (Exception e)
     {
         ErrorHandler.HandleException(e);
         return(TaskResult.Aborted);
     }
 }
Exemple #6
0
 protected virtual void OnCompleted()
 {
     ExecutionCompleted?.Invoke(this, EventArgs.Empty);
 }
Exemple #7
0
        /// <summary>
        /// Fires the execution completed event.
        /// </summary>
        private void FireExecutionCompletedEvent()
        {
            Status = EngineStatus.Completed;

            ExecutionCompleted?.Invoke(this, new ExecutionCompletedEventArgs());
        }
Exemple #8
0
        public Completion Execute(Class m)
        {
            IsAborting  = false;
            IsCompleted = false;
            _current    = m;
            if (_current == null)
            {
                return(null);
            }
            Completion           c           = Completion.Void;
            ExecutionEnvironment baseEnv     = this.GetBaseEnvironment();
            ExecutionEnvironment classEnv    = new ExecutionEnvironment(baseEnv);
            ExecutionEnvironment instanceEnv = new ExecutionEnvironment(classEnv);

            foreach (var v in m.Variables)
            {
                instanceEnv.RegisterValue(v.Name, v.Value);
            }
            foreach (var func in _current.Functions)
            {
                if ("main".Equals(func.Name, StringComparison.OrdinalIgnoreCase))
                {
                    var parameter = func.Params;
                    ExecutionEnvironment functionEnv = new ExecutionEnvironment(instanceEnv);
                    ExecutionStarted?.Invoke(this, null);
                    foreach (var p in parameter)
                    {
                        functionEnv.RegisterValue(p.Name, null);
                    }
                    foreach (var block in m.BlockStatements)
                    {
                        foreach (var s in block.Body)
                        {
                            if (s is ExpressionStatement)
                            {
                                Expression exp = (s as ExpressionStatement).Expression;
                                if (exp is VariableDeclarationExpression)
                                {
                                    exp.Execute(instanceEnv);
                                }
                            }
                        }
                    }
                    try
                    {
                        IsCompleted = false;
                        c           = func.Execute(functionEnv);
                        break;
                    }catch (Exception e)
                    {
                        IsCompleted = true;
                        Console.WriteLine(e.Message);
                        Console.WriteLine(e.StackTrace);
                        ExecutionAborted?.Invoke(this, new Completion(e.Message, CompletionType.Exception));
                        return(Completion.Void);
                    }
                }
            }
            IsCompleted = true;
            if (c.Type == CompletionType.Value)
            {
                ExecutionCompleted?.Invoke(this, c);
            }
            else if (c.Type == CompletionType.Exception)
            {
                ExecutionAborted?.Invoke(this, c);
            }
            else
            {
                ExecutionAborted?.Invoke(this, Completion.Exception(Properties.Language.UnknowException, null));
            }
            return(c);
        }