public SaveAwardBatchXMLResponseModel Process(SaveAwardBatchXMLRequestModel request) { DocumentArchive[] archives = _documentsClient.GetArchives(); DocumentAttribute[] attributes = _documentsClient.GetAttributesDefinition(request.ArchiveName); AwardBatch awardBatch = _preservationService.GetAwardBatch(request.IdAwardBatch); if (awardBatch == null) { _logger.Warn(string.Concat("GenerateAwardBatchRDVInteractor -> award batch with id ", request.IdAwardBatch, " not found")); throw new Exception(string.Concat("Award batch with id ", request.IdAwardBatch, " not found")); } DocumentArchive rdvArchive = archives.SingleOrDefault(s => s.Name.Equals(request.ArchiveName, StringComparison.InvariantCultureIgnoreCase)); if (rdvArchive == null) { _logger.Warn(string.Concat("GenerateAwardBatchRDVInteractor -> archive ", request.ArchiveName, " not found")); throw new Exception(string.Concat("Archive ", request.ArchiveName, " not found")); } Document chainDocument = new Document() { Archive = rdvArchive }; chainDocument = _documentsClient.InsertDocumentChain(chainDocument); Document document = new Document { Content = new DocumentContent() { Blob = request.Content }, Name = string.Concat(UtilityService.GetSafeFileName(awardBatch.Name), ".xml"), Archive = rdvArchive, AttributeValues = new System.ComponentModel.BindingList <DocumentAttributeValue>() }; document.AttributeValues.Add(new DocumentAttributeValue() { Value = document.Name, Attribute = attributes.Single(f => f.Name.Equals("Filename", StringComparison.InvariantCultureIgnoreCase)) }); document.AttributeValues.Add(new DocumentAttributeValue() { Value = awardBatch.Name, Attribute = attributes.Single(f => f.Name.Equals("Descrizione", StringComparison.InvariantCultureIgnoreCase)) }); document.AttributeValues.Add(new DocumentAttributeValue() { Value = awardBatch.DateFrom, Attribute = attributes.Single(f => f.Name.Equals("DataInizio", StringComparison.InvariantCultureIgnoreCase)) }); document.AttributeValues.Add(new DocumentAttributeValue() { Value = awardBatch.DateTo, Attribute = attributes.Single(f => f.Name.Equals("DataFine", StringComparison.InvariantCultureIgnoreCase)) }); document.AttributeValues.Add(new DocumentAttributeValue() { Value = DateTime.UtcNow, Attribute = attributes.Single(f => f.Name.Equals("DataGenerazione", StringComparison.InvariantCultureIgnoreCase)) }); document.AttributeValues.Add(new DocumentAttributeValue() { Value = _preservationService.GetAwardBatchDocumentsCounter(awardBatch.IdAwardBatch), Attribute = attributes.Single(f => f.Name.Equals("NumeroDocumenti", StringComparison.InvariantCultureIgnoreCase)) }); document = _documentsClient.AddDocumentToChain(document, chainDocument.IdDocument, Library.Common.Enums.DocumentContentFormat.Binary); awardBatch.IdRDVDocument = document.IdDocument; _preservationService.UpdateAwardBatch(awardBatch); return(new SaveAwardBatchXMLResponseModel() { IdDocument = document.IdDocument }); }
public override async Task Execute(CommandModel commandModel) { try { if (!(commandModel is CommandInsertPreservationRDV)) { _logger.Error($"Command is not of type {nameof(CommandInsertPreservationRDV)}"); return; } CommandInsertPreservationRDV @command = commandModel as CommandInsertPreservationRDV; await SendNotification(command.ReferenceId, $"Inizio salvataggio RDV per il lotto di versamento con id {command.IdAwardBatch}", NotifyLevel.Info); DocumentArchive rdvArchive = ArchiveService.GetArchiveByName(command.RDVArchive); if (rdvArchive == null) { _logger.Error($"Archive with name {command.RDVArchive} not found"); throw new Exception($"Non è stato trovato un archivio con nome {command.RDVArchive}"); } ICollection <DocumentAttribute> attributes = AttributeService.GetAttributesFromArchive(rdvArchive.IdArchive); AwardBatch awardBatch = _preservationService.GetAwardBatch(command.IdAwardBatch); if (awardBatch == null) { _logger.Error($"Award batch with id {command.IdAwardBatch} not found"); throw new Exception($"Non è stato trovato un lotto di versamento con id {command.IdAwardBatch}"); } Document document = new Document { Content = new DocumentContent() { Blob = Convert.FromBase64String(command.Content) }, Name = string.Concat(UtilityService.GetSafeFileName(awardBatch.Name), ".xml"), Archive = rdvArchive, AttributeValues = new BindingList <DocumentAttributeValue>() }; document.AttributeValues.Add(new DocumentAttributeValue() { Value = document.Name, Attribute = attributes.Single(f => f.Name.Equals("Filename", StringComparison.InvariantCultureIgnoreCase)) }); document.AttributeValues.Add(new DocumentAttributeValue() { Value = awardBatch.Name, Attribute = attributes.Single(f => f.Name.Equals("Descrizione", StringComparison.InvariantCultureIgnoreCase)) }); document.AttributeValues.Add(new DocumentAttributeValue() { Value = awardBatch.DateFrom, Attribute = attributes.Single(f => f.Name.Equals("DataInizio", StringComparison.InvariantCultureIgnoreCase)) }); document.AttributeValues.Add(new DocumentAttributeValue() { Value = awardBatch.DateTo, Attribute = attributes.Single(f => f.Name.Equals("DataFine", StringComparison.InvariantCultureIgnoreCase)) }); document.AttributeValues.Add(new DocumentAttributeValue() { Value = DateTime.UtcNow, Attribute = attributes.Single(f => f.Name.Equals("DataGenerazione", StringComparison.InvariantCultureIgnoreCase)) }); document.AttributeValues.Add(new DocumentAttributeValue() { Value = _preservationService.GetAwardBatchDocumentsCounter(awardBatch.IdAwardBatch), Attribute = attributes.Single(f => f.Name.Equals("NumeroDocumenti", StringComparison.InvariantCultureIgnoreCase)) }); using (var clientChannel = WCFUtility.GetClientConfigChannel <IDocuments>(ServerService.WCF_Document_HostName)) { document = (clientChannel as IDocuments).AddDocumentToChain(document, null, DocumentContentFormat.Binary); } awardBatch.IdRDVDocument = document.IdDocument; _preservationService.UpdateAwardBatch(awardBatch); _logger.Info($"Saved RDV with id {awardBatch.IdRDVDocument} for awardbatch {awardBatch.IdAwardBatch}"); await SendNotification(command.ReferenceId, $"RDV salvato con id {awardBatch.IdRDVDocument} per il lotto di versamento con id {awardBatch.IdAwardBatch}", NotifyLevel.Info); } catch (Exception ex) { _logger.Error("Error on insert RDV", ex); await SendNotification(commandModel.ReferenceId, $"Errore nella fase di inserimento RDV", NotifyLevel.Error); } }