v3.4.6
This commit is contained in:
31
common/Tnb.Common.Core/Job/DynamicJobCompiler.cs
Normal file
31
common/Tnb.Common.Core/Job/DynamicJobCompiler.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using JNPF.DependencyInjection;
|
||||
using JNPF.Schedule;
|
||||
|
||||
namespace JNPF.Common.Core;
|
||||
|
||||
/// <summary>
|
||||
/// 动态作业编译.
|
||||
/// </summary>
|
||||
public class DynamicJobCompiler : ISingleton
|
||||
{
|
||||
/// <summary>
|
||||
/// 编译代码并返回其中实现 IJob 的类型.
|
||||
/// </summary>
|
||||
/// <param name="script">动态编译的作业代码</param>
|
||||
/// <returns></returns>
|
||||
public Type BuildJob(string script)
|
||||
{
|
||||
// 初始化
|
||||
NatashaInitializer.Preheating();
|
||||
|
||||
// 动态创建作业
|
||||
var builder = new AssemblyCSharpBuilder("JNPF.Common.Core")
|
||||
{
|
||||
Domain = DomainManagement.Random()
|
||||
};
|
||||
|
||||
builder.Add(script);
|
||||
|
||||
return builder.GetAssembly().GetTypes().FirstOrDefault(u => typeof(IJob).IsAssignableFrom(u));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user