generated from wenjy/SlnMesnac
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
108 lines
3.8 KiB
C#
108 lines
3.8 KiB
C#
using Microsoft.Extensions.Hosting;
|
|
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Linq;
|
|
using SlnMesnac.Config;
|
|
using SlnMesnac.Model.AirportApiEntity;
|
|
using SQLitePCL;
|
|
using SqlSugar;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using System.Text.Json;
|
|
using TouchSocket.Rpc;
|
|
using TouchSocket.Sockets;
|
|
using TouchSocket.WebApi;
|
|
using JsonSerializer = System.Text.Json.JsonSerializer;
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
namespace SlnMesnac.TouchSocket
|
|
{
|
|
public class AirPorthttpClient : BackgroundService
|
|
{
|
|
private readonly AppConfig _appConfig;
|
|
private readonly ILogger<AirPorthttpClient> _logger;
|
|
|
|
public AirPorthttpClient(AppConfig appConfig, ILogger<AirPorthttpClient> logger)
|
|
{
|
|
_appConfig = appConfig;
|
|
_logger = logger;
|
|
}
|
|
|
|
public static WebApiClient AirportAGVClient;
|
|
public static WebApiClient AirportManipulatorClient;
|
|
|
|
private WebApiClient CreateWebApiClient(string IpHost)
|
|
{
|
|
var client = new WebApiClient();
|
|
client.Connect(IpHost);
|
|
_logger.LogInformation(IpHost + "连接成功");
|
|
return client;
|
|
}
|
|
|
|
protected override Task ExecuteAsync(CancellationToken stoppingToken)
|
|
{
|
|
try
|
|
{
|
|
AirportAGVClient = CreateWebApiClient(_appConfig.AGVIpConfig);
|
|
AirportManipulatorClient = CreateWebApiClient(_appConfig.ManipulatorIpConfig);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError("ERROR: " + ex);
|
|
return Task.FromException(ex);
|
|
}
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
public static string AGVCallRequest()
|
|
{
|
|
JToken responseValue = AirportAGVClient.InvokeT<JToken>("POST:", null, new AGVArrivalSingalEntity());
|
|
|
|
return responseValue.ToString();
|
|
}
|
|
|
|
public static string ManipulatorStartRequest()
|
|
{
|
|
JToken responseValue = AirportAGVClient.InvokeT<JToken>("POST:", null, new AGVArrivalSingalEntity());
|
|
|
|
return responseValue.ToString();
|
|
}
|
|
|
|
public static AGVStateResponseEntity AGVStateRequest(AGVStateRequestEntity aGVStateRequest)
|
|
{
|
|
JToken responseValue = AirportAGVClient.InvokeT<JToken>("POST:/m1/5051269-4712337-default/apitest/AGVtest", null, aGVStateRequest);
|
|
if (responseValue == null)
|
|
{
|
|
return new AGVStateResponseEntity();
|
|
}
|
|
string json = responseValue.ToString();
|
|
if (string.IsNullOrEmpty(json))
|
|
{
|
|
return new AGVStateResponseEntity();
|
|
}
|
|
AGVStateResponseEntity aGVStateResponseEntity = new AGVStateResponseEntity();
|
|
aGVStateResponseEntity = JsonSerializer.Deserialize<AGVStateResponseEntity>(json);
|
|
return aGVStateResponseEntity;
|
|
}
|
|
|
|
public static ManipulatorStateResponseEntity ManipulatorStateRequest(ManipulatorStateRequestEntity manipulatorStateRequest)
|
|
{
|
|
JToken responseValue = AirportAGVClient.InvokeT<JToken>("POST:/m1/5051269-4712337-default/apitest/manipulatortest", null, manipulatorStateRequest);
|
|
if (responseValue == null)
|
|
{
|
|
return new ManipulatorStateResponseEntity();
|
|
}
|
|
string json = responseValue.ToString();
|
|
if (string.IsNullOrEmpty(json))
|
|
{
|
|
return new ManipulatorStateResponseEntity();
|
|
}
|
|
ManipulatorStateResponseEntity manipulatorState = new ManipulatorStateResponseEntity();
|
|
manipulatorState = JsonSerializer.Deserialize<ManipulatorStateResponseEntity>(json);
|
|
return manipulatorState;
|
|
}
|
|
}
|
|
}
|