Beispiel #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);
        }
Beispiel #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());
        }
Beispiel #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);
     }
 }
        protected void Run(SurgeBranchManager branchManager, MessageConnection connection, string cacheDirectory, KeyManager keyManager)
        {
            BranchManager = branchManager;
            Connection    = connection;

            try
            {
                KeyManager = keyManager;

                Started = DateTime.UtcNow;

                if (cacheDirectory != null)
                {
                    ReportMessage(new ExecutionStarted(this));
                }

                this.PostMortemMetaData["ManagedThreadId"] = System.Threading.Thread.CurrentThread.ManagedThreadId.ToString(System.Globalization.CultureInfo.CurrentCulture);

                PrepareSet();

                int iNum = 0;
                while (true)
                {
                    if (_Instructions.Count <= iNum)
                    {
                        break;
                    }

                    if (_Stop)
                    {
                        return;
                    }

                    PrepareSet();

                    _Instructions[iNum].Message = "";
                    _Instructions[iNum].Start   = DateTime.UtcNow;

                    if (_Instructions[iNum].Stage == STEM.Surge.Stage.Skip || _Instructions[iNum].Stage == STEM.Surge.Stage.Completed)
                    {
                        string xml = SerializeWithLimitedRefresh(iNum - 1);

                        if (cacheDirectory != null)
                        {
                            File.WriteAllText(Path.Combine(cacheDirectory, ID.ToString() + ".is"), xml);
                        }

                        _Instructions[iNum].Finish = DateTime.UtcNow;
                        iNum++;
                        continue;
                    }
                    else
                    {
                        string xml = SerializeWithLimitedRefresh(iNum - 1, iNum);

                        if (cacheDirectory != null)
                        {
                            File.WriteAllText(Path.Combine(cacheDirectory, ID.ToString() + ".is"), xml);
                        }
                    }

                    try
                    {
                        _Instructions[iNum].PopulatePostMortemMeta = _Instructions[iNum].PopulatePostMortemMeta && CachePostMortem;
                        _Instructions[iNum].Run();
                    }
                    catch (Exception ex)
                    {
                        _Instructions[iNum].Exceptions.Add(ex);
                        STEM.Sys.EventLog.WriteEntry(ProcessName, ex.ToString(), STEM.Sys.EventLog.EventLogEntryType.Error);
                    }

                    _Instructions[iNum].Finish = DateTime.UtcNow;
                    iNum++;
                }

                SerializeWithLimitedRefresh(iNum - 1, iNum);
            }
            catch (Exception ex)
            {
                STEM.Sys.EventLog.WriteEntry("_InstructionSet.Run", ex.ToString(), STEM.Sys.EventLog.EventLogEntryType.Error);
            }
            finally
            {
                Completed = DateTime.UtcNow;

                _Stop = true;

                if (cacheDirectory != null)
                {
                    try
                    {
                        ExecutionCompleted ec = new ExecutionCompleted(this);
                        foreach (Instruction i in _Instructions)
                        {
                            foreach (Exception e in i.Exceptions)
                            {
                                STEM.Sys.EventLog.WriteEntry(ProcessName, e.ToString(), STEM.Sys.EventLog.EventLogEntryType.Error);
                            }
                        }

                        ReportMessage(ec);
                    }
                    catch (Exception ex)
                    {
                        STEM.Sys.EventLog.WriteEntry("_InstructionSet.Run", ex.ToString(), STEM.Sys.EventLog.EventLogEntryType.Error);
                    }
                }

                bool error = false;
                try
                {
                    foreach (Instruction i in _Instructions)
                    {
                        if (i.Exceptions.Count > 0)
                        {
                            error = true;
                            break;
                        }
                    }
                }
                catch (Exception ex)
                {
                    STEM.Sys.EventLog.WriteEntry("InstructionSet.Run", ex.ToString(), STEM.Sys.EventLog.EventLogEntryType.Error);
                }

                if (branchManager != null)
                {
                    try
                    {
                        branchManager.EndRun(this, error);
                    }
                    catch (Exception ex)
                    {
                        STEM.Sys.EventLog.WriteEntry("InstructionSet.Run", ex.ToString(), STEM.Sys.EventLog.EventLogEntryType.Error);
                    }
                }

                Dispose();
            }
        }
Beispiel #7
0
 protected virtual void OnCompleted()
 {
     ExecutionCompleted?.Invoke(this, EventArgs.Empty);
 }
Beispiel #8
0
        /// <summary>
        /// Fires the execution completed event.
        /// </summary>
        private void FireExecutionCompletedEvent()
        {
            Status = EngineStatus.Completed;

            ExecutionCompleted?.Invoke(this, new ExecutionCompletedEventArgs());
        }
Beispiel #9
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);
        }