| | | 1 | | using Elsa.Common.Services; |
| | | 2 | | using Elsa.Extensions; |
| | | 3 | | using Elsa.Workflows.Runtime.Entities; |
| | | 4 | | using Elsa.Workflows.Runtime.Filters; |
| | | 5 | | using Elsa.Workflows.Runtime.OrderDefinitions; |
| | | 6 | | |
| | | 7 | | namespace Elsa.Workflows.Runtime.Stores; |
| | | 8 | | |
| | | 9 | | /// <summary> |
| | | 10 | | /// Stores activity execution records in memory. |
| | | 11 | | /// </summary> |
| | | 12 | | public class MemoryActivityExecutionStore : IActivityExecutionStore |
| | | 13 | | { |
| | | 14 | | private readonly MemoryStore<ActivityExecutionRecord> _store; |
| | | 15 | | |
| | | 16 | | /// <summary> |
| | | 17 | | /// Initializes a new instance of the <see cref="MemoryActivityExecutionStore"/> class. |
| | | 18 | | /// </summary> |
| | 141 | 19 | | public MemoryActivityExecutionStore(MemoryStore<ActivityExecutionRecord> store) |
| | | 20 | | { |
| | 141 | 21 | | _store = store; |
| | 141 | 22 | | } |
| | | 23 | | |
| | | 24 | | /// <inheritdoc /> |
| | | 25 | | public Task SaveAsync(ActivityExecutionRecord record, CancellationToken cancellationToken = default) |
| | | 26 | | { |
| | 0 | 27 | | _store.Save(record, x => x.Id); |
| | 0 | 28 | | return Task.CompletedTask; |
| | | 29 | | } |
| | | 30 | | |
| | | 31 | | /// <inheritdoc /> |
| | | 32 | | public Task SaveManyAsync(IEnumerable<ActivityExecutionRecord> records, CancellationToken cancellationToken = defaul |
| | | 33 | | { |
| | 1453 | 34 | | _store.SaveMany(records, x => x.Id); |
| | 143 | 35 | | return Task.CompletedTask; |
| | | 36 | | } |
| | | 37 | | |
| | | 38 | | /// <inheritdoc /> |
| | | 39 | | public Task AddManyAsync(IEnumerable<ActivityExecutionRecord> records, CancellationToken cancellationToken = default |
| | | 40 | | { |
| | 0 | 41 | | _store.AddMany(records, x => x.Id); |
| | 0 | 42 | | return Task.CompletedTask; |
| | | 43 | | } |
| | | 44 | | |
| | | 45 | | /// <inheritdoc /> |
| | | 46 | | public Task<ActivityExecutionRecord?> FindAsync(ActivityExecutionRecordFilter filter, CancellationToken cancellation |
| | | 47 | | { |
| | 12 | 48 | | var result = _store.Query(query => Filter(query, filter)).FirstOrDefault(); |
| | 6 | 49 | | return Task.FromResult(result); |
| | | 50 | | } |
| | | 51 | | |
| | | 52 | | /// <inheritdoc /> |
| | | 53 | | public Task<IEnumerable<ActivityExecutionRecord>> FindManyAsync<TOrderBy>(ActivityExecutionRecordFilter filter, Acti |
| | | 54 | | { |
| | 0 | 55 | | var result = _store.Query(query => Filter(query, filter).OrderBy(order)).ToList().AsEnumerable(); |
| | 0 | 56 | | return Task.FromResult(result); |
| | | 57 | | } |
| | | 58 | | |
| | | 59 | | /// <inheritdoc /> |
| | | 60 | | public Task<IEnumerable<ActivityExecutionRecord>> FindManyAsync(ActivityExecutionRecordFilter filter, CancellationTo |
| | | 61 | | { |
| | 0 | 62 | | var result = _store.Query(query => Filter(query, filter)).ToList().AsEnumerable(); |
| | 0 | 63 | | return Task.FromResult(result); |
| | | 64 | | } |
| | | 65 | | |
| | | 66 | | /// <inheritdoc /> |
| | | 67 | | public async Task<IEnumerable<ActivityExecutionRecordSummary>> FindManySummariesAsync<TOrderBy>(ActivityExecutionRec |
| | | 68 | | { |
| | 0 | 69 | | var entities = await FindManyAsync(filter, order, cancellationToken); |
| | 0 | 70 | | return entities.Select(ActivityExecutionRecordSummary.FromRecord); |
| | 0 | 71 | | } |
| | | 72 | | |
| | | 73 | | /// <inheritdoc /> |
| | | 74 | | public async Task<IEnumerable<ActivityExecutionRecordSummary>> FindManySummariesAsync(ActivityExecutionRecordFilter |
| | | 75 | | { |
| | 0 | 76 | | var entities = await FindManyAsync(filter, cancellationToken); |
| | 0 | 77 | | return entities.Select(ActivityExecutionRecordSummary.FromRecord); |
| | 0 | 78 | | } |
| | | 79 | | |
| | | 80 | | /// <inheritdoc /> |
| | | 81 | | public Task<long> CountAsync(ActivityExecutionRecordFilter filter, CancellationToken cancellationToken = default) |
| | | 82 | | { |
| | 0 | 83 | | var count = _store.Query(query => Filter(query, filter)).LongCount(); |
| | 0 | 84 | | return Task.FromResult(count); |
| | | 85 | | } |
| | | 86 | | |
| | | 87 | | /// <inheritdoc /> |
| | | 88 | | public Task<long> DeleteManyAsync(ActivityExecutionRecordFilter filter, CancellationToken cancellationToken = defaul |
| | | 89 | | { |
| | 0 | 90 | | var records = _store.Query(query => Filter(query, filter)).ToList(); |
| | 0 | 91 | | _store.DeleteMany(records, x => x.Id); |
| | 0 | 92 | | return Task.FromResult(records.LongCount()); |
| | | 93 | | } |
| | | 94 | | |
| | 6 | 95 | | private static IQueryable<ActivityExecutionRecord> Filter(IQueryable<ActivityExecutionRecord> queryable, ActivityExe |
| | | 96 | | } |