Compare commits

..

No commits in common. "7512bafc4301b293846b78e011d010efe9c157e6" and "b8e88aaafe18752332b2777a1c68122bb98fe5a5" have entirely different histories.

3 changed files with 140 additions and 76 deletions

View File

@ -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 LaneDirection public enum VehicleDirection
{ {
In, In,
Out Out
@ -60,30 +60,25 @@ namespace AIParkingApplication
} }
} }
public async Task<Statistic.ParkInfo> GetStatisticInfo() //TODO For New API
{ //public async Task<LoginResponseModel> Login(LoginModel loginData)
try //{
{ // try
HttpResponseMessage response = await httpClient.GetAsync("/api/statistics"); // {
response.EnsureSuccessStatusCode(); // HttpResponseMessage response = await httpClient.PostAsJsonAsync("/api/login", loginData);
Statistic.ParkInfo parkInfo = await response.Content.ReadAsAsync<Statistic.ParkInfo>(); // response.EnsureSuccessStatusCode();
// var loginResult = await response.Content.ReadAsAsync<LoginResponseModel>();
if (string.IsNullOrEmpty(parkInfo.TotalIn)) // return loginResult;
{ // }
parkInfo.TotalIn = "0"; // catch (Exception ex)
} // {
if (string.IsNullOrEmpty(parkInfo.TotalOut)) // Console.WriteLine($"SendEngineRequest : {ex.Message}");
{ // 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()
{ {
@ -102,11 +97,34 @@ 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 CardModel() var request = new CardInfo()
{ {
CardNumber = cardNumber CardNumber = cardNumber
}; };
@ -123,7 +141,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(LaneDirection direction, string cardID, string cameraID, ModePlate squareOrLong, string timeInOrOut, string textPlate, Mat plateImage, Mat plateImageResult, Mat PlateFrameImage, Mat FrameImage, string logID = "") 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 = "")
{ {
string plateImageBase64 = Convert.ToBase64String(plateImage.ToBytes()); string plateImageBase64 = Convert.ToBase64String(plateImage.ToBytes());
string plateImageResultBase64 = Convert.ToBase64String(plateImageResult.ToBytes()); string plateImageResultBase64 = Convert.ToBase64String(plateImageResult.ToBytes());
@ -131,14 +149,14 @@ namespace AIParkingApplication
string FrameImageBase64 = Convert.ToBase64String(FrameImage.ToBytes()); string FrameImageBase64 = Convert.ToBase64String(FrameImage.ToBytes());
try try
{ {
var request = new SaveLogModel var request = new SaveLogParams
{ {
Direction = (direction == LaneDirection.In) ? "in" : "out", Direction = (direction == (int)VehicleDirection.In) ? "in" : "out",
LogID = logID, LogID = logID,
CardID = cardID, CardID = cardID,
TextPlate = textPlate, TextPlate = textPlate,
CameraID = cameraID, CameraID = cameraID,
ModePlate = (squareOrLong == ModePlate.Sqare) ? "1":"0", ModePlate = (squareOrLong == (int)ModePlate.Sqare) ? "1":"0",
TimeVehicleInOrOut = timeInOrOut, TimeVehicleInOrOut = timeInOrOut,
PlateImage = plateImageBase64, PlateImage = plateImageBase64,
PlateResultImage = plateImageResultBase64, PlateResultImage = plateImageResultBase64,
@ -167,8 +185,8 @@ namespace AIParkingApplication
} }
} }
} }
#region Check card validation API
public class CardModel public class CardInfo
{ {
[JsonProperty("card")] [JsonProperty("card")]
public string CardNumber { get; set; } public string CardNumber { get; set; }
@ -218,10 +236,7 @@ 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")]
@ -234,7 +249,7 @@ namespace AIParkingApplication
public string Cost { get; set; } public string Cost { get; set; }
} }
public class SaveLogModel public class SaveLogParams
{ {
[JsonProperty("card")] [JsonProperty("card")]
public string CardID { get; set; } public string CardID { get; set; }
@ -269,10 +284,13 @@ 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")]
@ -282,16 +300,55 @@ 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 Config LoginData { get; set; } public Data LoginData { get; set; }
} }
public class Config public class Data
{ {
[JsonProperty("userID")] [JsonProperty("userID")]
public int UserID { get; set; } public int UserID { get; set; }
@ -306,7 +363,7 @@ namespace AIParkingApplication
public bool IsSaveSystemLogs { get; set; } public bool IsSaveSystemLogs { get; set; }
[JsonProperty("api")] [JsonProperty("api")]
public APIPathModel APIPath { get; set; } public APIPath APIPath { get; set; }
[JsonProperty("camera1")] [JsonProperty("camera1")]
public CameraData CameraData1 { get; set; } public CameraData CameraData1 { get; set; }
@ -344,8 +401,7 @@ namespace AIParkingApplication
} }
#region API Path public class APIPath
public class APIPathModel
{ {
[JsonProperty("apiStatistics")] [JsonProperty("apiStatistics")]
public APIProperties ApiStatistics { get; set; } public APIProperties ApiStatistics { get; set; }
@ -375,7 +431,6 @@ namespace AIParkingApplication
[JsonProperty("path")] [JsonProperty("path")]
public string Path { get; set; } public string Path { get; set; }
} }
#endregion
public class CameraData public class CameraData
{ {
@ -478,14 +533,13 @@ 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 LaneConfigPosision Posision { get; set; } public LanePosision Posision { get; set; }
} }
public class LaneConfigPosision public class LanePosision
{ {
[JsonProperty("left")] [JsonProperty("left")]
public LaneConfigParam LeftLane { get; set; } public LaneConfigParam LeftLane { get; set; }
@ -505,7 +559,5 @@ namespace AIParkingApplication
[JsonProperty("longPlate")] [JsonProperty("longPlate")]
public bool IsLongPlate { get; set; } public bool IsLongPlate { get; set; }
} }
#endregion
#endregion
} }

View File

@ -3,7 +3,6 @@ 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
{ {
@ -13,7 +12,6 @@ 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;
@ -25,8 +23,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();
} }
@ -41,10 +39,27 @@ namespace AIParkingApplication
} }
} }
async void GetDataFromServer() private async void GetDataFromServer()
{ {
ApiController apiController = new ApiController(this.baseAddress); try
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()

View File

@ -23,29 +23,26 @@ namespace AIParkingApplication
{ {
while (true) while (true)
{ {
if (IsHandleCreated) lblDateTime.Invoke(new Action(() =>
{ {
lblDateTime.Invoke(new Action(() => lblDateTime.Text = DateTime.Now.ToString(AppConstant.DATETIME_FORMAT);
{ }));
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);
} }
} }