From 952e0b12f154e219310c877b66e6512e27c2f447 Mon Sep 17 00:00:00 2001 From: stidsborg Date: Sun, 6 Oct 2024 11:57:51 +0200 Subject: [PATCH] Improved MessageDrivenOrderFlow sample for presentation --- .../Flows/MessageDriven/MessageDrivenOrderFlow.cs | 15 +++++++++++++++ .../MessageDriven/OrderProcessingException.cs | 6 ++++++ .../MessageDriven/Other/EventsAndCommands.cs | 3 ++- .../Solution/MessageDrivenOrderFlow.cs | 2 +- .../G_SupportTicket/Solution/SupportTicketFlow.cs | 2 +- 5 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 Samples/Cleipnir.Flows.Sample.Presentation.AspNet/Flows/MessageDriven/OrderProcessingException.cs diff --git a/Samples/Cleipnir.Flows.Sample.Presentation.AspNet/Flows/MessageDriven/MessageDrivenOrderFlow.cs b/Samples/Cleipnir.Flows.Sample.Presentation.AspNet/Flows/MessageDriven/MessageDrivenOrderFlow.cs index 2f29f29..ac50a52 100644 --- a/Samples/Cleipnir.Flows.Sample.Presentation.AspNet/Flows/MessageDriven/MessageDrivenOrderFlow.cs +++ b/Samples/Cleipnir.Flows.Sample.Presentation.AspNet/Flows/MessageDriven/MessageDrivenOrderFlow.cs @@ -1,4 +1,6 @@ using Cleipnir.Flows.Sample.MicrosoftOpen.Flows.MessageDriven.Other; +using Cleipnir.ResilientFunctions.Helpers; +using Cleipnir.ResilientFunctions.Reactive.Extensions; namespace Cleipnir.Flows.Sample.MicrosoftOpen.Flows.MessageDriven; @@ -6,6 +8,7 @@ public class MessageDrivenOrderFlow(Bus bus) : Flow { public override async Task Run(Order order) { + //todo throw OrderProcessingException var transactionId = await Capture(Guid.NewGuid); await ReserveFunds(order, transactionId); @@ -24,14 +27,26 @@ private Task ReserveFunds(Order order, Guid transactionId) => Capture( () => bus.Send(new ReserveFunds(order.OrderId, order.TotalPrice, transactionId, order.CustomerId)) ); + private Task CancelFundsReservation(Order order, Guid transactionId) + => Capture( + () => bus.Send(new CancelFundsReservation(order.OrderId, transactionId)) + ); private Task ShipProducts(Order order) => Capture( () => bus.Send(new ShipProducts(order.OrderId, order.CustomerId, order.ProductIds)) ); + private Task CancelProductsShipment(Order order) + => Capture( + () => bus.Send(new CancelProductsShipment(order.OrderId)) + ); private Task CaptureFunds(Order order, Guid transactionId) => Capture( () => bus.Send(new CaptureFunds(order.OrderId, order.CustomerId, transactionId)) ); + private Task ReverseTransaction(Order order, Guid transactionId) + => Capture( + () => bus.Send(new ReverseTransaction(order.OrderId, transactionId)) + ); private Task SendOrderConfirmationEmail(Order order, string trackAndTraceNumber) => Capture( () => bus.Send(new SendOrderConfirmationEmail(order.OrderId, order.CustomerId, trackAndTraceNumber)) diff --git a/Samples/Cleipnir.Flows.Sample.Presentation.AspNet/Flows/MessageDriven/OrderProcessingException.cs b/Samples/Cleipnir.Flows.Sample.Presentation.AspNet/Flows/MessageDriven/OrderProcessingException.cs new file mode 100644 index 0000000..6b9ba3b --- /dev/null +++ b/Samples/Cleipnir.Flows.Sample.Presentation.AspNet/Flows/MessageDriven/OrderProcessingException.cs @@ -0,0 +1,6 @@ +namespace Cleipnir.Flows.Sample.MicrosoftOpen.Flows.MessageDriven; + +public class OrderProcessingException : Exception +{ + public OrderProcessingException(string message) : base(message) { } +} \ No newline at end of file diff --git a/Samples/Cleipnir.Flows.Sample.Presentation.AspNet/Flows/MessageDriven/Other/EventsAndCommands.cs b/Samples/Cleipnir.Flows.Sample.Presentation.AspNet/Flows/MessageDriven/Other/EventsAndCommands.cs index f47529d..4baef62 100644 --- a/Samples/Cleipnir.Flows.Sample.Presentation.AspNet/Flows/MessageDriven/Other/EventsAndCommands.cs +++ b/Samples/Cleipnir.Flows.Sample.Presentation.AspNet/Flows/MessageDriven/Other/EventsAndCommands.cs @@ -18,4 +18,5 @@ public record FundsReservationFailed(string OrderId) : EventsAndCommands; public record FundsCaptureFailed(string OrderId) : EventsAndCommands; public record ProductsShipmentFailed(string OrderId) : EventsAndCommands; public record OrderConfirmationEmailFailed(string OrderId) : EventsAndCommands; -public record CancelProductShipment(string OrderId) : EventsAndCommands; \ No newline at end of file +public record CancelProductsShipment(string OrderId) : EventsAndCommands; +public record ReverseTransaction(string OrderId, Guid TransactionId) : EventsAndCommands; \ No newline at end of file diff --git a/Samples/Cleipnir.Flows.Sample.Presentation.AspNet/Flows/MessageDriven/Solution/MessageDrivenOrderFlow.cs b/Samples/Cleipnir.Flows.Sample.Presentation.AspNet/Flows/MessageDriven/Solution/MessageDrivenOrderFlow.cs index 10f0aa1..11e41c3 100644 --- a/Samples/Cleipnir.Flows.Sample.Presentation.AspNet/Flows/MessageDriven/Solution/MessageDrivenOrderFlow.cs +++ b/Samples/Cleipnir.Flows.Sample.Presentation.AspNet/Flows/MessageDriven/Solution/MessageDrivenOrderFlow.cs @@ -59,7 +59,7 @@ private Task CaptureFunds(Order order, Guid transactionId) private Task SendOrderConfirmationEmail(Order order, ProductsShipped productsShipped) => Capture(() => bus.Send(new SendOrderConfirmationEmail(order.OrderId, order.CustomerId, productsShipped.TrackAndTraceNumber))); private Task CancelProductsShipment(Order order) - => Capture(() => bus.Send(new CancelProductShipment(order.OrderId))); + => Capture(() => bus.Send(new CancelProductsShipment(order.OrderId))); private Task CancelFundsReservation(Order order, Guid transactionId) => Capture(() => bus.Send(new CancelFundsReservation(order.OrderId, transactionId))); } diff --git a/Samples/Cleipnir.Flows.Sample.Presentation/G_SupportTicket/Solution/SupportTicketFlow.cs b/Samples/Cleipnir.Flows.Sample.Presentation/G_SupportTicket/Solution/SupportTicketFlow.cs index ef0c6f1..fc5669d 100644 --- a/Samples/Cleipnir.Flows.Sample.Presentation/G_SupportTicket/Solution/SupportTicketFlow.cs +++ b/Samples/Cleipnir.Flows.Sample.Presentation/G_SupportTicket/Solution/SupportTicketFlow.cs @@ -21,7 +21,7 @@ await Effect.Capture( .Where(e => e.Match(taken => taken.Iteration, rejected => rejected.Iteration) == i) .FirstOrNone(); - if (!option.HasValue && option.Value.AsObject() is SupportTicketTaken) + if (!option.HasNone && option.AsObject() is SupportTicketTaken) return; //ticket was taken in iteration i } }