From 67c7ad760a2c6c0ef6600da52f81bf2cce7be104 Mon Sep 17 00:00:00 2001 From: Arne Dumarey Date: Wed, 6 Nov 2024 11:41:55 +0100 Subject: [PATCH] feat: add AnySnapshotStrategy and AllSnapshotStrategy --- .../Snapshotting/AllSnapshotStrategy.cs | 21 +++++++++++++++++++ .../Snapshotting/AnySnapshotStrategy.cs | 21 +++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 src/Be.Vlaanderen.Basisregisters.AggregateSource/Snapshotting/AllSnapshotStrategy.cs create mode 100644 src/Be.Vlaanderen.Basisregisters.AggregateSource/Snapshotting/AnySnapshotStrategy.cs diff --git a/src/Be.Vlaanderen.Basisregisters.AggregateSource/Snapshotting/AllSnapshotStrategy.cs b/src/Be.Vlaanderen.Basisregisters.AggregateSource/Snapshotting/AllSnapshotStrategy.cs new file mode 100644 index 0000000..ccf7f47 --- /dev/null +++ b/src/Be.Vlaanderen.Basisregisters.AggregateSource/Snapshotting/AllSnapshotStrategy.cs @@ -0,0 +1,21 @@ +namespace Be.Vlaanderen.Basisregisters.AggregateSource.Snapshotting +{ + using System.Collections.Generic; + using System.Linq; + + /// + /// Snapshot strategy that returns true if all the given strategies returns true. + /// + public sealed class AllSnapshotStrategy : ISnapshotStrategy + { + private readonly IEnumerable _strategies; + + public AllSnapshotStrategy(IEnumerable strategies) + { + _strategies = strategies; + } + + public bool ShouldCreateSnapshot(SnapshotStrategyContext context) + => _strategies.All(x => x.ShouldCreateSnapshot(context)); + } +} diff --git a/src/Be.Vlaanderen.Basisregisters.AggregateSource/Snapshotting/AnySnapshotStrategy.cs b/src/Be.Vlaanderen.Basisregisters.AggregateSource/Snapshotting/AnySnapshotStrategy.cs new file mode 100644 index 0000000..f3c3d10 --- /dev/null +++ b/src/Be.Vlaanderen.Basisregisters.AggregateSource/Snapshotting/AnySnapshotStrategy.cs @@ -0,0 +1,21 @@ +namespace Be.Vlaanderen.Basisregisters.AggregateSource.Snapshotting +{ + using System.Collections.Generic; + using System.Linq; + + /// + /// Snapshot strategy that returns true if any of the given strategies returns true. + /// + public sealed class AnySnapshotStrategy : ISnapshotStrategy + { + private readonly IEnumerable _strategies; + + public AnySnapshotStrategy(IEnumerable strategies) + { + _strategies = strategies; + } + + public bool ShouldCreateSnapshot(SnapshotStrategyContext context) + => _strategies.Any(x => x.ShouldCreateSnapshot(context)); + } +}