Пример #1
0
        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("GenerateAwardBatchPDVInteractor -> award batch with id ", request.IdAwardBatch, " not found"));
                throw new Exception(string.Concat("Award batch with id ", request.IdAwardBatch, " not found"));
            }

            DocumentArchive pdvArchive = archives.SingleOrDefault(s => s.Name.Equals(request.ArchiveName, StringComparison.InvariantCultureIgnoreCase));

            if (pdvArchive == null)
            {
                _logger.Warn(string.Concat("GenerateAwardBatchPDVInteractor -> archive ", request.ArchiveName, " not found"));
                throw new Exception(string.Concat("Archive ", request.ArchiveName, " not found"));
            }
            Document chainDocument = new Document()
            {
                Archive = pdvArchive
            };

            chainDocument = _documentsClient.InsertDocumentChain(chainDocument);

            Document document = new Document
            {
                Content = new DocumentContent()
                {
                    Blob = request.Content
                },
                Name            = string.Concat(UtilityService.GetSafeFileName(awardBatch.Name), ".xml"),
                Archive         = pdvArchive,
                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("Signature", StringComparison.InvariantCultureIgnoreCase))
            });
            document = _documentsClient.AddDocumentToChain(document, chainDocument.IdDocument, Library.Common.Enums.DocumentContentFormat.Binary);
            awardBatch.IdPDVDocument = document.IdDocument;
            _preservationService.UpdateAwardBatch(awardBatch);
            return(new SaveAwardBatchXMLResponseModel()
            {
                IdDocument = document.IdDocument
            });
        }
Пример #2
0
        public ActionResult Detail(Guid id)
        {
            return(ActionResultHelper.TryCatchWithLogger(() =>
            {
                AwardBatch awardBatch = _preservationService.GetAwardBatch(id);
                if (awardBatch == null)
                {
                    throw new Exception(string.Format("Nessun pacchetto di versamento trovato con id {0}", id));
                }

                AwardBatchDetailsViewModel model = new AwardBatchDetailsViewModel()
                {
                    IdArchive = awardBatch.IdArchive,
                    IdAwardBatch = awardBatch.IdAwardBatch,
                    Name = awardBatch.Name,
                    IsOpen = awardBatch.IsOpen
                };
                return View(model);
            }, _loggerService));
        }
Пример #3
0
        public override async Task Execute(CommandModel commandModel)
        {
            try
            {
                if (!(commandModel is CommandInsertPreservationPDV))
                {
                    _logger.Error($"Command is not of type {nameof(CommandInsertPreservationPDV)}");
                    return;
                }

                CommandInsertPreservationPDV @command = commandModel as CommandInsertPreservationPDV;
                await SendNotification(command.ReferenceId, $"Inizio salvataggio PDV per il lotto di versamento con id {command.IdAwardBatch}", NotifyLevel.Info);

                DocumentArchive pdvArchive = ArchiveService.GetArchiveByName(command.PDVArchive);
                if (pdvArchive == null)
                {
                    _logger.Error($"Archive with name {command.PDVArchive} not found");
                    throw new Exception($"Non è stato trovato un archivio con nome {command.PDVArchive}");
                }

                ICollection <DocumentAttribute> attributes = AttributeService.GetAttributesFromArchive(pdvArchive.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         = pdvArchive,
                    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("Signature", StringComparison.InvariantCultureIgnoreCase))
                });

                using (var clientChannel = WCFUtility.GetClientConfigChannel <IDocuments>(ServerService.WCF_Document_HostName))
                {
                    document = (clientChannel as IDocuments).AddDocumentToChain(document, null, DocumentContentFormat.Binary);
                }
                awardBatch.IdPDVDocument = document.IdDocument;
                _preservationService.UpdateAwardBatch(awardBatch);
                _logger.Info($"Saved PDV with id {awardBatch.IdPDVDocument} for awardbatch {awardBatch.IdAwardBatch}");
                await SendNotification(command.ReferenceId, $"PDV salvato con id {awardBatch.IdPDVDocument} per il lotto di versamento con id {awardBatch.IdAwardBatch}", NotifyLevel.Info);
            }
            catch (Exception ex)
            {
                _logger.Error("Error on insert PDV", ex);
                await SendNotification(commandModel.ReferenceId, $"Errore nella fase di inserimento PDV", NotifyLevel.Error);
            }
        }