Beispiel #1
0
        public bool AddStep(string type, string command, string message, string[] stepParams)
        {
            // creat step
            DeploymentModelStepsStep step = new DeploymentModelStepsStep();

            step.Type    = type;
            step.Command = command;
            step.Message = message;

            // add command params to step
            List <DeploymentModelStepsStepCommandParam> commandParams = new List <DeploymentModelStepsStepCommandParam>();

            for (int iString = 0; iString < stepParams.Length;)
            {
                DeploymentModelStepsStepCommandParam commandParam = new DeploymentModelStepsStepCommandParam();
                commandParam.Name          = stepParams[iString++];
                commandParam.ParameterName = stepParams[iString++];
                commandParams.Add(commandParam);
            }

            step.CommandParam = commandParams.ToArray();

            // add step to steps
            return(AddStep(step));
        }
Beispiel #2
0
        private static List <StepInfo> ParseCommandParamsFile(string commandParamsFileName)
        {
            // read command params file
            string commandParamsFileText = File.ReadAllText(commandParamsFileName, Encoding.Default);

            string[] commandParamsLines = commandParamsFileText.Split("\r\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);

            // parse command params
            List <StepInfo> stepInfos = commandParamsLines.Select(commandParamsLine =>
            {
                if (commandParamsLine.StartsWith("Command,"))
                {
                    return(null);
                }

                var commandParamsSplitLine = commandParamsLine.CsvSplit();

                DeploymentModelStepsStep step = new DeploymentModelStepsStep();

                // command string format: <type>:<command>[.<index>]
                // index is used in case we have multiple steps with the same command e.g. Cmdlet:Add-LoadAssembly.1, Cmdlet:Add-LoadAssembly.2 etc.
                string commandString        = commandParamsSplitLine[0];
                string[] commandStringParts = commandString.Split(":".ToCharArray());

                step.Type    = commandStringParts[0];
                step.Command = commandStringParts[1].Split(".".ToCharArray())[0];

                List <DeploymentModelStepsStepCommandParam> commandParams = new List <DeploymentModelStepsStepCommandParam>();
                for (int iCol = 1; iCol < commandParamsSplitLine.Length;)
                {
                    if (string.IsNullOrEmpty(commandParamsSplitLine[iCol]))
                    {
                        break;
                    }

                    DeploymentModelStepsStepCommandParam commandParam = new DeploymentModelStepsStepCommandParam();
                    commandParam.Name          = commandParamsSplitLine[iCol++];
                    commandParam.ParameterName = commandParamsSplitLine[iCol++];
                    commandParams.Add(commandParam);
                }

                step.CommandParam = commandParams.ToArray();

                StepInfo stepInfo      = new StepInfo();
                stepInfo.commandString = commandString;
                stepInfo.step          = step;

                return(stepInfo);
            }
                                                                  ).ToList <StepInfo>();

            stepInfos.RemoveAll(s => s == null); // remove nulls

            return(stepInfos);
        }
        private bool ExecutePS1File(DeploymentModelStepsStep step)
        {
            bool bRet = true;

            Console.WriteLine(step.Message);
            Console.WriteLine("File: " + step.Command);
            try
            {
                string filePath = step.Command;
                if (!Path.IsPathRooted(filePath))
                {
                    filePath = Path.Combine(System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), step.Command);
                }

                Runspace executePs1FileRunspace = Runspace.DefaultRunspace;
                using (Pipeline executePsCmdletPipeline = executePs1FileRunspace.CreateNestedPipeline())
                {
                    Command scriptCommand = new Command(filePath);
                    if (step.CommandParam != null)
                    {
                        for (int i = 0; i < step.CommandParam.Length; i++)
                        {
                            DeploymentModelStepsStepCommandParam param = step.CommandParam[i];
                            String paramValue = GetParamValue(param.ParameterName);
                            if (String.IsNullOrEmpty(param.Name) == true)
                            {
                                scriptCommand.Parameters.Add(null, paramValue);
                            }
                            else
                            {
                                scriptCommand.Parameters.Add(param.Name, paramValue);
                            }
                        }
                    }
                    executePsCmdletPipeline.Error.DataReady  += new EventHandler(Error_DataReadyExecutePsCmdlet);
                    executePsCmdletPipeline.Output.DataReady += new EventHandler(Output_DataReadyExecutePsCmdlet);
                    executePsCmdletPipeline.Commands.Add(scriptCommand);
                    executePsCmdletPipeline.Invoke();
                }
            }
            catch (Exception exc)
            {
                Log(LogType.Error, "Exception while executing PS1 file: " + exc.Message);
                bRet = false;
            }
            return(bRet);
        }
Beispiel #4
0
        private static List<StepInfo> ParseCommandParamsFile(string commandParamsFileName)
        {
            // read command params file
            string commandParamsFileText = File.ReadAllText(commandParamsFileName, Encoding.Default);
            string[] commandParamsLines = commandParamsFileText.Split("\r\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);

            // parse command params
            List<StepInfo> stepInfos = commandParamsLines.Select(commandParamsLine =>
                {
                    if (commandParamsLine.StartsWith("Command,"))
                        return null;

                    var commandParamsSplitLine = commandParamsLine.CsvSplit();

                    DeploymentModelStepsStep step = new DeploymentModelStepsStep();

                    // command string format: <type>:<command>[.<index>]
                    // index is used in case we have multiple steps with the same command e.g. Cmdlet:Add-LoadAssembly.1, Cmdlet:Add-LoadAssembly.2 etc.
                    string commandString = commandParamsSplitLine[0];
                    string[] commandStringParts = commandString.Split(":".ToCharArray());

                    step.Type = commandStringParts[0];
                    step.Command = commandStringParts[1].Split(".".ToCharArray())[0];

                    List<DeploymentModelStepsStepCommandParam> commandParams = new List<DeploymentModelStepsStepCommandParam>();
                    for (int iCol = 1; iCol < commandParamsSplitLine.Length; )
                    {
                        if (string.IsNullOrEmpty(commandParamsSplitLine[iCol]))
                            break;

                        DeploymentModelStepsStepCommandParam commandParam = new DeploymentModelStepsStepCommandParam();
                        commandParam.Name = commandParamsSplitLine[iCol++];
                        commandParam.ParameterName = commandParamsSplitLine[iCol++];
                        commandParams.Add(commandParam);
                    }

                    step.CommandParam = commandParams.ToArray();

                    StepInfo stepInfo = new StepInfo();
                    stepInfo.commandString = commandString;
                    stepInfo.step = step;

                    return stepInfo;
                }
            ).ToList<StepInfo>();

            stepInfos.RemoveAll(s => s == null); // remove nulls

            return stepInfos;
        }
Beispiel #5
0
        public bool AddStep(string type, string command, string message, string[] stepParams)
        {
            // creat step
            DeploymentModelStepsStep step = new DeploymentModelStepsStep();
            step.Type = type;
            step.Command = command;
            step.Message = message;

            // add command params to step
            List<DeploymentModelStepsStepCommandParam> commandParams = new List<DeploymentModelStepsStepCommandParam>();

            for (int iString = 0; iString < stepParams.Length; )
            {
                DeploymentModelStepsStepCommandParam commandParam = new DeploymentModelStepsStepCommandParam();
                commandParam.Name = stepParams[iString++];
                commandParam.ParameterName = stepParams[iString++];
                commandParams.Add(commandParam);
            }

            step.CommandParam = commandParams.ToArray();

            // add step to steps
            return AddStep(step);
        }