41 lines
1.3 KiB
C#
41 lines
1.3 KiB
C#
|
|
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;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|