master
杨威 6 months ago
parent dfda193165
commit c3243e4c0c

@ -19,7 +19,7 @@ public class PclWorker:BackgroundService
protected override async Task ExecuteAsync(CancellationToken stoppingToken) protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{ {
_timer ??= new TimerX(DoPlc, "", 100, 1000); _timer ??= new TimerX(DoPlc, "", 100, 10000);
_timer.Async = true; _timer.Async = true;
// while (!stoppingToken.IsCancellationRequested) // while (!stoppingToken.IsCancellationRequested)
@ -31,7 +31,7 @@ public class PclWorker:BackgroundService
private void DoPlc(Object state) private void DoPlc(Object state)
{ {
_logger.LogInformation("{Data}",DateTime.Now.ToFullString()); // _logger.LogInformation("{Data}",DateTime.Now.ToFullString());
//todo 备份数据库 //todo 备份数据库
// using var scope = _scopeFactory.CreateScope(); // using var scope = _scopeFactory.CreateScope();

@ -8,16 +8,14 @@ XTrace.UseConsole();
IHost host = Host.CreateDefaultBuilder(args) IHost host = Host.CreateDefaultBuilder(args)
.ConfigureServices(services => .ConfigureServices(services =>
{ {
services.AddScoped<IDbContextLocal>(a => new DbContextLocal("Data Source=172.18.4.130;Initial Catalog=CWSSHG;user=sa;password=123456;")); services.AddScoped<IDbContextLocal>(a => new DbContextLocal("Data Source=172.18.4.130;Initial Catalog=CWSSHG;user=sa;password=123456;Encrypt=false;"));
services.AddScoped<IDbContextHttp>(a => new DbContextHttp("Data Source=192.168.202.22;Initial Catalog=CWSSHG;user=sa;password=Lanju@123;Encrypt=false;"));
services.AddScoped<IDbContextLocal>(a => new DbContextLocal("Data Source=172.18.4.130;Initial Catalog=CWSSHG;user=sa;password=123456;"));
services.AddHostedService<Worker>();
services.AddScoped<IDbContextHttp>(a => new DbContextHttp("Data Source=192.168.202.22;Initial Catalog=CWSSHG;user=sa;password=Lanju@123;")); // services.AddScoped<ReportReadDb>();
// services.AddHostedService<Worker>();
services.AddScoped<ReportReadDb>(); //services.AddHostedService<PclWorker>();
services.AddHostedService<PclWorker>();
}) })
.UseAgentService(options => .UseAgentService(options =>
{ {

@ -22,12 +22,12 @@ namespace WorkerSynReport
{ {
while (!stoppingToken.IsCancellationRequested) while (!stoppingToken.IsCancellationRequested)
{ {
await SynWetMixer();
await SynDry(); await SynDry();
await SynWetMixer();
await SynGel(); await SynGel();
await Task.Delay(1000*30, stoppingToken); await Task.Delay(1000*60, stoppingToken);
} }
} }
@ -59,7 +59,7 @@ namespace WorkerSynReport
if (lsMain.Any()) if (lsMain.Any())
{ {
XTrace.WriteLine("插入数据:{0}",lsMain.Count); XTrace.WriteLine("湿混机插入数据:{0}",lsMain.Count);
await dbContextHttp.InsertRangeAsync(lsMain); await dbContextHttp.InsertRangeAsync(lsMain);
await dbContextHttp.InsertRangeAsync(lsMainDetail); await dbContextHttp.InsertRangeAsync(lsMainDetail);
} }
@ -100,7 +100,7 @@ namespace WorkerSynReport
if (lsMain.Any()) if (lsMain.Any())
{ {
XTrace.WriteLine("插入数据:{0}",lsMain.Count); XTrace.WriteLine("干混机插入数据:{0}",lsMain.Count);
await dbContextHttp.InsertRangeAsync(lsMain); await dbContextHttp.InsertRangeAsync(lsMain);
await dbContextHttp.InsertRangeAsync(lsMainDetail); await dbContextHttp.InsertRangeAsync(lsMainDetail);
await dbContextHttp.InsertRangeAsync(lsMixerDetails); await dbContextHttp.InsertRangeAsync(lsMixerDetails);
@ -150,7 +150,7 @@ namespace WorkerSynReport
if (lsMain.Any()) if (lsMain.Any())
{ {
XTrace.WriteLine("插入数据:{0}",lsMain.Count); XTrace.WriteLine("糊化机插入数据:{0}",lsMain.Count);
await dbContextHttp.InsertRangeAsync(lsMain); await dbContextHttp.InsertRangeAsync(lsMain);
await dbContextHttp.InsertRangeAsync(lsMainDetail); await dbContextHttp.InsertRangeAsync(lsMainDetail);
await dbContextHttp.InsertRangeAsync(lsMixerDetails); await dbContextHttp.InsertRangeAsync(lsMixerDetails);

@ -13,12 +13,12 @@
<PackageReference Include="Chloe.SqlServer" Version="5.19.0" /> <PackageReference Include="Chloe.SqlServer" Version="5.19.0" />
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.2.0" /> <PackageReference Include="Microsoft.Data.SqlClient" Version="5.2.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" /> <PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
<PackageReference Include="NewLife.Core" Version="10.10.2024.501" /> <PackageReference Include="NewLife.Core" Version="10.10.2024.507" />
<PackageReference Include="NewLife.Extensions.Hosting.AgentService" Version="10.7.2024.402" /> <PackageReference Include="NewLife.Extensions.Hosting.AgentService" Version="10.7.2024.402" />
<PackageReference Include="Chloe" Version="5.19.0" /> <PackageReference Include="Chloe" Version="5.19.0" />
<PackageReference Include="Chloe.Extension" Version="5.19.0" /> <PackageReference Include="Chloe.Extension" Version="5.19.0" />
<PackageReference Include="Chloe.SqlServer" Version="5.19.0" /> <PackageReference Include="Chloe.SqlServer" Version="5.19.0" />
<PackageReference Include="HslCommunication" Version="11.8.1" /> <PackageReference Include="HslCommunication" Version="12.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" /> <PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
<PackageReference Include="NewLife.Core" Version="10.6.2024.101" /> <PackageReference Include="NewLife.Core" Version="10.6.2024.101" />
<PackageReference Include="NewLife.Extensions.Hosting.AgentService" Version="10.6.2024.101" /> <PackageReference Include="NewLife.Extensions.Hosting.AgentService" Version="10.6.2024.101" />

Loading…
Cancel
Save