| | | 1 | | using Elsa.Alterations.Core.Contracts; |
| | | 2 | | using Elsa.Alterations.Core.Entities; |
| | | 3 | | using Elsa.Alterations.Core.Filters; |
| | | 4 | | using Elsa.Common.Services; |
| | | 5 | | |
| | | 6 | | namespace Elsa.Alterations.Core.Stores; |
| | | 7 | | |
| | | 8 | | /// <summary> |
| | | 9 | | /// A memory-based store for alteration jobs. |
| | | 10 | | /// </summary> |
| | | 11 | | public class MemoryAlterationJobStore : IAlterationJobStore |
| | | 12 | | { |
| | | 13 | | private readonly MemoryStore<AlterationJob> _store; |
| | | 14 | | |
| | | 15 | | /// <summary> |
| | | 16 | | /// Initializes a new instance of the <see cref="MemoryAlterationJobStore"/> class. |
| | | 17 | | /// </summary> |
| | 0 | 18 | | public MemoryAlterationJobStore(MemoryStore<AlterationJob> store) |
| | | 19 | | { |
| | 0 | 20 | | _store = store; |
| | 0 | 21 | | } |
| | | 22 | | |
| | | 23 | | /// <inheritdoc /> |
| | | 24 | | public Task SaveAsync(AlterationJob job, CancellationToken cancellationToken = default) |
| | | 25 | | { |
| | 0 | 26 | | _store.Save(job, x => x.Id); |
| | 0 | 27 | | return Task.CompletedTask; |
| | | 28 | | } |
| | | 29 | | |
| | | 30 | | /// <inheritdoc /> |
| | | 31 | | public Task SaveManyAsync(IEnumerable<AlterationJob> jobs, CancellationToken cancellationToken = default) |
| | | 32 | | { |
| | 0 | 33 | | _store.SaveMany(jobs, x => x.Id); |
| | 0 | 34 | | return Task.CompletedTask; |
| | | 35 | | } |
| | | 36 | | |
| | | 37 | | /// <inheritdoc /> |
| | | 38 | | public Task<AlterationJob?> FindAsync(AlterationJobFilter filter, CancellationToken cancellationToken = default) |
| | | 39 | | { |
| | 0 | 40 | | var entity = _store.Query(query => Filter(query, filter)).FirstOrDefault(); |
| | 0 | 41 | | return Task.FromResult(entity); |
| | | 42 | | } |
| | | 43 | | |
| | | 44 | | /// <inheritdoc /> |
| | | 45 | | public Task<IEnumerable<AlterationJob>> FindManyAsync(AlterationJobFilter filter, CancellationToken cancellationToke |
| | | 46 | | { |
| | 0 | 47 | | var entities = _store.Query(query => Filter(query, filter)).ToList().AsEnumerable(); |
| | 0 | 48 | | return Task.FromResult(entities); |
| | | 49 | | } |
| | | 50 | | |
| | | 51 | | /// <inheritdoc /> |
| | | 52 | | public Task<IEnumerable<string>> FindManyIdsAsync(AlterationJobFilter filter, CancellationToken cancellationToken = |
| | | 53 | | { |
| | 0 | 54 | | var ids = _store.Query(query => Filter(query, filter)).Select(x => x.Id).ToList().AsEnumerable(); |
| | 0 | 55 | | return Task.FromResult(ids); |
| | | 56 | | } |
| | | 57 | | |
| | | 58 | | /// <inheritdoc /> |
| | | 59 | | public Task<long> CountAsync(AlterationJobFilter filter, CancellationToken cancellationToken = default) |
| | | 60 | | { |
| | 0 | 61 | | var count = _store.Query(query => Filter(query, filter)).LongCount(); |
| | 0 | 62 | | return Task.FromResult(count); |
| | | 63 | | } |
| | | 64 | | |
| | | 65 | | |
| | 0 | 66 | | private static IQueryable<AlterationJob> Filter(IQueryable<AlterationJob> query, AlterationJobFilter filter) => filt |
| | | 67 | | } |