| | | 1 | | using Elsa.Workflows; |
| | | 2 | | using Elsa.Workflows.Runtime; |
| | | 3 | | using Elsa.Workflows.Runtime.Entities; |
| | | 4 | | using Elsa.Workflows.Runtime.Filters; |
| | | 5 | | using JetBrains.Annotations; |
| | | 6 | | |
| | | 7 | | namespace Elsa.Persistence.EFCore.Modules.Runtime; |
| | | 8 | | |
| | | 9 | | /// <summary> |
| | | 10 | | /// An EF Core implementation of <see cref="IBookmarkStore"/>. |
| | | 11 | | /// </summary> |
| | | 12 | | [UsedImplicitly] |
| | 353 | 13 | | public class EFCoreBookmarkStore(Store<RuntimeElsaDbContext, StoredBookmark> store, IPayloadSerializer serializer) : IBo |
| | | 14 | | { |
| | | 15 | | /// <inheritdoc /> |
| | | 16 | | public async ValueTask SaveAsync(StoredBookmark record, CancellationToken cancellationToken = default) |
| | | 17 | | { |
| | 36 | 18 | | await store.SaveAsync(record, s => s.Id, OnSaveAsync, cancellationToken); |
| | 36 | 19 | | } |
| | | 20 | | |
| | | 21 | | /// <inheritdoc /> |
| | | 22 | | public async ValueTask SaveManyAsync(IEnumerable<StoredBookmark> records, CancellationToken cancellationToken) |
| | | 23 | | { |
| | 0 | 24 | | await store.SaveManyAsync(records, s => s.Id, OnSaveAsync, cancellationToken); |
| | 0 | 25 | | } |
| | | 26 | | |
| | | 27 | | /// <inheritdoc /> |
| | | 28 | | public async ValueTask<StoredBookmark?> FindAsync(BookmarkFilter filter, CancellationToken cancellationToken = defau |
| | | 29 | | { |
| | 0 | 30 | | return await store.FindAsync(filter.Apply, OnLoadAsync, filter.TenantAgnostic, cancellationToken); |
| | 0 | 31 | | } |
| | | 32 | | |
| | | 33 | | /// <inheritdoc /> |
| | | 34 | | public async ValueTask<IEnumerable<StoredBookmark>> FindManyAsync(BookmarkFilter filter, CancellationToken cancellat |
| | | 35 | | { |
| | 1206 | 36 | | return await store.QueryAsync(filter.Apply, OnLoadAsync, filter.TenantAgnostic, cancellationToken); |
| | 1206 | 37 | | } |
| | | 38 | | |
| | | 39 | | /// <inheritdoc /> |
| | | 40 | | public async ValueTask<long> DeleteAsync(BookmarkFilter filter, CancellationToken cancellationToken = default) |
| | | 41 | | { |
| | 41 | 42 | | return await store.DeleteWhereAsync(filter.Apply, cancellationToken); |
| | 41 | 43 | | } |
| | | 44 | | |
| | | 45 | | private ValueTask OnSaveAsync(RuntimeElsaDbContext dbContext, StoredBookmark entity, CancellationToken cancellationT |
| | | 46 | | { |
| | 36 | 47 | | dbContext.Entry(entity).Property("SerializedPayload").CurrentValue = entity.Payload != null ? serializer.Seriali |
| | 36 | 48 | | dbContext.Entry(entity).Property("SerializedMetadata").CurrentValue = entity.Metadata != null ? serializer.Seria |
| | 36 | 49 | | return default; |
| | | 50 | | } |
| | | 51 | | |
| | | 52 | | private ValueTask OnLoadAsync(RuntimeElsaDbContext dbContext, StoredBookmark? entity, CancellationToken cancellation |
| | | 53 | | { |
| | 93 | 54 | | if (entity is null) |
| | 0 | 55 | | return default; |
| | | 56 | | |
| | 93 | 57 | | var payloadJson = dbContext.Entry(entity).Property<string>("SerializedPayload").CurrentValue; |
| | 93 | 58 | | var metadataJson = dbContext.Entry(entity).Property<string>("SerializedMetadata").CurrentValue; |
| | 93 | 59 | | entity.Payload = !string.IsNullOrEmpty(payloadJson) ? serializer.Deserialize(payloadJson) : null; |
| | 93 | 60 | | entity.Metadata = !string.IsNullOrEmpty(metadataJson) ? serializer.Deserialize<Dictionary<string, string>>(metad |
| | | 61 | | |
| | 93 | 62 | | return default; |
| | | 63 | | } |
| | | 64 | | } |