生成特种设备检验计划定时任务
This commit is contained in:
@@ -16,6 +16,7 @@ using JNPF.Schedule;
|
||||
using JNPF.Systems.Interfaces.System;
|
||||
using JNPF.TaskScheduler.Entitys;
|
||||
using JNPF.TaskScheduler.Entitys.Dto.TaskScheduler;
|
||||
using JNPF.TaskScheduler.Entitys.Enum;
|
||||
using JNPF.TaskScheduler.Entitys.Model;
|
||||
using JNPF.TaskScheduler.Interfaces.TaskScheduler;
|
||||
using JNPF.TimeCrontab;
|
||||
@@ -412,40 +413,42 @@ public class TimeTaskService : ITimeTaskService, IDynamicApiController, ITransie
|
||||
/// <returns></returns>
|
||||
private async Task<List<TaskMethodInfo>> GetTaskMethods()
|
||||
{
|
||||
//var taskMethods = await _cacheManager.GetAsync<List<TaskMethodInfo>>(CommonConst.CACHEKEYTIMERJOB);
|
||||
//if (taskMethods != null) return taskMethods;
|
||||
// var taskMethods = await _cacheManager.GetAsync<List<TaskMethodInfo>>(CommonConst.CACHEKEYTIMERJOB);
|
||||
// if (taskMethods != null) return taskMethods;
|
||||
|
||||
//// 获取所有本地任务方法,必须有spareTimeAttribute特性
|
||||
//taskMethods = App.EffectiveTypes
|
||||
// .Where(u => u.IsClass && !u.IsInterface && !u.IsAbstract && typeof(ISpareTimeWorker).IsAssignableFrom(u))
|
||||
// .SelectMany(u => u.GetMethods(BindingFlags.Public | BindingFlags.Instance)
|
||||
// .Where(m => m.IsDefined(typeof(SpareTimeAttribute), false) &&
|
||||
// m.GetParameters().Length == 2 &&
|
||||
// m.GetParameters()[0].ParameterType == typeof(SpareTimer) &&
|
||||
// m.GetParameters()[1].ParameterType == typeof(long) && m.ReturnType == typeof(void))
|
||||
// .Select(m =>
|
||||
// {
|
||||
// // 默认获取第一条任务特性
|
||||
// var spareTimeAttribute = m.GetCustomAttribute<SpareTimeAttribute>();
|
||||
// return new TaskMethodInfo
|
||||
// {
|
||||
// id = $"{m.DeclaringType.Name}/{m.Name}",
|
||||
// fullName = spareTimeAttribute.WorkerName,
|
||||
// RequestUrl = $"{m.DeclaringType.Name}/{m.Name}",
|
||||
// cron = spareTimeAttribute.CronExpression,
|
||||
// DoOnce = spareTimeAttribute.DoOnce,
|
||||
// ExecuteType = spareTimeAttribute.ExecuteType,
|
||||
// Interval = (int)spareTimeAttribute.Interval / 1000,
|
||||
// StartNow = spareTimeAttribute.StartNow,
|
||||
// RequestType = RequestTypeEnum.BuiltIn,
|
||||
// Remark = spareTimeAttribute.Description,
|
||||
// TimerType = string.IsNullOrEmpty(spareTimeAttribute.CronExpression) ? SpareTimeTypes.Interval : SpareTimeTypes.Cron,
|
||||
// MethodName = m.Name,
|
||||
// DeclaringType = m.DeclaringType
|
||||
// };
|
||||
// })).ToList();
|
||||
//await _cacheManager.SetAsync(CommonConst.CACHEKEYTIMERJOB, taskMethods);
|
||||
//return taskMethods;
|
||||
List<TaskMethodInfo> taskMethods = null;
|
||||
|
||||
// 获取所有本地任务方法,必须有spareTimeAttribute特性
|
||||
taskMethods = App.EffectiveTypes
|
||||
.Where(u => u.IsClass && !u.IsInterface && !u.IsAbstract && typeof(ISpareTimeWorker).IsAssignableFrom(u))
|
||||
.SelectMany(u => u.GetMethods(BindingFlags.Public | BindingFlags.Instance)
|
||||
.Where(m => m.GetCustomAttributes(typeof(SpareTimeAttribute), false).ToString().Contains("SpareTime") &&
|
||||
m.GetParameters().Length == 2 &&
|
||||
m.GetParameters()[0].ParameterType == typeof(SpareTimer) &&
|
||||
m.GetParameters()[1].ParameterType == typeof(long) && m.ReturnType == typeof(void))
|
||||
.Select(m =>
|
||||
{
|
||||
// 默认获取第一条任务特性
|
||||
var spareTimeAttribute = m.GetCustomAttribute<SpareTimeAttribute>();
|
||||
return new TaskMethodInfo
|
||||
{
|
||||
id = $"{m.DeclaringType.Name}/{m.Name}",
|
||||
fullName = spareTimeAttribute.WorkerName,
|
||||
RequestUrl = $"{m.DeclaringType.Name}/{m.Name}",
|
||||
cron = spareTimeAttribute.CronExpression,
|
||||
DoOnce = spareTimeAttribute.DoOnce,
|
||||
ExecuteType = spareTimeAttribute.ExecuteType,
|
||||
Interval = (int)spareTimeAttribute.Interval / 1000,
|
||||
StartNow = spareTimeAttribute.StartNow,
|
||||
RequestType = RequestTypeEnum.BuiltIn,
|
||||
Remark = spareTimeAttribute.Description,
|
||||
TimerType = string.IsNullOrEmpty(spareTimeAttribute.CronExpression) ? SpareTimeTypes.Interval : SpareTimeTypes.Cron,
|
||||
MethodName = m.Name,
|
||||
DeclaringType = m.DeclaringType
|
||||
};
|
||||
})).ToList();
|
||||
await _cacheManager.SetAsync(CommonConst.CACHEKEYTIMERJOB, taskMethods);
|
||||
return taskMethods;
|
||||
return new List<TaskMethodInfo>();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user