public override void GenerateCode(RamlInfo data, Project proj, string targetNamespace, string clientRootClassName, string apiRefsFolderPath, string ramlDestFile, string destFolderPath, string destFolderName, ProjectItem ramlProjItem) { //ramlProjItem.Properties.Item("CustomTool").Value = string.Empty; // to cause a refresh when file already exists //ramlProjItem.Properties.Item("CustomTool").Value = "RamlClientTool"; var model = new ClientGeneratorService(data.RamlDocument, clientRootClassName, targetNamespace, targetNamespace + ".Models").BuildModel(); var directoryName = Path.GetDirectoryName(ramlDestFile).TrimEnd(Path.DirectorySeparatorChar); var templateFolder = directoryName.Substring(0, directoryName.LastIndexOf(Path.DirectorySeparatorChar)) + Path.DirectorySeparatorChar + "Templates" + Path.DirectorySeparatorChar; var templateFilePath = Path.Combine(templateFolder, ClientT4TemplateName); var extensionPath = Path.GetDirectoryName(GetType().Assembly.Location) + Path.DirectorySeparatorChar; TemplatesManager.CopyClientTemplateToProjectFolder(apiRefsFolderPath, "Client"); var t4Service = new T4Service(ServiceProvider); var res = t4Service.TransformText(templateFilePath, model, extensionPath, ramlDestFile, targetNamespace); if (res.HasErrors) { ActivityLog.LogError(VisualStudioAutomationHelper.RamlVsToolsActivityLogSource, res.Errors); MessageBox.Show(res.Errors); } else { var content = TemplatesManager.AddClientMetadataHeader(res.Content); var csTargetFile = Path.Combine(destFolderPath, destFolderName + ".cs"); File.WriteAllText(csTargetFile, content); ramlProjItem.ProjectItems.AddFromFile(csTargetFile); } }
public void GenerateCode(RamlInfo data, string targetNamespace, string clientRootClassName, string ramlDestFile, string destFolderPath, string destFolderName, ProjectItem ramlProjItem) { //var ramlInfo = await RamlInfoService.GetRamlInfo(ramlDestFile); //if (ramlInfo.HasErrors) //{ // ActivityLog.LogError(VisualStudioAutomationHelper.RamlVsToolsActivityLogSource, ramlInfo.ErrorMessage); // MessageBox.Show(ramlInfo.ErrorMessage); // return; //} var model = new ClientGeneratorService(data.RamlDocument, clientRootClassName, targetNamespace, targetNamespace + ".Models").BuildModel(); var directoryName = Path.GetDirectoryName(ramlDestFile).TrimEnd(Path.DirectorySeparatorChar); var templateFolder = directoryName.Substring(0, directoryName.LastIndexOf(Path.DirectorySeparatorChar)) + Path.DirectorySeparatorChar + "Templates" + Path.DirectorySeparatorChar; var templateFilePath = Path.Combine(templateFolder, ClientT4TemplateName); var extensionPath = Path.GetDirectoryName(GetType().Assembly.Location) + Path.DirectorySeparatorChar; var t4Service = new T4Service(ServiceProvider); var res = t4Service.TransformText(templateFilePath, model, extensionPath, ramlDestFile, targetNamespace); if (res.HasErrors) { ActivityLog.LogError(VisualStudioAutomationHelper.RamlVsToolsActivityLogSource, res.Errors); MessageBox.Show(res.Errors); return; } var content = TemplatesManager.AddClientMetadataHeader(res.Content); var csTargetFile = Path.Combine(destFolderPath, destFolderName + ".cs"); File.WriteAllText(csTargetFile, content); ramlProjItem.ProjectItems.AddFromFile(csTargetFile); }
public override void GenerateCode(RamlInfo data, Project proj, string targetNamespace, string clientRootClassName, string apiRefsFolderPath, string ramlDestFile, string destFolderPath, string destFolderName, ProjectItem ramlProjItem) { ThreadHelper.ThrowIfNotOnUIThread(); TemplatesManager.CopyClientTemplateToProjectFolder(apiRefsFolderPath, "ClientCore"); GenerateCode(data, targetNamespace, clientRootClassName, ramlDestFile, destFolderPath, destFolderName, ramlProjItem); }
private Result GenerateCodeUsingTemplate(string wszInputFilePath, RamlInfo ramlInfo, System.IServiceProvider globalProvider, string refFilePath) { var model = GetGeneratorModel(wszInputFilePath, ramlInfo); var vsixPath = Path.GetDirectoryName(GetType().Assembly.Location) + Path.DirectorySeparatorChar; var templateFileName = Path.Combine(vsixPath, "GeneratedModel.t4"); var t4Service = new T4Service(globalProvider); var targetNamespace = RamlReferenceReader.GetRamlNamespace(refFilePath); var res = t4Service.TransformText(templateFileName, model, vsixPath, wszInputFilePath, targetNamespace); return(res); }
private static Result GenerateCodeUsingTemplate(string wszInputFilePath, RamlInfo ramlInfo, System.IServiceProvider globalProvider, string refFilePath, string clientRootClassName, string extensionPath) { var targetNamespace = RamlReferenceReader.GetRamlNamespace(refFilePath); var model = GetGeneratorModel(clientRootClassName, ramlInfo, targetNamespace); var templateFolder = GetTemplateFolder(wszInputFilePath); var templateFilePath = Path.Combine(templateFolder, ClientT4TemplateName); var t4Service = new T4Service(globalProvider); var res = t4Service.TransformText(templateFilePath, model, extensionPath, wszInputFilePath, targetNamespace); return(res); }
protected void AddFilesToProject(RamlInfo data, string ramlSourceFile, Project proj, string targetNamespace, string ramlOriginalSource, string targetFileName, string clientRootClassName) { ThreadHelper.ThrowIfNotOnUIThread(); if (!File.Exists(ramlSourceFile)) { throw new FileNotFoundException("RAML file not found " + ramlSourceFile); } if (Path.GetInvalidFileNameChars().Any(targetFileName.Contains)) { throw new ArgumentException("Specified filename has invalid chars: " + targetFileName); } var destFolderName = Path.GetFileNameWithoutExtension(targetFileName); var apiRefsFolderPath = Path.GetDirectoryName(proj.FullName) + Path.DirectorySeparatorChar + ApiReferencesFolderName + Path.DirectorySeparatorChar; var destFolderPath = apiRefsFolderPath + destFolderName + Path.DirectorySeparatorChar; var apiRefsFolderItem = VisualStudioAutomationHelper.AddFolderIfNotExists(proj, ApiReferencesFolderName); var destFolderItem = VisualStudioAutomationHelper.AddFolderIfNotExists(apiRefsFolderItem, destFolderName, destFolderPath); var includesManager = new RamlIncludesManager(); var result = includesManager.Manage(ramlOriginalSource, destFolderPath + Path.DirectorySeparatorChar + InstallerServices.IncludesFolderName, destFolderPath + Path.DirectorySeparatorChar); var ramlDestFile = Path.Combine(destFolderPath, targetFileName); if (File.Exists(ramlDestFile)) { new FileInfo(ramlDestFile).IsReadOnly = false; } File.WriteAllText(ramlDestFile, result.ModifiedContents); var ramlProjItem = InstallerServices.AddOrUpdateRamlFile(ramlDestFile, destFolderPath, destFolderItem, targetFileName); var props = new RamlProperties { ClientName = clientRootClassName, Source = ramlOriginalSource, Namespace = targetNamespace }; var refFilePath = InstallerServices.AddRefFile(ramlSourceFile, destFolderPath, targetFileName, props); ramlProjItem.ProjectItems.AddFromFile(refFilePath); GenerateCode(data, proj, targetNamespace, clientRootClassName, apiRefsFolderPath, ramlDestFile, destFolderPath, destFolderName, ramlProjItem); }
public void GenerateCode(RamlInfo data, string targetNamespace, string clientRootClassName, string ramlDestFile, string destFolderPath, string destFolderName, ProjectItem ramlProjItem) { ThreadHelper.ThrowIfNotOnUIThread(); //var ramlInfo = await RamlInfoService.GetRamlInfo(ramlDestFile); //if (ramlInfo.HasErrors) //{ // ActivityLog.LogError(VisualStudioAutomationHelper.RamlVsToolsActivityLogSource, ramlInfo.ErrorMessage); // MessageBox.Show(ramlInfo.ErrorMessage); // return; //} var model = new ClientGeneratorService(data.RamlDocument, clientRootClassName, targetNamespace, targetNamespace + ".Models").BuildModel(); var directoryName = Path.GetDirectoryName(ramlDestFile).TrimEnd(Path.DirectorySeparatorChar); var templateFolder = directoryName.Substring(0, directoryName.LastIndexOf(Path.DirectorySeparatorChar)) + Path.DirectorySeparatorChar + "Templates" + Path.DirectorySeparatorChar; var templateFilePath = Path.Combine(templateFolder, ClientT4TemplateName); var extensionPath = Path.GetDirectoryName(GetType().Assembly.Location) + Path.DirectorySeparatorChar; // when array has no properties, set it collection on base type foreach (var arrayModel in model.Objects.Where(o => o.IsArray && o.Properties.Count == 0 && o.Type != null && CollectionTypeHelper.IsCollection(o.Type) && !NewNetTypeMapper.IsPrimitiveType(CollectionTypeHelper.GetBaseType(o.Type)))) { arrayModel.BaseClass = arrayModel.Type.Substring(1); // remove the initil "I" to make it a concrete class } var t4Service = new T4Service(ServiceProvider); var res = t4Service.TransformText(templateFilePath, model, extensionPath, ramlDestFile, targetNamespace); if (res.HasErrors) { ActivityLog.LogError(VisualStudioAutomationHelper.RamlVsToolsActivityLogSource, res.Errors); MessageBox.Show(res.Errors); return; } var content = TemplatesManager.AddClientMetadataHeader(res.Content); var csTargetFile = Path.Combine(destFolderPath, destFolderName + ".cs"); File.WriteAllText(csTargetFile, content); ramlProjItem.ProjectItems.AddFromFile(csTargetFile); }
private static ClientGeneratorModel GetGeneratorModel(string clientRootClassName, RamlInfo ramlInfo, string targetNamespace) { var model = new ClientGeneratorService(ramlInfo.RamlDocument, clientRootClassName, targetNamespace).BuildModel(); return(model); }
private static ClientGeneratorModel GetGeneratorModel(string wszInputFilePath, RamlInfo ramlInfo) { var rootName = NetNamingMapper.GetObjectName(Path.GetFileNameWithoutExtension(wszInputFilePath)); if (!rootName.ToLower().Contains("api")) { rootName += "Api"; } var model = new ClientGeneratorService(ramlInfo.RamlDocument, rootName).BuildModel(); return(model); }
public abstract void GenerateCode(RamlInfo data, Project proj, string targetNamespace, string clientRootClassName, string apiRefsFolderPath, string ramlDestFile, string destFolderPath, string destFolderName, ProjectItem ramlProjItem);