22 lines
592 B
C#
22 lines
592 B
C#
using System.Collections.Concurrent;
|
|
|
|
namespace backend.DeviceHub;
|
|
|
|
public class DeviceRegistry
|
|
{
|
|
private readonly ConcurrentDictionary<Guid, ActiveDevice> _online = new();
|
|
|
|
public bool TryRegister(ActiveDevice dev)
|
|
=> _online.TryAdd(dev.DeviceId, dev);
|
|
|
|
public bool Unregister(Guid deviceId)
|
|
=> _online.TryRemove(deviceId, out _);
|
|
|
|
public ActiveDevice? Get(Guid deviceId)
|
|
=> _online.TryGetValue(deviceId, out var d) ? d : null;
|
|
|
|
public bool IsOnline(Guid deviceId) => _online.ContainsKey(deviceId);
|
|
|
|
public int OnlineCount => _online.Count;
|
|
}
|