|
|
|
@ -9,20 +9,20 @@ public class TBoxApi
|
|
|
|
|
{
|
|
|
|
|
private static readonly ILog Log = LogManager.GetLogger(typeof(TBoxApi));
|
|
|
|
|
|
|
|
|
|
//TODO::TBox 服务地址
|
|
|
|
|
private static readonly string BASE_URL = "http://localhost:5036";
|
|
|
|
|
|
|
|
|
|
private static int _times = 5;
|
|
|
|
|
private static int _successTimes = 3;
|
|
|
|
|
|
|
|
|
|
private static readonly HttpClient _httpClient = new HttpClient()
|
|
|
|
|
{
|
|
|
|
|
Timeout = TimeSpan.FromSeconds(60)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
public static async Task<TboxCarInfoModel> GetCarInfo()
|
|
|
|
|
public static async Task<TboxCarInfoModel> GetCarInfo(string carNo)
|
|
|
|
|
{
|
|
|
|
|
Log.Info("GetCarInfo");
|
|
|
|
|
string url = BASE_URL + "/getCarInfo";
|
|
|
|
|
string url = BASE_URL + "/getCarInfo/" + carNo;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
string s = await _httpClient.GetStringAsync(url);
|
|
|
|
@ -37,15 +37,15 @@ public class TBoxApi
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine(e);
|
|
|
|
|
Log.Error($"GetCarInfo e = {e}");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static async Task<bool> Reset()
|
|
|
|
|
public static async Task<bool> Reset(string carNo)
|
|
|
|
|
{
|
|
|
|
|
Log.Info("Reset");
|
|
|
|
|
string url = BASE_URL + "/Clear";
|
|
|
|
|
string url = BASE_URL + "/Clear/" + carNo;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
string s = await _httpClient.GetStringAsync(url);
|
|
|
|
@ -55,15 +55,15 @@ public class TBoxApi
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine(e);
|
|
|
|
|
Log.Error($"Reset e = {e}");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static async Task<bool> IsConnected()
|
|
|
|
|
public static async Task<bool> IsConnected(string carNo)
|
|
|
|
|
{
|
|
|
|
|
Log.Info("IsConnected");
|
|
|
|
|
string url = BASE_URL + "/getCarInfo";
|
|
|
|
|
string url = BASE_URL + "/getCarInfo/"+carNo;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
string s = await _httpClient.GetStringAsync(url);
|
|
|
|
@ -78,7 +78,7 @@ public class TBoxApi
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine(e);
|
|
|
|
|
Log.Error($"IsConnected e = {e}");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -93,16 +93,13 @@ public class TBoxApi
|
|
|
|
|
var unLockCar = await UnLockCar(carNo);
|
|
|
|
|
if (unLockCar)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
bools.Add(unLockCar);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return bools.Select(i => i).Count() > _successTimes;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static async Task<bool> LockCarManyTimes(string carNo)
|
|
|
|
|
{
|
|
|
|
|
List<bool> bools = new List<bool>();
|
|
|
|
@ -112,13 +109,11 @@ public class TBoxApi
|
|
|
|
|
var unLockCar = await LockCar(carNo);
|
|
|
|
|
if (unLockCar)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
bools.Add(unLockCar);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return bools.Select(i => i).Count() > _successTimes;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -128,7 +123,7 @@ public class TBoxApi
|
|
|
|
|
public static async Task<bool> UnLockCar(string carNo)
|
|
|
|
|
{
|
|
|
|
|
Log.Info("UnLockCar");
|
|
|
|
|
string url = BASE_URL + "/unLock/"+carNo;
|
|
|
|
|
string url = BASE_URL + "/unLock/" + carNo;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
string s = await _httpClient.GetStringAsync(url);
|
|
|
|
@ -139,11 +134,34 @@ public class TBoxApi
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine(e);
|
|
|
|
|
Log.Error($"UnLockCar e = {e}");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static async Task<List<TboxCarInfoModel>> GetCarInfoList()
|
|
|
|
|
{
|
|
|
|
|
Log.Info("GetCarInfoList");
|
|
|
|
|
string url = BASE_URL + "/getCarInfoList" ;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
string s = await _httpClient.GetStringAsync(url);
|
|
|
|
|
List<TboxCarInfoModel>? tboxCarInfoModels = null;
|
|
|
|
|
if (!String.IsNullOrWhiteSpace(s))
|
|
|
|
|
{
|
|
|
|
|
tboxCarInfoModels = JsonConvert.DeserializeObject<List<TboxCarInfoModel>>(s);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Log.Info($"GetCarInfoList resp = {tboxCarInfoModels}");
|
|
|
|
|
return tboxCarInfoModels;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Log.Error($"GetCarInfoList e = {e}");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 车辆上锁
|
|
|
|
|
/// </summary>
|
|
|
|
@ -151,7 +169,7 @@ public class TBoxApi
|
|
|
|
|
public static async Task<bool> LockCar(string carNo)
|
|
|
|
|
{
|
|
|
|
|
Log.Info("LockCar");
|
|
|
|
|
string url = BASE_URL + "/lock/"+carNo;
|
|
|
|
|
string url = BASE_URL + "/lock/" + carNo;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
string s = await _httpClient.GetStringAsync(url);
|
|
|
|
@ -162,7 +180,7 @@ public class TBoxApi
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine(e);
|
|
|
|
|
Log.Error($"LockCar e = {e}");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|