1
0
mirror of https://github.com/ncblakely/GiantsTools synced 2024-07-01 02:01:45 +02:00
GiantsTools/Giants.Services/Store/InMemoryServerRegistryStore.cs

47 lines
1.2 KiB
C#
Raw Normal View History

namespace Giants.Services
{
2020-08-09 01:31:16 +02:00
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
2020-08-09 01:31:16 +02:00
using System.Linq.Expressions;
using System.Net;
using System.Threading.Tasks;
public class InMemoryServerRegistryStore : IServerRegistryStore
{
2020-08-09 01:31:16 +02:00
private ConcurrentDictionary<string, ServerInfo> servers = new ConcurrentDictionary<string, ServerInfo>();
2020-08-09 01:31:16 +02:00
public Task<IEnumerable<ServerInfo>> GetServerInfos(
Expression<Func<ServerInfo, bool>> whereExpression = null)
{
return Task.FromResult(
this.servers.Values.AsEnumerable());
}
2020-08-09 01:31:16 +02:00
public Task<ServerInfo> GetServerInfo(string ipAddress)
{
if (servers.ContainsKey(ipAddress))
{
return Task.FromResult(servers[ipAddress]);
}
return Task.FromResult((ServerInfo)null);
}
2020-08-09 01:31:16 +02:00
public Task Initialize()
{
2020-08-09 01:31:16 +02:00
this.servers.Clear();
return Task.CompletedTask;
}
public Task UpsertServerInfo(ServerInfo serverInfo)
{
this.servers.TryAdd(serverInfo.HostIpAddress, serverInfo);
return Task.CompletedTask;
}
}
}