public static ArchiveCompany UpdateArchiveCompany(ArchiveCompany archComp) { try { return(DbProvider.UpdateArchiveCompany(archComp)); } catch (Exception ex) { logger.Error(ex); throw; } }
public static ArchiveCompany AddArchiveCompany(ArchiveCompany archComp) { logger.Info("AddArchiveCompany - INIT"); try { var ret = DbProvider.AddArchiveCompany(archComp); logger.Info("AddArchiveCompany - END"); return(ret); } catch (Exception ex) { logger.Error(ex); throw; } }
public Guid CloneCompanyArchive(string templateName, string archiveName, Company company) { logger.InfoFormat("CloneCompanyArchive {0} - {1}", templateName, archiveName); try { var idArchive = ArchiveService.CloneArchive(templateName, archiveName); //TODO /* * 1.Verifica nella tabella company se l'idCompany esite (company.IdCompany) * 1.1 Se non esiste la company viene inserita la company con le informazioni nella tabella company * 2 Viene craata l'associazione ArchiveCompany * */ Company comp = null; if (company != null) { comp = ArchiveService.GetCompany(company.IdCompany); } if (comp == null) { comp = ArchiveService.AddCompany(company); var toAdd = new ArchiveCompany { IdArchive = idArchive, IdCompany = comp.IdCompany, WorkingDir = "", //Da dove la pesco? XmlFileTemplatePath = "" //Da dove lo prendo? }; toAdd = new BiblosDS.Library.Common.Preservation.Services.PreservationService().AddArchiveCompany(toAdd); } return(idArchive); } catch (Exception ex) { logger.Error(ex); throw; } }
public override async Task Execute(CommandModel commandModel) { try { if (!(commandModel is CommandConfigureArchiveForPreservation)) { _logger.Error($"Command is not of type {nameof(CommandConfigureArchiveForPreservation)}"); return; } CommandConfigureArchiveForPreservation @command = commandModel as CommandConfigureArchiveForPreservation; await SendNotification(command.ReferenceId, $"Inizio attività di configurazione per l'archivio con id {command.IdArchive}", NotifyLevel.Info); DocumentArchive currentArchive = ArchiveService.GetArchive(command.IdArchive); if (currentArchive == null) { _logger.Error($"Archive with Id {command.IdArchive} not found"); throw new Exception($"Non è stato trovato un archivio con ID {command.IdArchive}"); } Company currentCompany = ArchiveService.GetCompany(command.IdCompany); if (currentCompany == null) { _logger.Error($"Company with Id {command.IdCompany} not found"); throw new Exception($"Non è stata trovata una azienda con ID {command.IdCompany}"); } BindingList <DocumentAttribute> archiveAttributes = AttributeService.GetAttributesFromArchive(command.IdArchive); if (archiveAttributes == null || archiveAttributes.Count == 0) { _logger.Error($"There aren't attributes for archive with Id {command.IdArchive}"); throw new Exception($"Non sono stati trovati attributi per l'archivio con ID {command.IdArchive}"); } if (string.IsNullOrEmpty(currentArchive.PathPreservation)) { _logger.Error($"PathPreservation is null for archive with Id {command.IdArchive}"); throw new Exception($"Non è stato definito il percorso di conservazione per l'archivio con ID {command.IdArchive}"); } DocumentAttribute mainDateAttribute = archiveAttributes.SingleOrDefault(x => x.IsMainDate == true); if (mainDateAttribute == null) { _logger.Error($"MainDate attribute is not defined for archive with Id {command.IdArchive}"); throw new Exception($"Non è stato definito l'attributo di tipo MainDate per l'archivio con ID {command.IdArchive}"); } ICollection <DocumentAttribute> preservationAttributes = archiveAttributes.Where(x => x.ConservationPosition > 0).ToList(); if (preservationAttributes.Count == 0) { _logger.Error($"There aren't conservation attributes for archive with Id {command.IdArchive}"); throw new Exception($"Non sono stati definiti gli attributi di conservazione per l'archivio con ID {command.IdArchive}"); } if (_preservationService.ExistPreservationsByArchive(currentArchive)) { _logger.Error($"The archive {command.IdArchive} already has some conservation done"); throw new Exception($"L'archivio {command.IdArchive} presenta già delle conservazioni eseguite"); } _logger.Info($"Enable archive {currentArchive.Name} to conservation"); await SendNotification(commandModel.ReferenceId, $"Abilitazione archivio {currentArchive.Name}({currentArchive.IdArchive}) alla conservazione", NotifyLevel.Info); currentArchive.IsLegal = true; ArchiveService.UpdateArchive(currentArchive, false); ICollection <Document> documents = DocumentService.GetDocumentsFromArchive(currentArchive); _logger.Debug($"Found {documents.Count} documents to process"); await SendNotification(commandModel.ReferenceId, $"Trovati {documents.Count} documenti da processare. L'attività può richiedere diversi minuti...", NotifyLevel.Info); BindingList <DocumentAttributeValue> documentAttributeValues; DateTime?mainDate; string primaryKey; decimal percentage, pulsePercentageLimit = 20; int progress = 1, totalItems = documents.Count, totalErrorDocuments = 0; ICollection <NotificationDetailModel> errorDetails = new List <NotificationDetailModel>(); foreach (Document document in documents) { try { _logger.Debug($"Process document {document.IdDocument}({progress} di {totalItems})"); documentAttributeValues = AttributeService.GetFullDocumentAttributeValues(document.IdDocument); mainDate = document.DateCreated; primaryKey = AttributeService.ParseAttributeValues(documentAttributeValues, archiveAttributes, out mainDate); DocumentService.UpdatePrimaryKeyAndDateMainDocument(document, mainDate, primaryKey); } catch (Exception ex) { _logger.Error($"Error on update document {document.IdDocument}", ex); errorDetails.Add(new NotificationDetailModel() { Id = document.IdDocument, ActivityName = $"Modifica primary key e maindate del documento {document.IdDocument}", Detail = $"{ex.Message}\r\n{ex.StackTrace}" }); totalErrorDocuments++; } percentage = ((decimal)progress / totalItems) * 100.0m; if (Math.Ceiling(percentage) > pulsePercentageLimit) { await SendNotification(commandModel.ReferenceId, $"Migrazione documenti ({pulsePercentageLimit}%, {totalErrorDocuments} in errore)", (totalErrorDocuments > 0 ? NotifyLevel.Warning : NotifyLevel.Info), errorDetails); pulsePercentageLimit += 20; } progress++; } await SendNotification(commandModel.ReferenceId, $"Migrazione documenti (100%, {totalErrorDocuments} in errore)", (totalErrorDocuments > 0 ? NotifyLevel.Warning : NotifyLevel.Info)); _logger.Info("Build Index and AwardBatch style files"); await SendNotification(commandModel.ReferenceId, "Creazione fogli di stile per visualizzazione file di Indice e Lotti", NotifyLevel.Info); string indexXsl = _preservationService.BuildPreservationIndexXSL(currentArchive); string awardBatchXsl = _preservationService.GetAwardBatchXSL(); ArchiveCompany archiveCompany = _preservationService.GetArchiveCompanies(currentArchive.IdArchive).SingleOrDefault(); if (archiveCompany == null) { archiveCompany = new ArchiveCompany() { IdArchive = currentArchive.IdArchive, IdCompany = currentCompany.IdCompany, WorkingDir = $@"{currentArchive.PathPreservation}\{currentArchive.Name}\Comunicazioni", XmlFileTemplatePath = $@"{currentArchive.PathPreservation}\{currentArchive.Name}\Comunicazioni\Template.xml" }; archiveCompany = ArchiveService.AddArchiveCompany(archiveCompany); } archiveCompany.AwardBatchXSLTFile = awardBatchXsl; archiveCompany.TemplateXSLTFile = indexXsl; ArchiveService.UpdateArchiveCompany(archiveCompany); StringBuilder resultBuilder = new StringBuilder(); resultBuilder.Append($"Archivio {currentArchive.Name} configurato correttamente per la conservazione"); if (totalErrorDocuments > 0) { resultBuilder.Append(". Alcuni documenti non sono stati migrati e potrebbero dare errore in fase di conservazione"); } await SendNotification(commandModel.ReferenceId, resultBuilder.ToString(), NotifyLevel.Info, true); } catch (Exception ex) { _logger.Error("Error on configure archive for preservation", ex); await SendNotification(commandModel.ReferenceId, $"Errore nella configurazione dell'archivio per la conservazione", NotifyLevel.Error, new List <NotificationDetailModel>() { new NotificationDetailModel() { Id = Guid.NewGuid(), ActivityName = $"Errore configurazione archivo", Detail = $"{ex.Message}\r\n{ex.StackTrace}" } }, true); } }
private string CreateAwardBatchRptFile(Objects.Preservation preservation, Company company, string workingDir, string preservationName, string exceptions, IDictionary <Guid, BindingList <DocumentAttributeValue> > fullDocumentAttributes) { logger.InfoFormat("CreateAwbReportFile - 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 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 sFileNameBatch = Path.Combine(workingDir, "LOTTI_" + preservationName + ".xml"); var sFileBatchXsl = Path.Combine(workingDir, "LOTTI_" + preservationName + ".xsl"); //Scrive il file XSLT di trasformazione del AwardBatch Xml ArchiveCompany archiveCompany = null; var list = GetArchiveCompany(preservation.Archive.IdArchive, company.CompanyName); if (list != null && list.Count > 0) { archiveCompany = list[0]; } File.WriteAllText(sFileBatchXsl, archiveCompany.AwardBatchXSLTFile); //generazione oggetto AwbReport che sarà poi serializzato come file Xml AwbReport report = new AwbReport(); BindingList <Objects.AwardBatch> batches = GetPreservationAwardBatches(preservation.IdPreservation); //elenco dei lotti List <AwbBatch> batchList = new List <AwbBatch>(); foreach (Objects.AwardBatch awardBatch in batches) { batchList.Add(new AwbBatch { Descrizione = awardBatch.Name, Files = GetAwardBatchFiles(preservation, awardBatch.IdAwardBatch, fullDocumentAttributes) }); } //elenco dei file report.Batches = batchList.ToArray(); //salva nella cartella di destinazione report.SaveAs(sFileNameBatch, sFileBatchXsl); logger.Info("CreateAwbReportFile - ritorno al chiamante"); return(string.Empty); } catch (Exception e) { logger.Error(e); return(e.Message + " ===> " + e.Source); } }