初始化
This commit is contained in:
40
BooliveMQTT_Auth/job/DataAsync.cs
Normal file
40
BooliveMQTT_Auth/job/DataAsync.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using CommonEntity;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using MySQLAccess.PGModels;
|
||||
using NLog;
|
||||
using Quartz;
|
||||
using RestSharp;
|
||||
|
||||
namespace IotManager.job
|
||||
{
|
||||
public class DataAsync : IJob
|
||||
{
|
||||
private readonly Logger _logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
public PostgresContext dbcontext { get; set; }
|
||||
public DataAsync(PostgresContext context)
|
||||
{
|
||||
this.dbcontext = context;
|
||||
}
|
||||
public async Task Execute(IJobExecutionContext context)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
//using PostgresContext dbcontext = new PostgresContext();
|
||||
var userdata = await dbcontext.Deviceinfos.Select(A => new DeviceCacheInfo { ClientId = A.ClientId, SecretKey = A.SecretKey }).ToListAsync();
|
||||
|
||||
RestClient client1 = new RestClient("http://iot-manage.uts-data.com:5001");
|
||||
string ti = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
|
||||
var request1 = new RestRequest("/api/Values/SetDeviceInfoChache", Method.Post);
|
||||
request1.AddJsonBody(userdata);
|
||||
var re = await client1.ExecuteAsync(request1);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.Error("同步设备数据出错了:" + ex.Message);
|
||||
}
|
||||
await Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user