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 HttpClient httpClient;
|
||||||
private bool isHttpClientDisposabled;
|
private bool isHttpClientDisposabled;
|
||||||
private int numberOfRetry;
|
private int numberOfRetry;
|
||||||
private ApiPath apiPath;
|
|
||||||
public enum VehicleDirection
|
public enum LaneDirection
|
||||||
{
|
{
|
||||||
In,
|
In,
|
||||||
Out
|
Out
|
||||||
|
@ -60,25 +60,30 @@ namespace AIParkingApplication
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO For New API
|
public async Task<Statistic.ParkInfo> GetStatisticInfo()
|
||||||
//public async Task<LoginResponseModel> Login(LoginModel loginData)
|
{
|
||||||
//{
|
try
|
||||||
// try
|
{
|
||||||
// {
|
HttpResponseMessage response = await httpClient.GetAsync("/api/statistics");
|
||||||
// HttpResponseMessage response = await httpClient.PostAsJsonAsync("/api/login", loginData);
|
response.EnsureSuccessStatusCode();
|
||||||
// response.EnsureSuccessStatusCode();
|
Statistic.ParkInfo parkInfo = await response.Content.ReadAsAsync<Statistic.ParkInfo>();
|
||||||
// var loginResult = await response.Content.ReadAsAsync<LoginResponseModel>();
|
|
||||||
// return loginResult;
|
if (string.IsNullOrEmpty(parkInfo.TotalIn))
|
||||||
// }
|
{
|
||||||
// catch (Exception ex)
|
parkInfo.TotalIn = "0";
|
||||||
// {
|
}
|
||||||
// Console.WriteLine($"SendEngineRequest : {ex.Message}");
|
if (string.IsNullOrEmpty(parkInfo.TotalOut))
|
||||||
// return new LoginResponseModel
|
{
|
||||||
// {
|
parkInfo.TotalOut = "0";
|
||||||
// IsLoggedIn = false
|
}
|
||||||
// };
|
return parkInfo;
|
||||||
// }
|
}
|
||||||
//}
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"SendApiStatisticRequest : {ex.Message}");
|
||||||
|
return new Statistic.ParkInfo();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public async void GetApiPathFromServer()
|
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)
|
public async Task<CardValidation> CheckCard(string cardNumber)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var request = new CardInfo()
|
var request = new CardModel()
|
||||||
{
|
{
|
||||||
CardNumber = cardNumber
|
CardNumber = cardNumber
|
||||||
};
|
};
|
||||||
|
@ -141,7 +123,7 @@ namespace AIParkingApplication
|
||||||
}
|
}
|
||||||
|
|
||||||
//Neu Dicrection la Out thi logID la logID lay ve khi check the
|
//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 plateImageBase64 = Convert.ToBase64String(plateImage.ToBytes());
|
||||||
string plateImageResultBase64 = Convert.ToBase64String(plateImageResult.ToBytes());
|
string plateImageResultBase64 = Convert.ToBase64String(plateImageResult.ToBytes());
|
||||||
|
@ -149,14 +131,14 @@ namespace AIParkingApplication
|
||||||
string FrameImageBase64 = Convert.ToBase64String(FrameImage.ToBytes());
|
string FrameImageBase64 = Convert.ToBase64String(FrameImage.ToBytes());
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var request = new SaveLogParams
|
var request = new SaveLogModel
|
||||||
{
|
{
|
||||||
Direction = (direction == (int)VehicleDirection.In) ? "in" : "out",
|
Direction = (direction == LaneDirection.In) ? "in" : "out",
|
||||||
LogID = logID,
|
LogID = logID,
|
||||||
CardID = cardID,
|
CardID = cardID,
|
||||||
TextPlate = textPlate,
|
TextPlate = textPlate,
|
||||||
CameraID = cameraID,
|
CameraID = cameraID,
|
||||||
ModePlate = (squareOrLong == (int)ModePlate.Sqare) ? "1":"0",
|
ModePlate = (squareOrLong == ModePlate.Sqare) ? "1":"0",
|
||||||
TimeVehicleInOrOut = timeInOrOut,
|
TimeVehicleInOrOut = timeInOrOut,
|
||||||
PlateImage = plateImageBase64,
|
PlateImage = plateImageBase64,
|
||||||
PlateResultImage = plateImageResultBase64,
|
PlateResultImage = plateImageResultBase64,
|
||||||
|
@ -185,8 +167,8 @@ namespace AIParkingApplication
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#region Check card validation API
|
||||||
public class CardInfo
|
public class CardModel
|
||||||
{
|
{
|
||||||
[JsonProperty("card")]
|
[JsonProperty("card")]
|
||||||
public string CardNumber { get; set; }
|
public string CardNumber { get; set; }
|
||||||
|
@ -236,7 +218,10 @@ namespace AIParkingApplication
|
||||||
[JsonProperty("name")]
|
[JsonProperty("name")]
|
||||||
public string CustomerName { get; set; }
|
public string CustomerName { get; set; }
|
||||||
}
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
#region Save Log API
|
||||||
public class SaveLogRespone
|
public class SaveLogRespone
|
||||||
{
|
{
|
||||||
[JsonProperty("status")]
|
[JsonProperty("status")]
|
||||||
|
@ -249,7 +234,7 @@ namespace AIParkingApplication
|
||||||
public string Cost { get; set; }
|
public string Cost { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class SaveLogParams
|
public class SaveLogModel
|
||||||
{
|
{
|
||||||
[JsonProperty("card")]
|
[JsonProperty("card")]
|
||||||
public string CardID { get; set; }
|
public string CardID { get; set; }
|
||||||
|
@ -284,13 +269,10 @@ namespace AIParkingApplication
|
||||||
[JsonProperty("frameImage")]
|
[JsonProperty("frameImage")]
|
||||||
public string FrameImage { get; set; }
|
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
|
public class LoginModel
|
||||||
{
|
{
|
||||||
[JsonProperty("username")]
|
[JsonProperty("username")]
|
||||||
|
@ -300,55 +282,16 @@ namespace AIParkingApplication
|
||||||
public string Password { get; set; }
|
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
|
public class LoginDataModel
|
||||||
{
|
{
|
||||||
[JsonProperty("status")]
|
[JsonProperty("status")]
|
||||||
public bool IsLoginSuccess { get; set; }
|
public bool IsLoginSuccess { get; set; }
|
||||||
|
|
||||||
[JsonProperty("data")]
|
[JsonProperty("data")]
|
||||||
public Data LoginData { get; set; }
|
public Config LoginData { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Data
|
public class Config
|
||||||
{
|
{
|
||||||
[JsonProperty("userID")]
|
[JsonProperty("userID")]
|
||||||
public int UserID { get; set; }
|
public int UserID { get; set; }
|
||||||
|
@ -363,7 +306,7 @@ namespace AIParkingApplication
|
||||||
public bool IsSaveSystemLogs { get; set; }
|
public bool IsSaveSystemLogs { get; set; }
|
||||||
|
|
||||||
[JsonProperty("api")]
|
[JsonProperty("api")]
|
||||||
public APIPath APIPath { get; set; }
|
public APIPathModel APIPath { get; set; }
|
||||||
|
|
||||||
[JsonProperty("camera1")]
|
[JsonProperty("camera1")]
|
||||||
public CameraData CameraData1 { get; set; }
|
public CameraData CameraData1 { get; set; }
|
||||||
|
@ -401,7 +344,8 @@ namespace AIParkingApplication
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class APIPath
|
#region API Path
|
||||||
|
public class APIPathModel
|
||||||
{
|
{
|
||||||
[JsonProperty("apiStatistics")]
|
[JsonProperty("apiStatistics")]
|
||||||
public APIProperties ApiStatistics { get; set; }
|
public APIProperties ApiStatistics { get; set; }
|
||||||
|
@ -431,6 +375,7 @@ namespace AIParkingApplication
|
||||||
[JsonProperty("path")]
|
[JsonProperty("path")]
|
||||||
public string Path { get; set; }
|
public string Path { get; set; }
|
||||||
}
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
public class CameraData
|
public class CameraData
|
||||||
{
|
{
|
||||||
|
@ -533,13 +478,14 @@ namespace AIParkingApplication
|
||||||
public int Logs { get; set; }
|
public int Logs { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#region LaneConfig
|
||||||
public class LaneConfig
|
public class LaneConfig
|
||||||
{
|
{
|
||||||
[JsonProperty("laneConfig")]
|
[JsonProperty("laneConfig")]
|
||||||
public LanePosision Posision { get; set; }
|
public LaneConfigPosision Posision { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class LanePosision
|
public class LaneConfigPosision
|
||||||
{
|
{
|
||||||
[JsonProperty("left")]
|
[JsonProperty("left")]
|
||||||
public LaneConfigParam LeftLane { get; set; }
|
public LaneConfigParam LeftLane { get; set; }
|
||||||
|
@ -559,5 +505,7 @@ namespace AIParkingApplication
|
||||||
[JsonProperty("longPlate")]
|
[JsonProperty("longPlate")]
|
||||||
public bool IsLongPlate { get; set; }
|
public bool IsLongPlate { get; set; }
|
||||||
}
|
}
|
||||||
|
#endregion
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ using System.Windows.Forms;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
|
using System.Xml.Serialization;
|
||||||
|
|
||||||
namespace AIParkingApplication
|
namespace AIParkingApplication
|
||||||
{
|
{
|
||||||
|
@ -12,6 +13,7 @@ namespace AIParkingApplication
|
||||||
private readonly Thread thrStatistics;
|
private readonly Thread thrStatistics;
|
||||||
private readonly TimeSpan updateInterval;
|
private readonly TimeSpan updateInterval;
|
||||||
private ParkInfo parkInfo;
|
private ParkInfo parkInfo;
|
||||||
|
private string baseAddress;
|
||||||
|
|
||||||
private Label lblLoaiXe;
|
private Label lblLoaiXe;
|
||||||
private Label lblXeMay;
|
private Label lblXeMay;
|
||||||
|
@ -23,8 +25,8 @@ namespace AIParkingApplication
|
||||||
public Statistic(string baseAddress, TimeSpan updateInterval)
|
public Statistic(string baseAddress, TimeSpan updateInterval)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
this.baseAddress = baseAddress;
|
||||||
this.updateInterval = updateInterval;
|
this.updateInterval = updateInterval;
|
||||||
client = new HttpClient { BaseAddress = new Uri(baseAddress), Timeout = TimeSpan.FromMilliseconds(5000) };
|
|
||||||
thrStatistics = new Thread(new ThreadStart(GetStatistic)) { IsBackground = true };
|
thrStatistics = new Thread(new ThreadStart(GetStatistic)) { IsBackground = true };
|
||||||
thrStatistics.Start();
|
thrStatistics.Start();
|
||||||
}
|
}
|
||||||
|
@ -39,27 +41,10 @@ namespace AIParkingApplication
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void GetDataFromServer()
|
async void GetDataFromServer()
|
||||||
{
|
{
|
||||||
try
|
ApiController apiController = new ApiController(this.baseAddress);
|
||||||
{
|
parkInfo = await apiController.GetStatisticInfo();
|
||||||
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}");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ShowInfo()
|
private void ShowInfo()
|
||||||
|
|
|
@ -23,26 +23,29 @@ namespace AIParkingApplication
|
||||||
{
|
{
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
lblDateTime.Invoke(new Action(() =>
|
if (IsHandleCreated)
|
||||||
{
|
{
|
||||||
lblDateTime.Text = DateTime.Now.ToString(AppConstant.DATETIME_FORMAT);
|
lblDateTime.Invoke(new Action(() =>
|
||||||
}));
|
{
|
||||||
|
lblDateTime.Text = DateTime.Now.ToString(AppConstant.DATETIME_FORMAT);
|
||||||
|
}));
|
||||||
|
|
||||||
lblPingTimeC3.Invoke(new Action(() =>
|
lblPingTimeC3.Invoke(new Action(() =>
|
||||||
{
|
{
|
||||||
PingResult pingResult = GetPingStatus(c3IP);
|
PingResult pingResult = GetPingStatus(c3IP);
|
||||||
lblPingTimeC3.Text = $"{pingResult.ReplyTime} ms";
|
lblPingTimeC3.Text = $"{pingResult.ReplyTime} ms";
|
||||||
lblPingTimeC3.BackColor = pingResult.BackColor;
|
lblPingTimeC3.BackColor = pingResult.BackColor;
|
||||||
lblPingTimeC3.ForeColor = pingResult.ForceColor;
|
lblPingTimeC3.ForeColor = pingResult.ForceColor;
|
||||||
}));
|
}));
|
||||||
|
|
||||||
lblPingTimeServer.Invoke(new Action(() =>
|
lblPingTimeServer.Invoke(new Action(() =>
|
||||||
{
|
{
|
||||||
PingResult pingResult = GetPingStatus(webServerIP);
|
PingResult pingResult = GetPingStatus(webServerIP);
|
||||||
lblPingTimeServer.Text = $"{pingResult.ReplyTime} ms";
|
lblPingTimeServer.Text = $"{pingResult.ReplyTime} ms";
|
||||||
lblPingTimeServer.BackColor = pingResult.BackColor;
|
lblPingTimeServer.BackColor = pingResult.BackColor;
|
||||||
lblPingTimeServer.ForeColor = pingResult.ForceColor;
|
lblPingTimeServer.ForeColor = pingResult.ForceColor;
|
||||||
}));
|
}));
|
||||||
|
}
|
||||||
Thread.Sleep(1000);
|
Thread.Sleep(1000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user