|
|
@ -43,8 +43,6 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserClass |
|
|
|
//TcpClient tcpClient = new TcpClient();
|
|
|
|
tcpClient.Connecting = (client, e) => { return EasyTask.CompletedTask; };//即将连接到服务器,此时已经创建socket,但是还未建立tcp
|
|
|
|
tcpClient.Connected = (client, e) => |
|
|
|
{ |
|
|
|
lock (MainWindowViewModel.Machines) |
|
|
|
{ |
|
|
|
try |
|
|
|
{ |
|
|
@ -59,13 +57,10 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserClass |
|
|
|
{ |
|
|
|
LogGing.ERRDATA(ex); MainWindowViewModel.ERR_c++; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return EasyTask.CompletedTask; |
|
|
|
};//成功连接到服务器
|
|
|
|
tcpClient.Closing = (client, e) => |
|
|
|
{ |
|
|
|
lock (MainWindowViewModel.Machines) |
|
|
|
{ |
|
|
|
try |
|
|
|
{ |
|
|
@ -87,12 +82,9 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserClass |
|
|
|
{ |
|
|
|
LogGing.ERRDATA(ex); MainWindowViewModel.ERR_c++; |
|
|
|
} |
|
|
|
} |
|
|
|
return EasyTask.CompletedTask; |
|
|
|
};//即将从服务器断开连接。此处仅主动断开才有效。
|
|
|
|
tcpClient.Closed = (client, e) => |
|
|
|
{ |
|
|
|
lock (MainWindowViewModel.Machines) |
|
|
|
{ |
|
|
|
try |
|
|
|
{ |
|
|
@ -114,7 +106,6 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserClass |
|
|
|
{ |
|
|
|
LogGing.ERRDATA(ex); MainWindowViewModel.ERR_c++; |
|
|
|
} |
|
|
|
} |
|
|
|
return EasyTask.CompletedTask; |
|
|
|
};//从服务器断开连接,当连接不成功时不会触发。
|
|
|
|
tcpClient.Received = (client, e) => |
|
|
@ -123,15 +114,13 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserClass |
|
|
|
string SYSAPI = e.ByteBlock.Span.ToString(Encoding.ASCII).Substring(0, 5); |
|
|
|
string DAT = e.ByteBlock.Span.ToString(Encoding.UTF8); |
|
|
|
if (SYSAPI == "SC800") |
|
|
|
{ |
|
|
|
lock (MainWindowViewModel.Machines) |
|
|
|
{ |
|
|
|
try |
|
|
|
{ |
|
|
|
DAT = DAT.Substring(DAT.IndexOf("]") + 1); |
|
|
|
Dictionary<string, object> Chart_new = new Dictionary<string, object>();//缓存函数
|
|
|
|
Chart_new = JsonConvert.DeserializeObject<Dictionary<string, object>>(DAT);//反序列化
|
|
|
|
DataRow drEmployee = MainWindowViewModel.Machines.Select("IP='" + client.IP + "' AND port='" + client.Port + "'").First(); |
|
|
|
DataRow drEmployee = MainWindowViewModel.Machines.Select("IP='" + client.IP + "'").First(); |
|
|
|
drEmployee.BeginEdit(); |
|
|
|
drEmployee["SYSKEY"] = Chart_new.GetValue("SYSKEY").ToString(); |
|
|
|
drEmployee["NAME"] = Chart_new.GetValue("MACHINE").ToString(); |
|
|
@ -144,7 +133,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserClass |
|
|
|
{ |
|
|
|
LogGing.ERRDATA(ex); MainWindowViewModel.ERR_c++; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
else if (SYSAPI == "SC810") |
|
|
|
{ |
|
|
@ -172,16 +161,18 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserClass |
|
|
|
SQLiteHelpers.Update("WorkOrder", new Dictionary<string, object> { { "State", 101 } }, |
|
|
|
"WorkOrder ='" + DAT + "'", null); |
|
|
|
SQLiteHelpers.Close(); |
|
|
|
}catch (Exception ex) { LogGing.LogGingDATA("[ERR='" + ex + "']=Exception"); MainWindowViewModel.ERR_c++; } |
|
|
|
} |
|
|
|
catch (Exception ex) { LogGing.LogGingDATA("[ERR='" + ex + "']=Exception"); MainWindowViewModel.ERR_c++; } |
|
|
|
} |
|
|
|
else if (SYSAPI == "SC830") |
|
|
|
{ |
|
|
|
try |
|
|
|
{ |
|
|
|
|
|
|
|
DAT = DAT.Substring(DAT.IndexOf("]") + 1); |
|
|
|
Dictionary<string, object> _new = new Dictionary<string, object>();//缓存函数
|
|
|
|
_new = JsonConvert.DeserializeObject<Dictionary<string, object>>(DAT);//反序列化
|
|
|
|
DataRow drEmployee = MainWindowViewModel.Machines.Select("IP='" + client.IP + "' AND port='" + client.Port + "'").First(); |
|
|
|
DataRow drEmployee = MainWindowViewModel.Machines.Select("IP='" + client.IP + "'").First(); |
|
|
|
drEmployee.BeginEdit(); |
|
|
|
drEmployee["Message"] = _new.GetValue("Status"); |
|
|
|
drEmployee["WorkOrder"] = _new.GetValue("WorkNumder"); |
|
|
@ -191,7 +182,6 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserClass |
|
|
|
drEmployee["Step"] = _new.GetValue("Step"); |
|
|
|
drEmployee.EndEdit(); |
|
|
|
drEmployee.AcceptChanges(); |
|
|
|
drEmployee.ClearErrors(); |
|
|
|
|
|
|
|
if (_new.GetValue("Status").ToString() != "----------") |
|
|
|
{ |
|
|
@ -216,6 +206,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserClass |
|
|
|
SQLiteHelpers.InsertData("Chart", Chart_new);// 执行插入
|
|
|
|
SQLiteHelpers.Close(); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
catch (Exception ex) { LogGing.LogGingDATA("[ERR='" + ex + "']=Exception"); MainWindowViewModel.ERR_c++; } |
|
|
|
} |
|
|
@ -331,7 +322,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserClass |
|
|
|
{ |
|
|
|
a.UseCheckClear() |
|
|
|
.SetCheckClearType(CheckClearType.All) |
|
|
|
.SetTick(TimeSpan.FromSeconds(30)) |
|
|
|
.SetTick(TimeSpan.FromSeconds(60)) |
|
|
|
.SetOnClose((c, t) => |
|
|
|
{ |
|
|
|
c.TryShutdown(); |
|
|
|