| | |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Core; |
| | | |
| | | namespace WIDESEAWCS_QuartzJob |
| | | { |
| | | /// <summary> |
| | | /// Job注入 |
| | | /// </summary> |
| | | public class JobFactory : IJobFactory |
| | | { |
| | | /// <summary> |
| | | /// 注入反射获取依赖对象 |
| | | /// </summary> |
| | | private readonly IServiceProvider _serviceProvider; |
| | | |
| | | /// <summary> |
| | | /// Job注入 |
| | | /// </summary> |
| | | /// <param name="serviceProvider"></param> |
| | | public JobFactory(IServiceProvider serviceProvider) |
| | | { |
| | | _serviceProvider = serviceProvider; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 实现接口Job |
| | | /// </summary> |
| | |
| | | { |
| | | try |
| | | { |
| | | if (App.ExpDateTime != null && (DateTime.Now - App.ExpDateTime.GetValueOrDefault()).Seconds > 0) |
| | | { |
| | | throw new InvalidOperationException($"验证错误"); |
| | | } |
| | | |
| | | IServiceScope serviceScope = _serviceProvider.CreateScope(); |
| | | IJob? job = serviceScope.ServiceProvider.GetService(bundle.JobDetail.JobType) as IJob; |
| | | return job; |
| | | } |
| | | catch (Exception) |
| | | catch (Exception ex) |
| | | { |
| | | throw; |
| | | Console.Out.WriteLine(ex.ToString()); |
| | | throw new Exception(ex.Message); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// Job注入 |
| | | /// </summary> |
| | | /// <param name="job"></param> |
| | | public void ReturnJob(IJob job) |
| | | { |
| | | IDisposable? disposable = job as IDisposable; |