public ActionResult CreateIpda(Guid id) { return(ActionResultHelper.TryCatchWithLogger(() => { try { Preservation preservation = _preservationService.GetPreservation(id, false); if (preservation == null) { _loggerService.Error(string.Format("Nessuna conservazione trovata con id {0}", id)); return Content("Errore: Conservazione non valida"); } string closeFile = IpdaUtil.GetCloseFile(preservation.Path); if (string.IsNullOrEmpty(closeFile)) { return Content("Errore: Conservazione non valida"); } IpdaConverter converter = new IpdaConverter(); Ipda ipda = converter.ConvertCloseFile(closeFile, "NomeFileInArchivio"); ipda.SaveAs(IpdaUtil.Close2IpdaFilename(closeFile)); return Content("Il file IPDA è stato generato con successo"); } catch (Exception ex) { _loggerService.Error(ex.Message, ex); return Content(string.Concat("Errore durante la conversione del file di chiusura.<br/>", ex.Message)); } }, _loggerService)); }
private string GetIpdaInfo(Ipda ipda) { StringBuilder ipdaInfoBulder = new StringBuilder(); try { if (ipda == null) { return("Informazioni da file chiusura non disponibili"); } ipdaInfoBulder.AppendFormat("<br/><b>Elaborati n.{0} documenti - Tipo:'{1}' dalla data {2} alla data {3}</b>", ipda.descGenerale.extraInfo.metadatiIntegrati.metadati.documenti.numero, ipda.descGenerale.extraInfo.metadatiIntegrati.metadati.documenti.tipologia, ipda.descGenerale.extraInfo.metadatiIntegrati.metadati.documenti.dal, ipda.descGenerale.extraInfo.metadatiIntegrati.metadati.documenti.al ); foreach (DgmiBlocco blocco in ipda.descGenerale.extraInfo.metadatiIntegrati.metadati.blocchi.bloccoList) { ipdaInfoBulder.AppendFormat("<br/>- Gruppo <{0}> dal n.{1} al n.{2}", blocco.id, blocco.dal, blocco.al); } return(ipdaInfoBulder.ToString()); } catch (Exception ex) { _logger.Error("UnzipPreservationFile -> errore nella lettura del file IPDA", ex); return("Informazioni da file chiusura non disponibili"); } }
private string CreatePreservationIpdaFile(Objects.Preservation preservation, string workingDir, string preservationName, string exceptions, IDictionary <Guid, BindingList <DocumentAttributeValue> > fullDocumentAttributes) { logger.InfoFormat("CreatePreservationIpdaFile - work dir {0} eccezioni {1}", workingDir, exceptions); try { if (string.IsNullOrEmpty(workingDir)) { throw new Exception("Working directory non configurata correttamente."); } if (preservation.Documents == null) { throw new Exception(string.Format("Nessun documento associato alla conservazione con id {0}", preservation.IdPreservation)); } if (exceptions == null) { exceptions = string.Empty; } var user = preservation.User; var sCognomeNomeCf = string.Format("{0} {1} C.F. {2}", user.Name, user.Surname, user.FiscalId); var nDoc = preservation.Documents.Count(); var dtHlp = preservation.Documents.Select(x => x.DateMain).Min(); var sDataMinima = dtHlp.HasValue ? dtHlp.Value.ToString("dd/MM/yyyy") : "N.D."; dtHlp = preservation.Documents.Select(x => x.DateMain).Max(); var sDataMassima = dtHlp.HasValue ? dtHlp.Value.ToString("dd/MM/yyyy") : "N.D."; var sFileName = Path.Combine(workingDir, "CHIUSURA_" + preservationName + ".txt"); var sFileNameIpda = Path.Combine(workingDir, "IPDA_" + preservationName + ".xml"); var sFileIndice = Path.Combine(workingDir, "INDICE_" + preservationName + ".txt"); var sFileIndiceXML = Path.Combine(workingDir, "INDICE_" + preservationName + ".xml"); var sFileIndiceXsl = Path.Combine(workingDir, "INDICE_" + preservationName + ".xsl"); var sFileLottoXML = Path.Combine(workingDir, "LOTTI_" + preservationName + ".xml"); var sFileLottoXsl = Path.Combine(workingDir, "LOTTI_" + preservationName + ".xsl"); var sFileIndiceNome = "INDICE_" + preservationName + ".txt"; //generazione oggetto Ipda che sarà poi serializzato come file Xml Ipda ipda = new Ipda(); ipda.descGenerale = new DescGenerale { id = preservationName, applicazione = new DescApplicazione { nome = "Biblos Document Server", produttore = "Dgroove Srl", versione = "2015.0" } }; ipda.descGenerale.extraInfo = new DgExtraInfo(); Dictionary <string, List <long> > sectional = EstraiGruppi_v1(preservation); List <DgmiBlocco> blocchiList = new List <DgmiBlocco>(); foreach (var section in sectional) { blocchiList.Add(new DgmiBlocco { id = section.Key, documenti = section.Value.Count().ToString(), dal = section.Value.Min().ToString(), al = section.Value.Max().ToString() }); } ipda.descGenerale.extraInfo.metadatiIntegrati = new DgMetadatiIntegrati { metadati = new DgmiMetadati { blocchi = new DgmiBlocchi { bloccoList = blocchiList.ToArray() }, documenti = new DgmiDocumenti { tipologia = preservation.Archive.FiscalDocumentType, numero = nDoc.ToString(), dal = sDataMinima, al = sDataMassima } } }; List <DgMetadatiEsterni> metadatiEsterni = new List <DgMetadatiEsterni>(); if (File.Exists(sFileName)) { metadatiEsterni.Add(new DgMetadatiEsterni { id = "CHIUSURA_TXT", indirizzo = Path.GetFileName(sFileName), impronta = UtilityService.GetHash(sFileName, true) }); } if (File.Exists(sFileIndice)) { metadatiEsterni.Add(new DgMetadatiEsterni { id = "INDICE_TXT", indirizzo = Path.GetFileName(sFileIndice), impronta = UtilityService.GetHash(sFileIndice, true) }); } if (File.Exists(sFileIndiceXML)) { metadatiEsterni.Add(new DgMetadatiEsterni { id = "INDICE_XML", indirizzo = Path.GetFileName(sFileIndiceXML), impronta = UtilityService.GetHash(sFileIndiceXML, true) }); } if (File.Exists(sFileIndiceXsl)) { metadatiEsterni.Add(new DgMetadatiEsterni { id = "INDICE_XSL", indirizzo = Path.GetFileName(sFileIndiceXsl), impronta = UtilityService.GetHash(sFileIndiceXsl, true) }); } if (File.Exists(sFileLottoXML)) { metadatiEsterni.Add(new DgMetadatiEsterni { id = "LOTTI_XML", indirizzo = Path.GetFileName(sFileLottoXML), impronta = UtilityService.GetHash(sFileLottoXML, true) }); } if (File.Exists(sFileLottoXsl)) { metadatiEsterni.Add(new DgMetadatiEsterni { id = "LOTTI_XSL", indirizzo = Path.GetFileName(sFileLottoXsl), impronta = UtilityService.GetHash(sFileLottoXsl, true) }); } ipda.descGenerale.extraInfo.metadatiEsterniList = metadatiEsterni.ToArray(); ipda.pda = new Pda { id = Path.GetFileNameWithoutExtension(sFileIndice), extraInfo = new PdaExtraInfo { metadati = new PdaMetadati() } }; List <PdaAttributo> attrList = DbProvider.GetAttributeByPreservationPosition(preservation.IdArchive).Select(p => new PdaAttributo { nome = p.Description }).ToList(); attrList.Insert(0, new PdaAttributo { nome = "NomeFileInArchivio" }); attrList.Add(new PdaAttributo { nome = "ImprontaFileSHA256" }); ipda.pda.extraInfo.metadati.attributoList = attrList.ToArray(); //elenco dei file ipda.fileGruppo = new FileGruppo { files = GetIpdaFiles(preservation, fullDocumentAttributes) }; //processo ipda.processo = new Processo { soggetto = new Soggetto { soggettoID = sCognomeNomeCf }, tempo = new Tempo { rifTemporale = DateTime.Now.Date.ToString("d") + " " + DateTime.Now.ToString("HH:mm") }, rifNormativo = "" }; //sostituisce il file di chiusura logger.Info("Inizio serializzazione ipda"); string xmlString = XmlFile <Ipda> .Serialize(ipda); logger.Info("Fine serializzazione ipda"); preservation.CloseContent = Encoding.ASCII.GetBytes(xmlString); DbProvider.UpdatePreservation(preservation, true); //salva nella cartella di destinazione ipda.SaveAs(sFileNameIpda); logger.Info("CreatePreservationIpdaFile - ritorno al chiamante"); return(string.Empty); } catch (Exception e) { logger.Error(e); return(e.Message + " ===> " + e.Source); } }
public string CreateAwardBatchPDVXml(Objects.AwardBatch awardBatch, Objects.Preservation preservation) { try { Ipda ipda = new Ipda() { descGenerale = new DescGenerale() { id = awardBatch.Name, applicazione = new DescApplicazione() { nome = "Biblos Document Server", produttore = "Dgroove Srl", versione = "2015.0" } }, pda = new Pda() { extraInfo = new PdaExtraInfo() { metadati = new PdaMetadati() } } }; List <PdaAttributo> attrList = DbProvider.GetAttributeByPreservationPosition(awardBatch.IdArchive).Select(p => new PdaAttributo { nome = p.Description }).ToList(); attrList.Insert(0, new PdaAttributo() { nome = "NomeFile" }); attrList.Insert(1, new PdaAttributo() { nome = "DataVersamento" }); attrList.Add(new PdaAttributo() { nome = "ImprontaSHA" }); ipda.pda.extraInfo.metadati.attributoList = attrList.ToArray(); //TODO: Completamente da rivedere. Creare dei service specifici per creare e leggere i documenti da file system senza la necessità di chiamare ogni volta il WCFHost. List <FileGruppoFile> files = new List <FileGruppoFile>(); BindingList <Document> documents = DbProvider.GetAwardBatchDocuments(awardBatch.IdAwardBatch); List <DocumentAttribute> attributes = DbProvider.GetAttributesFromArchive(awardBatch.IdArchive).Where(x => !x.ConservationPosition.HasValue || x.ConservationPosition.Value > 0).OrderBy(x => x.ConservationPosition).ToList(); byte[] documentContent; string documentHash; BiblosStorageService.StorageService storageService = new BiblosStorageService.StorageService(); foreach (Document document in documents) { documentContent = null; documentHash = null; if (preservation != null && preservation.Documents != null) { Document currentDocument = preservation.Documents.SingleOrDefault(x => x.IdDocument == document.IdDocument); if (currentDocument != null) { documentHash = currentDocument.DocumentHash; } } if (string.IsNullOrEmpty(documentHash)) { DocumentContent currentDocumentContent = storageService.GetDocumentContent(document); documentContent = currentDocumentContent.Blob; documentHash = UtilityService.GetHash(documentContent, true); } document.AttributeValues = DbProvider.GetFullDocumentAttributeValues(document.IdDocument); List <FgAttributo> docAttrList = new List <FgAttributo>(); foreach (var attr in attributes) { FgAttributo fgAttr = new FgAttributo(); var currAttributeValue = document.AttributeValues.Where(x => x.IdAttribute == attr.IdAttribute).FirstOrDefault(); if (currAttributeValue == null) { continue; } if (currAttributeValue.Attribute == null) { currAttributeValue.Attribute = attr; } fgAttr.nome = string.IsNullOrEmpty(attr.Description) ? attr.Name : attr.Description; //L'attributo va formattato in funzione della proprieta' "Format" dell'Attributo, se valorizzata. string valoreAttr; if (currAttributeValue.Attribute != null && !string.IsNullOrEmpty(currAttributeValue.Attribute.Format)) { try { valoreAttr = string.Format(currAttributeValue.Attribute.Format, currAttributeValue.Value); } catch (Exception ex) { logger.Error(ex); valoreAttr = string.Empty; } } else { valoreAttr = (currAttributeValue.Value != null) ? currAttributeValue.Value.ToString() : string.Empty; } fgAttr.valore = valoreAttr; docAttrList.Add(fgAttr); } docAttrList.Insert(0, new FgAttributo() { nome = "NomeFile", valore = document.Name }); docAttrList.Insert(1, new FgAttributo() { nome = "DataVersamento", valore = document.DateMain.Value.ToString("dd/MM/yyyy") }); docAttrList.Add(new FgAttributo() { nome = "ImprontaSHA", valore = documentHash }); files.Add(new FileGruppoFile() { id = document.Name, impronta = documentHash, extraInfo = new FgExtraInfo() { metadati = new FgMetadati() { attributoList = docAttrList.ToArray() } } }); } ipda.fileGruppo = new FileGruppo() { files = files.ToArray() }; return(XmlFile <Ipda> .Serialize(ipda)); } catch (Exception ex) { logger.Error(ex.Message, ex); throw; } }