|  |  | 
 |  |  |  *----------------------------------------------------------------*/ | 
 |  |  | #endregion << 版 本 注 释 >> | 
 |  |  |  | 
 |  |  | using OfficeOpenXml.FormulaParsing.Excel.Functions.DateTime; | 
 |  |  | using Quartz.Impl.Matchers; | 
 |  |  | using Quartz; | 
 |  |  | using System; | 
 |  |  | using System.Collections.Generic; | 
 |  |  | using System.Linq; | 
 |  |  | using System.Text; | 
 |  |  | using System.Threading.Tasks; | 
 |  |  | using WIDESEAWCS_Core; | 
 |  |  | using WIDESEAWCS_Core.BaseRepository; | 
 |  |  | using WIDESEAWCS_Core.BaseServices; | 
 |  |  | using WIDESEAWCS_Core.Helper; | 
 |  |  | 
 |  |  | using WIDESEAWCS_QuartzJob.DTO; | 
 |  |  | using WIDESEAWCS_QuartzJob.Models; | 
 |  |  | using WIDESEAWCS_QuartzJob.Repository; | 
 |  |  | using Quartz.Impl; | 
 |  |  | using System.Collections.Specialized; | 
 |  |  |  | 
 |  |  | namespace WIDESEAWCS_QuartzJob.Service | 
 |  |  | { | 
 |  |  | 
 |  |  |     { | 
 |  |  |         private readonly IUnitOfWorkManage _unitOfWorkManage; | 
 |  |  |         private readonly IDeviceInfoRepository _deviceInfoRepository; | 
 |  |  |         public DispatchInfoService(IDispatchInfoRepository BaseDal, IUnitOfWorkManage unitOfWorkManage, IDeviceInfoRepository deviceInfoRepository) : base(BaseDal) | 
 |  |  |         private readonly ISchedulerCenter _schedulerCenter; | 
 |  |  |         public DispatchInfoService(IDispatchInfoRepository BaseDal, IUnitOfWorkManage unitOfWorkManage, IDeviceInfoRepository deviceInfoRepository, ISchedulerCenter schedulerCenter) : base(BaseDal) | 
 |  |  |         { | 
 |  |  |             _unitOfWorkManage = unitOfWorkManage; | 
 |  |  |             _deviceInfoRepository = deviceInfoRepository; | 
 |  |  |             _schedulerCenter = schedulerCenter; | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         /// <summary> | 
 |  |  | 
 |  |  |                 DeviceType = b.DeviceType | 
 |  |  |             }).ToList(); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         public async Task<WebResponseContent> GetDispatchInfosAsync() | 
 |  |  |         { | 
 |  |  |             WebResponseContent content = new WebResponseContent(); | 
 |  |  |             NameValueCollection collection = new NameValueCollection | 
 |  |  |             { | 
 |  |  |                 { "quartz.serializer.type", "binary" }, | 
 |  |  |             }; | 
 |  |  |             StdSchedulerFactory factory = new StdSchedulerFactory(collection); | 
 |  |  |             IScheduler scheduler = await factory.GetScheduler(); | 
 |  |  |             var jobKeys = await scheduler.GetJobKeys(GroupMatcher<JobKey>.AnyGroup()); | 
 |  |  |             foreach (var jobKey in jobKeys) | 
 |  |  |             { | 
 |  |  |                 // 在这里处理每个JobKey | 
 |  |  |                 IJobDetail jobDetail = await scheduler.GetJobDetail(jobKey); | 
 |  |  |                 if (jobDetail != null) | 
 |  |  |                 { | 
 |  |  |                     // 可以获取Job的描述信息 | 
 |  |  |                     string jobDescription = jobDetail.Description; | 
 |  |  |                     // 以及Job的数据映射(JobDataMap) | 
 |  |  |                     JobDataMap jobDataMap = jobDetail.JobDataMap; | 
 |  |  |                 } | 
 |  |  |             } | 
 |  |  |  | 
 |  |  |             var triggerKeys = await scheduler.GetTriggerKeys(GroupMatcher<TriggerKey>.AnyGroup()); | 
 |  |  |             foreach (var triggerKey in triggerKeys) | 
 |  |  |             { | 
 |  |  |                 // 在这里处理每个TriggerKey | 
 |  |  |                 ITrigger trigger = await scheduler.GetTrigger(triggerKey); | 
 |  |  |                 if (trigger != null) | 
 |  |  |                 { | 
 |  |  |                     // 获取下一次触发时间(如果有) | 
 |  |  |                     DateTimeOffset? nextFireTime = trigger.GetNextFireTimeUtc(); | 
 |  |  |                     // 获取上次触发时间(如果有) | 
 |  |  |                     DateTimeOffset? previousFireTime = trigger.GetPreviousFireTimeUtc(); | 
 |  |  |                     // 获取触发类型(如SimpleTrigger、CronTrigger) | 
 |  |  |                     string triggerType = trigger.GetType().Name; | 
 |  |  |                     // 对于CronTrigger,还可以获取Cron表达式(如果是) | 
 |  |  |                     //if (trigger is CronTrigger cronTrigger) | 
 |  |  |                     //{ | 
 |  |  |                     //    string cronExpression = cronTrigger.CronExpressionString; | 
 |  |  |                     //} | 
 |  |  |                     if (!previousFireTime.HasValue && nextFireTime.HasValue) | 
 |  |  |                     { | 
 |  |  |                         Console.WriteLine($"Job处于等待触发状态,Trigger名称: {triggerKey.Name}"); | 
 |  |  |                     } | 
 |  |  |                 } | 
 |  |  |             } | 
 |  |  |             return content; | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  | } |