Exemplo n.º 1
0
 public static void SetUnrestrictedExecution(this IShellCommandBuilder pwsh)
 {
     if (Environment.OSVersion.Platform == PlatformID.Win32NT)
     {
         //Only do this on Windows
         //pwsh.AddCommand($"Set-ExecutionPolicy -ExecutionPolicy Unrestricted");
     }
 }
        public void RunProcessVoid(IShellCommandBuilder builder, string invalidExitCodeMessage = "Invalid exit code for process.", int validExitCode = 0)
        {
            var escapedCommand = builder.CreateFinalEscapedCommand(out var args);
            var startInfo      = SetupArgs(escapedCommand, args);
            var exitCode       = runner.Run(startInfo);

            if (exitCode != validExitCode)
            {
                throw new InvalidOperationException($"Invalid exit code '{exitCode}' expected '{validExitCode}'. Message: '{invalidExitCodeMessage}'");
            }
        }
        public JToken RunProcess(IShellCommandBuilder builder, string invalidExitCodeMessage = "Invalid exit code for process.", int validExitCode = 0)
        {
            var runner    = new JsonOutputProcessRunner(this.runner);
            var jsonStart = EscapePwshSingleQuote(runner.JsonStart);
            var jsonEnd   = EscapePwshSingleQuote(runner.JsonEnd);

            var escapedCommand = builder.CreateFinalEscapedCommand(out var args);
            var finalCommand   = $"{escapedCommand};'{jsonStart}';${builder.ResultVariableName};'{jsonEnd}'";
            var startInfo      = SetupArgs(finalCommand, args);
            var exitCode       = runner.Run(startInfo);

            if (exitCode != validExitCode)
            {
                throw new InvalidOperationException($"Invalid exit code '{exitCode}' expected '{validExitCode}'. Message: '{invalidExitCodeMessage}'");
            }
            return(runner.GetResult());
        }
 public PowerShellGooseActionFactory(IPowerShellTaskFactory powerShellTaskFactory, IShellCommandBuilder commandBuilder)
 {
     this.powerShellTaskFactory = powerShellTaskFactory;
     this.commandBuilder = commandBuilder;
 }
 public Task RunProcessVoidAsync(IShellCommandBuilder builder, string invalidExitCodeMessage = "Invalid exit code for process.", int validExitCode = 0)
 {
     return(RunActionAsync(() => RunProcessVoid(builder, invalidExitCodeMessage, validExitCode)));
 }
 public Task <TResult?> RunProcessAsync <TResult>(IShellCommandBuilder builder, string invalidExitCodeMessage = "Invalid exit code for process.", int validExitCode = 0)
 {
     return(RunFuncAsync <TResult?>(() => RunProcess <TResult>(builder, invalidExitCodeMessage, validExitCode)));
 }
        public TResult?RunProcess <TResult>(IShellCommandBuilder builder, string invalidExitCodeMessage = "Invalid exit code for process.", int validExitCode = 0)
        {
            var result = RunProcess(builder, invalidExitCodeMessage, validExitCode);

            return(result.ToObject <TResult>());
        }
 private void Flush()
 {
     _shellCommandBuilder = null;
     _remoteActionBuilder = null;
     _currentStep         = null;
 }
 public IShellCommandBuilder AsShell()
 {
     _shellCommandBuilder = new ShellCommandBuilderImpl(this, _pipelineBuilder);
     _shellCommandBuilder.SetName(_currentStepName);
     return(_shellCommandBuilder);
 }