using IStation.DataDockingSocket.MsgHandle;
using IStation.Untity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace IStation.DataDockingSocket
{
///
/// 发送控制指令辅助类
///
public class SendControlJobHelper
{
///
/// 从MQ里面获取控制指令 辅助类
///
private static RabbitMqExChangeHelper _queueHelper = null;
///
/// 开始任务
///
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("NTTEST", (paras) =>
{
try
{
if (paras == null)
{
NtLogHelper.Info("南通控制命令,数据序列化失败");
return true;
}
switch (paras.ControlType)
{
case Model.MonitorTestControlParas.eControlType.Stop:
{
NtLogHelper.Info("Stop");
//ShunDownMsgHelper.StartJob(session);
}
break;
case Model.MonitorTestControlParas.eControlType.Start:
{
if (string.IsNullOrEmpty(paras.Context))
return false;
var context = Model.MonitorTestControlParas.StartContext.ToModel(paras.Context);
if (context == null)
return false;
NtLogHelper.Info(paras.Context);
// StartUpMsgHelper.StartJob(session);
}
break;
default:
return false;
}
return true;
}
catch (Exception ex)
{
NtLogHelper.Error("南通控制命令,数据消息队列出错,自动跳过", ex);
return true;
}
});
});
}
}
}