public async Task FromFile() { try { Filename = Path.GetFileName(RamlTempFilePath); SetDefaultClientRootClassName(); var result = includesManager.Manage(RamlTempFilePath, Path.GetTempPath(), Path.GetTempPath()); var parser = new RamlParser(); var tempPath = Path.GetTempFileName(); File.WriteAllText(tempPath, result.ModifiedContents); var document = await parser.LoadAsync(tempPath); SetPreview(document); } catch (Exception ex) { ShowErrorAndStopProgress("Error while parsing raml file. " + ex.Message); ActivityLog.LogError(VisualStudioAutomationHelper.RamlVsToolsActivityLogSource, VisualStudioAutomationHelper.GetExceptionInfo(ex)); } }
public int Generate(string wszInputFilePath, string bstrInputFileContents, string wszDefaultNamespace, IntPtr[] rgbOutputFileContents, out uint pcbOutput, IVsGeneratorProgress pGenerateProgress) { try { if (bstrInputFileContents == null) { throw new ArgumentNullException("bstrInputFileContents"); } var containingFolder = Path.GetDirectoryName(wszInputFilePath); var refFilePath = GetRefFilePath(wszInputFilePath, containingFolder); var ramlSource = RamlReferenceReader.GetRamlSource(refFilePath); var globalProvider = Microsoft.VisualStudio.Shell.ServiceProvider.GlobalProvider; var destFolderItem = GetDestinationFolderItem(wszInputFilePath, globalProvider); UpdateRamlAndIncludedFiles(wszInputFilePath, destFolderItem, ramlSource, containingFolder); var ramlInfo = RamlInfoService.GetRamlInfo(wszInputFilePath); if (ramlInfo.HasErrors) { MessageBox.Show(ramlInfo.ErrorMessage); pcbOutput = 0; return(VSConstants.E_ABORT); } var res = GenerateCodeUsingTemplate(wszInputFilePath, ramlInfo, globalProvider, refFilePath); if (res.HasErrors) { ActivityLog.LogError(VisualStudioAutomationHelper.RamlVsToolsActivityLogSource, res.Errors); MessageBox.Show(res.Errors); pcbOutput = 0; return(VSConstants.E_ABORT); } var bytes = Encoding.UTF8.GetBytes(res.Content); rgbOutputFileContents[0] = Marshal.AllocCoTaskMem(bytes.Length); Marshal.Copy(bytes, 0, rgbOutputFileContents[0], bytes.Length); pcbOutput = (uint)bytes.Length; return(VSConstants.S_OK); } catch (Exception ex) { ActivityLog.LogError(VisualStudioAutomationHelper.RamlVsToolsActivityLogSource, VisualStudioAutomationHelper.GetExceptionInfo(ex)); var errorMessage = ex.Message; if (ex.InnerException != null) { errorMessage += " - " + ex.InnerException.Message; } MessageBox.Show(errorMessage); pcbOutput = 0; return(VSConstants.E_ABORT); } }
private async Task GetRamlFromUrl() { //StartProgress(); //DoEvents(); try { var url = RamlOriginalSource; var result = includesManager.Manage(url, Path.GetTempPath(), Path.GetTempPath()); var raml = result.ModifiedContents; var parser = new RamlParser(); var tempPath = Path.GetTempFileName(); File.WriteAllText(tempPath, raml); var ramlDocument = await parser.LoadAsync(tempPath); SetFilename(url); var path = Path.Combine(Path.GetTempPath(), Filename); File.WriteAllText(path, raml); RamlTempFilePath = path; RamlOriginalSource = url; SetPreview(ramlDocument); //CanImport = true; //StopProgress(); } catch (UriFormatException uex) { ShowErrorAndDisableOk(uex.Message); } catch (HttpRequestException rex) { ShowErrorAndDisableOk(GetFriendlyMessage(rex)); ActivityLog.LogError(VisualStudioAutomationHelper.RamlVsToolsActivityLogSource, VisualStudioAutomationHelper.GetExceptionInfo(rex)); } catch (Exception ex) { ShowErrorAndDisableOk(ex.Message); ActivityLog.LogError(VisualStudioAutomationHelper.RamlVsToolsActivityLogSource, VisualStudioAutomationHelper.GetExceptionInfo(ex)); } }
public int Generate(string wszInputFilePath, string bstrInputFileContents, string wszDefaultNamespace, IntPtr[] rgbOutputFileContents, out uint pcbOutput, IVsGeneratorProgress pGenerateProgress) { try { if (bstrInputFileContents == null) { throw new ArgumentNullException("bstrInputFileContents"); } var extensionPath = Path.GetDirectoryName(GetType().Assembly.Location) + Path.DirectorySeparatorChar; var result = RegenerateCode(wszInputFilePath, extensionPath); if (!result.IsSuccess) { pcbOutput = 0; ActivityLog.LogError(VisualStudioAutomationHelper.RamlVsToolsActivityLogSource, result.ErrorMessage); MessageBox.Show(result.ErrorMessage); return(VSConstants.E_ABORT); } var bytes = Encoding.UTF8.GetBytes(result.Content); rgbOutputFileContents[0] = Marshal.AllocCoTaskMem(bytes.Length); Marshal.Copy(bytes, 0, rgbOutputFileContents[0], bytes.Length); pcbOutput = (uint)bytes.Length; return(VSConstants.S_OK); } catch (Exception ex) { ActivityLog.LogError(VisualStudioAutomationHelper.RamlVsToolsActivityLogSource, VisualStudioAutomationHelper.GetExceptionInfo(ex)); var errorMessage = ex.Message; if (ex.InnerException != null) { errorMessage += " - " + ex.InnerException.Message; } MessageBox.Show(errorMessage); pcbOutput = 0; return(VSConstants.E_ABORT); } }
public void RemoveReverseEngineering() { try { ActivityLog.LogInformation(VisualStudioAutomationHelper.RamlVsToolsActivityLogSource, "Disable RAML metadata output process started"); var dte = serviceProvider.GetService(typeof(SDTE)) as DTE; var proj = VisualStudioAutomationHelper.GetActiveProject(dte); UninstallNugetAndDependencies(proj); ActivityLog.LogInformation(VisualStudioAutomationHelper.RamlVsToolsActivityLogSource, "Nuget package uninstalled"); RemoveConfiguration(proj); } catch (Exception ex) { ActivityLog.LogError(VisualStudioAutomationHelper.RamlVsToolsActivityLogSource, VisualStudioAutomationHelper.GetExceptionInfo(ex)); MessageBox.Show("Error when trying to disable RAML metadata output. " + ex.Message); throw; } }
public void AddReverseEngineering() { try { ActivityLog.LogInformation(VisualStudioAutomationHelper.RamlVsToolsActivityLogSource, "Enable RAML metadata output process started"); var dte = serviceProvider.GetService(typeof(SDTE)) as DTE; var proj = VisualStudioAutomationHelper.GetActiveProject(dte); InstallNugetAndDependencies(proj); ActivityLog.LogInformation(VisualStudioAutomationHelper.RamlVsToolsActivityLogSource, "Nuget package and dependencies installed"); AddXmlCommentsDocumentation(proj); ActivityLog.LogInformation(VisualStudioAutomationHelper.RamlVsToolsActivityLogSource, "XML comments documentation added"); } catch (Exception ex) { ActivityLog.LogError(VisualStudioAutomationHelper.RamlVsToolsActivityLogSource, VisualStudioAutomationHelper.GetExceptionInfo(ex)); MessageBox.Show("Error when trying to enable RAML metadata output. " + ex.Message); throw; } }
public void AddRamlReference(RamlChooserActionParams parameters) { try { ActivityLog.LogInformation(VisualStudioAutomationHelper.RamlVsToolsActivityLogSource, "Add RAML Reference process started"); var dte = serviceProvider.GetService(typeof(SDTE)) as DTE; var proj = VisualStudioAutomationHelper.GetActiveProject(dte); InstallNugetDependencies(proj); ActivityLog.LogInformation(VisualStudioAutomationHelper.RamlVsToolsActivityLogSource, "Nuget Dependencies installed"); AddFilesToProject(parameters.RamlFilePath, proj, parameters.TargetNamespace, parameters.RamlSource, parameters.TargetFileName, parameters.ClientRootClassName); ActivityLog.LogInformation(VisualStudioAutomationHelper.RamlVsToolsActivityLogSource, "Files added to project"); } catch (Exception ex) { ActivityLog.LogError(VisualStudioAutomationHelper.RamlVsToolsActivityLogSource, VisualStudioAutomationHelper.GetExceptionInfo(ex)); MessageBox.Show("Error when trying to add the RAML reference. " + ex.Message); throw; } }
public void Import() { StartProgress(); // DoEvents(); if (string.IsNullOrWhiteSpace(Namespace)) { ShowErrorAndStopProgress("Error: you must specify a namespace."); return; } if (!Filename.ToLowerInvariant().EndsWith(RamlFileExtension)) { ShowErrorAndStopProgress("Error: the file must have the .raml extension."); return; } if (!IsContractUseCase && !File.Exists(RamlTempFilePath)) { ShowErrorAndStopProgress("Error: the specified file does not exist."); return; } if (IsContractUseCase && UseApiVersion && string.IsNullOrWhiteSpace(ApiVersion)) { ShowErrorAndStopProgress("Error: you need to specify a version."); return; } if (IsContractUseCase && ConfigFolders && HasInvalidPath(ModelsFolder)) { ShowErrorAndStopProgress("Error: invalid path specified for models. Path must be relative."); //txtModels.Focus(); return; } if (IsContractUseCase && ConfigFolders && HasInvalidPath(ImplementationControllersFolder)) { ShowErrorAndStopProgress("Error: invalid path specified for controllers. Path must be relative."); //txtImplementationControllers.Focus(); return; } var path = Path.GetDirectoryName(GetType().Assembly.Location) + Path.DirectorySeparatorChar; try { ResourcesPreview = "Processing. Please wait..." + Environment.NewLine + Environment.NewLine; // Execute action (add RAML Reference, Scaffold Web Api, etc) var parameters = new RamlChooserActionParams(RamlOriginalSource, RamlTempFilePath, RamlTitle, path, Filename, Namespace, doNotScaffold: isNewContract); if (isContractUseCase) { parameters.UseAsyncMethods = UseAsyncMethods; parameters.IncludeApiVersionInRoutePrefix = UseApiVersion; parameters.ImplementationControllersFolder = ImplementationControllersFolder; parameters.ModelsFolder = ModelsFolder; parameters.AddGeneratedSuffixToFiles = AddSuffixToGeneratedCode; } if (!isContractUseCase) { parameters.ClientRootClassName = ProxyClientName; } action(parameters); ResourcesPreview += "Succeeded"; StopProgress(); CanImport = true; WasImported = true; TryClose(); } catch (Exception ex) { ShowErrorAndStopProgress("Error: " + ex.Message); ActivityLog.LogError(VisualStudioAutomationHelper.RamlVsToolsActivityLogSource, VisualStudioAutomationHelper.GetExceptionInfo(ex)); } }
private void SetPreview(RamlDocument document) { Execute.OnUIThreadAsync(() => { try { ResourcesPreview = GetResourcesPreview(document); StopProgress(); SetNamespace(RamlTempFilePath); if (document.Version != null) { ApiVersion = NetNamingMapper.GetVersionName(document.Version); } CanImport = true; if (NetNamingMapper.HasIndalidChars(Filename)) { ShowErrorAndStopProgress("The specied file name has invalid chars"); // txtFileName.Focus(); } } catch (Exception ex) { ShowErrorAndStopProgress("Error while parsing raml file. " + ex.Message); ActivityLog.LogError(VisualStudioAutomationHelper.RamlVsToolsActivityLogSource, VisualStudioAutomationHelper.GetExceptionInfo(ex)); } }); }
public int Generate(string wszInputFilePath, string bstrInputFileContents, string wszDefaultNamespace, IntPtr[] rgbOutputFileContents, out uint pcbOutput, IVsGeneratorProgress pGenerateProgress) { try { if (bstrInputFileContents == null) { throw new ArgumentNullException("bstrInputFileContents"); } var containingFolder = Path.GetDirectoryName(wszInputFilePath); var refFilePath = InstallerServices.GetRefFilePath(wszInputFilePath); var ramlSource = RamlReferenceReader.GetRamlSource(refFilePath); var clientRootClassName = RamlReferenceReader.GetClientRootClassName(refFilePath); var globalProvider = ServiceProvider.GlobalProvider; var destFolderItem = GetDestinationFolderItem(wszInputFilePath, globalProvider); var result = UpdateRamlAndIncludedFiles(wszInputFilePath, destFolderItem, ramlSource, containingFolder); if (!result.IsSuccess) { MessageBox.Show("Error when tryng to download " + ramlSource + " - Status Code: " + Enum.GetName(typeof(HttpStatusCode), result.StatusCode)); pcbOutput = 0; return(VSConstants.E_ABORT); } var dte = ServiceProvider.GlobalProvider.GetService(typeof(SDTE)) as DTE; var proj = VisualStudioAutomationHelper.GetActiveProject(dte); var apiRefsFolderPath = Path.GetDirectoryName(proj.FullName) + Path.DirectorySeparatorChar + RamlReferenceService.ApiReferencesFolderName + Path.DirectorySeparatorChar; templatesManager.CopyClientTemplateToProjectFolder(apiRefsFolderPath); var ramlInfo = RamlInfoService.GetRamlInfo(wszInputFilePath); if (ramlInfo.HasErrors) { MessageBox.Show(ramlInfo.ErrorMessage); pcbOutput = 0; return(VSConstants.E_ABORT); } var res = GenerateCodeUsingTemplate(wszInputFilePath, ramlInfo, globalProvider, refFilePath, clientRootClassName); if (res.HasErrors) { ActivityLog.LogError(VisualStudioAutomationHelper.RamlVsToolsActivityLogSource, res.Errors); MessageBox.Show(res.Errors); pcbOutput = 0; return(VSConstants.E_ABORT); } var content = templatesManager.AddClientMetadataHeader(res.Content); var bytes = Encoding.UTF8.GetBytes(content); rgbOutputFileContents[0] = Marshal.AllocCoTaskMem(bytes.Length); Marshal.Copy(bytes, 0, rgbOutputFileContents[0], bytes.Length); pcbOutput = (uint)bytes.Length; return(VSConstants.S_OK); } catch (Exception ex) { ActivityLog.LogError(VisualStudioAutomationHelper.RamlVsToolsActivityLogSource, VisualStudioAutomationHelper.GetExceptionInfo(ex)); var errorMessage = ex.Message; if (ex.InnerException != null) { errorMessage += " - " + ex.InnerException.Message; } MessageBox.Show(errorMessage); pcbOutput = 0; return(VSConstants.E_ABORT); } }
public void LogError(Exception ex) { ActivityLog.LogError(VisualStudioAutomationHelper.RamlVsToolsActivityLogSource, VisualStudioAutomationHelper.GetExceptionInfo(ex)); }