60 lines
1.9 KiB
C#
60 lines
1.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using JNPF;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Hosting;
|
|
using Tnb.Common.Extension;
|
|
using Tnb.Common.Utils;
|
|
using Tnb.WarehouseMgr.Entities.Configs;
|
|
|
|
namespace Tnb.WarehouseMgr
|
|
{
|
|
/// <summary>
|
|
/// Agv心跳检测服务
|
|
/// </summary>
|
|
public class AgvHeartbeatMonitorService : BackgroundService
|
|
{
|
|
private readonly ElevatorControlConfiguration _elevatorControlConfiguration;
|
|
public bool IsStarted { get; set; }
|
|
|
|
public AgvHeartbeatMonitorService()
|
|
{
|
|
_elevatorControlConfiguration = App.Configuration.Build<ElevatorControlConfiguration>();
|
|
}
|
|
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
|
{
|
|
IsStarted = true;
|
|
var parameter = new Dictionary<string, string>();
|
|
parameter["DevName"] = _elevatorControlConfiguration.DevName;
|
|
parameter["TagName"] = "AGVKeepalive";
|
|
parameter["Value"] = "123";
|
|
parameter["token"] = _elevatorControlConfiguration.token;
|
|
while (!stoppingToken.IsCancellationRequested)
|
|
{
|
|
await HttpClientHelper.GetAsync(_elevatorControlConfiguration.WriteTagUrl, parameter);
|
|
await Task.Delay(TimeSpan.FromMinutes(1));
|
|
}
|
|
}
|
|
|
|
public override Task StopAsync(CancellationToken cancellationToken)
|
|
{
|
|
IsStarted = false;
|
|
return Task.CompletedTask;
|
|
}
|
|
}
|
|
|
|
public static class AgvHeartbeatMonitorServiceExtenstions
|
|
{
|
|
public static IServiceCollection AddAgvHeartbeatMonitor(this IServiceCollection services)
|
|
{
|
|
return services.AddSingleton<BackgroundService, AgvHeartbeatMonitorService>();
|
|
}
|
|
}
|
|
|
|
|
|
}
|