Exemplo n.º 1
0
        public override async Task <PersistedConfiguration> CollectAsync(IOperationCollectionContext context)
        {
            var scriptName = this.DefaultArgument.AsString();

            if (string.IsNullOrWhiteSpace(scriptName))
            {
                this.LogError("Bad or missing script name.");
                return(null);
            }

            if (context.Simulation)
            {
                this.LogInformation("Executing PowerShell Script...");
                return(null);
            }

            var result = await PSUtil.ExecuteScriptAssetAsync(
                logger : this,
                context : context,
                fullScriptName : scriptName,
                arguments : this.NamedArguments,
                outArguments : this.OutArguments,
                collectOutput : true,
                progressUpdateHandler : (s, e) => this.currentProgress = e,
                executionMode : PsExecutionMode.Collect
                );

            this.collectedConfiguration = new PSPersistedConfiguration(result);
            return(this.collectedConfiguration);
        }
Exemplo n.º 2
0
        public override Task ExecuteAsync(IOperationExecutionContext context)
        {
            if (context.Simulation)
            {
                this.LogInformation("Executing PowerShell Script...");
                return(Complete);
            }

            var fullScriptName = this.DefaultArgument.AsString();

            if (fullScriptName == null)
            {
                this.LogError("Bad or missing script name.");
                return(Complete);
            }

            return(PSUtil.ExecuteScriptAssetAsync(
                       logger: this,
                       context: context,
                       fullScriptName: fullScriptName,
                       arguments: this.NamedArguments,
                       outArguments: this.OutArguments,
                       collectOutput: false,
                       progressUpdateHandler: (s, e) => Interlocked.Exchange(ref this.currentProgress, e)
                       ));
        }