using Microsoft.AspNetCore.Builder;
using System;
using System.Collections.Generic;
using System.Text;
using WIDESEA.QuartzJob;
using WIDESEA_Core;
using WIDESEA_Core.Helper;
namespace WIDESEA_WMSServer
{
///
/// Quartz 启动服务
///
public static class QuartzJobMiddleWare
{
public static void UseQuartzJobMildd(this IApplicationBuilder app)
{
if (app == null) throw new ArgumentNullException(nameof(app));
var schedulerCenter = app.ApplicationServices.GetService(typeof(ISchedulerCenter)) as ISchedulerCenter;
try
{
var allQzServices = new List()
{
new TasksQz()
{
Id = 1,
AssemblyName = "WIDESEA_WMSServer",
ClassName = "AgvTaskJob",
CreateTime = DateTime.Now,
IntervalSecond = 3,
IsDeleted = false,
IsStart = false,
JobGroup = "WIDESEA_WMSServer",
Name = "AgvTaskJob",
TriggerType = 0
},
new TasksQz()
{
Id = 2,
AssemblyName = "WIDESEA_WMSServer",
ClassName = "InventoryLockJob",
CreateTime = DateTime.Now,
IntervalSecond = 3,
IsDeleted = false,
IsStart = false,
JobGroup = "WIDESEA_WMSServer",
Name = "InventoryLockJob",
TriggerType = 0
},new TasksQz()
{
Id = 3,
AssemblyName = "WIDESEA_WMSServer",
ClassName = "ErpJob",
CreateTime = DateTime.Now,
IntervalSecond = 50000,
IsDeleted = false,
IsStart = false,
JobGroup = "WIDESEA_WMSServer",
Name = "ErpJob",
TriggerType = 0
},
};
if (App.HostEnvironment.IsDevelopment())
{
return;
}
foreach (var item in allQzServices)
{
var ResuleModel = schedulerCenter.AddScheduleJobAsync(item).Result;
if (ResuleModel.Status)
{
ConsoleHelper.WriteSuccessLine($"{item.ClassName}启动成功");
}
else
{
Console.Out.WriteLine($"QuartzNetJob{item.Name}启动失败!错误信息:{ResuleModel.Message}");
}
}
schedulerCenter.StartScheduleAsync();
}
catch (Exception e)
{
throw;
}
}
}
}