using IStation.Untity;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
|
namespace IStation.DataDockingSocket
|
{
|
/// <summary>
|
/// 发送控制指令辅助类
|
/// </summary>
|
public class SendControlJobHelper
|
{
|
private static RabbitMqExChangeHelper _queueHelper = null;
|
|
/// <summary>
|
/// 开始任务
|
/// </summary>
|
public static Task StartJob(Model.IMonitorDataDockingSession session)
|
{
|
//已经开启就关闭
|
if (_queueHelper != null)
|
{
|
_queueHelper.Close();
|
_queueHelper = null;
|
}
|
|
//会话结束后关闭
|
session.SessionClosedEvent += () =>
|
{
|
if (_queueHelper != null)
|
{
|
_queueHelper.Close();
|
_queueHelper = null;
|
}
|
};
|
|
_queueHelper = new RabbitMqExChangeHelper();
|
return Task.Run(() =>
|
{
|
_queueHelper.Receive<Model.MonitorTestControlParas>("NTTEST", (paras) =>
|
{
|
try
|
{
|
if(paras==null)
|
{
|
LogHelper.Info("南通控制命令,数据序列化失败");
|
return true;
|
}
|
byte[] bts = null;
|
switch (paras.Type)
|
{
|
case 0:bts = null; break;//从辅助类中获取 关闭
|
case 1: bts = null; break;//从辅助类中获取 开启
|
case -1:bts = null;break;//从辅助类中获取 变频
|
default: break;
|
}
|
if (bts != null)
|
{
|
if (session != null)
|
{
|
if (session.IsConnected)
|
{
|
session.Send(bts, 0, bts.Length);
|
LogHelper.Info(session.SessionName + ":" + BitTransfer.ToString(bts) + ", 发送一条请求控制指令");
|
}
|
}
|
}
|
return true;
|
}
|
catch (Exception ex)
|
{
|
LogHelper.Error("南通控制命令,数据消息队列出错,自动跳过", ex);
|
return true;
|
}
|
});
|
});
|
|
}
|
|
}
|
}
|