|
|
|
@ -3,14 +3,13 @@ using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
|
using SlnMesnac.Model.domain;
|
|
|
|
|
using SlnMesnac.Repository.service;
|
|
|
|
|
using SlnMesnac.Repository.service.ScanLog;
|
|
|
|
|
using TouchSocket.Core;
|
|
|
|
|
using TouchSocket.Sockets;
|
|
|
|
|
using JsonSerializer = System.Text.Json.JsonSerializer;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region << 版 本 注 释 >>
|
|
|
|
|
/*--------------------------------------------------------------------
|
|
|
|
@ -57,8 +56,8 @@ namespace SlnMesnac.TouchSocket
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Action<ScanLogSocket> ScanLogSocketAction;
|
|
|
|
|
public Action<ScanStatusSocket> ScanStatusSocketAction;
|
|
|
|
|
public Action<ScanLogSocket>? ScanLogSocketAction;
|
|
|
|
|
public Action<ScanStatusSocket>? ScanStatusSocketAction;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public TcpServer(ILogger<TcpServer> logger,TcpService tcpService, IScanLogService scan, IBaseCodeService baseCodeService)
|
|
|
|
@ -74,22 +73,25 @@ namespace SlnMesnac.TouchSocket
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_service.Connecting = (client, e) => {
|
|
|
|
|
_logger.LogInformation($"客户端{client.IP}正在接入服务");
|
|
|
|
|
_logger.LogInformation("客户端{ClientIp}正在接入服务", client.IP);
|
|
|
|
|
return EasyTask.CompletedTask;
|
|
|
|
|
};
|
|
|
|
|
_service.Connected = (client, e) => {
|
|
|
|
|
_logger.LogInformation($"客户端{client.IP}接入服务成功");
|
|
|
|
|
_logger.LogInformation("客户端{ClientIp}接入服务成功", client.IP);
|
|
|
|
|
// RefreshClientInfoEvent?.Invoke(_service);
|
|
|
|
|
return EasyTask.CompletedTask;
|
|
|
|
|
};
|
|
|
|
|
_service.Disconnected = (client, e) => {
|
|
|
|
|
_logger.LogInformation($"客户端{client.IP}断开连接");
|
|
|
|
|
_logger.LogInformation("客户端{ClientIp}断开连接", client.IP);
|
|
|
|
|
// RefreshClientInfoEvent?.Invoke(_service);
|
|
|
|
|
return EasyTask.CompletedTask;
|
|
|
|
|
};
|
|
|
|
|
_service.Received = (client, e) =>
|
|
|
|
|
{
|
|
|
|
|
//从客户端收到信息
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
var mes = Encoding.UTF8.GetString(e.ByteBlock.Buffer, 0, e.ByteBlock.Len);//注意:数据长度是byteBlock.Len
|
|
|
|
|
_logger.LogInformation("收到数据:{Data}",mes);
|
|
|
|
|
// byte[] receivedBuffer = new byte[e.ByteBlock.Len];
|
|
|
|
@ -117,7 +119,6 @@ namespace SlnMesnac.TouchSocket
|
|
|
|
|
Ocr = scanStatus.ocr,
|
|
|
|
|
Url = scanStatus.url
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -128,10 +129,10 @@ namespace SlnMesnac.TouchSocket
|
|
|
|
|
{
|
|
|
|
|
ScanStatusSocket scanStatus = mes.FromJsonString<ScanStatusSocket>();
|
|
|
|
|
ScanStatusSocketAction?.Invoke(scanStatus);
|
|
|
|
|
if (scanStatus.device_status != null && scanStatus.device_status.Count > 0)
|
|
|
|
|
if (scanStatus.is_alarm == 1 && scanStatus.device_status != null && scanStatus.device_status.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
List<string> ls = new List<string>();
|
|
|
|
|
var baseCodes = _baseCodeService.Query();
|
|
|
|
|
var baseCodes = _baseCodeService.QuListCache();
|
|
|
|
|
foreach (var baseCode in scanStatus.device_status)
|
|
|
|
|
{
|
|
|
|
|
var enBaseCode = baseCodes.FirstOrDefault(x=>x.Code==baseCode);
|
|
|
|
@ -144,11 +145,12 @@ namespace SlnMesnac.TouchSocket
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// DateTimeOffset dateTimeOffset = DateTimeOffset.FromUnixTimeSeconds(timestamp);
|
|
|
|
|
// DateTime dateTime = dateTimeOffset.UtcDateTime;
|
|
|
|
|
|
|
|
|
|
client.SendAsync(new Back().ToJsonString());
|
|
|
|
|
}
|
|
|
|
|
catch (Exception exception)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(exception,exception.Message);
|
|
|
|
|
}
|
|
|
|
|
return EasyTask.CompletedTask;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|