Startup.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 _local_db = new SqlSugarClient(new ConnectionConfig()
  13. {
  14. DbType = DbType.PostgreSQL,
  15. ConnectionString = config.GetValue<string>("LocalDbConnectionString"),
  16. IsAutoCloseConnection = true
  17. });
  18. public Action<IApplicationBuilder> Configure(Action<IApplicationBuilder> next)
  19. {
  20. _local_db.DbMaintenance.CreateDatabase();
  21. _local_db.CodeFirst.InitTables(typeof(DefectModel));
  22. _local_db.CodeFirst.InitTables(typeof(Lot2Lot3Model));
  23. _local_db.CodeFirst.InitTables(typeof(ColourCastModel));
  24. if (config.GetValue<bool>("ReadLot2Thread") ==true)
  25. {
  26. LogerHelper.RecordLogTxt("Start ReadLot2Thread");
  27. ReadLot2Thread readLot2 = new ReadLot2Thread();
  28. readLot2.ReadThreadStart();
  29. }
  30. if (config.GetValue<bool>("SendLot2Lot3Thread") == true)
  31. {
  32. LogerHelper.RecordLogTxt("Start SendLot2Lot3Thread");
  33. SendLot2Lot3Thread sendLot2Lot3 = new SendLot2Lot3Thread();
  34. sendLot2Lot3.SendThreadStart();
  35. }
  36. if (config.GetValue<bool>("SendColourCastThread") == true)
  37. {
  38. LogerHelper.RecordLogTxt("Start SendColourCastThread");
  39. SendColourCastThread sendcolourcast = new SendColourCastThread();
  40. sendcolourcast.SendThreadStart();
  41. }
  42. if (config.GetValue<bool>("DeleteDBRecordThread") == true)
  43. {
  44. LogerHelper.RecordLogTxt("Start DeleteDBRecordThread");
  45. DeleteDBRecordThread deleterecord = new DeleteDBRecordThread(config.GetValue<int>("DaysAgo"));
  46. deleterecord.DeleteThreadStart();
  47. }
  48. return app => next(app);
  49. }
  50. }
  51. }