using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
using IStation.Untity;
|
using SuperSocket;
|
using static Org.BouncyCastle.Math.EC.ECCurve;
|
|
namespace IStation.Server
|
{
|
/// <summary>
|
/// 接收信息辅助类
|
/// </summary>
|
internal class PackageHandleHelper
|
{
|
public static List<Model.DataDockingConfigureExSocket> ConfigureList { get; set; }
|
|
//接收数据
|
public async ValueTask Handle(IAppSession session, PackageInfo requestInfo)
|
{
|
await Task.Run(() =>
|
{
|
var mySession = (MySession)session;
|
if (ConfigureList == null || ConfigureList.Count < 1)
|
{
|
LogHelper.Info("Socket数据对接任务中,未检索到采用Socket方式的数据对接配置!");
|
return;
|
}
|
|
var message_str = BytesTransfer.ToString(requestInfo.Body);
|
var message_bts = BitTransfer.ToString(requestInfo.Body);
|
LogHelper.Info($"Socket数据对接服务端口:{session.Server.Options.Listeners.First().Port},接收到数据:{message_bts}!");
|
|
bool reslut = false;
|
foreach (var config in ConfigureList)
|
{
|
var customDataDocking = DataDockingSocketFactory.CreateSocket<IDataDockingSocket.IHandleHelper>(config.ConfigureParas.DependencyFile);
|
if (customDataDocking.Valid(requestInfo.Body))
|
{
|
LogHelper.Info($"Socket数据对接中,{config.Name},接收到数据:{message_bts}");
|
customDataDocking.HandleData(mySession, requestInfo.Body, config.Mappers, (receive_list) =>
|
{
|
if (receive_list == null || receive_list.Count < 1)
|
{
|
LogHelper.Info($"Socket数据对接中,注册码:{config.Name},获取测点记录失败!");
|
return;
|
}
|
var queue = new RabbitMqQueueHelper();
|
queue.Push(ConfigHelper.QueueName, new Model.MonitorDataDockingCorpRecord()
|
{
|
CorpID = config.CorpID,
|
ConfigureID = config.ID,
|
Records = receive_list
|
});
|
LogHelper.Info($"Socket数据对接中:{config.Name},成功推入通道{receive_list.Count()}条数据!");
|
});
|
return;
|
}
|
}
|
|
if (!reslut)
|
{
|
LogHelper.Info($"自定义Socket数据对接任务中,端口:{mySession.Server.Options.Listeners.First().Port},收到一条无法识别的消息:{message_str}");
|
}
|
|
});
|
|
}
|
|
|
}
|
}
|