| | | 1 | | using Elsa.Common.Services; |
| | | 2 | | using Elsa.Identity.Contracts; |
| | | 3 | | using Elsa.Identity.Entities; |
| | | 4 | | using Elsa.Identity.Models; |
| | | 5 | | |
| | | 6 | | namespace Elsa.Identity.Services; |
| | | 7 | | |
| | | 8 | | /// <summary> |
| | | 9 | | /// Represents an in-memory application store. |
| | | 10 | | /// </summary> |
| | | 11 | | public class MemoryApplicationStore : IApplicationStore |
| | | 12 | | { |
| | | 13 | | private readonly MemoryStore<Application> _store; |
| | | 14 | | |
| | | 15 | | /// <summary> |
| | | 16 | | /// Initializes a new instance of the <see cref="MemoryApplicationStore"/> class. |
| | | 17 | | /// </summary> |
| | 0 | 18 | | public MemoryApplicationStore(MemoryStore<Application> store) |
| | | 19 | | { |
| | 0 | 20 | | _store = store; |
| | 0 | 21 | | } |
| | | 22 | | |
| | | 23 | | /// <inheritdoc /> |
| | | 24 | | public Task SaveAsync(Application application, CancellationToken cancellationToken = default) |
| | | 25 | | { |
| | 0 | 26 | | _store.Save(application, x => x.Id); |
| | 0 | 27 | | return Task.CompletedTask; |
| | | 28 | | } |
| | | 29 | | |
| | | 30 | | /// <inheritdoc /> |
| | | 31 | | public Task DeleteAsync(ApplicationFilter filter, CancellationToken cancellationToken = default) |
| | | 32 | | { |
| | 0 | 33 | | var ids = _store.Query(query => Filter(query, filter)).Select(x => x.Id).Distinct().ToList(); |
| | 0 | 34 | | _store.DeleteWhere(x => ids.Contains(x.Id)); |
| | 0 | 35 | | return Task.CompletedTask; |
| | | 36 | | } |
| | | 37 | | |
| | | 38 | | /// <inheritdoc /> |
| | | 39 | | public Task<Application?> FindAsync(ApplicationFilter filter, CancellationToken cancellationToken = default) |
| | | 40 | | { |
| | 0 | 41 | | var result = _store.Query(query => Filter(query, filter)).FirstOrDefault(); |
| | 0 | 42 | | return Task.FromResult(result); |
| | | 43 | | } |
| | | 44 | | |
| | 0 | 45 | | private IQueryable<Application> Filter(IQueryable<Application> queryable, ApplicationFilter filter) => filter.Apply( |
| | | 46 | | } |