22 lines
829 B
C#
22 lines
829 B
C#
using System.Collections.Concurrent;
|
|
using ZB.MOM.WW.OtOpcUa.Commons.Messages.Drivers;
|
|
|
|
namespace ZB.MOM.WW.OtOpcUa.AdminUI.Hubs;
|
|
|
|
/// <summary>
|
|
/// Thread-safe in-memory implementation of <see cref="IDriverStatusSnapshotStore"/>.
|
|
/// Keyed by <see cref="DriverHealthChanged.DriverInstanceId"/>; last write wins.
|
|
/// </summary>
|
|
public sealed class InMemoryDriverStatusSnapshotStore : IDriverStatusSnapshotStore
|
|
{
|
|
private readonly ConcurrentDictionary<string, DriverHealthChanged> _byInstance = new();
|
|
|
|
/// <inheritdoc />
|
|
public void Upsert(DriverHealthChanged snapshot)
|
|
=> _byInstance[snapshot.DriverInstanceId] = snapshot;
|
|
|
|
/// <inheritdoc />
|
|
public bool TryGet(string driverInstanceId, out DriverHealthChanged snapshot)
|
|
=> _byInstance.TryGetValue(driverInstanceId, out snapshot!);
|
|
}
|