diff --git a/Samples/Cleipnir.Flows.Sample.Presentation/A_NewsletterSender/Solution/NewsletterFlow.cs b/Samples/Cleipnir.Flows.Sample.Presentation/A_NewsletterSender/Solution/NewsletterFlow.cs index 725ecbc..facd139 100644 --- a/Samples/Cleipnir.Flows.Sample.Presentation/A_NewsletterSender/Solution/NewsletterFlow.cs +++ b/Samples/Cleipnir.Flows.Sample.Presentation/A_NewsletterSender/Solution/NewsletterFlow.cs @@ -5,17 +5,17 @@ namespace Cleipnir.Flows.Sample.Presentation.A_NewsletterSender.Solution; -public class NewsletterFlow : Flow +public class NewsletterFlow : Flow, IHaveState { + public required FlowState State { get; init; } + public override async Task Run(MailAndRecipients mailAndRecipients) { var (recipients, subject, content) = mailAndRecipients; using var client = new SmtpClient(); await client.ConnectAsync("mail.smtpbucket.com", 8025); - - var state = Workflow.States.CreateOrGet(); - for (var atRecipient = state.AtRecipient; atRecipient < mailAndRecipients.Recipients.Count; atRecipient++) + for (var atRecipient = State.AtRecipient; atRecipient < mailAndRecipients.Recipients.Count; atRecipient++) { var recipient = recipients[atRecipient]; var message = new MimeMessage(); @@ -26,12 +26,12 @@ public override async Task Run(MailAndRecipients mailAndRecipients) message.Body = new TextPart(TextFormat.Html) { Text = content }; await client.SendAsync(message); - state.AtRecipient = atRecipient; - await state.Save(); + State.AtRecipient = atRecipient; + await State.Save(); } } - private class State : WorkflowState + public class FlowState : WorkflowState { public int AtRecipient { get; set; } } diff --git a/Samples/Cleipnir.Flows.Sample.Presentation/Examples/OrderFlow/Messaging/Solution/EventsAndCommands.cs b/Samples/Cleipnir.Flows.Sample.Presentation/Examples/OrderFlow/Messaging/Solution/EventsAndCommands.cs index dbfa2ae..4690ff4 100644 --- a/Samples/Cleipnir.Flows.Sample.Presentation/Examples/OrderFlow/Messaging/Solution/EventsAndCommands.cs +++ b/Samples/Cleipnir.Flows.Sample.Presentation/Examples/OrderFlow/Messaging/Solution/EventsAndCommands.cs @@ -6,10 +6,10 @@ public record OrderConfirmationEmailSent(string OrderId, Guid CustomerId) : Even public record ReserveFunds(string OrderId, decimal Amount, Guid TransactionId, Guid CustomerId) : EventsAndCommands; public record FundsReserved(string OrderId) : EventsAndCommands; public record ShipProducts(string OrderId, Guid CustomerId, IEnumerable ProductIds) : EventsAndCommands; -public record ProductsShipped(string OrderId) : EventsAndCommands; +public record ProductsShipped(string OrderId, string TrackAndTrace) : EventsAndCommands; public record ProductsShipmentFailed(string OrderId) : EventsAndCommands; -public record SendOrderConfirmationEmail(string OrderId, Guid CustomerId) : EventsAndCommands; +public record SendOrderConfirmationEmail(string OrderId, Guid CustomerId, string TrackAndTrace) : EventsAndCommands; public record CaptureFunds(string OrderId, Guid CustomerId, Guid TransactionId) : EventsAndCommands; public record FundsCaptured(string OrderId) : EventsAndCommands; diff --git a/Samples/Cleipnir.Flows.Sample.Presentation/Examples/OrderFlow/Messaging/Solution/LogisticsServiceStub.cs b/Samples/Cleipnir.Flows.Sample.Presentation/Examples/OrderFlow/Messaging/Solution/LogisticsServiceStub.cs index 93421ab..e3d9938 100644 --- a/Samples/Cleipnir.Flows.Sample.Presentation/Examples/OrderFlow/Messaging/Solution/LogisticsServiceStub.cs +++ b/Samples/Cleipnir.Flows.Sample.Presentation/Examples/OrderFlow/Messaging/Solution/LogisticsServiceStub.cs @@ -16,6 +16,6 @@ private async Task MessageHandler(EventsAndCommands message) return; await Task.Delay(1_000); - await _messageBroker.Send(new ProductsShipped(command.OrderId)); + await _messageBroker.Send(new ProductsShipped(command.OrderId, TrackAndTrace: Guid.NewGuid().ToString())); } } \ No newline at end of file diff --git a/Samples/Cleipnir.Flows.Sample.Presentation/Examples/OrderFlow/Messaging/Solution/OrderFlow.cs b/Samples/Cleipnir.Flows.Sample.Presentation/Examples/OrderFlow/Messaging/Solution/OrderFlow.cs index 118c91b..81dfc23 100644 --- a/Samples/Cleipnir.Flows.Sample.Presentation/Examples/OrderFlow/Messaging/Solution/OrderFlow.cs +++ b/Samples/Cleipnir.Flows.Sample.Presentation/Examples/OrderFlow/Messaging/Solution/OrderFlow.cs @@ -1,4 +1,5 @@ -using Cleipnir.ResilientFunctions.Reactive.Extensions; +using Cleipnir.ResilientFunctions.Helpers; +using Cleipnir.ResilientFunctions.Reactive.Extensions; using Serilog; using ILogger = Serilog.ILogger; @@ -18,24 +19,14 @@ public override async Task Run(Order order) await Messages.FirstOfType(); await messageBroker.Send(new ShipProducts(order.OrderId, order.CustomerId, order.ProductIds)); - - await Messages.FirstOfType(); + var trackAndTrace = await Messages.FirstOfType().SelectAsync(msg => msg.TrackAndTrace); await messageBroker.Send(new CaptureFunds(order.OrderId, order.CustomerId, transactionId)); await Messages.FirstOfType(); - await messageBroker.Send(new SendOrderConfirmationEmail(order.OrderId, order.CustomerId)); + await messageBroker.Send(new SendOrderConfirmationEmail(order.OrderId, order.CustomerId, trackAndTrace)); await Messages.FirstOfType(); Logger.Information($"Processing of order '{order.OrderId}' completed"); } - - /* - var either = await Messages.OfTypes().First(); - if (either.HasSecond) - { - await _messageBroker.Send(new CancelFundsReservation(order.OrderId, transactionId)); - return; - } - */ }