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