2024-07-30 07:36:42 +00:00
|
|
|
using System.Net.WebSockets;
|
|
|
|
|
|
|
|
namespace LocalServer;
|
|
|
|
|
|
|
|
public class LocalSyncServerFactory
|
|
|
|
{
|
2024-07-31 09:14:07 +00:00
|
|
|
private readonly object Lock = new();
|
|
|
|
|
|
|
|
public async void CreateLocalSyncServer(WebSocket socket, string name)
|
2024-07-30 07:36:42 +00:00
|
|
|
{
|
|
|
|
if (Servers.Select(x => x.Name == name).Any())
|
|
|
|
{
|
|
|
|
throw new Exception("there already is a server with that name is Runing!");
|
|
|
|
}
|
2024-07-31 09:14:07 +00:00
|
|
|
var server = new LocalSyncServer(socket, name, this);
|
|
|
|
lock (Lock)
|
|
|
|
{
|
|
|
|
Servers.Add(server);
|
|
|
|
}
|
|
|
|
await server.Start();
|
2024-07-30 07:36:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private readonly List<LocalSyncServer> Servers = [];
|
|
|
|
|
|
|
|
public void RemoveLocalSyncServer(LocalSyncServer server)
|
|
|
|
{
|
2024-07-31 09:14:07 +00:00
|
|
|
lock (Lock)
|
|
|
|
{
|
|
|
|
Servers.Remove(server);
|
|
|
|
}
|
2024-07-30 07:36:42 +00:00
|
|
|
}
|
|
|
|
}
|