Esempio n. 1
0
        public override bool ProcessBatch(OcrBatch batch)
        {
            bool result;

            try
            {
                _mutex.WaitOne();
                PreProcessVouchers(this);
                foreach (VoucherType voucher in Enum.GetValues(typeof(VoucherType)))
                {
                    ProcessVouchers(batch.Vouchers, voucher);
                }

                CloseOcrChannel();
                result = true;
            }
            catch (Exception ex)
            {
                Log.Error(ex, "An exception has occurred processing batch {0}", batch.JobIdentifier);
                result = false;
                //throw;
            }
            finally
            {
                _mutex.ReleaseMutex();
                OnBatchComplete(this, batch);
            }
            return(result);
        }
Esempio n. 2
0
        private static void OcrService_BatchComplete(object sender, OcrBatch batch)
        {
            //Console.WriteLine("Batch {0} completed", batch.JobIdentifier);
            // publish result to outgoing queue/exchange
            var messageBatch = new RecogniseBatchCourtesyAmountResponse
            {
                jobIdentifier = batch.JobIdentifier,
                voucher       = batch.Vouchers.Select(v => new RecogniseCourtesyAmountResponse
                {
                    documentReferenceNumber = v.Id,
                    capturedAmount          = v.AmountResult.Result ?? "0",
                    amountConfidenceLevel   = v.AmountResult.Score ?? "0",
                    amountRegionOfInterest  = new RegionOfInterest
                    {
                        height = v.AmountResult.Location.Height,
                        left   = v.AmountResult.Location.Left,
                        top    = v.AmountResult.Location.Top,
                        width  = v.AmountResult.Location.Width
                    }
                }).ToArray()
            };

            //MessageBus.Publish(messageBatch, RoutingKey);
            //Queue.PublishToExchange(OutboundExchangeName, batch.JobIdentifier, RoutingKey, CustomJsonSerializer.MessageToBytes(messageBatch));
            Exchange.SendMessage(CustomJsonSerializer.MessageToBytes(messageBatch), RoutingKey, batch.JobIdentifier);
        }
Esempio n. 3
0
 public void ProcessBatch(OcrBatch batch)
 {
     foreach (var ocrVoucher in batch.Vouchers)
     {
         ProcessVoucher(ocrVoucher);
     }
 }
Esempio n. 4
0
        public virtual void ProcessBatch(OcrBatch batch)
        {
            try
            {
                mutex.WaitOne();
                PreProcessVouchers(a2iAOcrService);
                foreach (VoucherType voucher in Enum.GetValues(typeof(VoucherType)))
                {
                    ProcessVouchers(batch.Vouchers, voucher);
                }

                a2iAOcrService.CloseOcrChannel();
            }
            catch (Exception)
            {
                {
                }
                throw;
            }
            finally
            {
                mutex.ReleaseMutex();
                OnBatchComplete(this, batch.JobIdentifier);
            }
        }
Esempio n. 5
0
        protected void OnBatchComplete(object sender, OcrBatch batch)
        {
            var batchComplete = BatchComplete;

            if (batchComplete != null)
            {
                batchComplete(sender, batch);
            }
        }
Esempio n. 6
0
 public override void ProcessBatch(OcrBatch batch)
 {
     if (cancellationTokenSource != null)
     {
         cancellationTokenSource.Cancel(false);                                  //cancel the timeout
     }
     cancellationTokenSource = new CancellationTokenSource();
     batchProcessing         = true;
     base.ProcessBatch(batch);
 }
        public virtual void ProcessBatch(OcrBatch batch)
        {
            var vouchers = batch.Vouchers;

            foreach (var a2iAOcrService in a2iAOcrServices)
            {
                PreProcessVouchers(a2iAOcrService);
                ProcessVouchers(vouchers, a2iAOcrService.Key);
            }
            OnBatchComplete(this, batch.JobIdentifier);
        }
        public void ValidateImageFiles(OcrBatch batch)
        {
            var missingImages = batch.Vouchers
                                .Where(v => !File.Exists(v.ImagePath))
                                .Select(v => v.Id)
                                .ToList();

            if (missingImages.Any())
            {
                throw new FileNotFoundException(string.Format("Could not find image files for the following vouchers : {0}", string.Join(", ", missingImages)));
            }
        }
Esempio n. 9
0
        private static bool ValidateImageFiles(OcrBatch batch)
        {
            var missingImages = batch.Vouchers
                                .Where(v => !File.Exists(v.ImagePath))
                                .Select(v => v.Id)
                                .ToList();

            if (!missingImages.Any())
            {
                return(true);
            }
            Log.Warning(string.Format("Could not find image files for the following vouchers : {0}",
                                      string.Join(", ", missingImages)));
            return(false);
        }
Esempio n. 10
0
        public static void Consumer_ReceiveMessage(IBasicGetResult message)
        {
            // Process Message from queue
            if (message == null)
            {
                return;                 // queue is empty
            }
            var batch = CustomJsonSerializer.BytesToMessage <RecogniseBatchCourtesyAmountRequest>(message.Body);

            //var batch = message;

            if (message.Body.Count() == 0)
            {
                Log.Error(
                    "ProcessingService: Queue_MessageRecieved(message) - message.Body contains no data for message id {0}",
                    message.BasicProperties.MessageId);
            }
            if (batch == null)
            {
                if (message.Body.Count() > 0)
                {
                    Log.Error(
                        "ProcessingService: Queue_MessageRecieved(message) - message.Body contains data which is not compatible with RecogniseBatchCourtesyAmountRequest for message id {0}",
                        message.BasicProperties.MessageId);
                }
                // need to re-route message to CAR.Invalid queue
                if (!string.IsNullOrEmpty(InvalidQueueName))
                {
                    InvalidExchange.SendMessage(message.Body, InvalidRoutingKey, "");
                }
                return; // acknowledge message to remove from queue;
            }
            RoutingKey = message.RoutingKey;
            if (batch.voucher == null || batch.voucher.Length == 0)
            {
                Log.Error(
                    "ProcessingService: Queue_MessageRecieved(message) - there are no vouchers present for message id {0}",
                    message.BasicProperties.MessageId);
                // need to re-route message to CAR.Invalid queue
                if (!string.IsNullOrEmpty(InvalidQueueName))
                {
                    InvalidExchange.SendMessage(message.Body, InvalidRoutingKey, "");
                }
                return; // acknowledge message to remove from queue;
            }
            var ocrBatch = new OcrBatch
            {
                JobIdentifier = batch.jobIdentifier,
                Vouchers      = batch.voucher.Select(v => new OcrVoucher
                {
                    Id          = v.documentReferenceNumber,
                    ImagePath   = Path.Combine(ImageFilePath, batch.jobIdentifier, string.Format(ImageFileNameTemplate, v.processingDate, v.documentReferenceNumber)),
                    VoucherType = ParseTransactionCode(v.transactionCode)
                }).ToList()
            };

            // Validate the file path
            if (!ValidateImageFiles(ocrBatch))
            {
                return;                               // probably should send to an error queue
            }
            Log.Information("Batch {0} received from message queue containing {1} vouchers", ocrBatch.JobIdentifier, ocrBatch.Vouchers.Count());
            OcrService.ProcessBatch(ocrBatch);
        }
Esempio n. 11
0
 public abstract bool ProcessBatch(OcrBatch batch);
Esempio n. 12
0
 public void ProcessBatch(OcrBatch batch)
 {
     ProcessVoucherAsync(batch.Vouchers.Where(v => v.VoucherType == VoucherType.Debit).ToList());
     ProcessVoucherAsync(batch.Vouchers.Where(v => v.VoucherType == VoucherType.Credit).ToList());
 }