You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
1.8 KiB
65 lines
1.8 KiB
using log4net;
|
|
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Linq;
|
|
using Service.Execute.Model;
|
|
|
|
namespace Service.Execute.Api;
|
|
|
|
public class TBoxApi
|
|
{
|
|
private static readonly ILog Log = LogManager.GetLogger(typeof(TBoxApi));
|
|
|
|
//TODO::TBox 服务地址
|
|
private static readonly string BASE_URL = "http://localhost:7243";
|
|
|
|
private static readonly HttpClient _httpClient = new HttpClient()
|
|
{
|
|
Timeout = TimeSpan.FromSeconds(60)
|
|
};
|
|
|
|
public static async Task<TboxCarInfoModel> GetCarInfo()
|
|
{
|
|
Log.Info("GetCarInfo");
|
|
string url = BASE_URL + "/CarControl/getCarInfo";
|
|
try
|
|
{
|
|
string s = await _httpClient.GetStringAsync(url);
|
|
TboxCarInfoModel? tboxCarInfoModel = null;
|
|
if (!String.IsNullOrWhiteSpace(s))
|
|
{
|
|
tboxCarInfoModel = JsonConvert.DeserializeObject<TboxCarInfoModel>(s);
|
|
}
|
|
|
|
Log.Info($"GetCarInfo resp = {tboxCarInfoModel}");
|
|
return tboxCarInfoModel;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Console.WriteLine(e);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public static async Task<bool> IsConnected()
|
|
{
|
|
Log.Info("IsConnected");
|
|
string url = BASE_URL + "/CarControl/getCarInfo";
|
|
try
|
|
{
|
|
string s = await _httpClient.GetStringAsync(url);
|
|
TboxCarInfoModel? tboxCarInfoModel = null;
|
|
if (!String.IsNullOrWhiteSpace(s))
|
|
{
|
|
tboxCarInfoModel = JsonConvert.DeserializeObject<TboxCarInfoModel>(s);
|
|
}
|
|
|
|
Log.Info($"GetCarInfo resp = {tboxCarInfoModel}");
|
|
return tboxCarInfoModel.Connected;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Console.WriteLine(e);
|
|
return false;
|
|
}
|
|
}
|
|
} |