using EInk.TaskThread; using Microsoft.AspNetCore.Builder; using SqlSugar; using EInk.Models; namespace EInk.Lot2Lot3 { public class ReadLot2Filter : IStartupFilter { private readonly ISqlSugarClient _db = new SqlSugarClient(new ConnectionConfig() { DbType = DbType.PostgreSQL, ConnectionString = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json", optional: true, reloadOnChange: true).Build().GetValue("TargetDbConnectionString"), IsAutoCloseConnection = true }); private readonly ISqlSugarClient _local_db = new SqlSugarClient(new ConnectionConfig() { DbType = DbType.PostgreSQL, ConnectionString = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json", optional: true, reloadOnChange: true).Build().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)); ReadLot2Thread readLot2 = new ReadLot2Thread(_db, _local_db); if (new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json", optional: true, reloadOnChange: true).Build().GetValue("ReadLot2Thread") =="on") { readLot2.ReadThreadStart(); } return app => next(app); } } public class SendDataFilter : IStartupFilter { private readonly ISqlSugarClient _db = new SqlSugarClient(new ConnectionConfig() { DbType = DbType.PostgreSQL, ConnectionString = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json", optional: true, reloadOnChange: true).Build().GetValue("LocalDbConnectionString"), IsAutoCloseConnection = true }); public Action Configure(Action next) { SendLot2Lot3Thread sendLot2Lot3 = new SendLot2Lot3Thread(_db); if (new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json", optional: true, reloadOnChange: true).Build().GetValue("SendLot2Lot3Thread") == "on") { sendLot2Lot3.SendThreadStart(); } SendColourCastThread sendcolourcast = new SendColourCastThread(_db); if (new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json", optional: true, reloadOnChange: true).Build().GetValue("SendColourCastThread") == "on") { sendcolourcast.SendThreadStart(); } return app => next(app); } } public class DeleteDBRecordFilter : IStartupFilter { private readonly ISqlSugarClient _db = new SqlSugarClient(new ConnectionConfig() { DbType = DbType.PostgreSQL, ConnectionString = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json", optional: true, reloadOnChange: true).Build().GetValue("LocalDbConnectionString"), IsAutoCloseConnection = true }); public Action Configure(Action next) { DeleteDBRecordThread deleterecord = new DeleteDBRecordThread(_db); if (new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json", optional: true, reloadOnChange: true).Build().GetValue("DeleteDBRecordThread") == "on") { deleterecord.DeleteThreadStart(); } return app => next(app); } } }