Add machine ID on Deal param
This commit is contained in:
@@ -422,20 +422,34 @@ namespace Modbus.Net
|
|||||||
_parentJobKey = parentJobKey;
|
_parentJobKey = parentJobKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 处理写返回
|
/// 处理写返回
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="queryId">任务ID,每个触发器唯一</param>
|
/// <param name="queryId">任务ID,每个触发器唯一</param>
|
||||||
/// <param name="onSuccess">成功回调方法</param>
|
/// <param name="onSuccess">成功回调方法,参数为设备ID</param>
|
||||||
/// <param name="onFailure">失败回调方法</param>
|
/// <param name="onFailure">失败回调方法,参数为设备ID</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
/// <exception cref="NullReferenceException"></exception>
|
/// <exception cref="NullReferenceException"></exception>
|
||||||
public async Task<MachineSetJobScheduler> Deal(string queryId = null, Func<Task> onSuccess = null, Func<Task> onFailure = null)
|
public async Task<MachineSetJobScheduler> Deal(string queryId = null, Func<string, Task> onSuccess = null, Func<string, Task> onFailure = null)
|
||||||
|
{
|
||||||
|
return await Deal<string>(queryId, onSuccess, onFailure);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 处理写返回
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="queryId">任务ID,每个触发器唯一</param>
|
||||||
|
/// <param name="onSuccess">成功回调方法,参数为设备ID</param>
|
||||||
|
/// <param name="onFailure">失败回调方法,参数为设备ID</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
/// <exception cref="NullReferenceException"></exception>
|
||||||
|
public async Task<MachineSetJobScheduler> Deal<TMachineKey>(string queryId = null, Func<string, Task> onSuccess = null, Func<string, Task> onFailure = null) where TMachineKey : IEquatable<TMachineKey>
|
||||||
{
|
{
|
||||||
if (queryId == null) return new MachineSetJobScheduler(_scheduler, _trigger, _parentJobKey);
|
if (queryId == null) return new MachineSetJobScheduler(_scheduler, _trigger, _parentJobKey);
|
||||||
JobKey jobKey = JobKey.Create("Modbus.Net.DataQuery.Job." + queryId, "Modbus.Net.DataQuery.Group." + _trigger.Key.Name);
|
JobKey jobKey = JobKey.Create("Modbus.Net.DataQuery.Job." + queryId, "Modbus.Net.DataQuery.Group." + _trigger.Key.Name);
|
||||||
|
|
||||||
IJobDetail job = JobBuilder.Create<MachineDealDataJob>()
|
IJobDetail job = JobBuilder.Create<MachineDealDataJob<TMachineKey>>()
|
||||||
.WithIdentity(jobKey)
|
.WithIdentity(jobKey)
|
||||||
.StoreDurably(true)
|
.StoreDurably(true)
|
||||||
.Build();
|
.Build();
|
||||||
@@ -530,25 +544,27 @@ namespace Modbus.Net
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 处理写返回任务
|
/// 处理写返回任务
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class MachineDealDataJob : IJob
|
public class MachineDealDataJob<TMachineKey> : IJob where TMachineKey: IEquatable<TMachineKey>
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public async Task Execute(IJobExecutionContext context)
|
public async Task Execute(IJobExecutionContext context)
|
||||||
{
|
{
|
||||||
|
object machine;
|
||||||
object success;
|
object success;
|
||||||
object onSuccess;
|
object onSuccess;
|
||||||
object onFailure;
|
object onFailure;
|
||||||
|
context.JobDetail.JobDataMap.TryGetValue("Machine", out machine);
|
||||||
context.JobDetail.JobDataMap.TryGetValue("Success", out success);
|
context.JobDetail.JobDataMap.TryGetValue("Success", out success);
|
||||||
context.JobDetail.JobDataMap.TryGetValue("OnSuccess", out onSuccess);
|
context.JobDetail.JobDataMap.TryGetValue("OnSuccess", out onSuccess);
|
||||||
context.JobDetail.JobDataMap.TryGetValue("OnFailure", out onFailure);
|
context.JobDetail.JobDataMap.TryGetValue("OnFailure", out onFailure);
|
||||||
bool? successValue = (bool?)success;
|
bool? successValue = (bool?)success;
|
||||||
if (successValue == true && onSuccess != null)
|
if (successValue == true && onSuccess != null)
|
||||||
{
|
{
|
||||||
await ((Func<Task>)onSuccess)();
|
await ((Func<string, Task>)onSuccess)(((IMachineProperty<TMachineKey>)machine).GetMachineIdString());
|
||||||
}
|
}
|
||||||
if (successValue == false && onFailure != null)
|
if (successValue == false && onFailure != null)
|
||||||
{
|
{
|
||||||
await ((Func<Task>)onFailure)();
|
await ((Func<string, Task>)onFailure)(((IMachineProperty<TMachineKey>)machine).GetMachineIdString());
|
||||||
}
|
}
|
||||||
|
|
||||||
context.JobDetail.JobDataMap.Remove("Success");
|
context.JobDetail.JobDataMap.Remove("Success");
|
||||||
|
|||||||
@@ -40,15 +40,15 @@ namespace MachineJob.Service
|
|||||||
await MachineJobSchedulerCreator.CancelJob("Trigger1");
|
await MachineJobSchedulerCreator.CancelJob("Trigger1");
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task OnSuccess()
|
public Task OnSuccess(string machineId)
|
||||||
{
|
{
|
||||||
Console.WriteLine("дÈÎÎñ³É¹¦");
|
Console.WriteLine("Machine {0} set success", machineId);
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task OnFailure()
|
public Task OnFailure(string machineId)
|
||||||
{
|
{
|
||||||
Console.WriteLine("дÈÎÎñʧ°Ü");
|
Console.WriteLine("Machine {0} set failure", machineId);
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user