//Handles the loan LoanElectedWithHoldsEvent by firing a work item to WFM private void HandleLoanElectedWithHoldsEvent(PaymentEvent paymentEvent) { Trace.WriteLine("Handlinge LoanElectedWithHoldsEvent..."); workforceClient.PublishWorkItem(paymentEvent); paymentEvent.MarkAsHandled(); dbContext.SaveChanges(); }
//Publishes an event out over the bus. public void Publish(PaymentEvent paymentEvent) { //We could test to see what happens in the event of an error. //For example, we may not be able to communicate with our bus. //Uncomment the following line to test this. //throw new Exception("CommunicationException"); //This is being faked for now, so just write to the trace log. Trace.WriteLine("ServiceBus: " + paymentEvent.ToString()); }
//Handles the PaymentCreatedEvent by starting eligibility. private void HandlePaymentCreatedEvent(PaymentEvent paymentEvent) { Trace.WriteLine("Handling PaymentCreatedEvent..."); var payment = dbContext .Payments .Where(x=>x.PaymentId == paymentEvent.PaymentId) .First(); var loan = new Loan(true); payment.ElectLoan(loan); paymentEvent.MarkAsHandled(); dbContext.SaveChanges(); }
public void HandlePaymentEvent(PaymentEvent paymentEvent) { if (paymentEvent == null) { throw new ArgumentNullException("paymentEvent"); } switch (paymentEvent.EventType) { case PaymentEventType.PaymentCreated: HandlePaymentCreatedEvent(paymentEvent); break; case PaymentEventType.LoanElectedWithHolds: HandleLoanElectedWithHoldsEvent(paymentEvent); break; case PaymentEventType.PaymentEligible: HandlePaymentEligibleEvent(paymentEvent); break; default: throw new InvalidOperationException(); } }
//Handles the EligiblePaymentEvent by forwarding it out over the service bus. private void HandlePaymentEligibleEvent(PaymentEvent paymentEvent) { Trace.WriteLine("Handlinge PaymentEligibleEvent..."); serviceBusClient.Publish(paymentEvent); paymentEvent.MarkAsHandled(); dbContext.SaveChanges(); }
private void RaiseEvent(PaymentEvent paymentEvent) { if (Events == null) { Events = new List<PaymentEvent>(); } Events.Add(paymentEvent); }