Update logging message.

This commit is contained in:
DucDangAnh 2020-07-16 15:30:46 +07:00
parent a835ed626b
commit c9b65ba883
6 changed files with 43 additions and 19 deletions

View File

@ -63,6 +63,18 @@ namespace AIParkingApplication
MessageBox.Show("Cấu hình API Plate Recognize lỗi!", "Cấu hình API Engine lỗi!", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show("Cấu hình API Plate Recognize lỗi!", "Cấu hình API Engine lỗi!", MessageBoxButtons.OK, MessageBoxIcon.Error);
return; return;
} }
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
Application.ThreadException += Application_ThreadException;
}
private void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
{
appLogger.Log(LogLevel.Error, $"Application.ThreadException. ex:{e.Exception.Message}");
}
private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
appLogger.Log(LogLevel.Error, $"AppDomain.CurrentDomain.UnhandledException. ex:{(e.ExceptionObject as Exception).Message}");
} }
private void InitAllLanes() private void InitAllLanes()

View File

@ -5,6 +5,7 @@
<add key="DEFAULT_USERNAME" value="cong1vao" /> <add key="DEFAULT_USERNAME" value="cong1vao" />
<add key="DEFAULT_PASSWORD" value="123456a@" /> <add key="DEFAULT_PASSWORD" value="123456a@" />
<add key="CURRENT_LANE_SETTING" value="OUT-OUT" /> <add key="CURRENT_LANE_SETTING" value="OUT-OUT" />
<add key="AUTO_LOGIN" value="true" />
</appSettings> </appSettings>
<startup> <startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" /> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />

View File

@ -1,4 +1,5 @@
using System; using System;
using System.Diagnostics;
using System.Drawing; using System.Drawing;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -69,14 +70,14 @@ namespace AIParkingApplication
if (!cardInfoResult.IsValid) if (!cardInfoResult.IsValid)
{ {
lblStatusInfo.UpdateLabel("THẺ KHÔNG HỢP LỆ", Color.Purple); lblStatusInfo.UpdateLabel("THẺ KHÔNG HỢP LỆ", Color.Purple);
appLogger.Log(LogLevel.Error, $"Request thẻ cổng {doorId} vào | số thẻ : {cardNumber} | lỗi: THẺ KHÔNG HỢP LỆ"); appLogger.Log(LogLevel.Info, $"Request thẻ cổng {doorId} vào | số thẻ : {cardNumber} | lỗi: THẺ KHÔNG HỢP LỆ");
return; return;
} }
if (cardInfoResult.Direction != "in") if (cardInfoResult.Direction != "in")
{ {
lblStatusInfo.UpdateLabel("XE ĐÃ Ở TRONG BÃI", Color.Red); lblStatusInfo.UpdateLabel("XE ĐÃ Ở TRONG BÃI", Color.Red);
appLogger.Log(LogLevel.Error, $"Request thẻ cổng {doorId} vào | số thẻ : {cardNumber} | lỗi: XE ĐÃ Ở TRONG BÃI"); appLogger.Log(LogLevel.Info, $"Request thẻ cổng {doorId} vào | số thẻ : {cardNumber} | lỗi: XE ĐÃ Ở TRONG BÃI");
return; return;
} }
@ -148,21 +149,24 @@ namespace AIParkingApplication
{ {
try try
{ {
var starTime = DateTime.Now;
Cv2.Resize(frame, frame, new OpenCvSharp.Size(1280, 720)); Cv2.Resize(frame, frame, new OpenCvSharp.Size(1280, 720));
FinalPlateResult finalPlateResult = await plateProcessor.ProcessPlate(frame); FinalPlateResult finalPlateResult = await plateProcessor.ProcessPlate(frame);
if (isRetryMode && !plateProcessor.IsPlateStringValid(finalPlateResult.PlateString)) if (isRetryMode && !plateProcessor.IsPlateStringValid(finalPlateResult.PlateString))
{ {
Console.WriteLine("ProcessFrameImage Retry Mode");
Thread.Sleep(1000); Thread.Sleep(1000);
overviewCamera.RequestCaptureOneFrame(); overviewCamera.RequestCaptureOneFrame();
finalPlateResult = await plateProcessor.ProcessPlate(frame); finalPlateResult = await plateProcessor.ProcessPlate(frame);
Console.WriteLine("ProcessFrameImage Retry Mode");
} }
appLogger.Log(LogLevel.Info, $"ProcessFrameImage: {(DateTime.Now - starTime).TotalMilliseconds} ms");
return finalPlateResult; return finalPlateResult;
} }
catch (Exception ex) catch (Exception ex)
{ {
Console.WriteLine($"ProcessFrameImage\texMessage: {ex.Message}"); Console.WriteLine($"ProcessFrameImage\texMessage: {ex.Message}");
appLogger.Log(LogLevel.Info, $"ProcessFrameImage: ex: {ex.Message}");
return new FinalPlateResult return new FinalPlateResult
{ {
PlateImage = frame, PlateImage = frame,

View File

@ -72,14 +72,14 @@ namespace AIParkingApplication
if (!cardInfoResult.IsValid) if (!cardInfoResult.IsValid)
{ {
lblStatusInfo.UpdateLabel("THẺ KHÔNG HỢP LỆ", Color.Purple); lblStatusInfo.UpdateLabel("THẺ KHÔNG HỢP LỆ", Color.Purple);
appLogger.Log(LogLevel.Error, $"Request thẻ cổng {doorId} vào | số thẻ : {cardNumber} | lỗi: THẺ KHÔNG HỢP LỆ"); appLogger.Log(LogLevel.Info, $"Request thẻ cổng {doorId} vào | số thẻ : {cardNumber} | lỗi: THẺ KHÔNG HỢP LỆ");
return; return;
} }
if (cardInfoResult.Direction != "out") if (cardInfoResult.Direction != "out")
{ {
lblStatusInfo.UpdateLabel("CHƯA NHẬN THẺ VÀO", Color.Red); lblStatusInfo.UpdateLabel("CHƯA NHẬN THẺ VÀO", Color.Red);
appLogger.Log(LogLevel.Error, $"Request thẻ cổng {doorId} vào | số thẻ : {cardNumber} | lỗi: XE ĐÃ Ở TRONG BÃI"); appLogger.Log(LogLevel.Info, $"Request thẻ cổng {doorId} vào | số thẻ : {cardNumber} | lỗi: XE ĐÃ Ở TRONG BÃI");
return; return;
} }
@ -121,14 +121,17 @@ namespace AIParkingApplication
OpenDoor(doorId); OpenDoor(doorId);
appLogger.Log(LogLevel.Info, $"Request thẻ cổng {doorId} vào | số thẻ : {cardNumber} | biển số: {result.PlateString} | Đã mở cửa"); appLogger.Log(LogLevel.Info, $"Request thẻ cổng {doorId} vào | số thẻ : {cardNumber} | biển số: {result.PlateString} | Đã mở cửa");
} }
PrinterData printerData = new PrinterData if (false)
{ {
PlateString = result.PlateString, PrinterData printerData = new PrinterData
MoneyAmount = saveLogResult.Cost, {
TimeParkingIn = cardInformation.TimeIn, PlateString = result.PlateString,
TimeParkingOut = DateTime.Now.GetTimeFormatted() MoneyAmount = saveLogResult.Cost,
}; TimeParkingIn = cardInformation.TimeIn,
printer.DoPrint(printerData); TimeParkingOut = DateTime.Now.GetTimeFormatted()
};
printer.DoPrint(printerData);
}
} }
else else
{ {
@ -161,9 +164,11 @@ namespace AIParkingApplication
private void OpenDoor(int doorId) private void OpenDoor(int doorId)
{ {
if (doorControlAccess.OpenDoor(doorId).HasError) var openDoorResult = doorControlAccess.OpenDoor(doorId);
if (openDoorResult.HasError)
{ {
lblStatusInfo.UpdateLabel("KHÔNG THỂ MỞ CỬA", Color.Red); lblStatusInfo.UpdateLabel("KHÔNG THỂ MỞ CỬA", Color.Red);
appLogger.Log(LogLevel.Error, $"Không thể mở cửa {doorId}. Lỗi: {openDoorResult.Message}");
} }
} }
@ -171,6 +176,7 @@ namespace AIParkingApplication
{ {
try try
{ {
var starTime = DateTime.Now;
Cv2.Resize(frame, frame, new OpenCvSharp.Size(1280, 720)); Cv2.Resize(frame, frame, new OpenCvSharp.Size(1280, 720));
FinalPlateResult finalPlateResult = await plateProcessor.ProcessPlate(frame); FinalPlateResult finalPlateResult = await plateProcessor.ProcessPlate(frame);
@ -181,6 +187,7 @@ namespace AIParkingApplication
overviewCamera.RequestCaptureOneFrame(); overviewCamera.RequestCaptureOneFrame();
finalPlateResult = await plateProcessor.ProcessPlate(frame); finalPlateResult = await plateProcessor.ProcessPlate(frame);
} }
appLogger.Log(LogLevel.Info, $"ProcessFrameImage: {(DateTime.Now - starTime).TotalMilliseconds} ms");
return finalPlateResult; return finalPlateResult;
} }
catch (Exception ex) catch (Exception ex)

View File

@ -34,7 +34,7 @@ namespace AIParkingApplication
{ {
lblLoginStatus.Text = "Địa chỉ server không được để trống! \r\n ví dụ: 192.168.1.2:80"; lblLoginStatus.Text = "Địa chỉ server không được để trống! \r\n ví dụ: 192.168.1.2:80";
btnLogin.Enabled = true; btnLogin.Enabled = true;
applicationLogger.Log(LogLevel.Error, "Địa chỉ server không được để trống"); applicationLogger.Log(LogLevel.Info, "Địa chỉ server không được để trống");
return; return;
} }
@ -44,7 +44,7 @@ namespace AIParkingApplication
{ {
lblLoginStatus.Text = "Địa chỉ server không đúng định dạng: \r\n ví dụ: 192.168.1.122:80"; lblLoginStatus.Text = "Địa chỉ server không đúng định dạng: \r\n ví dụ: 192.168.1.122:80";
btnLogin.Enabled = true; btnLogin.Enabled = true;
applicationLogger.Log(LogLevel.Error, "Địa chỉ server không đúng định dạng"); applicationLogger.Log(LogLevel.Info, "Địa chỉ server không đúng định dạng");
return; return;
} }
@ -54,9 +54,9 @@ namespace AIParkingApplication
} }
catch (Exception ex) catch (Exception ex)
{ {
applicationLogger.Log(LogLevel.Error, $"Cấu máy chủ lỗi - Kiểm tra lại tên máy chủ, kết nối máy chủ! Không thể khởi tạo API Webserver. ex: {ex.Message}");
MessageBox.Show($"Cấu máy chủ lỗi - Kiểm tra lại tên máy chủ, kết nối máy chủ! \r\n {ex.Message}", "Lỗi khởi tạo API!", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show($"Cấu máy chủ lỗi - Kiểm tra lại tên máy chủ, kết nối máy chủ! \r\n {ex.Message}", "Lỗi khởi tạo API!", MessageBoxButtons.OK, MessageBoxIcon.Error);
btnLogin.Enabled = true; btnLogin.Enabled = true;
applicationLogger.Log(LogLevel.Error, "Cấu máy chủ lỗi - Kiểm tra lại tên máy chủ, kết nối máy chủ! Không thể khởi tạo API Webserver");
return; return;
} }
@ -67,7 +67,7 @@ namespace AIParkingApplication
{ {
lblLoginStatus.Text = "Tên tài khoản hoặc mật khẩu không được để trống"; lblLoginStatus.Text = "Tên tài khoản hoặc mật khẩu không được để trống";
btnLogin.Enabled = true; btnLogin.Enabled = true;
applicationLogger.Log(LogLevel.Error, "Tên tài khoản hoặc mật khẩu không được để trống"); applicationLogger.Log(LogLevel.Info, "Tên tài khoản hoặc mật khẩu không được để trống");
return; return;
} }
@ -79,7 +79,7 @@ namespace AIParkingApplication
if (execeptioMessage.Contains("Error converting value")) if (execeptioMessage.Contains("Error converting value"))
{ {
lblLoginStatus.UpdateLabel("Sai tên tài khoản hoặc mật khẩu!", Color.Red); lblLoginStatus.UpdateLabel("Sai tên tài khoản hoặc mật khẩu!", Color.Red);
applicationLogger.Log(LogLevel.Error, "Sai tên tài khoản hoặc mật khẩu"); applicationLogger.Log(LogLevel.Info, "Sai tên tài khoản hoặc mật khẩu");
return; return;
} }

View File

@ -47,7 +47,7 @@ namespace AIParkingApplication
catch (Exception ex) catch (Exception ex)
{ {
Console.WriteLine($"ProcessingString\texMessage:{ex.Message}"); Console.WriteLine($"ProcessingString\texMessage:{ex.Message}");
appLogger.Log(LogLevel.Info, $"Lỗi khi In hóa đơn: {ex.Message}"); appLogger.Log(LogLevel.Error, $"Lỗi khi In hóa đơn: {ex.Message}");
return string.Empty; return string.Empty;
} }
} }