Add appLogger.

This commit is contained in:
DucDangAnh 2020-07-15 14:34:13 +07:00
parent b4baa218b4
commit 153eba219f
5 changed files with 42 additions and 27 deletions

View File

@ -22,25 +22,24 @@ namespace AIParkingApplication
private Config configOnWeb; private Config configOnWeb;
private EngineApiController engineApiController; private EngineApiController engineApiController;
private string doorAccessControlDeviceIP; private string doorAccessControlDeviceIP;
private Logger appLogger;
private Logger applicationLogger; public AIParkingApplicationForm(ApiController apiController, string serverIPAddress, Config configOnWeb, Logger appLogger)
public AIParkingApplicationForm(ApiController apiController, string serverIPAddress, Config configOnWeb, Logger applicationLogger)
{ {
InitializeComponent(); InitializeComponent();
this.apiController = apiController; this.apiController = apiController;
this.configOnWeb = configOnWeb; this.configOnWeb = configOnWeb;
this.applicationLogger = applicationLogger; this.appLogger = appLogger;
ReadAccessControlDeviceIPConfigurationFile(); ReadAccessControlDeviceIPConfigurationFile();
if (string.IsNullOrEmpty(doorAccessControlDeviceIP) || !Util.IsValidIPAddress(doorAccessControlDeviceIP)) if (string.IsNullOrEmpty(doorAccessControlDeviceIP) || !Util.IsValidIPAddress(doorAccessControlDeviceIP))
{ {
applicationLogger.Log(LogLevel.Error, "Kiểm tra lại cấu hình IP thiết bị mở cửa!"); appLogger.Log(LogLevel.Error, "Kiểm tra lại cấu hình IP thiết bị mở cửa!");
MessageBox.Show("Kiểm tra lại cấu hình IP thiết bị mở cửa! (C3200)", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show("Kiểm tra lại cấu hình IP thiết bị mở cửa! (C3200)", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
Application.Exit(); Application.Exit();
} }
c3Device = new C3DeviceController(doorAccessControlDeviceIP); c3Device = new C3DeviceController(appLogger, doorAccessControlDeviceIP);
sidebar = new Sidebar(apiController) sidebar = new Sidebar(apiController)
{ {
Location = new Point(0, 0) Location = new Point(0, 0)
@ -60,7 +59,7 @@ namespace AIParkingApplication
} }
catch (Exception ex) catch (Exception ex)
{ {
applicationLogger.Log(LogLevel.Error, $"Cấu hình URL của Engine nhận diện biển số lỗi. exMessage: {ex.Message}"); appLogger.Log(LogLevel.Error, $"Cấu hình URL của Engine nhận diện biển số lỗi. exMessage: {ex.Message}");
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;
} }
@ -68,22 +67,22 @@ namespace AIParkingApplication
private void InitAllLanes() private void InitAllLanes()
{ {
laneIn12 = new LaneIn(10, configOnWeb.CameraData1.Id.ToString(), configOnWeb.CameraData1.StreamUrl, configOnWeb.CameraData2.StreamUrl, c3Device, apiController, engineApiController, true, false, true); laneIn12 = new LaneIn(10, configOnWeb.CameraData1.Id.ToString(), configOnWeb.CameraData1.StreamUrl, configOnWeb.CameraData2.StreamUrl, c3Device, apiController, engineApiController, appLogger, true, false, true);
laneIn12.BorderStyle = BorderStyle.FixedSingle; laneIn12.BorderStyle = BorderStyle.FixedSingle;
laneIn12.Hide(); laneIn12.Hide();
Controls.Add(laneIn12); Controls.Add(laneIn12);
laneOut34 = new LaneOut(20, configOnWeb.CameraData3.Id.ToString(), configOnWeb.CameraData3.StreamUrl, configOnWeb.CameraData4.StreamUrl, c3Device, apiController, engineApiController, true, false, true); laneOut34 = new LaneOut(20, configOnWeb.CameraData3.Id.ToString(), configOnWeb.CameraData3.StreamUrl, configOnWeb.CameraData4.StreamUrl, c3Device, apiController, engineApiController, appLogger, true, false, true);
laneOut34.BorderStyle = BorderStyle.FixedSingle; laneOut34.BorderStyle = BorderStyle.FixedSingle;
laneOut34.Hide(); laneOut34.Hide();
Controls.Add(laneOut34); Controls.Add(laneOut34);
laneIn56 = new LaneIn(10, configOnWeb.CameraData5.Id.ToString(), configOnWeb.CameraData5.StreamUrl, configOnWeb.CameraData6.StreamUrl, c3Device, apiController, engineApiController, true, false, true); laneIn56 = new LaneIn(10, configOnWeb.CameraData5.Id.ToString(), configOnWeb.CameraData5.StreamUrl, configOnWeb.CameraData6.StreamUrl, c3Device, apiController, engineApiController, appLogger, true, false, true);
laneIn56.BorderStyle = BorderStyle.FixedSingle; laneIn56.BorderStyle = BorderStyle.FixedSingle;
laneIn56.Hide(); laneIn56.Hide();
Controls.Add(laneIn56); Controls.Add(laneIn56);
laneOut78 = new LaneOut(20, configOnWeb.CameraData7.Id.ToString(), configOnWeb.CameraData7.StreamUrl, configOnWeb.CameraData8.StreamUrl, c3Device, apiController, engineApiController, true, false, true); laneOut78 = new LaneOut(20, configOnWeb.CameraData7.Id.ToString(), configOnWeb.CameraData7.StreamUrl, configOnWeb.CameraData8.StreamUrl, c3Device, apiController, engineApiController, appLogger, true, false, true);
laneOut78.BorderStyle = BorderStyle.FixedSingle; laneOut78.BorderStyle = BorderStyle.FixedSingle;
laneOut78.Hide(); laneOut78.Hide();
Controls.Add(laneOut78); Controls.Add(laneOut78);
@ -147,7 +146,7 @@ namespace AIParkingApplication
UpdateMenuStripItemStatus(sender as ToolStripMenuItem); UpdateMenuStripItemStatus(sender as ToolStripMenuItem);
StopAllLanes(); StopAllLanes();
UpdateLaneInIn(); UpdateLaneInIn();
applicationLogger.Log(LogLevel.Info, "Chuyển làn: IN-IN"); appLogger.Log(LogLevel.Info, "Chuyển làn: IN-IN");
} }
private void toolStripMenuItemSwitchLaneInOut_Click(object sender, EventArgs e) private void toolStripMenuItemSwitchLaneInOut_Click(object sender, EventArgs e)
@ -156,7 +155,7 @@ namespace AIParkingApplication
UpdateMenuStripItemStatus(sender as ToolStripMenuItem); UpdateMenuStripItemStatus(sender as ToolStripMenuItem);
StopAllLanes(); StopAllLanes();
UpdateLaneInOut(); UpdateLaneInOut();
applicationLogger.Log(LogLevel.Info, "Chuyển làn: IN-OUT"); appLogger.Log(LogLevel.Info, "Chuyển làn: IN-OUT");
} }
private void toolStripMenuItemSwitchLaneOutIn_Click(object sender, EventArgs e) private void toolStripMenuItemSwitchLaneOutIn_Click(object sender, EventArgs e)
@ -165,7 +164,7 @@ namespace AIParkingApplication
UpdateMenuStripItemStatus(sender as ToolStripMenuItem); UpdateMenuStripItemStatus(sender as ToolStripMenuItem);
StopAllLanes(); StopAllLanes();
UpdateLaneOutIn(); UpdateLaneOutIn();
applicationLogger.Log(LogLevel.Info, "Chuyển làn: OUT-IN"); appLogger.Log(LogLevel.Info, "Chuyển làn: OUT-IN");
} }
private void toolStripMenuItemSwitchLaneOutOut_Click(object sender, EventArgs e) private void toolStripMenuItemSwitchLaneOutOut_Click(object sender, EventArgs e)
@ -174,7 +173,7 @@ namespace AIParkingApplication
UpdateMenuStripItemStatus(sender as ToolStripMenuItem); UpdateMenuStripItemStatus(sender as ToolStripMenuItem);
StopAllLanes(); StopAllLanes();
UpdateLaneOutOut(); UpdateLaneOutOut();
applicationLogger.Log(LogLevel.Info, "Chuyển làn: OUT-OUT"); appLogger.Log(LogLevel.Info, "Chuyển làn: OUT-OUT");
} }
private void UpdateMenuStripItemStatus(ToolStripMenuItem selectedToolStripMenuItem) private void UpdateMenuStripItemStatus(ToolStripMenuItem selectedToolStripMenuItem)
@ -228,25 +227,25 @@ namespace AIParkingApplication
{ {
UpdateLaneInIn(); UpdateLaneInIn();
toolStripMenuItemSwitchLaneInIn.DisableSelected(); toolStripMenuItemSwitchLaneInIn.DisableSelected();
applicationLogger.Log(LogLevel.Info, $"Khởi động App sử dụng lane: IN-IN"); appLogger.Log(LogLevel.Info, $"Khởi động App sử dụng lane: IN-IN");
} }
if (lane0 == "in" && lane1 == "out") if (lane0 == "in" && lane1 == "out")
{ {
UpdateLaneInOut(); UpdateLaneInOut();
toolStripMenuItemSwitchLaneInOut.DisableSelected(); toolStripMenuItemSwitchLaneInOut.DisableSelected();
applicationLogger.Log(LogLevel.Info, $"Khởi động App sử dụng lane: IN-OUT"); appLogger.Log(LogLevel.Info, $"Khởi động App sử dụng lane: IN-OUT");
} }
if (lane0 == "out" && lane1 == "in") if (lane0 == "out" && lane1 == "in")
{ {
UpdateLaneOutIn(); UpdateLaneOutIn();
toolStripMenuItemSwitchLaneOutIn.DisableSelected(); toolStripMenuItemSwitchLaneOutIn.DisableSelected();
applicationLogger.Log(LogLevel.Info, $"Khởi động App sử dụng lane: OUT-IN"); appLogger.Log(LogLevel.Info, $"Khởi động App sử dụng lane: OUT-IN");
} }
if (lane0 == "out" && lane1 == "out") if (lane0 == "out" && lane1 == "out")
{ {
UpdateLaneOutOut(); UpdateLaneOutOut();
toolStripMenuItemSwitchLaneOutOut.DisableSelected(); toolStripMenuItemSwitchLaneOutOut.DisableSelected();
applicationLogger.Log(LogLevel.Info, $"Khởi động App sử dụng lane: OUT-OUT"); appLogger.Log(LogLevel.Info, $"Khởi động App sử dụng lane: OUT-OUT");
} }
} }
else else
@ -254,7 +253,7 @@ namespace AIParkingApplication
Util.AddOrUpdateAppSettings(CURRENT_LANE_SETTING_KEY, "IN-OUT"); Util.AddOrUpdateAppSettings(CURRENT_LANE_SETTING_KEY, "IN-OUT");
UpdateLaneInOut(); UpdateLaneInOut();
toolStripMenuItemSwitchLaneInOut.DisableSelected(); toolStripMenuItemSwitchLaneInOut.DisableSelected();
applicationLogger.Log(LogLevel.Info, $"Khởi động App đọc config không đủ 2 param: IN-OUT"); appLogger.Log(LogLevel.Info, $"Khởi động App đọc config không đủ 2 param: IN-OUT");
} }
} }
} }
@ -264,7 +263,7 @@ namespace AIParkingApplication
UpdateLaneInOut(); UpdateLaneInOut();
toolStripMenuItemSwitchLaneInOut.DisableSelected(); toolStripMenuItemSwitchLaneInOut.DisableSelected();
Console.WriteLine($"{DateTime.Now.GetTimeFormatted()}\tReadLaneSettingFromConfigurationFile\t{ex.Message}"); Console.WriteLine($"{DateTime.Now.GetTimeFormatted()}\tReadLaneSettingFromConfigurationFile\t{ex.Message}");
applicationLogger.Log(LogLevel.Error, $"Đọc config làn lỗi khi khởi động app!\texMessage: {ex.Message}"); appLogger.Log(LogLevel.Error, $"Đọc config làn lỗi khi khởi động app!\texMessage: {ex.Message}");
} }
} }
@ -278,7 +277,7 @@ namespace AIParkingApplication
{ {
doorAccessControlDeviceIP = string.Empty; doorAccessControlDeviceIP = string.Empty;
Console.WriteLine($"{DateTime.Now.GetTimeFormatted()}\tReadAccessControlDeviceIPConfiguration\t{ex.Message}"); Console.WriteLine($"{DateTime.Now.GetTimeFormatted()}\tReadAccessControlDeviceIPConfiguration\t{ex.Message}");
applicationLogger.Log(LogLevel.Error, $"Cấu hình IP thiết bị mở cửa lỗi(DOOR_ACCESS_DEVICE_CONTROL_IP)!\texMessage: {ex.Message}"); appLogger.Log(LogLevel.Error, $"Cấu hình IP thiết bị mở cửa lỗi(DOOR_ACCESS_DEVICE_CONTROL_IP)!\texMessage: {ex.Message}");
} }
} }
@ -290,7 +289,7 @@ namespace AIParkingApplication
private void AIParkingApplicationForm_FormClosing(object sender, FormClosingEventArgs e) private void AIParkingApplicationForm_FormClosing(object sender, FormClosingEventArgs e)
{ {
applicationLogger.Log(LogLevel.Info, $"Đóng ứng dụng"); appLogger.Log(LogLevel.Info, $"Đóng ứng dụng");
Application.Exit(); Application.Exit();
} }
} }

View File

@ -1,4 +1,5 @@
using System; using NLog;
using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -15,10 +16,11 @@ namespace AIParkingApplication
private string connectionString; private string connectionString;
private bool isReconnected; private bool isReconnected;
private int reconnectCounter; private int reconnectCounter;
private Logger appLogger;
public event C3DeviceEvent OnNewCardReceived; public event C3DeviceEvent OnNewCardReceived;
public C3DeviceController(string ipAddress, int port = C3Constant.DEFAULT_C3_PORT) public C3DeviceController(Logger appLogger, string ipAddress, int port = C3Constant.DEFAULT_C3_PORT)
{ {
this.ipAddress = ipAddress; this.ipAddress = ipAddress;
this.port = port; this.port = port;
@ -26,6 +28,7 @@ namespace AIParkingApplication
oneTimeConnectedParamHandler = IntPtr.Zero; oneTimeConnectedParamHandler = IntPtr.Zero;
isReconnected = true; isReconnected = true;
reconnectCounter = 0; reconnectCounter = 0;
this.appLogger = appLogger;
} }
~C3DeviceController() ~C3DeviceController()

View File

@ -3,6 +3,7 @@ using System.Drawing;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using NLog;
using OpenCvSharp; using OpenCvSharp;
using OpenCvSharp.Extensions; using OpenCvSharp.Extensions;
@ -21,6 +22,7 @@ namespace AIParkingApplication
private bool isRetryMode; private bool isRetryMode;
private IDoorControlAccess doorControlAccess; private IDoorControlAccess doorControlAccess;
private ApiController apiController; private ApiController apiController;
private Logger appLogger;
public LaneIn(int doorId, public LaneIn(int doorId,
string cameraId, string cameraId,
@ -29,12 +31,14 @@ namespace AIParkingApplication
IDoorControlAccess doorControlAccess, IDoorControlAccess doorControlAccess,
ApiController apiController, ApiController apiController,
EngineApiController engineApiController, EngineApiController engineApiController,
Logger appLogger,
bool isSupportSquarePlate = true, bool isSupportSquarePlate = true,
bool isSupportLongPlate = false, bool isSupportLongPlate = false,
bool isAutoOpenDoor = true, bool isAutoOpenDoor = true,
bool isRetryMode = false) bool isRetryMode = false)
{ {
InitializeComponent(); InitializeComponent();
this.appLogger = appLogger;
DoorId = doorId; DoorId = doorId;
this.cameraId = cameraId; this.cameraId = cameraId;
this.isSupportSquarePlate = isSupportSquarePlate; this.isSupportSquarePlate = isSupportSquarePlate;

View File

@ -3,6 +3,7 @@ using System.Drawing;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using NLog;
using OpenCvSharp; using OpenCvSharp;
using OpenCvSharp.Extensions; using OpenCvSharp.Extensions;
@ -22,6 +23,7 @@ namespace AIParkingApplication
private IDoorControlAccess doorControlAccess; private IDoorControlAccess doorControlAccess;
private ApiController apiController; private ApiController apiController;
private Printer printer; private Printer printer;
private Logger appLogger;
public LaneOut(int doorId, public LaneOut(int doorId,
string cameraId, string cameraId,
@ -30,12 +32,14 @@ namespace AIParkingApplication
IDoorControlAccess doorControlAccess, IDoorControlAccess doorControlAccess,
ApiController apiController, ApiController apiController,
EngineApiController engineApiController, EngineApiController engineApiController,
Logger appLogger,
bool isSupportSquarePlate = true, bool isSupportSquarePlate = true,
bool isSupportLongPlate = false, bool isSupportLongPlate = false,
bool isAutoOpenDoor = true, bool isAutoOpenDoor = true,
bool isRetryMode = false) bool isRetryMode = false)
{ {
InitializeComponent(); InitializeComponent();
this.appLogger = appLogger;
DoorId = doorId; DoorId = doorId;
this.cameraId = cameraId; this.cameraId = cameraId;
this.isSupportSquarePlate = isSupportSquarePlate; this.isSupportSquarePlate = isSupportSquarePlate;
@ -46,7 +50,7 @@ namespace AIParkingApplication
plateCamera = new Camera(plateStream); plateCamera = new Camera(plateStream);
this.apiController = apiController; this.apiController = apiController;
this.doorControlAccess = doorControlAccess; this.doorControlAccess = doorControlAccess;
printer = new Printer(); printer = new Printer(appLogger);
plateProcessor = new PlateProcessor(engineApiController, this.isSupportSquarePlate, this.isSupportLongPlate); plateProcessor = new PlateProcessor(engineApiController, this.isSupportSquarePlate, this.isSupportLongPlate);
} }

View File

@ -1,4 +1,5 @@
using Microsoft.Win32; using Microsoft.Win32;
using NLog;
using System; using System;
using System.IO; using System.IO;
using System.Windows.Forms; using System.Windows.Forms;
@ -7,8 +8,11 @@ namespace AIParkingApplication
{ {
public class Printer public class Printer
{ {
public Printer() private Logger appLogger;
public Printer(Logger appLogger)
{ {
this.appLogger = appLogger;
SetupPrinterPageSetting(); SetupPrinterPageSetting();
} }
@ -43,6 +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}");
return string.Empty; return string.Empty;
} }
} }