public async Task ProcessTemplate(ItemTemplate template, Project project, NewItemConfiguration config) { var itemTemplate = (MicrosoftTemplateEngineItemTemplate)template; var parameters = GetParameters(project, itemTemplate, config); var result = await MicrosoftTemplateEngine.InstantiateAsync(itemTemplate.TemplateInfo, config, parameters); if (result.Status != CreationResultStatus.Success) { string message = string.Format("Could not create template. Id='{0}' {1} {2}", template.Id, result.Status, result.Message); throw new InvalidOperationException(message); } foreach (var path in result.ResultInfo.PrimaryOutputs) { string fullPath = Path.Combine(config.Directory, GetPath(path)); await MicrosoftTemplateEngine.FormatFile(project?.Policies, fullPath); if (project != null) { AddFileToProject(project, fullPath); } IdeApp.Workbench.OpenDocument(fullPath, project).Ignore(); if (project != null) { await InstallNuGetPackages(project, result.ResultInfo); } } }
public MicrosoftTemplateEngineItemTemplate(ItemTemplateExtensionNode template, ITemplateInfo templateInfo) : base(template.TemplateId, template.OverrideName ?? templateInfo.Name) { TemplateInfo = templateInfo; Language = MicrosoftTemplateEngine.GetLanguage(templateInfo); }
internal MicrosoftTemplateEngineSolutionTemplate(TemplateExtensionNode template, ITemplateInfo templateInfo) : base(template.Id, template.OverrideName ?? templateInfo.Name, template.Icon) { this.templateInfo = templateInfo; Description = ParseDescription(template.OverrideDescription) ?? templateInfo.Description; Category = template.Category; Language = template.OverrideLanguage ?? MicrosoftTemplateEngine.GetLanguage(templateInfo); GroupId = template.GroupId ?? templateInfo.GroupIdentity; //TODO: Support all this params Condition = template.Condition; //ProjectFileExtension = template.FileExtension; Wizard = template.Wizard; SupportedParameters = template.SupportedParameters; DefaultParameters = MicrosoftTemplateEngine.MergeDefaultParameters(template.DefaultParameters, templateInfo); ImageId = template.ImageId; FileFormattingExclude = template.FileFormatExclude; //ImageFile = template.ImageFile; //Visibility = GetVisibility (template.Visibility); //HasProjects = (template.SolutionDescriptor.EntryDescriptors.Length > 0); }
public IEnumerable <ItemTemplate> GetTemplates() { return(MicrosoftTemplateEngine.GetItemTemplates()); }
static string GetPath(ICreationPath path) { return(MicrosoftTemplateEngine.GetPath(path)); }
public override Stream GetStream(string path) { return(MicrosoftTemplateEngine.GetStream(TemplateInfo, path)); }
public async Task <ProcessedTemplateResult> ProcessTemplate(SolutionTemplate template, NewProjectConfiguration config, SolutionFolder parentFolder) { var solutionTemplate = (MicrosoftTemplateEngineSolutionTemplate)template; var parameters = GetParameters(solutionTemplate, config); var templateInfo = solutionTemplate.templateInfo; var workspaceItems = new List <IWorkspaceFileObject> (); var filesBeforeCreation = Directory.GetFiles(config.ProjectLocation, "*", SearchOption.AllDirectories); var result = await MicrosoftTemplateEngine.InstantiateAsync(templateInfo, config, parameters); if (result.Status != CreationResultStatus.Success) { string message = string.Format("Could not create template. Id='{0}' {1} {2}", template.Id, result.Status, result.Message); throw new InvalidOperationException(message); } var filesToOpen = new List <string> (); foreach (var postAction in result.ResultInfo.PostActions) { switch (postAction.ActionId.ToString().ToUpper()) { case "84C0DA21-51C8-4541-9940-6CA19AF04EE6": if (postAction.Args.TryGetValue("files", out var files)) { foreach (var fi in files.Split(';')) { if (int.TryParse(fi.Trim(), out var i)) { filesToOpen.Add(Path.Combine(config.ProjectLocation, GetPath(result.ResultInfo.PrimaryOutputs [i]))); } } } break; case "D396686C-DE0E-4DE6-906D-291CD29FC5DE": //TODO: Load project files break; } } //TODO: Once templates support "D396686C-DE0E-4DE6-906D-291CD29FC5DE" use that to load projects foreach (var path in result.ResultInfo.PrimaryOutputs) { var fullPath = Path.Combine(config.ProjectLocation, GetPath(path)); if (Services.ProjectService.IsSolutionItemFile(fullPath)) { workspaceItems.Add(await MonoDevelop.Projects.Services.ProjectService.ReadSolutionItem(new Core.ProgressMonitor(), fullPath)); } } var metadata = new Dictionary <string, string> (); metadata ["Id"] = templateInfo.Identity; metadata ["Name"] = templateInfo.Name; metadata ["Language"] = template.Language; metadata ["Platform"] = string.Join(";", templateInfo.Classifications); TemplateCounter.Inc(1, null, metadata); MicrosoftTemplateEngineProcessedTemplateResult processResult; if (parentFolder == null) { var solution = new Solution(); solution.SetLocation(config.SolutionLocation, config.SolutionName); foreach (var item in workspaceItems.Cast <SolutionFolderItem> ()) { IConfigurationTarget configurationTarget = item as IConfigurationTarget; if (configurationTarget != null) { foreach (ItemConfiguration configuration in configurationTarget.Configurations) { bool flag = false; foreach (SolutionConfiguration solutionCollection in solution.Configurations) { if (solutionCollection.Id == configuration.Id) { flag = true; } } if (!flag) { solution.AddConfiguration(configuration.Id, true); } } } solution.RootFolder.AddItem(item); } processResult = new MicrosoftTemplateEngineProcessedTemplateResult(new [] { solution }, solution.FileName, config.ProjectLocation); } else { processResult = new MicrosoftTemplateEngineProcessedTemplateResult(workspaceItems.ToArray(), parentFolder.ParentSolution.FileName, config.ProjectLocation); } // Format all source files generated during the project creation foreach (var p in workspaceItems.OfType <Project> ()) { foreach (var file in p.Files) { if (!filesBeforeCreation.Contains((string)file.FilePath, FilePath.PathComparer)) //Format only newly created files { if (solutionTemplate.ShouldFormatFile(file.FilePath)) { await MicrosoftTemplateEngine.FormatFile(parentFolder?.Policies ?? p.Policies, file.FilePath); } } } } processResult.SetFilesToOpen(filesToOpen); return(processResult); }
/// <summary> /// Used by unit tests to create a new solution template without having to use an addin. /// </summary> static internal SolutionTemplate CreateTemplate(string templateId, string scanPath) { return(MicrosoftTemplateEngine.CreateProjectTemplate(templateId, scanPath)); }
public IEnumerable <SolutionTemplate> GetTemplates() { return(MicrosoftTemplateEngine.GetProjectTemplates()); }
public override Image GetImage(string path) { return(MicrosoftTemplateEngine.GetImage(TemplateInfo, path)); }