| | | 1 | | using Elsa.Common.Services; |
| | | 2 | | using Elsa.Labels.Contracts; |
| | | 3 | | using Elsa.Labels.Entities; |
| | | 4 | | |
| | | 5 | | namespace Elsa.Labels.Services; |
| | | 6 | | |
| | | 7 | | /// <summary> |
| | | 8 | | /// An in-memory store of workflow-label associations. |
| | | 9 | | /// </summary> |
| | | 10 | | public class InMemoryWorkflowDefinitionLabelStore : IWorkflowDefinitionLabelStore |
| | | 11 | | { |
| | | 12 | | private readonly MemoryStore<WorkflowDefinitionLabel> _store; |
| | | 13 | | |
| | | 14 | | /// <summary> |
| | | 15 | | /// Constructor. |
| | | 16 | | /// </summary> |
| | 0 | 17 | | public InMemoryWorkflowDefinitionLabelStore(MemoryStore<WorkflowDefinitionLabel> store) |
| | | 18 | | { |
| | 0 | 19 | | _store = store; |
| | 0 | 20 | | } |
| | | 21 | | |
| | | 22 | | /// <inheritdoc /> |
| | | 23 | | public Task SaveAsync(WorkflowDefinitionLabel record, CancellationToken cancellationToken = default) |
| | | 24 | | { |
| | 0 | 25 | | _store.Save(record, x => x.Id); |
| | 0 | 26 | | return Task.CompletedTask; |
| | | 27 | | } |
| | | 28 | | |
| | | 29 | | /// <inheritdoc /> |
| | | 30 | | public Task SaveManyAsync(IEnumerable<WorkflowDefinitionLabel> records, CancellationToken cancellationToken = defaul |
| | | 31 | | { |
| | 0 | 32 | | _store.SaveMany(records, x => x.Id); |
| | 0 | 33 | | return Task.CompletedTask; |
| | | 34 | | } |
| | | 35 | | |
| | | 36 | | /// <inheritdoc /> |
| | | 37 | | public Task<bool> DeleteAsync(string id, CancellationToken cancellationToken = default) |
| | | 38 | | { |
| | 0 | 39 | | var result = _store.Delete(id); |
| | 0 | 40 | | return Task.FromResult(result); |
| | | 41 | | } |
| | | 42 | | |
| | | 43 | | /// <inheritdoc /> |
| | | 44 | | public Task<IEnumerable<WorkflowDefinitionLabel>> FindByWorkflowDefinitionVersionIdAsync(string workflowDefinitionVe |
| | | 45 | | { |
| | 0 | 46 | | var result = _store.FindMany(x => x.WorkflowDefinitionVersionId == workflowDefinitionVersionId); |
| | 0 | 47 | | return Task.FromResult(result); |
| | | 48 | | } |
| | | 49 | | |
| | | 50 | | /// <inheritdoc /> |
| | | 51 | | public Task ReplaceAsync(IEnumerable<WorkflowDefinitionLabel> removed, IEnumerable<WorkflowDefinitionLabel> added, C |
| | | 52 | | { |
| | 0 | 53 | | _store.DeleteMany(removed, x => x.Id); |
| | 0 | 54 | | _store.SaveMany(added, x => x.Id); |
| | 0 | 55 | | return Task.CompletedTask; |
| | | 56 | | } |
| | | 57 | | |
| | | 58 | | /// <inheritdoc /> |
| | | 59 | | public Task<long> DeleteByWorkflowDefinitionIdAsync(string workflowDefinitionId, CancellationToken cancellationToken |
| | | 60 | | { |
| | 0 | 61 | | var result = _store.DeleteWhere(x => x.WorkflowDefinitionId == workflowDefinitionId); |
| | 0 | 62 | | return Task.FromResult(result); |
| | | 63 | | } |
| | | 64 | | |
| | | 65 | | /// <inheritdoc /> |
| | | 66 | | public Task<long> DeleteByWorkflowDefinitionVersionIdAsync(string workflowDefinitionVersionId, CancellationToken can |
| | | 67 | | { |
| | 0 | 68 | | var result = _store.DeleteWhere(x => x.WorkflowDefinitionVersionId == workflowDefinitionVersionId); |
| | 0 | 69 | | return Task.FromResult(result); |
| | | 70 | | } |
| | | 71 | | |
| | | 72 | | /// <inheritdoc /> |
| | | 73 | | public Task<long> DeleteByWorkflowDefinitionIdsAsync(IEnumerable<string> workflowDefinitionIds, CancellationToken ca |
| | | 74 | | { |
| | 0 | 75 | | var ids = workflowDefinitionIds.ToList(); |
| | 0 | 76 | | var result = _store.DeleteWhere(x => ids.Contains(x.WorkflowDefinitionId)); |
| | 0 | 77 | | return Task.FromResult(result); |
| | | 78 | | } |
| | | 79 | | |
| | | 80 | | /// <inheritdoc /> |
| | | 81 | | public Task<long> DeleteByWorkflowDefinitionVersionIdsAsync(IEnumerable<string> workflowDefinitionVersionIds, Cancel |
| | | 82 | | { |
| | 0 | 83 | | var ids = workflowDefinitionVersionIds.ToList(); |
| | 0 | 84 | | var result = _store.DeleteWhere(x => ids.Contains(x.WorkflowDefinitionVersionId)); |
| | 0 | 85 | | return Task.FromResult(result); |
| | | 86 | | } |
| | | 87 | | |
| | | 88 | | private Task<long> DeleteManyAsync(IEnumerable<string> ids, CancellationToken cancellationToken = default) |
| | | 89 | | { |
| | 0 | 90 | | var result = _store.DeleteMany(ids); |
| | 0 | 91 | | return Task.FromResult(result); |
| | | 92 | | } |
| | | 93 | | |
| | | 94 | | } |