using EInk.TaskThread; using Microsoft.AspNetCore.Builder; using SqlSugar; using EInk.Models; using EInk.Tools; using Microsoft.Extensions.Options; namespace EInk.Lot2Lot3 { public class TaskFilter : IStartupFilter { private static IConfigurationRoot config = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json", optional: true, reloadOnChange: true).Build(); private readonly ISqlSugarClient _local_db = new SqlSugarClient(new ConnectionConfig() { DbType = DbType.PostgreSQL, ConnectionString = config.GetValue("LocalDbConnectionString"), IsAutoCloseConnection = true }); public Action Configure(Action next) { _local_db.DbMaintenance.CreateDatabase(); _local_db.CodeFirst.InitTables(typeof(DefectModel)); _local_db.CodeFirst.InitTables(typeof(Lot2Lot3Model)); _local_db.CodeFirst.InitTables(typeof(ColourCastModel)); if (config.GetValue("ReadLot2Thread") ==true) { LogerHelper.RecordLogTxt("Start ReadLot2Thread"); ReadLot2Thread readLot2 = new ReadLot2Thread(); readLot2.ReadThreadStart(); } if (config.GetValue("SendLot2Lot3Thread") == true) { LogerHelper.RecordLogTxt("Start SendLot2Lot3Thread"); SendLot2Lot3Thread sendLot2Lot3 = new SendLot2Lot3Thread(); sendLot2Lot3.SendThreadStart(); } if (config.GetValue("SendColourCastThread") == true) { LogerHelper.RecordLogTxt("Start SendColourCastThread"); SendColourCastThread sendcolourcast = new SendColourCastThread(); sendcolourcast.SendThreadStart(); } if (config.GetValue("DeleteDBRecordThread") == true) { LogerHelper.RecordLogTxt("Start DeleteDBRecordThread"); DeleteDBRecordThread deleterecord = new DeleteDBRecordThread(config.GetValue("DaysAgo")); deleterecord.DeleteThreadStart(); } return app => next(app); } } }