| | | 1 | | using Elsa.Common.Models; |
| | | 2 | | using Elsa.Extensions; |
| | | 3 | | using Elsa.Workflows; |
| | | 4 | | using Elsa.Workflows.Runtime; |
| | | 5 | | using Elsa.Workflows.Runtime.Entities; |
| | | 6 | | using Elsa.Workflows.Runtime.Filters; |
| | | 7 | | using Elsa.Workflows.Runtime.Options; |
| | | 8 | | using Elsa.Workflows.Runtime.OrderDefinitions; |
| | | 9 | | using JetBrains.Annotations; |
| | | 10 | | using Open.Linq.AsyncExtensions; |
| | | 11 | | |
| | | 12 | | namespace Elsa.Persistence.EFCore.Modules.Runtime; |
| | | 13 | | |
| | | 14 | | /// <summary> |
| | | 15 | | /// An EF Core implementation of <see cref="IBookmarkQueueStore"/>. |
| | | 16 | | /// </summary> |
| | | 17 | | [UsedImplicitly] |
| | 351 | 18 | | public class EFBookmarkQueueStore(Store<RuntimeElsaDbContext, BookmarkQueueItem> store, IPayloadSerializer serializer) : |
| | | 19 | | { |
| | | 20 | | /// <inheritdoc /> |
| | | 21 | | public Task SaveAsync(BookmarkQueueItem record, CancellationToken cancellationToken = default) |
| | | 22 | | { |
| | 0 | 23 | | return store.SaveAsync(record, s => s.Id, OnSaveAsync, cancellationToken); |
| | | 24 | | } |
| | | 25 | | |
| | | 26 | | /// <inheritdoc /> |
| | | 27 | | public Task AddAsync(BookmarkQueueItem record, CancellationToken cancellationToken = default) |
| | | 28 | | { |
| | 48 | 29 | | return store.AddAsync(record, OnSaveAsync, cancellationToken); |
| | | 30 | | } |
| | | 31 | | |
| | | 32 | | /// <inheritdoc /> |
| | | 33 | | public Task<BookmarkQueueItem?> FindAsync(BookmarkQueueFilter filter, CancellationToken cancellationToken = default) |
| | | 34 | | { |
| | 0 | 35 | | return store.FindAsync(filter.Apply, OnLoadAsync, cancellationToken); |
| | | 36 | | } |
| | | 37 | | |
| | | 38 | | /// <inheritdoc /> |
| | | 39 | | public async Task<IEnumerable<BookmarkQueueItem>> FindManyAsync(BookmarkQueueFilter filter, CancellationToken cancel |
| | | 40 | | { |
| | 0 | 41 | | return await store.QueryAsync(filter.Apply, OnLoadAsync, filter.TenantAgnostic, cancellationToken); |
| | 0 | 42 | | } |
| | | 43 | | |
| | | 44 | | public async Task<Page<BookmarkQueueItem>> PageAsync<TOrderBy>(PageArgs pageArgs, BookmarkQueueItemOrder<TOrderBy> o |
| | | 45 | | { |
| | 76 | 46 | | var count = await store.QueryAsync(queryable => queryable, cancellationToken).LongCount(); |
| | 76 | 47 | | var results = await store.QueryAsync(queryable => queryable.OrderBy(orderBy).Paginate(pageArgs), OnLoadAsync, ca |
| | 38 | 48 | | return new(results, count); |
| | 38 | 49 | | } |
| | | 50 | | |
| | | 51 | | public async Task<Page<BookmarkQueueItem>> PageAsync<TOrderBy>(PageArgs pageArgs, BookmarkQueueFilter filter, Bookma |
| | | 52 | | { |
| | 0 | 53 | | var count = await store.QueryAsync(filter.Apply, cancellationToken).LongCount(); |
| | 0 | 54 | | var results = await store.QueryAsync(queryable => filter.Apply(queryable).OrderBy(orderBy).Paginate(pageArgs), O |
| | 0 | 55 | | return new(results, count); |
| | 0 | 56 | | } |
| | | 57 | | |
| | | 58 | | /// <inheritdoc /> |
| | | 59 | | public async Task<long> DeleteAsync(BookmarkQueueFilter filter, CancellationToken cancellationToken = default) |
| | | 60 | | { |
| | 15 | 61 | | return await store.DeleteWhereAsync(filter.Apply, cancellationToken); |
| | 15 | 62 | | } |
| | | 63 | | |
| | | 64 | | private ValueTask OnSaveAsync(RuntimeElsaDbContext dbContext, BookmarkQueueItem entity, CancellationToken cancellati |
| | | 65 | | { |
| | 48 | 66 | | dbContext.Entry(entity).Property("SerializedOptions").CurrentValue = entity.Options != null ? serializer.Seriali |
| | 48 | 67 | | return default; |
| | | 68 | | } |
| | | 69 | | |
| | | 70 | | private ValueTask OnLoadAsync(RuntimeElsaDbContext dbContext, BookmarkQueueItem? entity, CancellationToken cancellat |
| | | 71 | | { |
| | 1097 | 72 | | if (entity is null) |
| | 0 | 73 | | return default; |
| | | 74 | | |
| | 1097 | 75 | | var optionsJson = dbContext.Entry(entity).Property<string>("SerializedOptions").CurrentValue; |
| | 1097 | 76 | | entity.Options = !string.IsNullOrEmpty(optionsJson) ? serializer.Deserialize<ResumeBookmarkOptions>(optionsJson) |
| | | 77 | | |
| | 1097 | 78 | | return default; |
| | | 79 | | } |
| | | 80 | | } |