private async Task OnExecuteAsync(DTE dte, AsyncPackage package) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); var result = EnterOpenApiSpecDialog.GetResult(); if (result == null) { return; } var selectedItem = ProjectExtensions.GetSelectedItem(); var folder = FindFolder(selectedItem, dte); if (string.IsNullOrWhiteSpace(folder)) { Trace.WriteLine("Unable to get folder name"); return; } var contents = result.OpenApiSpecification; var filename = result.OutputFilename + ".json"; if (CodeGenerator == SupportedCodeGenerator.NSwagStudio) { var outputNamespace = ProjectExtensions.GetActiveProject(dte)?.GetTopLevelNamespace(); contents = await NSwagStudioFileHelper.CreateNSwagStudioFileAsync( result, new NSwagStudioOptions(), outputNamespace); filename = filename.Replace(".json", ".nswag"); } var filePath = Path.Combine(folder, filename); File.WriteAllText(filePath, contents); var fileInfo = new FileInfo(filePath); var project = ProjectExtensions.GetActiveProject(dte); var projectItem = project.AddFileToProject(dte, fileInfo, "None"); projectItem.Properties.Item("BuildAction").Value = prjBuildAction.prjBuildActionNone; if (CodeGenerator != SupportedCodeGenerator.NSwagStudio) { var customTool = CodeGenerator.GetCustomToolName(); projectItem.Properties.Item("CustomTool").Value = customTool; } else { var generator = new NSwagStudioCodeGenerator(filePath, new CustomPathOptions(), new ProcessLauncher()); generator.GenerateCode(null); dynamic nswag = JsonConvert.DeserializeObject(contents); var nswagOutput = nswag.codeGenerators.swaggerToCSharpClient.output.ToString(); project.AddFileToProject(dte, new FileInfo(Path.Combine(folder, nswagOutput))); } await project.InstallMissingPackagesAsync(package, CodeGenerator); }
private async Task OnExecuteAsync(DTE dte, AsyncPackage package) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); var result = EnterOpenApiSpecDialog.GetResult(); if (result == null) { return; } var selectedItem = ProjectExtensions.GetSelectedItem(); var folder = FindFolder(selectedItem, dte); if (string.IsNullOrWhiteSpace(folder)) { Trace.WriteLine("Unable to get folder name"); return; } var contents = result.OpenApiSpecification; var filename = result.OutputFilename + ".json"; var filePath = Path.Combine(folder, filename); File.WriteAllText(filePath, contents); var fileInfo = new FileInfo(filePath); var project = ProjectExtensions.GetActiveProject(dte); var projectItem = project.AddFileToProject(dte, fileInfo, "None"); projectItem.Properties.Item("BuildAction").Value = prjBuildAction.prjBuildActionNone; var customTool = CodeGenerator.GetCustomToolName(); projectItem.Properties.Item("CustomTool").Value = customTool; await project.InstallMissingPackagesAsync(package, CodeGenerator); }