Worker.cs 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using DBHelper_SqlSugar;
  2. using SqlSugar;
  3. using WCS.Entity;
  4. using WCS.Entity.Protocol;
  5. namespace TEST
  6. {
  7. public class Worker : BackgroundService
  8. {
  9. private readonly ILogger<Worker> _logger;
  10. public Worker(ILogger<Worker> logger)
  11. {
  12. _logger = logger;
  13. }
  14. protected override async Task ExecuteAsync(CancellationToken stoppingToken)
  15. {
  16. Db.CreateContext(new ConnectionConfig()
  17. {
  18. ConnectionString = AppSettings.Config.GetConnectionString("WCSDB"),
  19. DbType = DbType.MySql
  20. }, "WCSDB");
  21. Db.SetDefaultDbContextType("WCSDB");
  22. Db.Do(db =>
  23. {
  24. //TODO:DbMaintenance.CreateDatabase()并没起到作用,如果没有对应的数据库的话任然需要手动新建一个
  25. db.Default.DbMaintenance.CreateDatabase();
  26. db.Default.CodeFirst.InitTables(typeof(WCS_CMD));
  27. db.Default.CodeFirst.InitTables(typeof(WCS_PLC));
  28. db.Default.CodeFirst.InitTables(typeof(WCS_DATABLOCK));
  29. db.Default.CodeFirst.InitTables(typeof(WCS_DEVICE));
  30. db.Default.CodeFirst.InitTables(typeof(WCS_PATH));
  31. db.Default.CodeFirst.InitTables(typeof(WCS_PATHPOINT));
  32. db.Default.CodeFirst.InitTables(typeof(WCS_ROUTE));
  33. db.Default.CodeFirst.InitTables(typeof(WCS_TASK));
  34. db.Default.CodeFirst.InitTables(typeof(WCS_TASK_OLD));
  35. db.Default.CodeFirst.InitTables(typeof(WCS_EXCEPTION));
  36. db.Default.CodeFirst.InitTables(typeof(WCS_SystemConfig));
  37. db.Default.CodeFirst.InitTables(typeof(WCS_AGVTask));
  38. db.Default.CodeFirst.InitTables(typeof(WCS_DEVICEPROTOCOL));
  39. db.Default.CodeFirst.InitTables(typeof(WCS_GROUPMEMBER));
  40. db.Default.CodeFirst.InitTables(typeof(WCS_MAPPINGENTRY));
  41. db.Default.CodeFirst.InitTables(typeof(WCS_USERS));
  42. db.Default.CodeFirst.InitTables(typeof(WCS_StatusLog));
  43. //db.Default.CodeFirst.InitTables(typeof(WCS_DATABLOCK));
  44. //db.Default.CodeFirst.InitTables(typeof(WCS_DATABLOCK));
  45. //db.Default.CodeFirst.InitTables(typeof(WCS_DATABLOCK));
  46. //db.Default.CodeFirst.InitTables(typeof(WCS_DATABLOCK));
  47. //db.Default.CodeFirst.InitTables(typeof(WCS_DATABLOCK));
  48. //db.Default.CodeFirst.InitTables(typeof(WCS_DATABLOCK));
  49. //db.Default.CodeFirst.InitTables(typeof(WCS_DATABLOCK));
  50. //db.Default.CodeFirst.InitTables(typeof(WCS_DATABLOCK));
  51. });
  52. //while (!stoppingToken.IsCancellationRequested)
  53. //{
  54. // _logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now);
  55. // await Task.Delay(1000, stoppingToken);
  56. //}
  57. }
  58. }
  59. }