|
|
|
@ -1,26 +1,21 @@ |
|
|
|
using System; |
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Reflection; |
|
|
|
using System.Reflection; |
|
|
|
using System.Runtime.InteropServices; |
|
|
|
|
|
|
|
using DotXxlJob.Core.DefaultHandlers; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace DotXxlJob.Core |
|
|
|
namespace DotXxlJob.Core |
|
|
|
{ |
|
|
|
{ |
|
|
|
public class JobHandlerCache |
|
|
|
public class JobHandlerCache |
|
|
|
{ |
|
|
|
{ |
|
|
|
internal Dictionary<string, JobHandlerItem> HandlersCache { get; } = new Dictionary<string, JobHandlerItem>(); |
|
|
|
private readonly Dictionary<string, JobHandlerItem> _handlersCache = new Dictionary<string, JobHandlerItem>(); |
|
|
|
|
|
|
|
|
|
|
|
public void AddJobHandler<TJob>(params object[] constructorParameters) |
|
|
|
public bool IsEmpty => _handlersCache.Count < 1; |
|
|
|
where TJob : IJobHandler => |
|
|
|
|
|
|
|
|
|
|
|
public void AddJobHandler<TJob>() where TJob : IJobHandler => |
|
|
|
AddJobHandler<TJob>(typeof(TJob).GetCustomAttribute<JobHandlerAttribute>()?.Name ?? |
|
|
|
AddJobHandler<TJob>(typeof(TJob).GetCustomAttribute<JobHandlerAttribute>()?.Name ?? |
|
|
|
typeof(TJob).Name, constructorParameters); |
|
|
|
typeof(TJob).Name); |
|
|
|
|
|
|
|
|
|
|
|
public void AddJobHandler<TJob>(string handlerName, params object[] constructorParameters) |
|
|
|
public void AddJobHandler<TJob>(string handlerName) where TJob : IJobHandler => |
|
|
|
where TJob : IJobHandler => |
|
|
|
AddJobHandler(handlerName, new JobHandlerItem { JobHandlerType = typeof(TJob) }); |
|
|
|
AddJobHandler(handlerName, new JobHandlerItem { |
|
|
|
|
|
|
|
JobHandlerType = typeof(TJob), |
|
|
|
|
|
|
|
JobHandlerConstructorParameters = constructorParameters, |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void AddJobHandler(IJobHandler jobHandler) |
|
|
|
public void AddJobHandler(IJobHandler jobHandler) |
|
|
|
{ |
|
|
|
{ |
|
|
|
@ -39,24 +34,22 @@ namespace DotXxlJob.Core |
|
|
|
|
|
|
|
|
|
|
|
private void AddJobHandler(string handlerName, JobHandlerItem jobHandler) |
|
|
|
private void AddJobHandler(string handlerName, JobHandlerItem jobHandler) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (HandlersCache.ContainsKey(handlerName)) |
|
|
|
if (_handlersCache.ContainsKey(handlerName)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
throw new ArgumentException($"Same IJobHandler' name: [{handlerName}]", nameof(handlerName)); |
|
|
|
throw new ArgumentException($"Same IJobHandler' name: [{handlerName}]", nameof(handlerName)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
HandlersCache.Add(handlerName, jobHandler); |
|
|
|
_handlersCache.Add(handlerName, jobHandler); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public JobHandlerItem Get(string handlerName) => |
|
|
|
public JobHandlerItem Get(string handlerName) => |
|
|
|
HandlersCache.TryGetValue(handlerName, out var item) ? item : null; |
|
|
|
_handlersCache.TryGetValue(handlerName, out var item) ? item : null; |
|
|
|
|
|
|
|
|
|
|
|
public class JobHandlerItem |
|
|
|
public class JobHandlerItem |
|
|
|
{ |
|
|
|
{ |
|
|
|
public IJobHandler JobHandler { get; set; } |
|
|
|
public IJobHandler JobHandler { get; set; } |
|
|
|
|
|
|
|
|
|
|
|
public Type JobHandlerType { get; set; } |
|
|
|
public Type JobHandlerType { get; set; } |
|
|
|
|
|
|
|
|
|
|
|
public object[] JobHandlerConstructorParameters { get; set; } |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|