using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Threading;
|
using System.Threading.Tasks;
|
using IStation.Model;
|
|
namespace IStation.DataDockingSocket
|
{
|
public class HandleHelper : IDataDockingSocket.IHandleHelper
|
{
|
/// <summary>
|
/// 处理注册码
|
/// </summary>
|
public void HandleRegisterCode(IMonitorDataDockingSession session)
|
{
|
if (session == null)
|
return;
|
if (!session.IsConnected)
|
return;
|
|
if (SessionHelper.Cache != null)
|
{
|
if (SessionHelper.Cache != session)
|
{
|
if (SessionHelper.Cache.IsConnected)
|
{
|
SessionHelper.Cache.Close($"{session.SessionName} 中,产生新的会话!");
|
}
|
}
|
}
|
|
SessionHelper.Cache = session;
|
|
var appParas = AppParasHelper.Get();
|
if (appParas == null)
|
{
|
LogHelper.Error("Socket 数据对接中,NT 缺少数据对接配置文件");
|
return;
|
}
|
foreach (var item in appParas.InstructionItems)
|
{
|
SendInstructionJobHelper.StartJob(session, item);
|
Thread.Sleep(appParas.InstructionSendSpace * 1000);
|
}
|
|
SendControlJobHelper.StartJob(session);
|
}
|
|
/// <summary>
|
/// 处理心跳包
|
/// </summary>
|
public void HandleHeartbeat(IMonitorDataDockingSession session)
|
{
|
|
}
|
|
/// <summary>
|
/// 处理数据
|
/// </summary>
|
public void HandleData
|
(
|
IMonitorDataDockingSession session,
|
byte[] bytes,
|
List<Model.DataDockingConfigure.Mapper> mappers,
|
Action<List<Model.MonitorDataDockingReceiveRecord>> receive
|
)
|
{
|
if (session == null)
|
return;
|
if (!session.IsConnected)
|
return;
|
if (bytes == null)
|
return;
|
var appParas = AppParasHelper.Get();
|
if (appParas == null)
|
{
|
LogHelper.Error("Socket 数据对接中,NT 缺少数据对接配置文件");
|
return;
|
}
|
|
var receList = HandleDataHelper.HandleData(bytes);
|
if (receList != null && receList.Count > 0)
|
{
|
receive(receList);
|
}
|
|
if (appParas.Src)
|
{
|
SrcHelper.Src(bytes);
|
}
|
if (appParas.Debug)
|
{
|
DebugHelper.Debug(receList);
|
}
|
}
|
|
|
|
|
|
|
|
}
|
}
|