ningshuxia
2022-10-28 0a1f644804e884ed2d612b78a916e59a6d320011
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
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;
                    }
                });
            });
        }
 
 
  
 
    }
}