lixiaojun
2024-11-19 a5b6334ae09f2be1a5c073169458b55df68b0b2e
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
namespace IStation.DataDockingSocket
{
    /// <summary>
    /// 发送指令任务
    /// </summary>
    [DisallowConcurrentExecution]//此特性标识 必须等待这次任务执行完成后,才能执行下次任务
    public class SendInstructionJob : IJob
    {
        internal const string Session = "Session";//会话字符
        internal const string Instruction = "Instruction";//指令字符
 
        public async Task Execute(IJobExecutionContext context)
        {
            try
            {
                await Task.Run(() =>
                {
                    var dataMap = context.MergedJobDataMap;
                    var bytes = (byte[])dataMap[Instruction];
                    if (bytes == null)
                        return;
                    var session = (Yw.Model.IMonitorDataDockingSession)dataMap[Session];
                    if (session == null)
                        return;
                    if (session.IsConnected)
                    {
                        SessionHelper.Cache.Send(bytes, 0, bytes.Length);
                        LogHelper.Info(session.SessionName + ":" + BitConverter.ToString(bytes) + ", 发送一条请求数据指令");
                    }
 
                });
            }
            catch (Exception ex)
            {
                var e = new JobExecutionException(ex);
                throw e;
            }
        }
    }
}