Merge branch 'master' of http://gitea.beetai.com/ducda/AIParkingApplication
This commit is contained in:
commit
963bba78a8
|
@ -11,8 +11,8 @@ namespace AIParkingApplication
|
|||
private HttpClient httpClient;
|
||||
private bool isHttpClientDisposabled;
|
||||
private int numberOfRetry;
|
||||
private ApiPath apiPath;
|
||||
public enum VehicleDirection
|
||||
|
||||
public enum LaneDirection
|
||||
{
|
||||
In,
|
||||
Out
|
||||
|
@ -60,25 +60,30 @@ namespace AIParkingApplication
|
|||
}
|
||||
}
|
||||
|
||||
//TODO For New API
|
||||
//public async Task<LoginResponseModel> Login(LoginModel loginData)
|
||||
//{
|
||||
// try
|
||||
// {
|
||||
// HttpResponseMessage response = await httpClient.PostAsJsonAsync("/api/login", loginData);
|
||||
// response.EnsureSuccessStatusCode();
|
||||
// var loginResult = await response.Content.ReadAsAsync<LoginResponseModel>();
|
||||
// return loginResult;
|
||||
// }
|
||||
// catch (Exception ex)
|
||||
// {
|
||||
// Console.WriteLine($"SendEngineRequest : {ex.Message}");
|
||||
// return new LoginResponseModel
|
||||
// {
|
||||
// IsLoggedIn = false
|
||||
// };
|
||||
// }
|
||||
//}
|
||||
public async Task<Statistic.ParkInfo> GetStatisticInfo()
|
||||
{
|
||||
try
|
||||
{
|
||||
HttpResponseMessage response = await httpClient.GetAsync("/api/statistics");
|
||||
response.EnsureSuccessStatusCode();
|
||||
Statistic.ParkInfo parkInfo = await response.Content.ReadAsAsync<Statistic.ParkInfo>();
|
||||
|
||||
if (string.IsNullOrEmpty(parkInfo.TotalIn))
|
||||
{
|
||||
parkInfo.TotalIn = "0";
|
||||
}
|
||||
if (string.IsNullOrEmpty(parkInfo.TotalOut))
|
||||
{
|
||||
parkInfo.TotalOut = "0";
|
||||
}
|
||||
return parkInfo;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"SendApiStatisticRequest : {ex.Message}");
|
||||
return new Statistic.ParkInfo();
|
||||
}
|
||||
}
|
||||
|
||||
public async void GetApiPathFromServer()
|
||||
{
|
||||
|
@ -97,34 +102,11 @@ namespace AIParkingApplication
|
|||
}
|
||||
}
|
||||
|
||||
public async Task<OcrResult> SaveLogIn(Mat plateImage, PlateType plateType)
|
||||
{
|
||||
string plateImageBase64 = Convert.ToBase64String(plateImage.ToBytes());
|
||||
try
|
||||
{
|
||||
var request = new PlateRequestEngineModel
|
||||
{
|
||||
Img64 = plateImageBase64,
|
||||
Mode = plateType == PlateType.Square ? "square" : "long",
|
||||
Display = "full"
|
||||
};
|
||||
HttpResponseMessage response = await httpClient.PostAsJsonAsync("/get-from-frame", request);
|
||||
response.EnsureSuccessStatusCode();
|
||||
var ocrResult = await response.Content.ReadAsAsync<OcrResult>();
|
||||
return ocrResult;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"SendEngineRequest : {ex.Message}");
|
||||
return new OcrResult();
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<CardValidation> CheckCard(string cardNumber)
|
||||
{
|
||||
try
|
||||
{
|
||||
var request = new CardInfo()
|
||||
var request = new CardModel()
|
||||
{
|
||||
CardNumber = cardNumber
|
||||
};
|
||||
|
@ -141,7 +123,7 @@ namespace AIParkingApplication
|
|||
}
|
||||
|
||||
//Neu Dicrection la Out thi logID la logID lay ve khi check the
|
||||
public async Task<SaveLogRespone> SaveLog(int direction, string cardID, string cameraID, int squareOrLong, string timeInOrOut, string textPlate, Mat plateImage, Mat plateImageResult, Mat PlateFrameImage, Mat FrameImage, string logID = "")
|
||||
public async Task<SaveLogRespone> SaveLog(LaneDirection direction, string cardID, string cameraID, ModePlate squareOrLong, string timeInOrOut, string textPlate, Mat plateImage, Mat plateImageResult, Mat PlateFrameImage, Mat FrameImage, string logID = "")
|
||||
{
|
||||
string plateImageBase64 = Convert.ToBase64String(plateImage.ToBytes());
|
||||
string plateImageResultBase64 = Convert.ToBase64String(plateImageResult.ToBytes());
|
||||
|
@ -149,14 +131,14 @@ namespace AIParkingApplication
|
|||
string FrameImageBase64 = Convert.ToBase64String(FrameImage.ToBytes());
|
||||
try
|
||||
{
|
||||
var request = new SaveLogParams
|
||||
var request = new SaveLogModel
|
||||
{
|
||||
Direction = (direction == (int)VehicleDirection.In) ? "in" : "out",
|
||||
Direction = (direction == LaneDirection.In) ? "in" : "out",
|
||||
LogID = logID,
|
||||
CardID = cardID,
|
||||
TextPlate = textPlate,
|
||||
CameraID = cameraID,
|
||||
ModePlate = (squareOrLong == (int)ModePlate.Sqare) ? "1":"0",
|
||||
ModePlate = (squareOrLong == ModePlate.Sqare) ? "1":"0",
|
||||
TimeVehicleInOrOut = timeInOrOut,
|
||||
PlateImage = plateImageBase64,
|
||||
PlateResultImage = plateImageResultBase64,
|
||||
|
@ -185,8 +167,8 @@ namespace AIParkingApplication
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class CardInfo
|
||||
#region Check card validation API
|
||||
public class CardModel
|
||||
{
|
||||
[JsonProperty("card")]
|
||||
public string CardNumber { get; set; }
|
||||
|
@ -236,7 +218,10 @@ namespace AIParkingApplication
|
|||
[JsonProperty("name")]
|
||||
public string CustomerName { get; set; }
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
#region Save Log API
|
||||
public class SaveLogRespone
|
||||
{
|
||||
[JsonProperty("status")]
|
||||
|
@ -249,7 +234,7 @@ namespace AIParkingApplication
|
|||
public string Cost { get; set; }
|
||||
}
|
||||
|
||||
public class SaveLogParams
|
||||
public class SaveLogModel
|
||||
{
|
||||
[JsonProperty("card")]
|
||||
public string CardID { get; set; }
|
||||
|
@ -284,13 +269,10 @@ namespace AIParkingApplication
|
|||
[JsonProperty("frameImage")]
|
||||
public string FrameImage { get; set; }
|
||||
}
|
||||
#endregion
|
||||
|
||||
public class ApiPath
|
||||
{
|
||||
[JsonProperty("savelogsin")] //wtf is this from server.
|
||||
public string SaveVehicleIn { get; set; }
|
||||
}
|
||||
|
||||
#region Get Config API
|
||||
public class LoginModel
|
||||
{
|
||||
[JsonProperty("username")]
|
||||
|
@ -300,55 +282,16 @@ namespace AIParkingApplication
|
|||
public string Password { get; set; }
|
||||
}
|
||||
|
||||
public class LoginResponseOldModel
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
public class PlateLogModel
|
||||
{
|
||||
[JsonProperty("card")]
|
||||
public string CardID { get; set; }
|
||||
|
||||
[JsonProperty("plate")]
|
||||
public string PlateString { get; set; }
|
||||
|
||||
[JsonProperty("type")]
|
||||
public string LaneType { get; set; }
|
||||
|
||||
[JsonProperty("mod")]
|
||||
public string PlateMode { get; set; } //0 or 1
|
||||
|
||||
[JsonProperty("camera")]
|
||||
public string CameraID { get; set; }
|
||||
|
||||
[JsonProperty("time")]
|
||||
public string Time { get; set; }
|
||||
|
||||
[JsonProperty("plateImage")]
|
||||
public string PlateImageBase64 { get; set; }
|
||||
|
||||
[JsonProperty("plateResultImage")]
|
||||
public string PlateResultImageBase64 { get; set; }
|
||||
|
||||
[JsonProperty("plateFrameImage")]
|
||||
public string PlateFrameImageBase64 { get; set; }
|
||||
|
||||
[JsonProperty("frameImage")]
|
||||
public string FrameImageBase64 { get; set; }
|
||||
}
|
||||
|
||||
public class LoginDataModel
|
||||
{
|
||||
[JsonProperty("status")]
|
||||
public bool IsLoginSuccess { get; set; }
|
||||
|
||||
[JsonProperty("data")]
|
||||
public Data LoginData { get; set; }
|
||||
public Config LoginData { get; set; }
|
||||
}
|
||||
|
||||
public class Data
|
||||
public class Config
|
||||
{
|
||||
[JsonProperty("userID")]
|
||||
public int UserID { get; set; }
|
||||
|
@ -363,7 +306,7 @@ namespace AIParkingApplication
|
|||
public bool IsSaveSystemLogs { get; set; }
|
||||
|
||||
[JsonProperty("api")]
|
||||
public APIPath APIPath { get; set; }
|
||||
public APIPathModel APIPath { get; set; }
|
||||
|
||||
[JsonProperty("camera1")]
|
||||
public CameraData CameraData1 { get; set; }
|
||||
|
@ -401,7 +344,8 @@ namespace AIParkingApplication
|
|||
|
||||
}
|
||||
|
||||
public class APIPath
|
||||
#region API Path
|
||||
public class APIPathModel
|
||||
{
|
||||
[JsonProperty("apiStatistics")]
|
||||
public APIProperties ApiStatistics { get; set; }
|
||||
|
@ -431,6 +375,7 @@ namespace AIParkingApplication
|
|||
[JsonProperty("path")]
|
||||
public string Path { get; set; }
|
||||
}
|
||||
#endregion
|
||||
|
||||
public class CameraData
|
||||
{
|
||||
|
@ -533,13 +478,14 @@ namespace AIParkingApplication
|
|||
public int Logs { get; set; }
|
||||
}
|
||||
|
||||
#region LaneConfig
|
||||
public class LaneConfig
|
||||
{
|
||||
[JsonProperty("laneConfig")]
|
||||
public LanePosision Posision { get; set; }
|
||||
public LaneConfigPosision Posision { get; set; }
|
||||
}
|
||||
|
||||
public class LanePosision
|
||||
public class LaneConfigPosision
|
||||
{
|
||||
[JsonProperty("left")]
|
||||
public LaneConfigParam LeftLane { get; set; }
|
||||
|
@ -559,5 +505,7 @@ namespace AIParkingApplication
|
|||
[JsonProperty("longPlate")]
|
||||
public bool IsLongPlate { get; set; }
|
||||
}
|
||||
#endregion
|
||||
#endregion
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ using System.Windows.Forms;
|
|||
using System.Threading;
|
||||
using Newtonsoft.Json;
|
||||
using System.Net.Http;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace AIParkingApplication
|
||||
{
|
||||
|
@ -12,6 +13,7 @@ namespace AIParkingApplication
|
|||
private readonly Thread thrStatistics;
|
||||
private readonly TimeSpan updateInterval;
|
||||
private ParkInfo parkInfo;
|
||||
private string baseAddress;
|
||||
|
||||
private Label lblLoaiXe;
|
||||
private Label lblXeMay;
|
||||
|
@ -23,8 +25,8 @@ namespace AIParkingApplication
|
|||
public Statistic(string baseAddress, TimeSpan updateInterval)
|
||||
{
|
||||
InitializeComponent();
|
||||
this.baseAddress = baseAddress;
|
||||
this.updateInterval = updateInterval;
|
||||
client = new HttpClient { BaseAddress = new Uri(baseAddress), Timeout = TimeSpan.FromMilliseconds(5000) };
|
||||
thrStatistics = new Thread(new ThreadStart(GetStatistic)) { IsBackground = true };
|
||||
thrStatistics.Start();
|
||||
}
|
||||
|
@ -39,27 +41,10 @@ namespace AIParkingApplication
|
|||
}
|
||||
}
|
||||
|
||||
private async void GetDataFromServer()
|
||||
async void GetDataFromServer()
|
||||
{
|
||||
try
|
||||
{
|
||||
HttpResponseMessage response = await client.GetAsync("/api/statistics");
|
||||
response.EnsureSuccessStatusCode();
|
||||
parkInfo = await response.Content.ReadAsAsync<ParkInfo>();
|
||||
|
||||
if (string.IsNullOrEmpty(parkInfo.TotalIn))
|
||||
{
|
||||
parkInfo.TotalIn = "0";
|
||||
}
|
||||
if (string.IsNullOrEmpty(parkInfo.TotalOut))
|
||||
{
|
||||
parkInfo.TotalOut = "0";
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"SendApiStatisticRequest : {ex.Message}");
|
||||
}
|
||||
ApiController apiController = new ApiController(this.baseAddress);
|
||||
parkInfo = await apiController.GetStatisticInfo();
|
||||
}
|
||||
|
||||
private void ShowInfo()
|
||||
|
|
|
@ -22,6 +22,8 @@ namespace AIParkingApplication
|
|||
private void UpdateStatus()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
if (IsHandleCreated)
|
||||
{
|
||||
lblDateTime.Invoke(new Action(() =>
|
||||
{
|
||||
|
@ -43,6 +45,7 @@ namespace AIParkingApplication
|
|||
lblPingTimeServer.BackColor = pingResult.BackColor;
|
||||
lblPingTimeServer.ForeColor = pingResult.ForceColor;
|
||||
}));
|
||||
}
|
||||
Thread.Sleep(1000);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user