Beispiel #1
0
        public override async Task <object> ExecuteAsync(CancellationToken cancellationToken)
        {
            using (var runner = new PowerShellScriptRunner {
                DebugLogging = this.DebugLogging, VerboseLogging = this.VerboseLogging
            })
            {
                runner.MessageLogged += (s, e) => this.Log(e.Level, e.Message);
                if (this.LogOutput)
                {
                    runner.OutputReceived += (s, e) => this.LogInformation(e.Output?.ToString());
                }

                var output = new Dictionary <string, RuntimeValue>
                {
Beispiel #2
0
            public async Task <Result> ExecuteAsync(string script, Dictionary <string, RuntimeValue> variables, Dictionary <string, RuntimeValue> parameters, string[] outVariables, string workingDirectory, CancellationToken cancellationToken)
            {
                using var runner = new PowerShellScriptRunner { DebugLogging = this.DebugLogging, VerboseLogging = this.VerboseLogging };
                var outputData = new List <RuntimeValue>();

                runner.MessageLogged += (s, e) => this.MessageLogged?.Invoke(this, e);
                if (this.LogOutput)
                {
                    runner.OutputReceived += (s, e) => this.OutputReceived?.Invoke(this, e);
                }

                var outVariables2 = outVariables.ToDictionary(v => v, v => new RuntimeValue(string.Empty), StringComparer.OrdinalIgnoreCase);

                if (this.CollectOutput)
                {
                    runner.OutputReceived +=
                        (s, e) =>
                    {
                        var output = PSUtil.ToRuntimeValue(e.Output);
                        lock (outputData)
                        {
                            outputData.Add(output);
                        }
                    };
                }

                runner.ProgressUpdate += (s, e) => this.ProgressUpdate?.Invoke(this, e);

                int?exitCode = await runner.RunAsync(script, variables, parameters, outVariables2, workingDirectory, cancellationToken);

                return(new Result
                {
                    ExitCode = exitCode,
                    Output = outputData,
                    OutVariables = outVariables2
                });
            }