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;
|
}
|
}
|
}
|
}
|