using DBHelper_SqlSugar; using SqlSugar; using WCS.Entity; using WCS.Entity.Protocol; namespace TEST { public class Worker : BackgroundService { private readonly ILogger _logger; public Worker(ILogger logger) { _logger = logger; } protected override async Task ExecuteAsync(CancellationToken stoppingToken) { Db.CreateContext(new ConnectionConfig() { ConnectionString = AppSettings.Config.GetConnectionString("WCSDB"), DbType = DbType.MySql }, "WCSDB"); Db.SetDefaultDbContextType("WCSDB"); Db.Do(db => { //TODO:DbMaintenance.CreateDatabase()并没起到作用,如果没有对应的数据库的话任然需要手动新建一个 db.Default.DbMaintenance.CreateDatabase(); db.Default.CodeFirst.InitTables(typeof(WCS_CMD)); db.Default.CodeFirst.InitTables(typeof(WCS_PLC)); db.Default.CodeFirst.InitTables(typeof(WCS_DATABLOCK)); db.Default.CodeFirst.InitTables(typeof(WCS_DEVICE)); db.Default.CodeFirst.InitTables(typeof(WCS_PATH)); db.Default.CodeFirst.InitTables(typeof(WCS_PATHPOINT)); db.Default.CodeFirst.InitTables(typeof(WCS_ROUTE)); db.Default.CodeFirst.InitTables(typeof(WCS_TASK)); db.Default.CodeFirst.InitTables(typeof(WCS_TASK_OLD)); db.Default.CodeFirst.InitTables(typeof(WCS_EXCEPTION)); db.Default.CodeFirst.InitTables(typeof(WCS_SystemConfig)); db.Default.CodeFirst.InitTables(typeof(WCS_AGVTask)); db.Default.CodeFirst.InitTables(typeof(WCS_DEVICEPROTOCOL)); db.Default.CodeFirst.InitTables(typeof(WCS_GROUPMEMBER)); db.Default.CodeFirst.InitTables(typeof(WCS_MAPPINGENTRY)); db.Default.CodeFirst.InitTables(typeof(WCS_USERS)); db.Default.CodeFirst.InitTables(typeof(WCS_StatusLog)); //db.Default.CodeFirst.InitTables(typeof(WCS_DATABLOCK)); //db.Default.CodeFirst.InitTables(typeof(WCS_DATABLOCK)); //db.Default.CodeFirst.InitTables(typeof(WCS_DATABLOCK)); //db.Default.CodeFirst.InitTables(typeof(WCS_DATABLOCK)); //db.Default.CodeFirst.InitTables(typeof(WCS_DATABLOCK)); //db.Default.CodeFirst.InitTables(typeof(WCS_DATABLOCK)); //db.Default.CodeFirst.InitTables(typeof(WCS_DATABLOCK)); //db.Default.CodeFirst.InitTables(typeof(WCS_DATABLOCK)); }); //while (!stoppingToken.IsCancellationRequested) //{ // _logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now); // await Task.Delay(1000, stoppingToken); //} } } }