| | | 1 | | using System.Collections.Concurrent; |
| | | 2 | | using Elsa.Common.Multitenancy; |
| | | 3 | | using Elsa.Workflows.Management.Contracts; |
| | | 4 | | |
| | | 5 | | namespace Elsa.Workflows.Management.Stores; |
| | | 6 | | |
| | | 7 | | /// <summary> |
| | | 8 | | /// An in-memory registry generation store for single-node use and tests. |
| | | 9 | | /// </summary> |
| | | 10 | | public class MemoryWorkflowDefinitionRegistryGenerationStore : IWorkflowDefinitionRegistryGenerationStore |
| | | 11 | | { |
| | 4 | 12 | | private readonly ConcurrentDictionary<string, long> _generations = new(); |
| | | 13 | | |
| | | 14 | | /// <inheritdoc /> |
| | 0 | 15 | | public bool IsShared => false; |
| | | 16 | | |
| | | 17 | | /// <inheritdoc /> |
| | | 18 | | public Task<long> IncrementAsync(string? tenantId, CancellationToken cancellationToken = default) |
| | | 19 | | { |
| | 18 | 20 | | var generation = _generations.AddOrUpdate(NormalizeTenantId(tenantId), 1, (_, current) => current + 1); |
| | 13 | 21 | | return Task.FromResult(generation); |
| | | 22 | | } |
| | | 23 | | |
| | | 24 | | /// <inheritdoc /> |
| | | 25 | | public Task<long> GetGenerationAsync(string? tenantId, CancellationToken cancellationToken = default) |
| | | 26 | | { |
| | 11 | 27 | | return Task.FromResult(_generations.GetValueOrDefault(NormalizeTenantId(tenantId))); |
| | | 28 | | } |
| | | 29 | | |
| | | 30 | | /// <inheritdoc /> |
| | 24 | 31 | | private static string NormalizeTenantId(string? tenantId) => tenantId ?? Tenant.DefaultTenantId; |
| | | 32 | | } |