Exemplo n.º 1
0
 public MessageEndpointContext AddUnprocessed(DomainMessage e)
 {
     return(new MessageEndpointContext(
                ProcessedSuccessfully,
                ProcessedUnsuccessfully,
                Unprocessed.Concat(new[] { e }),
                this.SourceQueue));
 }
Exemplo n.º 2
0
        public async Task <FileUploadResult> HandleUploadAsync(
            int userId,
            HttpFile file,
            ILiquidacaoStore liquidacaoStore,
            IEventStore eventStore)
        {
            using (var reader = new StreamReader(file.Value))
            {
                string line;
                while ((line = await reader.ReadLineAsync()) != null)
                {
                    var currentLine = LineValidation
                                      .ValidateLine(line)
                                      .IsHeader()
                                      .IsEmpty()
                                      .IsOk();

                    if (currentLine.IsValid)
                    {
                        var receipt = currentLine.Receipt;
                        SetReceiptDate(receipt.Recebimento);

                        if (LineValidation.ValidateCnpj(receipt.Cnpj))
                        {
                            var errorMessage = MessageHandler(receipt.Nf, ErrorEnum.CnpjInvalido);
                            Unprocessed.AppendLine(errorMessage);
                            continue;
                        }

                        await ProccessReceiptAsync(receipt);
                    }
                }
            }

            var hum = new HandlerUploadModel
            {
                UserId          = userId,
                LiquidacaoStore = liquidacaoStore,
                EventStore      = eventStore,
                VirtualPath     = Guid.NewGuid().ToString().Replace("-", "")
            };

            return(FileUploadResult(hum, true));
        }