public void Scaffold(string ramlSource, RamlChooserActionParams parameters) { var data = RamlScaffolderHelper.GetRamlData(ramlSource, parameters.TargetNamespace); if (data == null || data.Model == null) { return; } var model = data.Model; var dte = serviceProvider.GetService(typeof(SDTE)) as DTE; var proj = VisualStudioAutomationHelper.GetActiveProject(dte); var contractsFolderItem = VisualStudioAutomationHelper.AddFolderIfNotExists(proj, contractsFolderName); var ramlItem = contractsFolderItem.ProjectItems.Cast <ProjectItem>() .First(i => i.Name.ToLowerInvariant() == parameters.TargetFileName.ToLowerInvariant()); var contractsFolderPath = Path.GetDirectoryName(proj.FullName) + Path.DirectorySeparatorChar + contractsFolderName + Path.DirectorySeparatorChar; if (VisualStudioAutomationHelper.IsAVisualStudio2015Project(proj)) { templateSubFolder = "AspNet5"; } else { templateSubFolder = "RAMLWebApi2Scaffolder"; } var templates = new[] { ControllerBaseTemplateName, ControllerInterfaceTemplateName, ControllerImplementationTemplateName, ModelTemplateName, EnumTemplateName }; if (!templatesManager.ConfirmWhenIncompatibleServerTemplate(contractsFolderPath, templates)) { return; } var extensionPath = Path.GetDirectoryName(GetType().Assembly.Location) + Path.DirectorySeparatorChar; AddOrUpdateModels(parameters, contractsFolderPath, ramlItem, model, contractsFolderItem, extensionPath); AddOrUpdateEnums(parameters, contractsFolderPath, ramlItem, model, contractsFolderItem, extensionPath); AddOrUpdateControllerBase(parameters, contractsFolderPath, ramlItem, model, contractsFolderItem, extensionPath); AddOrUpdateControllerInterfaces(parameters, contractsFolderPath, ramlItem, model, contractsFolderItem, extensionPath); AddOrUpdateControllerImplementations(parameters, contractsFolderPath, proj, model, contractsFolderItem, extensionPath); }
public void Scaffold(string ramlSource, string targetNamespace, string ramlFileName, bool useAsyncMethods) { var data = RamlScaffolderHelper.GetRamlData(ramlSource, targetNamespace); if (data == null || data.Model == null) { return; } var model = data.Model; var dte = serviceProvider.GetService(typeof(SDTE)) as DTE; var proj = VisualStudioAutomationHelper.GetActiveProject(dte); var folderItem = VisualStudioAutomationHelper.AddFolderIfNotExists(proj, ContractsFolderName); var ramlItem = folderItem.ProjectItems.Cast <ProjectItem>().First(i => i.Name.ToLowerInvariant() == ramlFileName.ToLowerInvariant()); var generatedFolderPath = Path.GetDirectoryName(proj.FullName) + Path.DirectorySeparatorChar + ContractsFolderName + Path.DirectorySeparatorChar; if (!templatesManager.ConfirmWhenIncompatibleServerTemplate(generatedFolderPath, new[] { ControllerBaseTemplateName, ControllerInterfaceTemplateName, ControllerImplementationTemplateName, ModelTemplateName, EnumTemplateName })) { return; } var extensionPath = Path.GetDirectoryName(GetType().Assembly.Location) + Path.DirectorySeparatorChar; AddOrUpdateModels(targetNamespace, generatedFolderPath, ramlItem, model, folderItem, extensionPath); AddOrUpdateEnums(targetNamespace, generatedFolderPath, ramlItem, model, folderItem, extensionPath); AddOrUpdateControllerBase(targetNamespace, generatedFolderPath, ramlItem, model, folderItem, extensionPath, useAsyncMethods); AddOrUpdateControllerInterfaces(targetNamespace, generatedFolderPath, ramlItem, model, folderItem, extensionPath, useAsyncMethods); AddOrUpdateControllerImplementations(targetNamespace, generatedFolderPath, proj, model, folderItem, extensionPath, useAsyncMethods); }