From 004c5a1020f717535df83dbe730b4cec84660235 Mon Sep 17 00:00:00 2001 From: "gitauto-ai[bot]" <161652217+gitauto-ai[bot]@users.noreply.github.com> Date: Wed, 23 Oct 2024 00:08:54 +0000 Subject: [PATCH 1/8] Update Src/CrispyWaffle/Commands/CommandsConsumer.cs. --- Src/CrispyWaffle/Commands/CommandsConsumer.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Src/CrispyWaffle/Commands/CommandsConsumer.cs b/Src/CrispyWaffle/Commands/CommandsConsumer.cs index 177a2ba9..3974b67e 100644 --- a/Src/CrispyWaffle/Commands/CommandsConsumer.cs +++ b/Src/CrispyWaffle/Commands/CommandsConsumer.cs @@ -1,4 +1,5 @@ using System.Threading.Tasks; +using CrispyWaffle.Sagas; using CrispyWaffle.Composition; using CrispyWaffle.Log; From 308a47ef5531acdd4dcf0b4ce6c846c4745251a5 Mon Sep 17 00:00:00 2001 From: "gitauto-ai[bot]" <161652217+gitauto-ai[bot]@users.noreply.github.com> Date: Wed, 23 Oct 2024 00:08:58 +0000 Subject: [PATCH 2/8] Update Src/CrispyWaffle/Events/EventsConsumer.cs. --- Src/CrispyWaffle/Events/EventsConsumer.cs | 107 +++++++++++----------- 1 file changed, 54 insertions(+), 53 deletions(-) diff --git a/Src/CrispyWaffle/Events/EventsConsumer.cs b/Src/CrispyWaffle/Events/EventsConsumer.cs index 0f7ff7b8..ef847107 100644 --- a/Src/CrispyWaffle/Events/EventsConsumer.cs +++ b/Src/CrispyWaffle/Events/EventsConsumer.cs @@ -1,53 +1,54 @@ -using System.Threading.Tasks; -using CrispyWaffle.Composition; -using CrispyWaffle.Log; - -namespace CrispyWaffle.Events -{ - /// - /// Manage events raising - /// - public static class EventsConsumer - { - /// - /// Raises the specified event. - /// - /// The type of the event. - /// The event. - public static void Raise(TEvent @event) - where TEvent : IEvent - { - var handlers = ServiceLocator.ResolveAll>(); - - foreach (var handler in handlers) - { - LogConsumer.Trace( - $"Calling {handler.GetType().FullName} for event {@event.GetType().FullName}" - ); - - handler.Handle(@event); - } - } - - /// - /// Raises the specified event asynchronously. - /// - /// The type of the event. - /// The event. - public static async Task RaiseAsync(TEvent @event) - where TEvent : IEvent - { - await Task.Run(() => - { - var handlers = ServiceLocator.ResolveAll>(); - foreach (var handler in handlers) - { - LogConsumer.Trace( - $"Calling {handler.GetType().FullName} for event {@event.GetType().FullName}" - ); - handler.HandleAsync(@event); - } - }); - } - } -} +using System.Threading.Tasks; +using CrispyWaffle.Sagas; +using CrispyWaffle.Composition; +using CrispyWaffle.Log; + +namespace CrispyWaffle.Events +{ + /// + /// Manage events raising + /// + public static class EventsConsumer + { + /// + /// Raises the specified event. + /// + /// The type of the event. + /// The event. + public static void Raise(TEvent @event) + where TEvent : IEvent + { + var handlers = ServiceLocator.ResolveAll>(); + + foreach (var handler in handlers) + { + LogConsumer.Trace( + $"Calling {handler.GetType().FullName} for event {@event.GetType().FullName}" + ); + + handler.Handle(@event); + } + } + + /// + /// Raises the specified event asynchronously. + /// + /// The type of the event. + /// The event. + public static async Task RaiseAsync(TEvent @event) + where TEvent : IEvent + { + await Task.Run(() => + { + var handlers = ServiceLocator.ResolveAll>(); + foreach (var handler in handlers) + { + LogConsumer.Trace( + $"Calling {handler.GetType().FullName} for event {@event.GetType().FullName}" + ); + handler.HandleAsync(@event); + } + }); + } + } +} From d8c3b0c98e82fb277db1ca9cd9c834626919c079 Mon Sep 17 00:00:00 2001 From: "gitauto-ai[bot]" <161652217+gitauto-ai[bot]@users.noreply.github.com> Date: Wed, 23 Oct 2024 00:11:21 +0000 Subject: [PATCH 3/8] Update Src/CrispyWaffle/Sagas/GenericSagaHandler.cs. --- Src/CrispyWaffle/Sagas/GenericSagaHandler.cs | 23 ++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Src/CrispyWaffle/Sagas/GenericSagaHandler.cs diff --git a/Src/CrispyWaffle/Sagas/GenericSagaHandler.cs b/Src/CrispyWaffle/Sagas/GenericSagaHandler.cs new file mode 100644 index 00000000..b6282be7 --- /dev/null +++ b/Src/CrispyWaffle/Sagas/GenericSagaHandler.cs @@ -0,0 +1,23 @@ +namespace CrispyWaffle.Sagas; + +public abstract class GenericSagaHandler : ISagaHandler +{ + public abstract void Handle(T message); + + public abstract void HandleTimeout(T message); + + protected void StartSaga(T message) + { + // Logic to start a saga + } + + protected void UpdateSagaState(T message) + { + // Logic to update saga state + } + + protected void CompleteSaga() + { + // Logic to complete a saga + } +} From b9c2b80c87f3630cb8d90a1cc93fb167b0d51e8f Mon Sep 17 00:00:00 2001 From: "gitauto-ai[bot]" <161652217+gitauto-ai[bot]@users.noreply.github.com> Date: Wed, 23 Oct 2024 00:11:26 +0000 Subject: [PATCH 4/8] Update Src/CrispyWaffle/Sagas/SagaData.cs. --- Src/CrispyWaffle/Sagas/SagaData.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 Src/CrispyWaffle/Sagas/SagaData.cs diff --git a/Src/CrispyWaffle/Sagas/SagaData.cs b/Src/CrispyWaffle/Sagas/SagaData.cs new file mode 100644 index 00000000..af93c6d1 --- /dev/null +++ b/Src/CrispyWaffle/Sagas/SagaData.cs @@ -0,0 +1,15 @@ +namespace CrispyWaffle.Sagas; + +public class SagaData : ISagaData +{ + public Guid SagaId { get; set; } + public string State { get; set; } + public DateTime CreatedAt { get; set; } + // Additional properties as needed + + public SagaData() + { + SagaId = Guid.NewGuid(); + CreatedAt = DateTime.UtcNow; + } +} From 8cfa2fbddeed7f377efffab23c5a76b6371b7c2c Mon Sep 17 00:00:00 2001 From: "gitauto-ai[bot]" <161652217+gitauto-ai[bot]@users.noreply.github.com> Date: Wed, 23 Oct 2024 00:11:33 +0000 Subject: [PATCH 5/8] Update Src/CrispyWaffle/Sagas/SagaRepository.cs. --- Src/CrispyWaffle/Sagas/SagaRepository.cs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Src/CrispyWaffle/Sagas/SagaRepository.cs diff --git a/Src/CrispyWaffle/Sagas/SagaRepository.cs b/Src/CrispyWaffle/Sagas/SagaRepository.cs new file mode 100644 index 00000000..d2265cd0 --- /dev/null +++ b/Src/CrispyWaffle/Sagas/SagaRepository.cs @@ -0,0 +1,22 @@ +namespace CrispyWaffle.Sagas; + +public class SagaRepository +{ + private readonly Dictionary _storage = new Dictionary(); + + public void Save(SagaData sagaData) + { + _storage[sagaData.SagaId] = sagaData; + } + + public SagaData Load(Guid sagaId) + { + _storage.TryGetValue(sagaId, out var sagaData); + return sagaData; + } + + public void Delete(Guid sagaId) + { + _storage.Remove(sagaId); + } +} From 2b1b8dd7a27dc25d32811a178688ff03455bf9a7 Mon Sep 17 00:00:00 2001 From: "gitauto-ai[bot]" <161652217+gitauto-ai[bot]@users.noreply.github.com> Date: Wed, 23 Oct 2024 00:11:41 +0000 Subject: [PATCH 6/8] Update Src/CrispyWaffle/Sagas/ISagaHandler.cs. --- Src/CrispyWaffle/Sagas/ISagaHandler.cs | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 Src/CrispyWaffle/Sagas/ISagaHandler.cs diff --git a/Src/CrispyWaffle/Sagas/ISagaHandler.cs b/Src/CrispyWaffle/Sagas/ISagaHandler.cs new file mode 100644 index 00000000..60b00641 --- /dev/null +++ b/Src/CrispyWaffle/Sagas/ISagaHandler.cs @@ -0,0 +1,7 @@ +namespace CrispyWaffle.Sagas; + +public interface ISagaHandler +{ + void Handle(T message); + void HandleTimeout(T message); +} From 4d8c1275e00029b1745adaef503301dc7aafeb44 Mon Sep 17 00:00:00 2001 From: "gitauto-ai[bot]" <161652217+gitauto-ai[bot]@users.noreply.github.com> Date: Wed, 23 Oct 2024 00:11:45 +0000 Subject: [PATCH 7/8] Update Src/CrispyWaffle/Sagas/ISaga.cs. --- Src/CrispyWaffle/Sagas/ISaga.cs | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 Src/CrispyWaffle/Sagas/ISaga.cs diff --git a/Src/CrispyWaffle/Sagas/ISaga.cs b/Src/CrispyWaffle/Sagas/ISaga.cs new file mode 100644 index 00000000..9633fd4e --- /dev/null +++ b/Src/CrispyWaffle/Sagas/ISaga.cs @@ -0,0 +1,6 @@ +namespace CrispyWaffle.Sagas; + +public interface ISaga +{ + Guid SagaId { get; } +} From db5604cd571e054f36ce65d8cb47c48f7e510f4b Mon Sep 17 00:00:00 2001 From: "gitauto-ai[bot]" <161652217+gitauto-ai[bot]@users.noreply.github.com> Date: Wed, 23 Oct 2024 00:11:54 +0000 Subject: [PATCH 8/8] Update Src/CrispyWaffle/Sagas/ISagaData.cs. --- Src/CrispyWaffle/Sagas/ISagaData.cs | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 Src/CrispyWaffle/Sagas/ISagaData.cs diff --git a/Src/CrispyWaffle/Sagas/ISagaData.cs b/Src/CrispyWaffle/Sagas/ISagaData.cs new file mode 100644 index 00000000..60526b41 --- /dev/null +++ b/Src/CrispyWaffle/Sagas/ISagaData.cs @@ -0,0 +1,6 @@ +namespace CrispyWaffle.Sagas; + +public interface ISagaData +{ + Guid SagaId { get; set; } +}