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 bool isHttpClientDisposabled;
private int numberOfRetry;
public enum LaneDirection
private ApiPath apiPath;
public enum VehicleDirection
{
In,
Out
@ -60,30 +60,25 @@ namespace AIParkingApplication
}
}
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();
}
}
//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 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)
{
try
{
var request = new CardModel()
var request = new CardInfo()
{
CardNumber = cardNumber
};
@ -123,7 +141,7 @@ namespace AIParkingApplication
}
//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 plateImageResultBase64 = Convert.ToBase64String(plateImageResult.ToBytes());
@ -131,14 +149,14 @@ namespace AIParkingApplication
string FrameImageBase64 = Convert.ToBase64String(FrameImage.ToBytes());
try
{
var request = new SaveLogModel
var request = new SaveLogParams
{
Direction = (direction == LaneDirection.In) ? "in" : "out",
Direction = (direction == (int)VehicleDirection.In) ? "in" : "out",
LogID = logID,
CardID = cardID,
TextPlate = textPlate,
CameraID = cameraID,
ModePlate = (squareOrLong == ModePlate.Sqare) ? "1":"0",
ModePlate = (squareOrLong == (int)ModePlate.Sqare) ? "1":"0",
TimeVehicleInOrOut = timeInOrOut,
PlateImage = plateImageBase64,
PlateResultImage = plateImageResultBase64,
@ -167,8 +185,8 @@ namespace AIParkingApplication
}
}
}
#region Check card validation API
public class CardModel
public class CardInfo
{
[JsonProperty("card")]
public string CardNumber { get; set; }
@ -218,10 +236,7 @@ namespace AIParkingApplication
[JsonProperty("name")]
public string CustomerName { get; set; }
}
#endregion
#region Save Log API
public class SaveLogRespone
{
[JsonProperty("status")]
@ -234,7 +249,7 @@ namespace AIParkingApplication
public string Cost { get; set; }
}
public class SaveLogModel
public class SaveLogParams
{
[JsonProperty("card")]
public string CardID { get; set; }
@ -269,10 +284,13 @@ 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")]
@ -282,16 +300,55 @@ 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 Config LoginData { get; set; }
public Data LoginData { get; set; }
}
public class Config
public class Data
{
[JsonProperty("userID")]
public int UserID { get; set; }
@ -306,7 +363,7 @@ namespace AIParkingApplication
public bool IsSaveSystemLogs { get; set; }
[JsonProperty("api")]
public APIPathModel APIPath { get; set; }
public APIPath APIPath { get; set; }
[JsonProperty("camera1")]
public CameraData CameraData1 { get; set; }
@ -344,8 +401,7 @@ namespace AIParkingApplication
}
#region API Path
public class APIPathModel
public class APIPath
{
[JsonProperty("apiStatistics")]
public APIProperties ApiStatistics { get; set; }
@ -375,7 +431,6 @@ namespace AIParkingApplication
[JsonProperty("path")]
public string Path { get; set; }
}
#endregion
public class CameraData
{
@ -478,14 +533,13 @@ namespace AIParkingApplication
public int Logs { get; set; }
}
#region LaneConfig
public class LaneConfig
{
[JsonProperty("laneConfig")]
public LaneConfigPosision Posision { get; set; }
public LanePosision Posision { get; set; }
}
public class LaneConfigPosision
public class LanePosision
{
[JsonProperty("left")]
public LaneConfigParam LeftLane { get; set; }
@ -505,7 +559,5 @@ namespace AIParkingApplication
[JsonProperty("longPlate")]
public bool IsLongPlate { get; set; }
}
#endregion
#endregion
}

View File

@ -3,7 +3,6 @@ using System.Windows.Forms;
using System.Threading;
using Newtonsoft.Json;
using System.Net.Http;
using System.Xml.Serialization;
namespace AIParkingApplication
{
@ -13,7 +12,6 @@ namespace AIParkingApplication
private readonly Thread thrStatistics;
private readonly TimeSpan updateInterval;
private ParkInfo parkInfo;
private string baseAddress;
private Label lblLoaiXe;
private Label lblXeMay;
@ -25,8 +23,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();
}
@ -41,10 +39,27 @@ namespace AIParkingApplication
}
}
async void GetDataFromServer()
private async void GetDataFromServer()
{
ApiController apiController = new ApiController(this.baseAddress);
parkInfo = await apiController.GetStatisticInfo();
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}");
}
}
private void ShowInfo()

View File

@ -22,8 +22,6 @@ namespace AIParkingApplication
private void UpdateStatus()
{
while (true)
{
if (IsHandleCreated)
{
lblDateTime.Invoke(new Action(() =>
{
@ -45,7 +43,6 @@ namespace AIParkingApplication
lblPingTimeServer.BackColor = pingResult.BackColor;
lblPingTimeServer.ForeColor = pingResult.ForceColor;
}));
}
Thread.Sleep(1000);
}
}