FileSqlServerSync/Server/LocalServer/LocalSyncServer.cs
zerlei bfdda810d1 fix: 单元测试完成~快搞完了
1. RemoteSyncServer 的 StateHelper 改为私有
2. 修改删除的文件做一个备份
3. 更加详细的测试,主要是观察文件对比是否成功
4. websocket 正式测试
2024-10-12 22:01:48 +08:00

100 lines
2.2 KiB
C#

using Common;
namespace LocalServer;
public class LocalSyncServer
{
#pragma warning disable CA2211 // Non-constant fields should not be visible
public static string TempRootFile = "C:/TempPack";
#pragma warning restore CA2211 // Non-constant fields should not be visible
private StateHelpBase StateHelper;
public void SetStateHelper(StateHelpBase helper)
{
StateHelper = helper;
}
public StateHelpBase GetStateHelper()
{
return StateHelper;
}
public Config? SyncConfig;
public Config NotNullSyncConfig
{
get
{
if (SyncConfig == null)
{
throw new ArgumentNullException("SyncConfig");
}
return SyncConfig;
}
}
public string Name;
/// <summary>
/// 发布源连接
/// </summary>
public readonly AbsPipeLine LocalPipe;
public readonly AbsPipeLine RemotePipe;
/// <summary>
/// 父工程,用于释放资源
/// </summary>
public readonly LocalSyncServerFactory Factory;
public LocalSyncServer(
AbsPipeLine pipe,
LocalSyncServerFactory factory,
string name,
AbsPipeLine remotePipe
)
{
LocalPipe = pipe;
Factory = factory;
StateHelper = new ConnectAuthorityHelper(this);
Name = name;
RemotePipe = remotePipe;
Task.Run(async () =>
{
try
{
var rs = LocalPipe.Work(
(byte[] b) =>
{
return StateHelper.ReceiveLocalMsg(b);
}
);
await foreach (var r in rs) { }
}
catch (Exception e)
{
Close(e.Message);
}
});
}
public void Close(string? CloseReason)
{
try
{
LocalPipe.Close(CloseReason);
RemotePipe.Close(CloseReason);
}
catch (Exception e)
{
//TODO 日志
Console.WriteLine(e.Message);
}
finally
{
Factory.RemoveLocalSyncServer(this);
}
}
}