add 加入后台服务
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Worker">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
<UserSecretsId>dotnet-Ewide.Nbzs.BackWorkerService-5E150AE7-682D-42D1-AF3F-1C9CA78CDAD8</UserSecretsId>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="5.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Ewide.Nbzs.Entity\Ewide.Nbzs.Entity.csproj" />
|
||||
<ProjectReference Include="..\framework\Api\Furion\framework\Furion.Extras.DatabaseAccessor.SqlSugar\Furion.Extras.DatabaseAccessor.SqlSugar.csproj" />
|
||||
<ProjectReference Include="..\framework\Api\Furion\framework\Furion\Furion.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
28
Ewide.Nbzs.BackWorkerService/Program.cs
Normal file
28
Ewide.Nbzs.BackWorkerService/Program.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using Furion;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ewide.Nbzs.BackWorkerService
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
CreateHostBuilder(args).Build().Run();
|
||||
}
|
||||
|
||||
public static IHostBuilder CreateHostBuilder(string[] args) =>
|
||||
Host.CreateDefaultBuilder(args)
|
||||
.Inject()
|
||||
.ConfigureServices((hostContext, services) =>
|
||||
{
|
||||
services.AddHostedService<Worker>();
|
||||
});
|
||||
}
|
||||
}
|
||||
11
Ewide.Nbzs.BackWorkerService/Properties/launchSettings.json
Normal file
11
Ewide.Nbzs.BackWorkerService/Properties/launchSettings.json
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"profiles": {
|
||||
"Ewide.Nbzs.BackWorkerService": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": "true",
|
||||
"environmentVariables": {
|
||||
"DOTNET_ENVIRONMENT": "Development"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
60
Ewide.Nbzs.BackWorkerService/Worker.cs
Normal file
60
Ewide.Nbzs.BackWorkerService/Worker.cs
Normal file
@@ -0,0 +1,60 @@
|
||||
using Furion;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ewide.Nbzs.BackWorkerService
|
||||
{
|
||||
public class Worker : BackgroundService
|
||||
{
|
||||
public SqlSugarClient db;
|
||||
private readonly ILogger<Worker> _logger;
|
||||
|
||||
public Worker(ILogger<Worker> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
List<ConnectionConfig> connectConfigList = new()
|
||||
{
|
||||
new ConnectionConfig
|
||||
{
|
||||
ConnectionString = App.Configuration["SqlServerConnectionString:DefaultConnection"],
|
||||
DbType = DbType.SqlServer,
|
||||
IsAutoCloseConnection = true,
|
||||
InitKeyType = InitKeyType.Attribute,
|
||||
ConfigId = "0"
|
||||
}
|
||||
};
|
||||
db = new SqlSugarClient(connectConfigList);
|
||||
}
|
||||
|
||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
{
|
||||
while (!stoppingToken.IsCancellationRequested)
|
||||
{
|
||||
ExecProcess();
|
||||
//var asd = db.Queryable<Ewide.NbzsZheliban.Entity.zjzwfwTickets>().ToList();
|
||||
var asd = db.Queryable<Ewide.NbzsZheliban.Entity.InvestigateTable>().ToList();
|
||||
_logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now);
|
||||
await Task.Delay(1000, stoppingToken);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Ö´ÐÐÈÎÎñ ÿÃë
|
||||
/// </summary>
|
||||
private void ExecProcess()
|
||||
{
|
||||
Thread.Sleep(3000);
|
||||
}
|
||||
|
||||
private void ExecPushProcess()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft": "Warning",
|
||||
"Microsoft.Hosting.Lifetime": "Information"
|
||||
}
|
||||
}
|
||||
}
|
||||
15
Ewide.Nbzs.BackWorkerService/appsettings.json
Normal file
15
Ewide.Nbzs.BackWorkerService/appsettings.json
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft": "Warning",
|
||||
"Microsoft.Hosting.Lifetime": "Information"
|
||||
}
|
||||
},
|
||||
"Product_Conn": {
|
||||
"DefaultConnection": "data source=118.178.224.202;initial catalog=Nbcqb2;persist security info=True;user id=KYSQLSERVERADMIN;password=KYDBLogin20161103...;MultipleActiveResultSets=True;App=EntityFramework"
|
||||
},
|
||||
"Zlb_Conn": {
|
||||
"DefaultConnection": "data source=118.178.224.202;initial catalog=NbzsZlb;persist security info=True;user id=KYSQLSERVERADMIN;password=KYDBLogin20161103...;MultipleActiveResultSets=True;App=EntityFramework"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user