void LoadTemplateCategories() { Predicate <SolutionTemplate> templateMatch = GetTemplateFilter(); templateCategories = TemplatingService.GetProjectTemplateCategories(templateMatch).ToList(); if (IsNewSolution) { recentTemplates = TemplatingService.RecentTemplates.GetTemplates(templateCategories).Where(t => t.IsMatch(SolutionTemplateVisibility.NewSolution)).ToList(); } else { recentTemplates = TemplatingService.RecentTemplates.GetTemplates(templateCategories).ToList(); } }
SolutionTemplate FindTemplate() { var categories = templatingService .GetProjectTemplateCategories(t => t.Id == templateId) .ToList(); var templates = categories.First() .Categories.First() .Categories.First() .Templates.ToList(); var template = templates.Single(); string language = GetLanguage(templateId); return(template.GetTemplate(language, Config.Parameters)); }
SolutionTemplate FindTemplate(string templateId, NewProjectConfiguration config) { var categories = templatingService .GetProjectTemplateCategories(t => MatchTemplate(t, templateId)) .ToList(); var templates = categories.First() .Categories.First() .Categories.First() .Templates.ToList(); var template = templates.Single(); string language = GetLanguage(templateId); return(template.GetTemplate(language, config.Parameters)); }
public async Task Bug57840() { var templatingService = new TemplatingService(); var mutliplatformLibraryCategory = templatingService.GetProjectTemplateCategories().Single(c => c.Id == "multiplat") .Categories.Single(c => c.Id == "library") .Categories.Single(c => c.Id == "general"); var pclTemplate = mutliplatformLibraryCategory.Templates.Single(t => t.GroupId == "md-project-portable-library").GetTemplate("C#"); var standardTemplate = mutliplatformLibraryCategory.Templates.Single(t => t.GroupId == "Microsoft.Common.Library").GetTemplate("C#"); var tempDirectory = Util.CreateTmpDir("Bug57840Test"); var result = await templatingService.ProcessTemplate(pclTemplate, new Ide.Projects.NewProjectConfiguration() { CreateSolution = true, Location = tempDirectory, SolutionName = "Bug57840Test", ProjectName = "Bug57840PclTestProject", CreateProjectDirectoryInsideSolutionDirectory = false }, null); solution = result.WorkspaceItems.OfType <Solution> ().Single(); await solution.SaveAsync(Util.GetMonitor()); var project = solution.GetAllProjects().Single(); project.Policies.Set <TextStylePolicy> (new TextStylePolicy(1, 1, 1, true, true, true, EolMarker.Mac), "text/x-csharp"); var file = project.Files.Single(f => f.FilePath.FileName == "MyClass.cs").FilePath; var fileContentBeforeFormat = await TextFileUtility.ReadAllTextAsync(file); await FormatFile(project, file); var fileContentAfterFormat = await TextFileUtility.ReadAllTextAsync(file); Assert.AreNotEqual(fileContentBeforeFormat.Text, fileContentAfterFormat.Text); //Make sure our weird formatting applied solution.Policies.Set <TextStylePolicy> (new TextStylePolicy(3, 3, 3, true, true, true, EolMarker.Mac), "text/x-csharp"); var result2 = await templatingService.ProcessTemplate(standardTemplate, new Ide.Projects.NewProjectConfiguration() { CreateSolution = false, Location = solution.BaseDirectory, ProjectName = "Bug57840StandardTestProject", CreateProjectDirectoryInsideSolutionDirectory = false }, solution.RootFolder); var standardProject = result2.WorkspaceItems.OfType <DotNetProject> ().Single(); solution.RootFolder.AddItem(standardProject); await solution.SaveAsync(Util.GetMonitor()); var fileContentAfterSecondProject = await TextFileUtility.ReadAllTextAsync(file); Assert.AreEqual(fileContentAfterSecondProject.Text, fileContentAfterFormat.Text); //Make sure our weird formatting is preserved var class1File = standardProject.Files.Single(f => f.FilePath.FileName == "Class1.cs").FilePath; var fileContentAfterCreation = await TextFileUtility.ReadAllTextAsync(class1File); standardProject.Policies.Set <TextStylePolicy> (new TextStylePolicy(3, 3, 3, true, true, true, EolMarker.Mac), "text/x-csharp"); await FormatFile(standardProject, class1File); standardProject.Dispose(); var fileContentAfterForceFormatting = await TextFileUtility.ReadAllTextAsync(class1File); Assert.AreEqual(fileContentAfterForceFormatting.Text, fileContentAfterCreation.Text, "We expect them to be same because we placed same formatting policy on solution before creataion as after creation on project when we manually formatted."); }