public static BiblosDocumentInfo[] FillUDSDocuments(Helpers.UDS.Document document) { if (document == null || document.Instances == null) { return(new BiblosDocumentInfo[] { }); } IList <BiblosDocumentInfo> docInfos = new List <BiblosDocumentInfo>(); IList <BiblosDocumentInfo> bibDocs; foreach (DocumentInstance instance in document.Instances) { bibDocs = BiblosDocumentInfo.GetDocumentsLatestVersion(Guid.Parse(instance.StoredChainId)); foreach (BiblosDocumentInfo doc in bibDocs) { docInfos.Add(doc); } } return(docInfos.ToArray()); }
public void ElaborateDocument(HttpContext context) { Guid idResolution = context.Request.QueryString.GetValueOrDefault("UniqueId", Guid.Empty); byte[] stream = { }; try { Resolution resolution = GetResolution(idResolution); if (!CheckValidity(context, resolution)) { return; } string cached_file_path = Path.Combine(CachePath, string.Concat(resolution.UniqueId.ToString(), ".pdf")); if (!File.Exists(cached_file_path)) { DocumentUnitChain documentChain = GetDocumentUnitChain(idResolution, ChainType.MainOmissisChain); if (documentChain == null) { documentChain = GetDocumentUnitChain(idResolution, ChainType.MainChain); } if (documentChain == null) { ElaborateException(context); return; } IList <BiblosDocumentInfo> documents = BiblosDocumentInfo.GetDocumentsLatestVersion(string.Empty, documentChain.IdArchiveChain); if (documents == null || !documents.Any()) { ElaborateException(context); return; } IEnumerable <byte[]> streams = documents.Select(f => !ViewLockedPdf ? f.GetPdfStream() : Services.StampaConforme.Service.ConvertToSimplePdf(f.Stream, "pdf")); if (MergeAllChainDocuments) { //recupero gli allegati DocumentUnitChain attachmentsChain = GetDocumentUnitChain(idResolution, ChainType.AttachmentOmissisChain); if (attachmentsChain == null) { attachmentsChain = GetDocumentUnitChain(idResolution, ChainType.AttachmentsChain); } if (attachmentsChain != null) { IList <BiblosDocumentInfo> attachmentDocuments = BiblosDocumentInfo.GetDocumentsLatestVersion(string.Empty, attachmentsChain.IdArchiveChain); if (attachmentDocuments != null && attachmentDocuments.Any()) { streams = streams.Concat(attachmentDocuments.Select(f => !ViewLockedPdf ? f.GetPdfStream() : Services.StampaConforme.Service.ConvertToSimplePdf(f.Stream, "pdf"))); } } //recupero il frontalino di pubblicazione DocumentUnitChain frontespieceChain = GetDocumentUnitChain(idResolution, ChainType.FrontespizioChain); if (frontespieceChain != null) { IList <BiblosDocumentInfo> frontespieceDocuments = BiblosDocumentInfo.GetDocumentsLatestVersion(string.Empty, frontespieceChain.IdArchiveChain); if (frontespieceDocuments != null && frontespieceDocuments.Any()) { streams = streams.Concat(frontespieceDocuments.Select(f => !ViewLockedPdf ? f.GetPdfStream() : Services.StampaConforme.Service.ConvertToSimplePdf(f.Stream, "pdf"))); } } } stream = MergePDF(streams); if (ViewLockedPdf) { using (MemoryDocumentInfo mdi = new MemoryDocumentInfo(stream, cached_file_path)) { stream = mdi.GetPdfLocked(documents.First().Signature, PdfWatermark); } } if (!Encoding.Default.GetString(stream, 0, 4).Equals("%PDF")) { throw new Exception("Il pdf non può essere visualizzato a causa di un errore di conversione.", new Exception("Lo stream non inizia con '%PDF'")); } File.WriteAllBytes(cached_file_path, stream); } else { stream = File.ReadAllBytes(cached_file_path); } ElaborateStream(context, stream, string.Empty); } catch (Exception ex) { FileLogger.Error(LogName.BiblosServiceLog, ex.Message, ex); ElaborateException(context); return; } }