From e0579077bf5b1d9cb16a671da5c36c379e32af66 Mon Sep 17 00:00:00 2001 From: Aaron Stannard Date: Tue, 26 Mar 2024 15:52:14 -0500 Subject: [PATCH] cleaned up projector (#164) --- .../Actors/ProductTotalsActor.cs | 37 ++++++------------- .../CqrsSqlServer.Backend.csproj | 4 -- 2 files changed, 12 insertions(+), 29 deletions(-) diff --git a/src/cqrs/cqrs-sqlserver/CqrsSqlServer.Backend/Actors/ProductTotalsActor.cs b/src/cqrs/cqrs-sqlserver/CqrsSqlServer.Backend/Actors/ProductTotalsActor.cs index 2401369..b5e53fd 100644 --- a/src/cqrs/cqrs-sqlserver/CqrsSqlServer.Backend/Actors/ProductTotalsActor.cs +++ b/src/cqrs/cqrs-sqlserver/CqrsSqlServer.Backend/Actors/ProductTotalsActor.cs @@ -18,7 +18,7 @@ public static Props GetProps(string persistenceId) { return Props.Create(() => new ProductTotalsActor(persistenceId)); } - + /// /// Used to help differentiate what type of entity this is inside Akka.Persistence's database /// @@ -30,7 +30,7 @@ public ProductTotalsActor(string persistenceId) { PersistenceId = $"{TotalsEntityNameConstant}-" + persistenceId; State = new ProductState(); - + Recover(offer => { if (offer.Snapshot is ProductState state) @@ -39,43 +39,33 @@ public ProductTotalsActor(string persistenceId) } }); - Recover(productEvent => - { - State = State.ProcessEvent(productEvent); - }); + Recover(productEvent => { State = State.ProcessEvent(productEvent); }); Command(cmd => { var response = State.ProcessCommand(cmd); var sentResponse = false; - if (response.ResponseEvents.Any()) + if (response.ResponseEvents.Count != 0) { PersistAll(response.ResponseEvents, productEvent => { _log.Info("Processed: {0}", productEvent); - + if (productEvent is ProductInventoryWarningEvent warning) { _log.Warning(warning.ToString()); } + State = State.ProcessEvent(productEvent); if (!sentResponse) // otherwise we'll generate a response-per-event { sentResponse = true; - - async Task ReplyToSender() - { - await Task.Delay(1); - return response; - } - var sender = Sender; - ReplyToSender().PipeTo(sender, failure: ex => new Status.Failure(ex)); - + Sender.Tell(response); } - - if(LastSequenceNr % 10 == 0) + + if (LastSequenceNr % 10 == 0) SaveSnapshot(State); }); } @@ -86,10 +76,7 @@ async Task ReplyToSender() }); - Command(success => - { - - }); + Command(success => { }); Command(fetch => { @@ -102,8 +89,8 @@ async Task ReplyToSender() } }); } - + public override string PersistenceId { get; } - + public ProductState State { get; set; } } \ No newline at end of file diff --git a/src/cqrs/cqrs-sqlserver/CqrsSqlServer.Backend/CqrsSqlServer.Backend.csproj b/src/cqrs/cqrs-sqlserver/CqrsSqlServer.Backend/CqrsSqlServer.Backend.csproj index f53fda6..7c40808 100644 --- a/src/cqrs/cqrs-sqlserver/CqrsSqlServer.Backend/CqrsSqlServer.Backend.csproj +++ b/src/cqrs/cqrs-sqlserver/CqrsSqlServer.Backend/CqrsSqlServer.Backend.csproj @@ -33,8 +33,4 @@ - - - -