예제 #1
0
        public async Task ExecuteAsync()
        {
            var startTime = DateTime.UtcNow;

            this.ExecutionId            = RompDb.CreateExecution(startTime, Domains.ExecutionStatus.Normal, Domains.ExecutionRunState.Executing, this.Simulation);
            this.DefaultExternalContext = new RompExecutionContext(this);

            this.Executer = new ExecuterThread(new AnonymousBlockStatement(this.plan), this);

            var result = ExecutionStatus.Error;

            try
            {
                await RompSessionVariable.ExpandValuesAsync(this.DefaultExternalContext);

                var targetDir = RompSessionVariable.GetSessionVariable(new RuntimeVariableName("TargetDirectory", RuntimeValueType.Scalar))?.GetValue().AsString();
                if (string.IsNullOrWhiteSpace(targetDir) || !PathEx.IsPathRooted(targetDir))
                {
                    this.Executer.RootLogScope.Log(LogLevel.Error, "Invalid value for $TargetDirectory.");
                    result = ExecutionStatus.Error;
                }
                else
                {
                    PackageInstaller.TargetDirectory = targetDir;
                    DirectoryEx.Create(targetDir);
                    result = await this.Executer.ExecuteAsync();
                }
            }
            catch (Exception ex)
            {
                if (!(ex is ExecutionFailureException))
                {
                    Logger.Log(MessageLevel.Error, "Unhandled exception in executer: " + ex.ToString());
                }

                result = ExecutionStatus.Error;
            }
            finally
            {
                try
                {
                    this.CleanTempDirectory();
                }
                catch
                {
                }

                await this.RootExecutionLog.CompleteAllAsync();

                RompDb.CompleteExecution(
                    executionId: this.ExecutionId.Value,
                    endDate: DateTime.UtcNow,
                    statusCode: result >= ExecutionStatus.Error ? Domains.ExecutionStatus.Error : result >= ExecutionStatus.Warning ? Domains.ExecutionStatus.Warning : Domains.ExecutionStatus.Normal
                    );
            }
        }
예제 #2
0
        public RuntimeValue?TryGetVariableValue(RuntimeVariableName variableName)
        {
            if (variableName == null)
            {
                throw new ArgumentNullException(nameof(variableName));
            }

            var maybeValue = this.executerContext?.GetVariableValue(variableName);

            if (maybeValue != null)
            {
                return(maybeValue);
            }

            return(RompSessionVariable.GetSessionVariable(variableName)?.GetValue());
        }
예제 #3
0
 public Task <IRuntimeVariable> TryGetGlobalVariableAsync(RuntimeVariableName variableName, IExecuterContext context) => Task.FromResult <IRuntimeVariable>(RompSessionVariable.GetSessionVariable(variableName));
예제 #4
0
 public static void SetSessionVariable(string name, RuntimeValue value) => variables[name] = new RompSessionVariable(new RuntimeVariableName(name, value.ValueType), value);