Beispiel #1
0
        private static async Task RunPlanAsync(ScopedStatementBlock script, bool simulate)
        {
            if (simulate)
            {
                Console.WriteLine("Running as simulation");
            }

            Console.WriteLine();

            var executer = new RompExecutionEnvironment(script, simulate);

            if (!Console.IsOutputRedirected)
            {
                RompConsoleMessenger.ShowProgress = true;
                using (var done = new CancellationTokenSource())
                {
                    Task consoleTask = null;
                    try
                    {
                        consoleTask = Task.Run(() => RompConsoleMessenger.MonitorStatus(executer, done.Token));
                        await executer.ExecuteAsync();
                    }
                    finally
                    {
                        done.Cancel();
                        try
                        {
                            if (consoleTask != null)
                            {
                                await consoleTask;
                            }
                        }
                        catch
                        {
                        }
                    }
                }
            }
            else
            {
                RompConsoleMessenger.ShowProgress = false;
                await executer.ExecuteAsync();
            }

            var exec = RompDb.GetExecutions()
                       .FirstOrDefault(e => e.ExecutionId == executer.ExecutionId);

            if (exec != null)
            {
                var logs = RompDb.GetExecutionLogs(exec.ExecutionId);
                foreach (var log in logs)
                {
                    log.WriteErrors(Console.Out);
                }

                if (exec.StatusCode == Domains.ExecutionStatus.Normal)
                {
                    RompConsoleMessenger.WriteDirect($"Job #{executer.ExecutionId} completed successfully.", ConsoleColor.White);
                }
                else if (exec.StatusCode == Domains.ExecutionStatus.Warning)
                {
                    RompConsoleMessenger.WriteDirect($"Job #{executer.ExecutionId} completed with warnings.", ConsoleColor.Yellow);
                }
                else
                {
                    RompConsoleMessenger.WriteDirect($"Job #{executer.ExecutionId} encountered an error.", ConsoleColor.Red);
                    throw new RompException("Job execution failed.");
                }

                Console.WriteLine();
            }
            else
            {
                throw new RompException("Execution could not be created.");
            }
        }
Beispiel #2
0
 public RompExecutionEnvironment(ScopedStatementBlock script, bool simulate)
 {
     this.plan                 = script;
     this.Simulation           = simulate;
     this.rootExecutionLogLazy = new Lazy <RompScopedExecutionLog>(() => RompScopedExecutionLog.Create(this.ExecutionId.GetValueOrDefault()));
 }