Example #1
0
        public async Task Generate(
            ProgressMonitor monitor,
            ProjectFile file,
            SingleFileCustomToolResult result)
        {
            Bootstrapper.Initialize();

            using var traceListener = new DisposableTraceListener(
                      new LoggingServiceTraceListener(
                          new ProgressMonitorLoggingService(monitor, "Generating code...")));

            var swaggerFile = file.FilePath;
            var outputFile  = swaggerFile.ChangeExtension(".cs");

            result.GeneratedFilePath = outputFile;

            var customToolNamespace = file.CustomToolNamespace;

            if (string.IsNullOrWhiteSpace(customToolNamespace))
            {
                customToolNamespace = CustomToolService.GetFileNamespace(file, outputFile);
            }

            var generator        = GetCodeGenerator(swaggerFile, customToolNamespace);
            var progressReporter = new ProgressReporter(monitor);
            var contents         = await Task.Run(() => generator.GenerateCode(progressReporter));

            await Task.Run(() => File.WriteAllText(outputFile, contents));
        }
        public async Task Generate(
            ProgressMonitor monitor,
            ProjectFile file,
            SingleFileCustomToolResult result)
        {
            string generatorName;

            if (GetType() == typeof(OpenApiSingleFileCustomTool))
            {
                generatorName = "OpenAPI Generator";
            }
            else if (GetType() == typeof(SwaggerSingleFileCustomTool))
            {
                generatorName = "Swagger Codegen CLI";
            }
            else
            {
                generatorName = GetType().Name.Replace("SingleFileCustomTool", string.Empty);
            }

            Logger.Instance.TrackFeatureUsage(generatorName, "VSMac");

            Bootstrapper.Initialize();

            var swaggerFile = file.FilePath;
            var outputFile  = swaggerFile.ChangeExtension(".cs");

            result.GeneratedFilePath = outputFile;

            using var traceListener = new DisposableTraceListener(
                      new LoggingServiceTraceListener(
                          new ProgressMonitorLoggingService(monitor, "Generating code...")));

            var customToolNamespace = file.CustomToolNamespace;

            if (string.IsNullOrWhiteSpace(customToolNamespace))
            {
                customToolNamespace = CustomToolService.GetFileNamespace(file, outputFile);
            }

            var generator        = GetCodeGenerator(swaggerFile, customToolNamespace);
            var progressReporter = new ProgressReporter(monitor);
            var contents         = await Task.Run(() => generator.GenerateCode(progressReporter));

            await Task.Run(() => File.WriteAllText(outputFile, contents));
        }