コード例 #1
0
 public override SingleWorkflowStep Undo()
 {
     var to = DoAllReplaces(To);
     var destinationPath = _setupFile.GetKey("DestinationPath");
     var destinationFile = Path.Combine(destinationPath, to);
     if (_setupFile.Unattended)
     {
         return new DeleteTemplateStep
             {
                 From = destinationFile,
                 Help = string.Format("Delete {0}", destinationFile)
             };
     }
     var varName = Guid.NewGuid().ToString();
     var toret = new AskWorkflowStep
         {
             Help = string.Format("Sould be {0} deleted?", destinationFile),
             For = "YesNo",
             ApplyOn = "${" + varName + "}"
         };
     var ifStep = new IfWorkflowStep
         {
             Value = "${" + varName + "}",
             Is = "true"
         };
     toret.WorkflowSteps.Add(ifStep);
     ifStep.WorkflowSteps.Add(new DeleteTemplateStep
         {
             From = destinationFile
         });
     return toret;
 }
コード例 #2
0
ファイル: AskWorkflowStep.cs プロジェクト: kendarorg/ZakSetup
 private static void DoStepAsk(AskWorkflowStep workflowStep, ref string template)
 {
     //Retrieve the setup config for wich the question is made
     if (!string.IsNullOrEmpty(workflowStep.For) && _setupFile.SetupConfigs.ContainsKey(workflowStep.For))
     {
         HandleMultipleChoices(workflowStep, ref template);
     }
     else
     {
         HandleSpecificValueChoice(workflowStep, ref template);
     }
 }
コード例 #3
0
ファイル: AskWorkflowStep.cs プロジェクト: kendarorg/ZakSetup
 private static int HandleMultipleAskChoices(AskWorkflowStep workflowStep, int selectedResult, int i)
 {
     var applyOn = GetEnv(workflowStep.ApplyOn);
     if (applyOn != null)
     {
         if (!int.TryParse(applyOn, out selectedResult))
         {
             selectedResult = -1;
         }
     }
     int maxTimes = MAX_RETRY_COUNT;
     while (selectedResult == -1 && maxTimes >= 0)
     {
         Console.WriteLine("Select 0-{0}", (i - 1));
         var result = Console.ReadLine();
         if (!int.TryParse(result, out selectedResult))
         {
             maxTimes--;
             Console.WriteLine("Invalid value, retry!");
             selectedResult = -1;
         }
     }
     if (maxTimes < 0 && selectedResult==-1)
     {
         throw new Exception("Maximum retry count reached.");
     }
     return selectedResult;
 }
コード例 #4
0
ファイル: AskWorkflowStep.cs プロジェクト: kendarorg/ZakSetup
        private static void HandleSpecificValueChoice(AskWorkflowStep workflowStep, ref string template)
        {
            Console.WriteLine(" Insert the value:");
            if (!string.IsNullOrEmpty(workflowStep.Value))
            {
                var possibleDefault = _setupFile.GetKey(workflowStep.Value);
                if (!string.IsNullOrEmpty(possibleDefault) && possibleDefault != workflowStep.Value)
                {
                    workflowStep.Value = possibleDefault;
                }
                workflowStep.Value = DoAllReplaces(workflowStep.Value);
                Console.WriteLine(" Default: {0}", workflowStep.Value);
            }
            string lineRead = GetEnv(workflowStep.ApplyOn);

            if (DEFAULT_VALUE_APPLIED == lineRead)
            {
                lineRead = workflowStep.Value;
            }
            int maxTimes = MAX_RETRY_COUNT;
            while (string.IsNullOrEmpty(lineRead) && maxTimes>=0)
            {
                lineRead = Console.ReadLine();
                if (string.IsNullOrEmpty(lineRead))
                {
                    if (!string.IsNullOrEmpty(workflowStep.Value))
                    {
                        Console.WriteLine("Applying Default");
                        lineRead = workflowStep.Value;
                    }
                    else
                    {
                        maxTimes--;
                        Console.WriteLine("Invalid value, retry!");
                    }
                }
            }
            if (maxTimes < 0)
            {
                throw new Exception("Maximum retry count reached.");
            }
            if (lineRead == null)
            {
                throw new Exception("No value selected.");
            }
            var selectedValue = lineRead.Trim();
            template = template.Replace(workflowStep.ApplyOn, selectedValue);
            _setupFile.SetKey(workflowStep.ApplyOn, selectedValue);
            string orkey = workflowStep.ApplyOn;
            if (orkey.StartsWith("${"))
            {
                orkey = orkey.Substring(2).TrimEnd('}');
                _setupFile.SetKey(orkey + IfWorkflowStep.TEMPLATE_VALUE, selectedValue);
            }
        }
コード例 #5
0
ファイル: AskWorkflowStep.cs プロジェクト: kendarorg/ZakSetup
        private static void HandleMultipleChoices(AskWorkflowStep workflowStep, ref string template)
        {
            var configFor = _setupFile.SetupConfigs[workflowStep.For];

            int i;
            for (i = 0; i < configFor.SetupChoices.Count; i++)
            {
                var setupChoice = configFor.SetupChoices[i];
                Console.Write("-{0}: {1}", i, setupChoice.Value);
                if (!string.IsNullOrEmpty(setupChoice.Help))
                    Console.WriteLine(" ({0})", setupChoice.Help);
                else
                    Console.WriteLine("");
            }

            int selectedResult = -1;
            if (configFor.SetupChoices.Count > 1)
            {
                selectedResult = HandleMultipleAskChoices(workflowStep, selectedResult, i);
            }
            else
            {
                if (!int.TryParse(configFor.Default, out selectedResult))
                {
                    selectedResult = 0;
                }
                Console.WriteLine("Selecting default!");
            }
            var selectedConfig = configFor.SetupChoices[selectedResult];

            string orkey = workflowStep.ApplyOn;
            if (orkey.StartsWith("${"))
            {
                orkey = orkey.Substring(2).TrimEnd('}');
            }

            if (selectedConfig.IsNull)
            {
                template = template.Replace("${" + workflowStep.ApplyOn + "}", string.Empty);
                _setupFile.SetKey(workflowStep.ApplyOn, string.Empty);
                _setupFile.SetKey(orkey + IfWorkflowStep.TEMPLATE_VALUE, string.Empty);
            }
            else if (configFor.ConfigType == ConfigTypes.Value)
            {
                template = template.Replace("${" + workflowStep.ApplyOn + "}", selectedConfig.Value);
                _setupFile.SetKey(workflowStep.ApplyOn, selectedConfig.Value);
                _setupFile.SetKey(orkey + IfWorkflowStep.TEMPLATE_VALUE, selectedConfig.Value);
            }
            else
            {
                var newTemplate = _setupFile.SetupTemplates[selectedConfig.Value].Content;
                foreach (var step in selectedConfig.WorkflowSteps)
                {
                    _setupFile.AddUndo(step.Undo());
                    step.Execute(ref newTemplate);
                }

                newTemplate = DoAllReplaces(newTemplate);
                template = template.Replace("${" + workflowStep.ApplyOn + "}", newTemplate);
                _setupFile.SetKey(workflowStep.ApplyOn, newTemplate);
                _setupFile.SetKey(orkey + IfWorkflowStep.TEMPLATE_VALUE, selectedConfig.Value);
            }
        }
コード例 #6
0
        public static SingleWorkflowStep CreateStep(XmlNode node)
        {
            SingleWorkflowStep toret = null;
            string workflowType = node.Name.ToUpperInvariant();
            switch (workflowType)
            {
                case ("IF"):
                    {
                        toret = new IfWorkflowStep
                        {
                            Help = node.GetAttribute("help"),
                            Is = node.GetAttribute("is"),
                            Value = node.GetAttribute("value"),
                            MustBeTrue = node.IsAttributeSet("not") == false
                        };
                    }
                    break;
                case ("DOWHILE"):
                    {
                        toret = new DoWhileStep
                        {
                            Help = node.GetAttribute("help"),
                            Is = node.GetAttribute("is"),
                            Value = node.GetAttribute("value"),
                            MustBeTrue = node.IsAttributeSet("not") == false
                        };
                    }
                    break;
                case ("DELETE"):
                    {
                        toret = new DeleteWorkflowStep
                        {
                            Help = node.GetAttribute("help"),
                            From = node.GetAttribute("from")
                        };
                    }
                    break;
                case ("DELETETEMPLATE"):
                    {
                        toret = new DeleteTemplateStep
                        {
                            From = node.GetAttribute("from")
                        };
                    }
                    break;
                case ("ASK"):
                    {
                        toret = new AskWorkflowStep
                        {
                            Help = node.GetAttribute("help"),
                            For = node.GetAttribute("for"),
                            ApplyOn = node.GetAttribute("applyOn"),
                            Value = node.GetAttribute("value")
                        };
                    }
                    break;
                case ("COPY"):
                    {
                        toret = new CopyWorkflowStep
                        {
                            Help = node.GetAttribute("help"),
                            From = node.GetAttribute("from"),
                            To = node.GetAttribute("to"),
                            What = node.GetAttribute("what")
                        };

                    }
                    break;
                case ("TELL"):
                    {
                        toret = new TellWorkflowStep
                        {
                            Help = node.GetAttribute("help"),
                            ApplyOn = node.GetAttribute("applyOn"),
                            Value = node.GetAttribute("value")
                        };
                    }
                    break;
                case ("WRITETEMPLATE"):
                    {
                        toret = new WriteTemplateStep
                        {
                            Help = node.GetAttribute("help"),
                            To = node.GetAttribute("to"),
                            Template = node.GetAttribute("template")
                        };
                    }
                    break;
                case ("PARAM"):
                    {
                        toret = new ParamStep
                        {
                            Name = node.GetAttribute("name"),
                            Value = node.GetAttribute("value")
                        };
                    }
                    break;
                case ("SWITCH"):
                    {
                        toret = new SwitchWorkflowStep
                        {
                            Value = node.GetAttribute("value")
                        };
                    }
                    break;
                case ("CASE"):
                    {
                        toret = new CaseWorkflowStep
                        {
                            Value = node.GetAttribute("value")
                        };
                    }
                    break;
                case ("INCLUDE"):
                    {
                        toret = new IncludeStep();
                    }
                    break;
                default:
                    foreach (var factory in _factories)
                    {
                        toret = factory.Value.Create(workflowType, node);
                        if (toret != null) break;
                    }
                    break;
            }

            return toret;
        }