| | | 1 | | using Elsa.ExternalAuthentication.Contracts; |
| | | 2 | | using Elsa.ExternalAuthentication.Models; |
| | | 3 | | |
| | | 4 | | namespace Elsa.ExternalAuthentication.Stores.InMemory; |
| | | 5 | | |
| | | 6 | | public sealed class InMemoryConnectionObservationStore : IConnectionObservationStore |
| | | 7 | | { |
| | 25 | 8 | | private readonly object _syncRoot = new(); |
| | 25 | 9 | | private readonly Dictionary<string, ConnectionObservation> _observations = new(StringComparer.Ordinal); |
| | | 10 | | |
| | | 11 | | public ValueTask<ConnectionObservation?> FindLatestAsync(string connectionId, CancellationToken cancellationToken = |
| | | 12 | | { |
| | 13 | 13 | | cancellationToken.ThrowIfCancellationRequested(); |
| | | 14 | | |
| | 13 | 15 | | lock (_syncRoot) |
| | 13 | 16 | | return ValueTask.FromResult(_observations.GetValueOrDefault(connectionId)); |
| | 13 | 17 | | } |
| | | 18 | | |
| | | 19 | | public ValueTask SaveLatestAsync(ConnectionObservation observation, CancellationToken cancellationToken = default) |
| | | 20 | | { |
| | 5 | 21 | | cancellationToken.ThrowIfCancellationRequested(); |
| | | 22 | | |
| | 5 | 23 | | lock (_syncRoot) |
| | | 24 | | { |
| | 5 | 25 | | if (!_observations.TryGetValue(observation.ConnectionId, out var existing) || observation.ObservedAt >= exis |
| | 4 | 26 | | _observations[observation.ConnectionId] = observation; |
| | 5 | 27 | | } |
| | | 28 | | |
| | 5 | 29 | | return ValueTask.CompletedTask; |
| | | 30 | | } |
| | | 31 | | } |