using ImpressãoFaturamento.Controllers; using ImpressãoFaturamento.Models; //args = [@"C:\Users\contratos\AppData\Local\Temp\json_input.json"]; if (args.Length > 0) { ProcessCommandLineArguments(args); return; } var builder = WebApplication.CreateBuilder(args); // Add services to the container. builder.Services.AddControllers(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(); var app = builder.Build(); // Configure the HTTP request pipeline. if (app.Environment.IsDevelopment()) { app.UseSwagger(); app.UseSwaggerUI(); } app.UseHttpsRedirection(); app.UseAuthorization(); app.MapControllers(); app.Run(); static void ProcessCommandLineArguments(string[] arguments) { Console.WriteLine("Recebendo JSON via linha de comando..."); if (arguments.Length != 1) { Console.WriteLine("Erro: Um único argumento contendo o JSON é esperado."); return; } string jsonInput = arguments[0]; if (!File.Exists(jsonInput)) { Console.WriteLine($"Erro: O arquivo '{jsonInput}' não foi encontrado."); return; } try { string jsonContent = File.ReadAllText(jsonInput); var data = System.Text.Json.JsonSerializer.Deserialize(jsonContent); if (data != null) { ExcelController controller = new(); string pdfPath = controller.WriteDataToExcel(data); Console.WriteLine($"PDF gerado com sucesso: {pdfPath}"); } else { throw new ArgumentNullException("Faturamento", "Dados inválidos."); } } catch (Exception ex) { Console.WriteLine($"Erro ao processar o JSON: {ex.Message}"); } }