private async Task <Dictionary <Guid, BodyModel> > GeneraPDFEmendamenti(IEnumerable <EmendamentiDto> Emendamenti, string _pathTemp)
        {
            var listaPercorsiEM = new Dictionary <Guid, BodyModel>();

            try
            {
                var listaEmendamenti = Emendamenti.ToList();

                listaPercorsiEM = listaEmendamenti.ToDictionary(em => em.UIDEM, em => new BodyModel());
                foreach (var item in listaEmendamenti)
                {
                    var bodyPDF = await apiGateway.Emendamento.GetBody(item.UIDEM, TemplateTypeEnum.PDF);

                    var nameFilePDF =
                        $"{item.N_EM.Replace(" ", "_").Replace("all'", "")}_{item.UIDEM}_{DateTime.Now:ddMMyyyy_hhmmss}.pdf";
                    var FilePathComplete = Path.Combine(_pathTemp, nameFilePDF);

                    var dettagliCreaPDF = new BodyModel
                    {
                        Path = FilePathComplete,
                        Body = bodyPDF,
                        EM   = item
                    };
                    listaPercorsiEM[item.UIDEM] = dettagliCreaPDF;
                    await CreaPDF(dettagliCreaPDF, listaPercorsiEM.Count);
                }
            }
            catch (Exception ex)
            {
                Log.Error("GeneraPDFEmendamenti Error-->", ex);
            }

            return(listaPercorsiEM);
        }
 private async Task CreaPDF(BodyModel item, long total)
 {
     PdfStamper.CreaPDF(item.Body, item.Path, item.EM, _model.UrlCLIENT);
     var dirInfo = new DirectoryInfo(Path.GetDirectoryName(item.Path));
     var files   = dirInfo.GetFiles().Where(f => !f.Name.ToLower().Contains("copertina"));
     await apiGateway.Stampe.AddInfo(_stampa.UIDStampa, $"Progresso {files.Count()}/{total}");
 }
Ejemplo n.º 3
0
        internal async Task <Dictionary <Guid, BodyModel> > GeneraPDFEmendamenti(IEnumerable <EmendamentiDto> Emendamenti,
                                                                                 int Da, int A,
                                                                                 string _pathTemp)
        {
            var listaPercorsiEM = new Dictionary <Guid, BodyModel>();

            try
            {
                listaPercorsiEM = Emendamenti.ToDictionary(em => em.UIDEM, em => new BodyModel());
                Action <BodyModel> CreaPDF = item =>
                {
                    Log.Debug($"Percorso EM [{item.Path}]");
                    //Creo PDF EM con allegati
                    PdfStamper.CreaPDF(item.Body, item.Path, item.EM, model.urlCLIENT);
                };

                if (Da != 0 && A != 0)
                {
                    Log.Debug($"Stampo solo DA [{Da}], A [{A}]");
                    var j     = 1;
                    var k     = Da;
                    var k_end = A;
                    foreach (var item in Emendamenti)
                    {
                        if (j >= k)
                        {
                            if (j > k_end)
                            {
                                break;
                            }

                            var bodyPDF = await ApiGateway.GetBodyEM(item.UIDEM, TemplateTypeEnum.PDF);

                            var nameFilePDF =
                                $"{item.DisplayTitle.Replace(" ", "_").Replace("all'", "")}_{item.UIDEM}_{DateTime.Now:ddMMyyyy_hhmmss}.pdf";
                            var FilePathComplete = Path.Combine(_pathTemp, nameFilePDF);

                            var dettagliCreaPDF = new BodyModel
                            {
                                Path = FilePathComplete,
                                Body = bodyPDF,
                                EM   = item
                            };

                            listaPercorsiEM[item.UIDEM] = dettagliCreaPDF;
                        }

                        j++;
                    }
                }
                else
                {
                    foreach (var item in Emendamenti)
                    {
                        var bodyPDF = await ApiGateway.GetBodyEM(item.UIDEM, TemplateTypeEnum.PDF);

                        var nameFilePDF =
                            $"{item.DisplayTitle.Replace(" ", "_").Replace("all'", "")}_{item.UIDEM}_{DateTime.Now:ddMMyyyy_hhmmss}.pdf";
                        var FilePathComplete = Path.Combine(_pathTemp, nameFilePDF);

                        var dettagliCreaPDF = new BodyModel
                        {
                            Path = FilePathComplete,
                            Body = bodyPDF,
                            EM   = item
                        };

                        listaPercorsiEM[item.UIDEM] = dettagliCreaPDF;
                    }
                }

                listaPercorsiEM.AsParallel().ForAll(item => CreaPDF(item.Value));
            }
            catch (Exception ex)
            {
                Log.Error("GeneraPDFEmendamenti Error-->", ex);
            }

            return(listaPercorsiEM);
        }