1
0
mirror of https://github.com/ncblakely/GiantsTools synced 2024-11-04 22:35:37 +01:00
GiantsTools/Giants.Services/Services/InMemoryServerRegistryStore.cs
2020-08-07 23:53:35 -07:00

37 lines
1.0 KiB
C#

namespace Giants.Services
{
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
public class InMemoryServerRegistryStore : IServerRegistryStore
{
private ConcurrentDictionary<IPAddress, ServerInfo> servers = new ConcurrentDictionary<IPAddress, ServerInfo>();
public Task<IEnumerable<ServerInfo>> GetAllServerInfos()
{
return Task.FromResult(
this.servers.Values.AsEnumerable());
}
public Task<ServerInfo> GetServerInfo(IPAddress ipAddress)
{
if (servers.ContainsKey(ipAddress))
{
return Task.FromResult(servers[ipAddress]);
}
return Task.FromResult((ServerInfo)null);
}
public Task UpsertServerInfo(IPAddress ipAddress, ServerInfo serverInfo)
{
servers.TryAdd(ipAddress, serverInfo);
return Task.CompletedTask;
}
}
}