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
|
{
|
/// <summary>
|
/// 从MQ里面获取控制指令 辅助类
|
/// </summary>
|
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)
|
{
|
NtLogHelper.Info("南通控制命令,数据序列化失败");
|
return true;
|
}
|
switch (paras.ControlType)
|
{
|
case Model.MonitorTestControlParas.eControlType.Stop:
|
{
|
ShutDownMsgHelper.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 default;
|
NtLogHelper.Debug(context.ToJson());
|
StartUpMsgHelper.StartJob(session, context);
|
}
|
break;
|
default:
|
return false;
|
}
|
return true;
|
}
|
catch (Exception ex)
|
{
|
NtLogHelper.Error("南通控制命令,数据消息队列出错,自动跳过", ex);
|
return true;
|
}
|
});
|
});
|
}
|
|
|
|
|
}
|
}
|