12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- 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<string>("TargetDbConnectionString"),
- IsAutoCloseConnection = true
- });
- private readonly ISqlSugarClient _local_db = new SqlSugarClient(new ConnectionConfig()
- {
- DbType = DbType.PostgreSQL,
- ConnectionString = config.GetValue<string>("LocalDbConnectionString"),
- IsAutoCloseConnection = true
- });
- public Action<IApplicationBuilder> Configure(Action<IApplicationBuilder> 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<bool>("ReadLot2Thread") ==true)
- {
- ReadLot2Thread readLot2 = new ReadLot2Thread(_db, _local_db);
- readLot2.ReadThreadStart();
- }
- if (config.GetValue<bool>("SendLot2Lot3Thread") == true)
- {
- SendLot2Lot3Thread sendLot2Lot3 = new SendLot2Lot3Thread(_db);
- sendLot2Lot3.SendThreadStart();
- }
- if (config.GetValue<bool>("SendColourCastThread") == true)
- {
- SendColourCastThread sendcolourcast = new SendColourCastThread(_db);
- sendcolourcast.SendThreadStart();
- }
- if (config.GetValue<bool>("DeleteDBRecordThread") == true)
- {
- DeleteDBRecordThread deleterecord = new DeleteDBRecordThread(_db, config.GetValue<int>("DaysAgo"));
- deleterecord.DeleteThreadStart();
- }
- return app => next(app);
- }
- }
- }
|