コード例 #1
0
        public void Configure(TemplateChoices choices, ProjectRequest request)
        {
            choices.Options = (choices.Options ?? ((IEnumerable <string>) new string[0]));
            Option option = choices.Selections.Has(this.Name) ? this.FindOption(choices.Selections[this.Name]) : (this.Options.FirstOrDefault((Option x) => choices.Options.Any((string o) => FubuCore.StringExtensions.EqualsIgnoreCase(o, x.Name))) ?? this.Options.First <Option>());

            GenericEnumerableExtensions.AddRange <string>(request.Alterations, option.Alterations);
        }
コード例 #2
0
        public ProjectRequest BuildProjectRequest(TemplateChoices choices)
        {
            if (FubuCore.StringExtensions.IsEmpty(choices.Category))
            {
                throw new Exception("Category is required");
            }
            if (FubuCore.StringExtensions.IsEmpty(choices.ProjectName))
            {
                throw new Exception("ProjectName is required");
            }
            ProjectCategory category = this.FindCategory(choices.Category);

            if (category == null)
            {
                throw new Exception(FubuCore.StringExtensions.ToFormat("Category '{0}' is unknown", new object[]
                {
                    choices.Category
                }));
            }
            ProjectTemplate project = category.FindTemplate(choices.ProjectType);

            if (project == null)
            {
                throw new Exception(FubuCore.StringExtensions.ToFormat("ProjectTemplate '{0}' for category {1} is unknown", new object[]
                {
                    choices.ProjectType,
                    choices.Category
                }));
            }
            return(project.BuildProjectRequest(choices));
        }
コード例 #3
0
        private bool tryResolveSelection(string optionName, TemplateChoices choices)
        {
            OptionSelection selection = (this.Selections ?? ((IList <OptionSelection>) new OptionSelection[0])).FirstOrDefault((OptionSelection x) => x.FindOption(optionName) != null);

            if (selection == null)
            {
                return(false);
            }
            choices.Selections.Fill(selection.Name, optionName);
            return(true);
        }
コード例 #4
0
        public ProjectRequest BuildProjectRequest(TemplateChoices choices)
        {
            ProjectRequest request = new ProjectRequest(choices.ProjectName, this.Template);

            GenericEnumerableExtensions.AddRange <string>(request.Alterations, this.Alterations);
            if (FubuCore.StringExtensions.IsNotEmpty(this.DotNetVersion))
            {
                request.Version = this.DotNetVersion;
            }
            if (choices.Options != null)
            {
                GenericEnumerableExtensions.Each <string>(choices.Options, delegate(string o)
                {
                    Option opt = this.FindOption(o);
                    if (opt == null)
                    {
                        if (!this.tryResolveSelection(o, choices) && opt == null)
                        {
                            throw new Exception(FubuCore.StringExtensions.ToFormat("Unknown option '{0}' for project type {1}", new object[]
                            {
                                o,
                                this.Name
                            }));
                        }
                    }
                    else
                    {
                        GenericEnumerableExtensions.AddRange <string>(request.Alterations, opt.Alterations);
                    }
                });
            }
            if (this.Selections != null)
            {
                GenericEnumerableExtensions.Each <OptionSelection>(this.Selections, delegate(OptionSelection selection)
                {
                    selection.Configure(choices, request);
                });
            }
            choices.Inputs.Each(delegate(string key, string value)
            {
                request.Substitutions.Set(key, value);
            });
            return(request);
        }