コード例 #1
0
        public async Task <bool> Handle(GerarRelatorioAtaFinalHtmlParaPdfCommand request, CancellationToken cancellationToken)
        {
            List <string> paginasEmHtml = new List <string>();

            foreach (var modelPagina in request.Paginas)
            {
                string html = string.Empty;

                html = GerarHtmlRazor(modelPagina, request.NomeTemplate);

                html = html.Replace("logo.png", SmeConstants.LogoSme);

                paginasEmHtml.Add(html);
            }

            //TODO: FILA PARA RELATORIO SEM DADOS?
            if (paginasEmHtml.Any())
            {
                PdfGenerator pdfGenerator = new PdfGenerator(converter);

                var directory = AppDomain.CurrentDomain.BaseDirectory;
                SentrySdk.AddBreadcrumb($"Gerando PDF", $"Caminho geração : {directory}");

                pdfGenerator.ConvertToPdf(paginasEmHtml, directory, request.CodigoCorrelacao.ToString());

                SentrySdk.AddBreadcrumb($"Indo publicar na fila Prontos..", "8 - MonitorarStatusRelatorioUseCase");
                servicoFila.PublicaFila(new PublicaFilaDto(new MensagemRelatorioProntoDto(request.MensagemUsuario, string.Empty), RotasRabbit.RotaRelatoriosProntosSgp, RotasRabbit.ExchangeSgp, request.CodigoCorrelacao));
                SentrySdk.CaptureMessage("8 - MonitorarStatusRelatorioUseCase - Publicado na fila PRONTO OK!");
            }

            return(true);
        }
コード例 #2
0
        private static void ConvertTextToPdf(string markdownText, string outputFile, Action <Settings> settingsAction, ICakeLog log, string sourceWorkingDirectory)
        {
            if (!CanWriteToOutputFile(outputFile))
            {
                log.Error("Please close the output file first: " + outputFile);
                return;
            }

            var settings = new Settings();

            settingsAction?.Invoke(settings);

            if (string.IsNullOrEmpty(settings.WorkingDirectory))
            {
                settings.WorkingDirectory = sourceWorkingDirectory;
            }

            string htmlFile = Path.Combine(Path.GetTempPath(), $"convert{Guid.NewGuid().ToString("n")}.html");

            settings.MarkdownPipeline.DebugLog = Console.Out;

            var html = Markdown.ToHtml(markdownText, settings.MarkdownPipeline.Build());

            var baseDirectory = GetBaseDirectory();

            html = ApplyTheme(html, settings, log, baseDirectory, settings.WorkingDirectory);

            try
            {
                File.WriteAllText(htmlFile, html);
                var generator = new PdfGenerator();
                var exitCode  = generator.ConvertToPdf(htmlFile, outputFile, settings.Pdf, baseDirectory, log);

                if (exitCode != 0)
                {
                    log.Error("Error creating pdf document. Exit code: " + exitCode);
                    log.Error(generator.ExecutionOutputText);
                }
            }
            finally
            {
                if (File.Exists(htmlFile))
                {
                    File.Delete(htmlFile);
                }
            }
        }