| | | 1 | | using Elsa.Common.Services; |
| | | 2 | | using Elsa.Workflows.Runtime.Entities; |
| | | 3 | | using Elsa.Workflows.Runtime.Filters; |
| | | 4 | | using JetBrains.Annotations; |
| | | 5 | | |
| | | 6 | | namespace Elsa.Workflows.Runtime.Stores; |
| | | 7 | | |
| | | 8 | | /// <inheritdoc /> |
| | | 9 | | [UsedImplicitly] |
| | 158 | 10 | | public class MemoryBookmarkStore(MemoryStore<StoredBookmark> store) : IBookmarkStore |
| | | 11 | | { |
| | | 12 | | /// <inheritdoc /> |
| | | 13 | | public ValueTask SaveAsync(StoredBookmark record, CancellationToken cancellationToken = default) |
| | | 14 | | { |
| | 42 | 15 | | store.Save(record, x => x.Id); |
| | 21 | 16 | | return ValueTask.CompletedTask; |
| | | 17 | | } |
| | | 18 | | |
| | | 19 | | /// <inheritdoc /> |
| | | 20 | | public ValueTask SaveManyAsync(IEnumerable<StoredBookmark> records, CancellationToken cancellationToken) |
| | | 21 | | { |
| | 0 | 22 | | store.SaveMany(records, x => x.Id); |
| | 0 | 23 | | return ValueTask.CompletedTask; |
| | | 24 | | } |
| | | 25 | | |
| | | 26 | | /// <inheritdoc /> |
| | | 27 | | public ValueTask<StoredBookmark?> FindAsync(BookmarkFilter filter, CancellationToken cancellationToken = default) |
| | | 28 | | { |
| | 0 | 29 | | var entity = store.Query(query => Filter(query, filter)).FirstOrDefault(); |
| | 0 | 30 | | return new(entity); |
| | | 31 | | } |
| | | 32 | | |
| | | 33 | | /// <inheritdoc /> |
| | | 34 | | public ValueTask<IEnumerable<StoredBookmark>> FindManyAsync(BookmarkFilter filter, CancellationToken cancellationTok |
| | | 35 | | { |
| | 100 | 36 | | var entities = store.Query(query => Filter(query, filter)).AsEnumerable(); |
| | 50 | 37 | | return new(entities); |
| | | 38 | | } |
| | | 39 | | |
| | | 40 | | /// <inheritdoc /> |
| | | 41 | | public async ValueTask<long> DeleteAsync(BookmarkFilter filter, CancellationToken cancellationToken = default) |
| | | 42 | | { |
| | 32 | 43 | | var ids = (await FindManyAsync(filter, cancellationToken)).Select(x => x.Id); |
| | 14 | 44 | | return store.DeleteMany(ids); |
| | 14 | 45 | | } |
| | | 46 | | |
| | 50 | 47 | | private static IQueryable<StoredBookmark> Filter(IQueryable<StoredBookmark> query, BookmarkFilter filter) => filter. |
| | | 48 | | } |