// ========================================================================== // Squidex Headless CMS // ========================================================================== // Copyright (c) Squidex UG (haftungsbeschränkt) // All rights reserved. Licensed under the MIT license. // ========================================================================== using System; using System.Threading.Tasks; using Squidex.Infrastructure.EventSourcing; using Squidex.Infrastructure.Tasks; namespace Squidex.Infrastructure.States { public static class StoreExtensions { public static IPersistence WithEventSourcing(this IStore store, TKey key, Func, Task> applyEvent) { return store.WithEventSourcing(typeof(TOwner), key, applyEvent); } public static IPersistence WithSnapshots(this IStore store, TKey key, Func applySnapshot) { return store.WithSnapshots(typeof(TOwner), key, applySnapshot); } public static IPersistence WithSnapshotsAndEventSourcing(this IStore store, TKey key, Func applySnapshot, Func, Task> applyEvent) { return store.WithSnapshotsAndEventSourcing(typeof(TOwner), key, applySnapshot, applyEvent); } public static IPersistence WithEventSourcing(this IStore store, Type owner, TKey key, Action> applyEvent) { return store.WithEventSourcing(owner, key, applyEvent.ToAsync()); } public static IPersistence WithSnapshots(this IStore store, Type owner, TKey key, Action applySnapshot) { return store.WithSnapshots(owner, key, applySnapshot.ToAsync()); } public static IPersistence WithSnapshotsAndEventSourcing(this IStore store, Type owner, TKey key, Action applySnapshot, Action> applyEvent) { return store.WithSnapshotsAndEventSourcing(owner, key, applySnapshot.ToAsync(), applyEvent.ToAsync()); } public static IPersistence WithEventSourcing(this IStore store, TKey key, Action> applyEvent) { return store.WithEventSourcing(typeof(TOwner), key, applyEvent.ToAsync()); } public static IPersistence WithSnapshots(this IStore store, TKey key, Action applySnapshot) { return store.WithSnapshots(typeof(TOwner), key, applySnapshot.ToAsync()); } public static IPersistence WithSnapshotsAndEventSourcing(this IStore store, TKey key, Action applySnapshot, Action> applyEvent) { return store.WithSnapshotsAndEventSourcing(typeof(TOwner), key, applySnapshot.ToAsync(), applyEvent.ToAsync()); } public static Task ClearSnapshotsAsync(this IStore store) { return store.GetSnapshotStore().ClearAsync(); } public static Task RemoveSnapshotAsync(this IStore store, TKey key) { return store.GetSnapshotStore().RemoveAsync(key); } public static async Task GetSnapshotAsync(this IStore store, TKey key) { var result = await store.GetSnapshotStore().ReadAsync(key); return result.Value; } } }