示例#1
0
        protected override ScriptExecution PrepareExecution(Script script, CalamariVariableDictionary variables,
            Dictionary<string, string> environmentVars = null)
        {
            var workingDirectory = Path.GetDirectoryName(script.File);

            var executable = PowerShellBootstrapper.PathToPowerShellExecutable();
            var bootstrapFile = PowerShellBootstrapper.PrepareBootstrapFile(script, variables);
            var debuggingBootstrapFile = PowerShellBootstrapper.PrepareDebuggingBootstrapFile(script);
            var arguments =
                PowerShellBootstrapper.FormatCommandArguments(bootstrapFile, debuggingBootstrapFile, variables);

            var userName = variables.Get(SpecialVariables.Action.PowerShell.UserName);
            var password = ToSecureString(variables.Get(SpecialVariables.Action.PowerShell.Password));

            return new ScriptExecution(
                new CommandLineInvocation(
                    executable,
                    arguments,
                    workingDirectory,
                    environmentVars,
                    userName,
                    password),
                new[] {bootstrapFile, debuggingBootstrapFile}
            );
        }
        public CommandResult Execute(
            Script script,
            CalamariVariableDictionary variables,
            ICommandLineRunner commandLineRunner,
            StringDictionary environmentVars = null)
        {
            var workingDirectory = Path.GetDirectoryName(script.File);

            var executable             = PowerShellBootstrapper.PathToPowerShellExecutable();
            var bootstrapFile          = PowerShellBootstrapper.PrepareBootstrapFile(script, variables);
            var debuggingBootstrapFile = PowerShellBootstrapper.PrepareDebuggingBootstrapFile(script);
            var arguments = PowerShellBootstrapper.FormatCommandArguments(bootstrapFile, debuggingBootstrapFile, variables);

            var userName = variables.Get(SpecialVariables.Action.PowerShell.UserName);
            var password = ToSecureString(variables.Get(SpecialVariables.Action.PowerShell.Password));

            using (new TemporaryFile(bootstrapFile))
            {
                using (new TemporaryFile(debuggingBootstrapFile))
                {
                    var invocation = new CommandLineInvocation(
                        executable,
                        arguments,
                        workingDirectory,
                        environmentVars,
                        userName,
                        password);
                    return(commandLineRunner.Execute(invocation));
                }
            }
        }