Example #1
0
        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 static Task <TemplateCreationResult> InstantiateAsync(
     ITemplateInfo templateInfo,
     NewItemConfiguration config,
     IReadOnlyDictionary <string, string> parameters)
 {
     return(templateCreator.InstantiateAsync(
                templateInfo,
                config.NameWithoutExtension,
                config.NameWithoutExtension,
                config.Directory,
                parameters,
                true,
                false,
                null
                ));
 }
Example #3
0
        static Dictionary <string, string> GetParameters(Project project, MicrosoftTemplateEngineItemTemplate template, NewItemConfiguration config)
        {
            var parameters = new Dictionary <string, string> ();

            var model = (IStringTagModel)config;

            foreach (ITemplateParameter parameter in template.TemplateInfo.Parameters)
            {
                string parameterValue = (string)model.GetValue(parameter.Name);
                if (parameterValue != null)
                {
                    parameters [parameter.Name] = parameterValue;
                }
            }

            var dotNetProject = project as DotNetProject;

            if (dotNetProject != null)
            {
                string fileName = GetFullPathIncludingFileExtension(template, config);
                parameters ["namespace"] = dotNetProject.GetDefaultNamespace(fileName);
            }

            return(parameters);
        }
Example #4
0
        static string GetFullPathIncludingFileExtension(MicrosoftTemplateEngineItemTemplate template, NewItemConfiguration config)
        {
            string fileName = config.Name;

            if (StringComparer.OrdinalIgnoreCase.Equals(template.Language, "C#"))
            {
                fileName = Path.ChangeExtension(config.Name, ".cs");
            }
            return(Path.Combine(config.Directory, fileName));
        }
Example #5
0
 public Task ProcessTemplate(ItemTemplate template, Project project, NewItemConfiguration config)
 {
     return(itemTemplatingProvider.ProcessTemplate(template, project, config));
 }