示例#1
0
        public override async Task ExecuteAsync(IOperationExecutionContext context)
        {
            int exitCode = await SHUtil.ExecuteScriptAsync(context, new StringReader(this.ScriptText), null, this, this.Verbose, this.OutputLevel, this.ErrorLevel) ?? 0;

            bool exitCodeLogged = false;

            if (!string.IsNullOrWhiteSpace(this.SuccessExitCode))
            {
                var comparator = ExitCodeComparator.TryParse(this.SuccessExitCode);
                if (comparator != null)
                {
                    bool result = comparator.Evaluate(exitCode);
                    if (result)
                    {
                        this.LogInformation($"Script exited with code: {exitCode} (success)");
                    }
                    else
                    {
                        this.LogError($"Script exited with code: {exitCode} (failure)");
                    }

                    exitCodeLogged = true;
                }
            }

            if (!exitCodeLogged)
            {
                this.LogDebug("Script exited with code: " + exitCode);
            }
        }
示例#2
0
        public override async Task <PersistedConfiguration> CollectAsync(IOperationCollectionContext context)
        {
            if (!this.ValidateConfiguration())
            {
                return(null);
            }

            int?exitCode;
            var output = new List <string>();

            using (var scriptReader = this.OpenCollectScript(context))
            {
                exitCode = await SHUtil.ExecuteScriptAsync(
                    context,
                    scriptReader,
                    !string.IsNullOrWhiteSpace(this.CollectScriptAsset)?this.CollectScriptArgs : null,
                    this,
                    this.Verbose,
                    !this.UseExitCode?(Action <string>)
                        (s =>
                {
                    if (!string.IsNullOrWhiteSpace(s))
                    {
                        output.Add(s);
                    }
                }) : null
                    );
            }

            return(new KeyValueConfiguration
            {
                Key = this.ConfigurationKey,
                Value = this.UseExitCode ? exitCode?.ToString() : string.Join(Environment.NewLine, output)
            });
        }
示例#3
0
        public override async Task ExecuteAsync(IOperationExecutionContext context)
        {
            using var scriptReader = SHUtil.OpenScriptAsset(this.ScriptName, this, context);
            if (scriptReader == null)
            {
                return;
            }

            this.ExitCode = await SHUtil.ExecuteScriptAsync(context, scriptReader, this.Arguments, this, this.Verbose, this.OutputLevel, this.ErrorLevel).ConfigureAwait(false);
        }
示例#4
0
 private TextReader OpenConfigureScript(IOperationExecutionContext context)
 {
     if (!string.IsNullOrWhiteSpace(this.ConfigureScriptAsset))
     {
         return(SHUtil.OpenScriptAsset(this.ConfigureScriptAsset, this, context));
     }
     else
     {
         return(new StringReader(this.ConfigureScript));
     }
 }
示例#5
0
        public override async Task ConfigureAsync(IOperationExecutionContext context)
        {
            if (!this.ValidateConfiguration())
            {
                return;
            }

            using (var scriptReader = this.OpenConfigureScript(context))
            {
                await SHUtil.ExecuteScriptAsync(
                    context,
                    scriptReader,
                    !string.IsNullOrWhiteSpace(this.ConfigureScriptAsset)?this.ConfigureScriptArgs : null,
                    this,
                    this.Verbose
                    );
            }
        }