SHARE
TWEET

Untitled

a guest Mar 23rd, 2019 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using CreditCardValidator;
  2. using Domain;
  3. using EasyNetQ;
  4. using Microsoft.Extensions.Hosting;
  5. using System;
  6. using System.Threading;
  7. using System.Threading.Tasks;
  8.  
  9. namespace PagamentoService.BackgroundServices
  10. {
  11.     public class NovoPedidoEventHandler : BackgroundService
  12.     {
  13.         private IBus _bus;
  14.  
  15.         protected override async Task ExecuteAsync(CancellationToken stoppingToken)
  16.         {
  17.             _bus = RabbitHutch.CreateBus("host=127.0.0.1");
  18.             _bus.Subscribe<OrderCreatedEvent>("PagamentoService", ProccessPayment);
  19.  
  20.             while (!stoppingToken.IsCancellationRequested)
  21.             {
  22.                 await Task.Delay(TimeSpan.FromSeconds(15), stoppingToken);
  23.             }
  24.             _bus.Dispose();
  25.         }
  26.  
  27.         private void ProccessPayment(OrderCreatedEvent order)
  28.         {
  29.             var payment = new Payment(order.Id, order.CreditCard.CardNumber, order.CreditCard.Expiration, order.CreditCard.Name);
  30.             var detector = new CreditCardDetector(order.CreditCard.CardNumber);
  31.             if (detector.IsValid())
  32.                 payment.Apply(detector.BrandName);
  33.             else
  34.                 payment.Deny();
  35.             // Businness rules, save at database, etc...
  36.         }
  37.     }
  38. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top