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 _db = new SqlSugarClient(new ConnectionConfig() { DbType = DbType.PostgreSQL, ConnectionString = config.GetValue("TargetDbConnectionString"), IsAutoCloseConnection = true }); 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) { ReadLot2Thread readLot2 = new ReadLot2Thread(_db, _local_db); readLot2.ReadThreadStart(); } if (config.GetValue("SendLot2Lot3Thread") == true) { SendLot2Lot3Thread sendLot2Lot3 = new SendLot2Lot3Thread(_db); sendLot2Lot3.SendThreadStart(); } if (config.GetValue("SendColourCastThread") == true) { SendColourCastThread sendcolourcast = new SendColourCastThread(_db); sendcolourcast.SendThreadStart(); } if (config.GetValue("DeleteDBRecordThread") == true) { DeleteDBRecordThread deleterecord = new DeleteDBRecordThread(_db, config.GetValue("DaysAgo")); deleterecord.DeleteThreadStart(); } return app => next(app); } } }