Startup.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using EInk.TaskThread;
  2. using Microsoft.AspNetCore.Builder;
  3. using SqlSugar;
  4. using EInk.Models;
  5. using EInk.Tools;
  6. using Microsoft.Extensions.Options;
  7. namespace EInk.Lot2Lot3
  8. {
  9. public class TaskFilter : IStartupFilter
  10. {
  11. private static IConfigurationRoot config = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json", optional: true, reloadOnChange: true).Build();
  12. private readonly ISqlSugarClient _db = new SqlSugarClient(new ConnectionConfig()
  13. {
  14. DbType = DbType.PostgreSQL,
  15. ConnectionString = config.GetValue<string>("TargetDbConnectionString"),
  16. IsAutoCloseConnection = true
  17. });
  18. private readonly ISqlSugarClient _local_db = new SqlSugarClient(new ConnectionConfig()
  19. {
  20. DbType = DbType.PostgreSQL,
  21. ConnectionString = config.GetValue<string>("LocalDbConnectionString"),
  22. IsAutoCloseConnection = true
  23. });
  24. public Action<IApplicationBuilder> Configure(Action<IApplicationBuilder> next)
  25. {
  26. _local_db.DbMaintenance.CreateDatabase();
  27. _local_db.CodeFirst.InitTables(typeof(DefectModel));
  28. _local_db.CodeFirst.InitTables(typeof(Lot2Lot3Model));
  29. _local_db.CodeFirst.InitTables(typeof(ColourCastModel));
  30. if (config.GetValue<bool>("ReadLot2Thread") ==true)
  31. {
  32. ReadLot2Thread readLot2 = new ReadLot2Thread(_db, _local_db);
  33. readLot2.ReadThreadStart();
  34. }
  35. if (config.GetValue<bool>("SendLot2Lot3Thread") == true)
  36. {
  37. SendLot2Lot3Thread sendLot2Lot3 = new SendLot2Lot3Thread(_db);
  38. sendLot2Lot3.SendThreadStart();
  39. }
  40. if (config.GetValue<bool>("SendColourCastThread") == true)
  41. {
  42. SendColourCastThread sendcolourcast = new SendColourCastThread(_db);
  43. sendcolourcast.SendThreadStart();
  44. }
  45. if (config.GetValue<bool>("DeleteDBRecordThread") == true)
  46. {
  47. DeleteDBRecordThread deleterecord = new DeleteDBRecordThread(_db, config.GetValue<int>("DaysAgo"));
  48. deleterecord.DeleteThreadStart();
  49. }
  50. return app => next(app);
  51. }
  52. }
  53. }