public async Task <IActionResult> AddSend(DocumentToSend document)
 {
     try
     {
         return(Ok(await _iSender.addSend(document)));
     }
     catch (Exception e)
     {
         return(BadRequest(new { message = "error al intentar agregar el envío solicitado." }));
     }
 }
        private async Task <bool> SendToVirtualUser(DocumentToSend documentToSend, bool vuSuccess, ParsedDocument result)
        {
            if (typesToSendToVu.Contains(result.DocumentType))
            {
                if (!await virtualUserConnector.SendInput(result.Data))
                {
                    logger.Error($"File {documentToSend.FileName} was not successfully processed by Virtual User");
                }
                ;
                logger.Information($"File {documentToSend.FileName} was processed by Virtual User");
                vuSuccess = true;
            }

            return(vuSuccess);
        }
        private async Task <bool> SaveToArchive(DocumentToSend documentToSend, byte[] bytesToSend, bool archivingSuccess, ParsedDocument result)
        {
            if (typesToArchive.Contains(result.DocumentType))
            {
                await repository.AddOneAsync(new DocumentToArchive()
                {
                    Data = bytesToSend
                });

                logger.Information($"File {documentToSend.FileName} was successfully archived");
                archivingSuccess = true;
            }

            return(archivingSuccess);
        }
예제 #4
0
        public async Task <bool> addSend(DocumentToSend document)
        {
            DocumentToSend newDocumentToSend;

            try
            {
                document.Date      = DateTime.Now;
                document.Sent      = false;
                document.TimesSent = 0;
                _dbContex.Entry(document).State = EntityState.Added;
                return(await _dbContex.SaveChangesAsync() > 0);
            }
            catch (Exception e)
            {
                throw;
            }
        }
예제 #5
0
        /// <summary>
        /// Use this method to send a document. On success, the sent Message is returned.
        /// </summary>
        public async Task <MessageResponse> SendDocumentAsync(DocumentToSend document)
        {
            await InitAsync();

            MessageResponse result = null;

            if (document.DocumentStream != null)
            {
                document.Method = "POST";
                result          = await DoRequest <MessageResponse>("sendDocument", document);
            }
            else
            {
                document.Method = "JSON";
                result          = await DoRequest <MessageResponse>("sendDocument", document);
            }

            return(result);
        }
        private async Task SendAndProcessDocument(string pathToFile)
        {
            var documentToSend = new DocumentToSend();

            documentToSend.FileName = Path.GetFileName(pathToFile);
            logger.Debug($"Processing of file:{Path.GetFileName(pathToFile)} started");
            var bytesToSend = await File.ReadAllBytesAsync(pathToFile);

            documentToSend.Data = bytesToSend;
            bool archivingSuccess = false;
            bool vuSuccess        = false;

            var result = await client.Post(documentToSend, "");

            if (result.Success)
            {
                archivingSuccess = await SaveToArchive(documentToSend, bytesToSend, archivingSuccess, result);

                vuSuccess = await SendToVirtualUser(documentToSend, vuSuccess, result);

                DeleteFileIfSuccess(archivingSuccess, vuSuccess, pathToFile);
                logger.Debug($"Processing of file:{documentToSend.FileName} was successful");
            }
        }