|
|
@ -31,7 +31,9 @@ namespace SunlightAggregationManager.UserClass |
|
|
//TcpService service = new TcpService();
|
|
|
//TcpService service = new TcpService();
|
|
|
service.Connecting = (client, e) => { return EasyTask.CompletedTask; };//有客户端正在连接
|
|
|
service.Connecting = (client, e) => { return EasyTask.CompletedTask; };//有客户端正在连接
|
|
|
service.Connected = (client, e) => {return EasyTask.CompletedTask;};//有客户端成功连接
|
|
|
service.Connected = (client, e) => {return EasyTask.CompletedTask;};//有客户端成功连接
|
|
|
service.Closing = (client, e) => { return EasyTask.CompletedTask; };//有客户端正在断开连接,只有当主动断开时才有效。
|
|
|
service.Closing = (client, e) => { |
|
|
|
|
|
Console.WriteLine("[Disconnecting]IP[" + client.IP + "]ID[" + client.Id + "]"); |
|
|
|
|
|
return EasyTask.CompletedTask; };//有客户端正在断开连接,只有当主动断开时才有效。
|
|
|
service.Closed = (client, e) => { |
|
|
service.Closed = (client, e) => { |
|
|
//离线记录
|
|
|
//离线记录
|
|
|
Dictionary<string, object> myDictOff = new Dictionary<string, object>(); |
|
|
Dictionary<string, object> myDictOff = new Dictionary<string, object>(); |
|
|
@ -66,7 +68,7 @@ namespace SunlightAggregationManager.UserClass |
|
|
MainWindowViewModel.Updata_Memory(MainWindowViewModel._userData, "User='" + deserializedPerson?.User + "'", myDict); |
|
|
MainWindowViewModel.Updata_Memory(MainWindowViewModel._userData, "User='" + deserializedPerson?.User + "'", myDict); |
|
|
|
|
|
|
|
|
Console.WriteLine("[Log on]User[" + deserializedPerson?.User + "]Note[" + (deserializedPerson?.Dat ?? "unknown") + "]"); |
|
|
Console.WriteLine("[Log on]User[" + deserializedPerson?.User + "]Note[" + (deserializedPerson?.Dat ?? "unknown") + "]"); |
|
|
client.SendAsync(Command(deserializedPerson?.Dat?? "NOT")); |
|
|
Command(deserializedPerson?.Dat ?? "NOT", client.Id); |
|
|
} |
|
|
} |
|
|
else |
|
|
else |
|
|
{//首次登录记录
|
|
|
{//首次登录记录
|
|
|
@ -140,18 +142,12 @@ namespace SunlightAggregationManager.UserClass |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//string DAT = e.ByteBlock.Span.ToString(Encoding.UTF8).Substring(5);
|
|
|
|
|
|
//string SYSDAT = "";// = e.ByteBlock.Span.ToString(Encoding.ASCII).Substring(5);
|
|
|
|
|
|
// string SYSKEY = "";
|
|
|
|
|
|
// if (DAT.Length >= 16) SYSKEY = DAT.Substring(0, 16);
|
|
|
|
|
|
// if (DAT.Length > 16) SYSDAT = DAT.Substring(16);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return EasyTask.CompletedTask; |
|
|
return EasyTask.CompletedTask; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await service.SetupAsync(new TouchSocketConfig()//载入配置
|
|
|
await service.SetupAsync(new TouchSocketConfig()//载入配置
|
|
|
// .SetMaxBufferSize(1024 * 1024 * 100)
|
|
|
// .SetMaxBufferSize(1024 * 1024 * 100)
|
|
|
//.SetMinBufferSize(1024 * 1024)
|
|
|
//.SetMinBufferSize(1024 * 1024)
|
|
|
.SetListenIPHosts(new IPHost[] { new IPHost(port1), new IPHost(port2) })//同时监听两个地址
|
|
|
.SetListenIPHosts(new IPHost[] { new IPHost(port1), new IPHost(port2) })//同时监听两个地址
|
|
|
.ConfigureContainer(a =>//容器的配置顺序应该在最前面
|
|
|
.ConfigureContainer(a =>//容器的配置顺序应该在最前面
|
|
|
@ -161,6 +157,7 @@ namespace SunlightAggregationManager.UserClass |
|
|
{ |
|
|
{ |
|
|
}) |
|
|
}) |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
await service.StartAsync();//启动
|
|
|
await service.StartAsync();//启动
|
|
|
|
|
|
|
|
|
Console.WriteLine("TCP Port:"+ port1.ToString()); |
|
|
Console.WriteLine("TCP Port:"+ port1.ToString()); |
|
|
@ -168,7 +165,7 @@ namespace SunlightAggregationManager.UserClass |
|
|
Console.WriteLine("TCP SERVER:START"); |
|
|
Console.WriteLine("TCP SERVER:START"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public static string Command(string dat)//
|
|
|
public static async void Command(string dat,string id)//
|
|
|
{ |
|
|
{ |
|
|
string Command="", ret =""; |
|
|
string Command="", ret =""; |
|
|
|
|
|
|
|
|
@ -179,14 +176,27 @@ namespace SunlightAggregationManager.UserClass |
|
|
if (Command == "Info")//回复info请求的信息
|
|
|
if (Command == "Info")//回复info请求的信息
|
|
|
{ |
|
|
{ |
|
|
var t = ToList(MainWindowViewModel._machines).ToJsonString(); |
|
|
var t = ToList(MainWindowViewModel._machines).ToJsonString(); |
|
|
|
|
|
//格式化返回信息
|
|
|
data_.Add("Info", t); |
|
|
data_.Add("Info", t); |
|
|
|
|
|
ret = JsonSerializer.Serialize(data_); |
|
|
|
|
|
} |
|
|
|
|
|
if (Command == "Query")//回复Query请求的信息
|
|
|
|
|
|
{ |
|
|
|
|
|
string s_ = deserialized.GetValue("StartTime").ToString()!; |
|
|
|
|
|
string e_ = deserialized.GetValue("EndTime").ToString()!; |
|
|
|
|
|
|
|
|
|
|
|
DataTable resultTable = await MainWindowViewModel.dataBase.ExecuteQueryAsync("SELECT * FROM [dbo].[Dyelots] " + |
|
|
|
|
|
"WHERE CreationTime>'"+s_+"'and CreationTime<'"+e_+"'"); |
|
|
|
|
|
//格式化返回信息
|
|
|
|
|
|
data_.Add("Query", Newtonsoft.Json.JsonConvert.SerializeObject(resultTable)); |
|
|
ret = JsonSerializer.Serialize(data_); |
|
|
ret = JsonSerializer.Serialize(data_); |
|
|
} |
|
|
} |
|
|
|
|
|
if (Command == "QueryDetail")//回复info请求的信息
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
return ret; |
|
|
await service.SendAsync(id, ret); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public static List<Dictionary<string, object?>>? ToList(DataTable table)//datatable转list
|
|
|
public static List<Dictionary<string, object?>>? ToList(DataTable table)//datatable转list
|
|
|
|