| | | 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 Elsa.Workflows.Runtime.OrderDefinitions; |
| | | 7 | | using JetBrains.Annotations; |
| | | 8 | | |
| | | 9 | | namespace Elsa.Workflows.Runtime.Stores; |
| | | 10 | | |
| | | 11 | | /// <inheritdoc /> |
| | | 12 | | [UsedImplicitly] |
| | 160 | 13 | | public class MemoryBookmarkQueueStore(MemoryStore<BookmarkQueueItem> store) : IBookmarkQueueStore |
| | | 14 | | { |
| | | 15 | | /// <inheritdoc /> |
| | | 16 | | public Task SaveAsync(BookmarkQueueItem record, CancellationToken cancellationToken = default) |
| | | 17 | | { |
| | 0 | 18 | | store.Save(record, x => x.Id); |
| | 0 | 19 | | return Task.CompletedTask; |
| | | 20 | | } |
| | | 21 | | |
| | | 22 | | public Task AddAsync(BookmarkQueueItem record, CancellationToken cancellationToken = default) |
| | | 23 | | { |
| | 32 | 24 | | store.Add(record, x => x.Id); |
| | 16 | 25 | | return Task.CompletedTask; |
| | | 26 | | } |
| | | 27 | | |
| | | 28 | | /// <inheritdoc /> |
| | | 29 | | public Task<BookmarkQueueItem?> FindAsync(BookmarkQueueFilter filter, CancellationToken cancellationToken = default) |
| | | 30 | | { |
| | 0 | 31 | | var entity = store.Query(query => Filter(query, filter)).FirstOrDefault(); |
| | 0 | 32 | | return Task.FromResult(entity); |
| | | 33 | | } |
| | | 34 | | |
| | | 35 | | public Task<Page<BookmarkQueueItem>> PageAsync<TOrderBy>(PageArgs pageArgs, BookmarkQueueItemOrder<TOrderBy> orderBy |
| | | 36 | | { |
| | 12 | 37 | | var entities = store.Query(query => query.OrderBy(orderBy)).Paginate(pageArgs); |
| | 6 | 38 | | return Task.FromResult(entities); |
| | | 39 | | } |
| | | 40 | | |
| | | 41 | | public Task<Page<BookmarkQueueItem>> PageAsync<TOrderBy>(PageArgs pageArgs, BookmarkQueueFilter filter, BookmarkQueu |
| | | 42 | | { |
| | 0 | 43 | | var entities = store.Query(query => Filter(query, filter).OrderBy(orderBy)).Paginate(pageArgs); |
| | 0 | 44 | | return Task.FromResult(entities); |
| | | 45 | | } |
| | | 46 | | |
| | | 47 | | public Task<IEnumerable<BookmarkQueueItem>> FindManyAsync(BookmarkQueueFilter filter, CancellationToken cancellation |
| | | 48 | | { |
| | 6 | 49 | | var entities = store.Query(query => Filter(query, filter)).AsEnumerable(); |
| | 3 | 50 | | return Task.FromResult(entities); |
| | | 51 | | } |
| | | 52 | | |
| | | 53 | | /// <inheritdoc /> |
| | | 54 | | public async Task<long> DeleteAsync(BookmarkQueueFilter filter, CancellationToken cancellationToken = default) |
| | | 55 | | { |
| | 6 | 56 | | var ids = (await FindManyAsync(filter, cancellationToken)).Select(x => x.Id); |
| | 3 | 57 | | return store.DeleteMany(ids); |
| | 3 | 58 | | } |
| | | 59 | | |
| | 3 | 60 | | private static IQueryable<BookmarkQueueItem> Filter(IQueryable<BookmarkQueueItem> query, BookmarkQueueFilter filter) |
| | | 61 | | } |