FileSqlServerSync/Server/RemoteServer/RemoteSyncServerFactory.cs

51 lines
1.3 KiB
C#
Raw Normal View History

using Common;
2024-09-05 01:59:57 +00:00
namespace RemoteServer;
public class RemoteSyncServerFactory
{
private readonly object Lock = new();
#pragma warning disable CA2211 // Non-constant fields should not be visible
/// <summary>
/// 发布的名称和密码
/// </summary>
public static List<Tuple<string, string>> NamePwd = [];
#pragma warning restore CA2211 // Non-constant fields should not be visible
public async Task CreateRemoteSyncServer(AbsPipeLine pipeLine, string Name)
2024-09-05 01:59:57 +00:00
{
var pwd =
NamePwd.Where(x => x.Item1 == Name).FirstOrDefault()
?? throw new Exception("RemoteServer: 不被允许的发布名称!");
var server = new RemoteSyncServer(pipeLine, this, Name, pwd.Item2);
2024-09-05 01:59:57 +00:00
lock (Lock)
{
Servers.Add(server);
}
await server.Connect();
2024-09-05 01:59:57 +00:00
}
private readonly List<RemoteSyncServer> Servers = [];
public void RemoveSyncServer(RemoteSyncServer server)
2024-09-05 01:59:57 +00:00
{
lock (Lock)
{
Servers.Remove(server);
}
}
public RemoteSyncServer? GetServerByName(string name)
{
var it = Servers.Where(x => x.Name == name).FirstOrDefault();
return it;
}
2024-09-22 05:27:52 +00:00
public RemoteSyncServer? GetServerById(string Id)
{
return Servers.Where(x => x.NotNullSyncConfig.Id.ToString() == Id).FirstOrDefault();
}
2024-09-05 01:59:57 +00:00
}