/// <summary> /// 初始化任务 /// </summary> private List <JobSchedule> InitJobSchedules() { //配置为SQL查询 var dbJobs = _repository.AllNoTracking <SysConfig_ServiceRunning>(s => s.IsEnable && !s.IsDelete) .OrderBy(o => o.OrderIndex).ToList(); var runJobs = new List <JobSchedule>(); var codeJobs = new List <(string jobKey, Type jobType)>(); var jobTypes = _typeFinder.FindClassesOfType <INGPJob>(); foreach (var jobType in jobTypes) { var job = Singleton <IEngine> .Instance.ResolveUnregistered(jobType) as INGPJob; if (job == null) { continue; } codeJobs.Add((job.JobKey, jobType)); } foreach (var dbJob in dbJobs) { var codeJob = codeJobs.FirstOrDefault(s => s.jobKey.ToLower() == dbJob.ConfigKey.ToLower()); if (codeJob == (null, null)) { continue; } runJobs.Add(new JobSchedule { CronExpression = dbJob.CronConfig, JobType = codeJob.jobType, OrderIndex = dbJob.OrderIndex, ServiceKey = dbJob.ConfigKey, ServiceName = dbJob.ConfigName, ValidEndTime = dbJob.ValidEndTime, ValidStartTime = dbJob.ValidStartTime }); } return(runJobs); }