public ProjectTemplateCategorizer (IEnumerable<TemplateCategory> categories, Predicate<SolutionTemplate> templateMatch) { this.categories = categories.Select (category => category.Clone ()).ToList (); this.templateMatch = templateMatch; PopulateMappedCategories (); defaultCategory = GetDefaultCategory (); }
public void GetCategorizedTemplates_TwoTemplatesWithGroupCondition_TemplateFilteredUsingTemplateParameters() { CreateCategories("android", "app", "general"); CreateCategorizer(); SolutionTemplate template1 = AddTemplate("template-id1", "android/app/general"); template1.GroupId = "console"; template1.Language = "C#"; template1.Condition = "Device=IPhone"; SolutionTemplate template2 = AddTemplate("template-id2", "android/app/general"); template2.GroupId = "console"; template2.Language = "C#"; template2.Condition = "Device=IPad"; ProjectCreateParameters parameters = CreateParameters("Device", "IPad"); CategorizeTemplates(); TemplateCategory generalCategory = categorizedTemplates.First().Categories.First().Categories.First(); SolutionTemplate firstTemplate = generalCategory.Templates.FirstOrDefault(); SolutionTemplate matchedTemplate = firstTemplate.GetTemplate("C#", parameters); parameters.Clear(); SolutionTemplate noMatchedTemplate = firstTemplate.GetTemplate("C#", parameters); Assert.AreEqual(template2, matchedTemplate); Assert.IsNull(noMatchedTemplate); }
TemplateCategory AddTemplateCategory(string categoryName, TemplateCategory parent) { var templateCategory = new TemplateCategory(categoryName, categoryName, "iconid"); parent.AddCategory(templateCategory); return(templateCategory); }
public void GetCategorizedTemplates_CategorizeTwoGroupedConsoleProjectTemplatesMultipleTimes_GroupedTemplatesDoesNotGrow() { CreateCategories("android", "app", "general"); CreateCategorizer(); SolutionTemplate template1 = AddTemplate("template-id1", "android/app/general"); template1.GroupId = "console"; template1.Language = "C#"; SolutionTemplate template2 = AddTemplate("template-id2", "android/app/general"); template2.GroupId = "console"; template2.Language = "F#"; CategorizeTemplates(); // Categorize the templates again after re-creating the categorizer but not // recreating the templates. CreateCategorizer(); CategorizeTemplates(); TemplateCategory generalCategory = categorizedTemplates.First().Categories.First().Categories.First(); SolutionTemplate template = generalCategory.Templates.FirstOrDefault(); int templateCount = 0; template.GetTemplate(t => { templateCount++; return(false); }); Assert.AreEqual(2, templateCount); }
public void GetCategorizedTemplates_TwoTemplatesWithGroupCondition_CanGetTemplateMatchingConditionFromAnyGroupedTemplate() { CreateCategories("android", "app", "general"); CreateCategorizer(); SolutionTemplate template1 = AddTemplate("template-id1", "android/app/general"); template1.GroupId = "console"; template1.Language = "C#"; template1.Condition = "Device=IPhone"; SolutionTemplate template2 = AddTemplate("template-id2", "android/app/general"); template2.GroupId = "console"; template2.Language = "C#"; template2.Condition = "Device=IPad"; ProjectCreateParameters ipadParameters = CreateParameters("Device", "IPad"); ProjectCreateParameters iphoneParameters = CreateParameters("Device", "IPhone"); CategorizeTemplates(); TemplateCategory generalCategory = categorizedTemplates.First().Categories.First().Categories.First(); SolutionTemplate firstTemplate = generalCategory.Templates.FirstOrDefault(); SolutionTemplate matchedIPadTemplate = firstTemplate.GetTemplate("C#", ipadParameters); SolutionTemplate matchedIPhoneTemplate = firstTemplate.GetTemplate("C#", iphoneParameters); Assert.AreEqual(template2, matchedIPadTemplate); Assert.AreEqual(template1, matchedIPhoneTemplate); Assert.AreEqual(template2, matchedIPadTemplate.GetTemplate("C#", ipadParameters)); Assert.AreEqual(template1, matchedIPadTemplate.GetTemplate("C#", iphoneParameters)); }
TemplateCategory GetCategory(SolutionTemplate template, IEnumerable <TemplateCategory> currentCategories) { TemplateCategory match = null; match = GetMappedCategory(template); if (match != null) { return(match); } var path = new TemplateCategoryPath(template.Category); foreach (string part in path.GetParts()) { match = currentCategories.FirstOrDefault(category => category.IsMatch(part)); if (match != null) { currentCategories = match.Categories; } else { return(null); } } return(match); }
public ProjectTemplateCategorizer(IEnumerable <TemplateCategory> categories, Predicate <SolutionTemplate> templateMatch) { this.categories = categories.Select(category => category.Clone()).ToList(); this.templateMatch = templateMatch; PopulateMappedCategories(); defaultCategory = GetDefaultCategory(); }
void CreateCategories(string topLevelCategoryName, string secondLevelCategoryName, string thirdLevelCategoryName) { TemplateCategory topLevelCategory = AddTemplateCategory(topLevelCategoryName); TemplateCategory secondLevelCategory = AddTemplateCategory(secondLevelCategoryName, topLevelCategory); AddTemplateCategory(thirdLevelCategoryName, secondLevelCategory); }
void AddMappedCategory(TemplateCategory category) { foreach (string mappedCategory in category.MappedCategories.Split(new [] { ';' }, StringSplitOptions.RemoveEmptyEntries)) { mappedCategories.Add(mappedCategory, category); } }
TemplateCategory AddTemplateCategory(string categoryName) { var templateCategory = new TemplateCategory(categoryName, categoryName, "iconid"); categories.Add(templateCategory); return(templateCategory); }
public void GetCategorizedTemplates_OneTemplateOneCategoryWithGroupConditionHavingMultipleParameterConditionsSeparatedByComma_TemplateFilteredUsingAllParametersInCondition() { CreateCategories("android", "app", "general"); CreateCategorizer(); SolutionTemplate template = AddTemplate("template-id", "android/app/general"); template.GroupId = "console"; template.Language = "C#"; template.Condition = "Device=MyDevice,SupportsSizeClasses=true"; ProjectCreateParameters parameters = CreateParameters("Device", "MyDevice"); parameters ["SupportsSizeClasses"] = true.ToString(); CategorizeTemplates(); TemplateCategory generalCategory = categorizedTemplates.First().Categories.First().Categories.First(); SolutionTemplate firstTemplate = generalCategory.Templates.FirstOrDefault(); SolutionTemplate matchedTemplate = firstTemplate.GetTemplate("C#", parameters); Assert.AreEqual(template, matchedTemplate); parameters = CreateParameters("Device", "MyDevice"); parameters ["SupportsSizeClasses"] = false.ToString(); SolutionTemplate noMatchedTemplate = firstTemplate.GetTemplate("C#", parameters); Assert.IsNull(noMatchedTemplate); }
public TemplateCategory ToTemplateCategory () { var category = new TemplateCategory (Id, name, icon); category.MappedCategories = mappedCategories; category.IsDefault = IsDefaultCategory (); AddChildren (category); return category; }
TemplateCategory GetMappedCategory(SolutionTemplate template) { TemplateCategory category = null; if (mappedCategories.TryGetValue(template.Category, out category)) { return(category); } return(null); }
public void GetCategorizedTemplates_OneTemplateOneCategoryWithDefaultNoCategoryMatch_TemplateAddedToDefaultCategory() { CreateCategoriesWithDefaultCategory("Android", "App", "General"); CreateCategorizer(); SolutionTemplate template = AddTemplate("template-id", "unknown-category"); CategorizeTemplates(); TemplateCategory generalCategory = categorizedTemplates.First().Categories.First().Categories.First(); Assert.That(generalCategory.Templates.ToList(), Contains.Item(template)); }
public void GetCategorizedTemplates_OneTemplateOneCategory_TemplateAddedToMatchingCategory() { CreateCategories("android", "app", "general"); CreateCategorizer(); SolutionTemplate template = AddTemplate("template-id", "android/app/general"); CategorizeTemplates(); TemplateCategory generalCategory = categorizedTemplates.First().Categories.First().Categories.First(); Assert.That(generalCategory.Templates.ToList(), Contains.Item(template)); }
public TemplateCategory Clone () { var clone = new TemplateCategory (Id, Name, IconId) { IsDefault = IsDefault, IsTopLevel = IsTopLevel, MappedCategories = MappedCategories }; foreach (TemplateCategory child in categories) { clone.AddCategory (child.Clone ()); } return clone; }
public TemplateCategory Clone() { var clone = new TemplateCategory(Id, Name, IconId) { IsDefault = IsDefault, IsTopLevel = IsTopLevel, MappedCategories = MappedCategories }; foreach (TemplateCategory child in categories) { clone.AddCategory(child.Clone()); } return(clone); }
public void CategorizeTemplates(IEnumerable <SolutionTemplate> templates) { foreach (SolutionTemplate template in GetFilteredTemplates(templates)) { TemplateCategory category = GetCategory(template); if (category != null) { category.AddTemplate(template); } else { LogNoCategoryMatch(template); } } }
public void GetCategorizedTemplates_OneTemplateTwoTopLevelCategories_EmptyTopLevelCategoryIsRemoved() { CreateCategories("android", "app", "general"); CreateCategories("ios", "app", "general"); CreateCategorizer(); SolutionTemplate template = AddTemplate("template-id", "android/app/general"); CategorizeTemplates(); TemplateCategory appCategory = categorizedTemplates.First().Categories.First(); TemplateCategory generalCategory = appCategory.Categories.First(); Assert.That(generalCategory.Templates.ToList(), Contains.Item(template)); Assert.AreEqual(1, categorizedTemplates.Count); Assert.AreEqual(1, appCategory.Categories.Count()); }
TemplateCategory GetCategory(SolutionTemplate template) { TemplateCategory match = GetCategory(template, categories); if (match != null) { return(match); } else if (defaultCategory != null) { LogUsingDefaultCategory(template); return(defaultCategory); } return(null); }
public void GetCategorizedTemplates_TemplateUsesGoogleGlassLegacyCategory_TemplateIsMappedToNewCategories() { TemplateCategory topLevelCategory = AddTemplateCategory("android"); TemplateCategory secondLevelCategory = AddTemplateCategory("app", topLevelCategory); TemplateCategory category = AddTemplateCategory("general", secondLevelCategory); category.MappedCategories = "C#/Glass"; CreateCategorizer(); SolutionTemplate template = AddTemplate("template-id", "C#/Glass"); CategorizeTemplates(); TemplateCategory appCategory = categorizedTemplates.First().Categories.First(); TemplateCategory generalCategory = appCategory.Categories.First(); Assert.That(generalCategory.Templates.ToList(), Contains.Item(template)); }
public void GetCategorizedTemplates_TwoLegacyCategoriesMappedToNewCategory_TemplatesAreMappedToNewCategories() { TemplateCategory topLevelCategory = AddTemplateCategory("android"); TemplateCategory secondLevelCategory = AddTemplateCategory("app", topLevelCategory); TemplateCategory category = AddTemplateCategory("general", secondLevelCategory); category.MappedCategories = "C#/Android;VBNet/Android"; CreateCategorizer(); SolutionTemplate csharpTemplate = AddTemplate("template-id", "C#/Android"); SolutionTemplate vbnetTemplate = AddTemplate("template-id2", "VBNet/Android"); CategorizeTemplates(); TemplateCategory appCategory = categorizedTemplates.First().Categories.First(); TemplateCategory generalCategory = appCategory.Categories.First(); Assert.That(generalCategory.Templates.ToList(), Contains.Item(csharpTemplate)); Assert.That(generalCategory.Templates.ToList(), Contains.Item(vbnetTemplate)); }
public void GetCategorizedTemplates_OneTemplateOneCategoryWithGroupConditionContainingExtraWhitespace_TemplateFilteredUsingTemplateParameters() { CreateCategories("android", "app", "general"); CreateCategorizer(); SolutionTemplate template = AddTemplate("template-id", "android/app/general"); template.GroupId = "console"; template.Language = "C#"; template.Condition = " Device = MyDevice "; ProjectCreateParameters parameters = CreateParameters("Device", "MyDevice"); CategorizeTemplates(); TemplateCategory generalCategory = categorizedTemplates.First().Categories.First().Categories.First(); SolutionTemplate firstTemplate = generalCategory.Templates.FirstOrDefault(); SolutionTemplate matchedTemplate = firstTemplate.GetTemplate("C#", parameters); Assert.AreEqual(template, matchedTemplate); }
public void GetCategorizedTemplates_TwoTemplatesAndFilterByNewSolution_TemplatesFiltered() { CreateCategories("android", "app", "general"); CreateCategorizer(ProjectTemplateCategorizer.MatchNewSolutionTemplates); SolutionTemplate template1 = AddTemplate("template-id1", "android/app/general"); template1.Language = "C#"; template1.Visibility = SolutionTemplateVisibility.NewProject; SolutionTemplate template2 = AddTemplate("template-id2", "android/app/general"); template2.Language = "C#"; template2.Visibility = SolutionTemplateVisibility.All; CategorizeTemplates(); TemplateCategory generalCategory = categorizedTemplates.First().Categories.First().Categories.First(); SolutionTemplate firstTemplate = generalCategory.Templates.FirstOrDefault(); Assert.AreEqual(1, generalCategory.Templates.Count()); Assert.AreEqual("template-id2", firstTemplate.Id); }
public void GetCategorizedTemplates_TwoTemplatesAndFilterShouldRemoveOneTemplate_TemplatesFiltered() { CreateCategories("android", "app", "general"); CreateCategorizer(solutionTemplate => { return(solutionTemplate.Id == "template-id2"); }); SolutionTemplate template1 = AddTemplate("template-id1", "android/app/general"); template1.Language = "C#"; SolutionTemplate template2 = AddTemplate("template-id2", "android/app/general"); template2.Language = "C#"; CategorizeTemplates(); TemplateCategory generalCategory = categorizedTemplates.First().Categories.First().Categories.First(); SolutionTemplate firstTemplate = generalCategory.Templates.FirstOrDefault(); Assert.AreEqual(1, generalCategory.Templates.Count()); Assert.AreEqual("template-id2", firstTemplate.Id); }
public void GetCategorizedTemplates_OneTemplateTwoDifferentSecondLevelCategories_EmptySecondLevelCategoryIsRemoved() { TemplateCategory topLevelCategory = AddTemplateCategory("android"); TemplateCategory secondLevelCategory = AddTemplateCategory("app", topLevelCategory); AddTemplateCategory("general", secondLevelCategory); secondLevelCategory = AddTemplateCategory("tests", topLevelCategory); AddTemplateCategory("general", secondLevelCategory); CreateCategorizer(); SolutionTemplate template = AddTemplate("template-id", "android/app/general"); CategorizeTemplates(); TemplateCategory androidCategory = categorizedTemplates.First(); TemplateCategory appCategory = androidCategory.Categories.First(); TemplateCategory generalCategory = appCategory.Categories.First(); Assert.That(generalCategory.Templates.ToList(), Contains.Item(template)); Assert.AreEqual(1, categorizedTemplates.Count); Assert.AreEqual(1, androidCategory.Categories.Count()); }
public void GetCategorizedTemplates_TwoConsoleProjectTemplatesWithSameLanguageInSameGroup_TemplatesCombinedIntoOneGroupWarningLoggedAboutDuplicateLanguageOneLanguageShown() { CreateCategories("android", "app", "general"); CreateCategorizer(); SolutionTemplate template1 = AddTemplate("template-id1", "android/app/general"); template1.GroupId = "console"; template1.Language = "C#"; SolutionTemplate template2 = AddTemplate("template-id2", "android/app/general"); template2.GroupId = "console"; template2.Language = "C#"; CategorizeTemplates(); TemplateCategory generalCategory = categorizedTemplates.First().Categories.First().Categories.First(); SolutionTemplate template = generalCategory.Templates.FirstOrDefault(); Assert.That(template.AvailableLanguages, Contains.Item("C#")); Assert.AreEqual(1, template.AvailableLanguages.Count); Assert.AreEqual(1, generalCategory.Templates.Count()); }
public void GetCategorizedTemplates_OneTemplateOneCategoryWithGroupConditionAndParameterIsBoolean_TemplateFilteredUsingTemplateParameters() { CreateCategories("android", "app", "general"); CreateCategorizer(); SolutionTemplate template = AddTemplate("template-id", "android/app/general"); template.GroupId = "console"; template.Language = "C#"; template.Condition = "SupportsSizeClasses=True"; ProjectCreateParameters parameters = CreateParameters("SupportsSizeClasses", true.ToString()); CategorizeTemplates(); TemplateCategory generalCategory = categorizedTemplates.First().Categories.First().Categories.First(); SolutionTemplate firstTemplate = generalCategory.Templates.FirstOrDefault(); SolutionTemplate matchedTemplate = firstTemplate.GetTemplate("C#", parameters); Assert.AreEqual(template, matchedTemplate); parameters.Clear(); SolutionTemplate noMatchedTemplate = firstTemplate.GetTemplate("C#", parameters); Assert.IsNull(noMatchedTemplate); }
public void GetCategorizedTemplates_OneTemplateOneCategoryWithGroupConditionAndParameterNameAndValueHaveDifferentCase_TemplateFilteredUsingTemplateParametersIgnoringCase() { CreateCategories("android", "app", "general"); CreateCategorizer(); SolutionTemplate template = AddTemplate("template-id", "android/app/general"); template.GroupId = "console"; template.Language = "C#"; template.Condition = "Device=MyDevice"; ProjectCreateParameters parameters = CreateParameters("device", "mydevice"); CategorizeTemplates(); TemplateCategory generalCategory = categorizedTemplates.First().Categories.First().Categories.First(); SolutionTemplate firstTemplate = generalCategory.Templates.FirstOrDefault(); SolutionTemplate matchedTemplate = firstTemplate.GetTemplate("C#", parameters); Assert.AreEqual(template, matchedTemplate); parameters = CreateParameters("device", "no-match"); SolutionTemplate noMatchedTemplate = firstTemplate.GetTemplate("C#", parameters); Assert.IsNull(noMatchedTemplate); }
public void GetCategorizedTemplates_TwoTemplateProvidersEachWithOneTemplateForTwoDifferentThirdLevelCategories_ThirdLevelCategoriresAreNotRemoved() { TemplateCategory topLevelCategory = AddTemplateCategory("android"); TemplateCategory secondLevelCategory = AddTemplateCategory("app", topLevelCategory); AddTemplateCategory("general", secondLevelCategory); AddTemplateCategory("tests", secondLevelCategory); CreateCategorizer(); SolutionTemplate firstTemplateProviderTemplate = AddTemplate("first-provider-template-id", "android/app/general"); categorizer.CategorizeTemplates(templates); templates.Clear(); SolutionTemplate secondTemplateProviderTemplate = AddTemplate("second-provider-template-id", "android/app/tests"); CategorizeTemplates(); TemplateCategory appCategory = categorizedTemplates.First().Categories.First(); TemplateCategory generalCategory = appCategory.Categories.First(category => category.Id == "general"); TemplateCategory testsCategory = appCategory.Categories.First(category => category.Id == "tests"); Assert.That(generalCategory.Templates.ToList(), Contains.Item(firstTemplateProviderTemplate)); Assert.That(testsCategory.Templates.ToList(), Contains.Item(secondTemplateProviderTemplate)); Assert.AreEqual(2, appCategory.Categories.Count()); }
void AddSubTemplateCategory (TemplateCategory category) { templateCategoriesListStore.AppendValues ( GLib.Markup.EscapeText (category.Name), null, category); }
void AddTopLevelTemplateCategory (TemplateCategory category) { Xwt.Drawing.Image icon = GetIcon (category.IconId, IconSize.Menu); categoryTextRenderer.CategoryIconWidth = (int)icon.Width; templateCategoriesListStore.AppendValues ( MarkupTopLevelCategoryName (category.Name), icon, category); foreach (TemplateCategory subCategory in category.Categories) { AddSubTemplateCategory (subCategory); } }
void LoadTemplateCategories () { // Load all builtin project templates. var builtins = System.Reflection.Assembly.GetExecutingAssembly ().GetTypes () .Where (x => typeof (IProtobuildModuleTemplate).IsAssignableFrom (x)) .Where (x => x.GetCustomAttributes (typeof (BuiltinProtobuildModuleTemplateAttribute), false).Length > 0) .Select (Activator.CreateInstance) .OfType<IProtobuildModuleTemplate> (); var featuredCategory = new TemplateCategory("featured", "Featured", null); var generalCategory = new TemplateCategory("general", "General", null); var onlineCategory = new TemplateCategory("online", "Online", null); var miscCategory = new TemplateCategory("misc", "Miscellanous", null); var protobuildCategory = new TemplateCategory ("protobuild", "Protobuild", "md-platform-other"); protobuildCategory.AddCategory(featuredCategory); protobuildCategory.AddCategory(onlineCategory); protobuildCategory.AddCategory(generalCategory); protobuildCategory.AddCategory(miscCategory); var featuredGeneralCategory = new TemplateCategory("featured-general", "Featured", "md-platform-other"); featuredCategory.AddCategory(featuredGeneralCategory); var generalGeneralCategory = new TemplateCategory("general-general", "General", "md-platform-other"); generalCategory.AddCategory(generalGeneralCategory); string message; if (string.IsNullOrEmpty (LastSearch)) { message = "Use the search in the top right!"; } else { message = "No Results for '" + LastSearch + "'"; } var onlineResultsCategory = new TemplateCategory("online-general", "Results for '" + LastSearch + "'", "md-platform-other"); var onlineNoResultsCategory = new TemplateCategory("online-general", message, "md-platform-other"); var miscGeneralCategory = new TemplateCategory("misc-general", "Miscellanous", "md-platform-other"); miscCategory.AddCategory(miscGeneralCategory); var online = new List<ProtobuildSolutionTemplate> (); foreach (var builtin in builtins.Concat(OnlineProtobuildModuleTemplates)) { var project = new ProtobuildSolutionTemplate(builtin.Id, builtin.Name, builtin.IconId) { Description = builtin.Description, GroupId = builtin.GroupId, ImageId = builtin.ImageId }; if (builtin.IsFeatured) { featuredGeneralCategory.AddTemplate(project); } if (builtin.IsOnline) { onlineResultsCategory.AddTemplate(project); online.Add(project); } if (builtin.IsGeneral) { generalGeneralCategory.AddTemplate(project); } if (builtin.IsMisc) { miscGeneralCategory.AddTemplate(project); } } onlineCategory.AddCategory(online.Count == 0 ? onlineNoResultsCategory : onlineResultsCategory); var selected = online.FirstOrDefault(); if (selected != null) { this.SelectedTemplate = selected; } if (this.SelectedSecondLevelCategory != null) { this.SelectedSecondLevelCategory = onlineCategory; } templateCategories = new List<TemplateCategory>(); templateCategories.Add(protobuildCategory); }
void AddChildren (TemplateCategory category) { foreach (var childCodon in ChildNodes.OfType<TemplateCategoryCodon> ()) { category.AddCategory (childCodon.ToTemplateCategory ()); } }
public void AddCategory(TemplateCategory category) { categories.Add(category); }
TemplateCategory AddTemplateCategory (string categoryName) { var templateCategory = new TemplateCategory (categoryName, categoryName, "iconid"); categories.Add (templateCategory); return templateCategory; }
TemplateCategory AddTemplateCategory (string categoryName, TemplateCategory parent) { var templateCategory = new TemplateCategory (categoryName, categoryName, "iconid"); parent.AddCategory (templateCategory); return templateCategory; }
void AddMappedCategory (TemplateCategory category) { foreach (string mappedCategory in category.MappedCategories.Split (new [] { ';' }, StringSplitOptions.RemoveEmptyEntries)) { mappedCategories.Add (mappedCategory, category); } }
void ShowTemplatesForCategory (TemplateCategory category) { foreach (TemplateCategory subCategory in category.Categories) { templatesListStore.AppendValues ( MarkupTopLevelCategoryName (subCategory.Name), null, null); foreach (SolutionTemplate template in subCategory.Templates) { if (template.HasProjects || controller.IsNewSolution) { templatesListStore.AppendValues ( template.Name, GetIcon (template.IconId, IconSize.Dnd), template); } } } }
void SelectTemplateCategory (TemplateCategory category) { TreeIter iter = TreeIter.Zero; if (!templateCategoriesListStore.GetIterFirst (out iter)) { return; } while (templateCategoriesListStore.IterNext (ref iter)) { var currentCategory = templateCategoriesListStore.GetValue (iter, TemplateCategoryColumn) as TemplateCategory; if (currentCategory == category) { templateCategoriesTreeView.Selection.SelectIter (iter); TreePath path = templateCategoriesListStore.GetPath (iter); templateCategoriesTreeView.ScrollToCell (path, null, true, 1, 0); break; } } }
public void AddCategory (TemplateCategory category) { categories.Add (category); }