-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathQuartzExecutionContext.cs
43 lines (38 loc) · 1.33 KB
/
QuartzExecutionContext.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
namespace Util.Scheduling;
/// <summary>
/// Quartz执行上下文
/// </summary>
public class QuartzExecutionContext {
/// <summary>
/// 初始化Quartz执行上下文
/// </summary>
/// <param name="serviceProvider">服务提供器</param>
/// <param name="context">执行上下文</param>
public QuartzExecutionContext( IServiceProvider serviceProvider, IJobExecutionContext context ) {
ServiceProvider = serviceProvider ?? throw new ArgumentNullException( nameof( serviceProvider ) );
Context = context ?? throw new ArgumentNullException( nameof( context ) );
}
/// <summary>
/// 服务提供器
/// </summary>
public IServiceProvider ServiceProvider { get; }
/// <summary>
/// 执行上下文
/// </summary>
public IJobExecutionContext Context { get; }
/// <summary>
/// 获取服务
/// </summary>
/// <typeparam name="T">服务类型</typeparam>
public T GetService<T>() {
return ServiceProvider.GetService<T>();
}
/// <summary>
/// 获取参数
/// </summary>
/// <typeparam name="T">参数类型</typeparam>
public T GetData<T>() {
var json = Context.JobDetail.JobDataMap.GetString( JobBase.DataKey );
return Util.Helpers.Json.ToObject<T>( json );
}
}