Compare commits

...

6 Commits

38 changed files with 297707 additions and 75 deletions

View File

@ -77,6 +77,9 @@
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
<HintPath>..\packages\NLog.4.7.2\lib\net45\NLog.dll</HintPath>
</Reference>
<Reference Include="OpenCvSharp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6adad1e807fea099, processorArchitecture=MSIL">
<HintPath>..\packages\OpenCvSharp4.4.3.0.20200524\lib\net461\OpenCvSharp.dll</HintPath>
</Reference>
@ -89,12 +92,16 @@
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.IO.Compression" />
<Reference Include="System.Net.Http.Formatting, Version=5.2.7.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.AspNet.WebApi.Client.5.2.7\lib\net45\System.Net.Http.Formatting.dll</HintPath>
</Reference>
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=4.0.6.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.4.7.1\lib\net461\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
</Reference>
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.ServiceModel" />
<Reference Include="System.Transactions" />
<Reference Include="System.Web.Extensions" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
@ -120,6 +127,7 @@
<Compile Include="Camera.cs" />
<Compile Include="EngineApiController.cs" />
<Compile Include="Enums.cs" />
<Compile Include="ExtensitionMethods.cs" />
<Compile Include="IDoorControlAccess.cs" />
<Compile Include="ILane.cs" />
<Compile Include="LaneIn.cs">
@ -198,6 +206,12 @@
<None Include="engine.bat">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<Content Include="NLog.config">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<None Include="NLog.xsd">
<SubType>Designer</SubType>
</None>
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>

View File

@ -1,4 +1,5 @@
using System;
using NLog;
using System;
using System.Configuration;
using System.Drawing;
using System.Linq;
@ -8,6 +9,8 @@ namespace AIParkingApplication
{
public partial class AIParkingApplicationForm : Form
{
private const string CURRENT_LANE_SETTING_KEY = "CURRENT_LANE_SETTING";
private ApiController apiController;
private IDoorControlAccess c3Device;
private LaneIn laneIn12;
@ -20,15 +23,19 @@ namespace AIParkingApplication
private EngineApiController engineApiController;
private string doorAccessControlDeviceIP;
private Logger applicationLogger;
public AIParkingApplicationForm(ApiController apiController, string serverIPAddress, Config configOnWeb)
{
InitializeComponent();
this.apiController = apiController;
this.configOnWeb = configOnWeb;
applicationLogger = LogManager.GetLogger(AppConstant.APPLICATION_LOGGER_NAME);
ReadAccessControlDeviceIPConfigurationFile();
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!");
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();
}
@ -40,7 +47,7 @@ namespace AIParkingApplication
};
Controls.Add(sidebar);
statusBar = new StatusBar("192.168.1.122", doorAccessControlDeviceIP)
statusBar = new StatusBar(serverIPAddress, doorAccessControlDeviceIP)
{
Location = new Point(0, sidebar.Location.Y + sidebar.Height + 26),
Anchor = AnchorStyles.Bottom | AnchorStyles.Left
@ -53,6 +60,7 @@ namespace AIParkingApplication
}
catch (Exception)
{
applicationLogger.Log(LogLevel.Error, "Cấu hình URL của Engine nhận diện biển số lỗi!");
MessageBox.Show("Cấu hình API Plate Recognize lỗi!", "Cấu hình API Engine lỗi!", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
@ -92,6 +100,8 @@ namespace AIParkingApplication
laneOut34.Location = new Point(laneIn12.Location.X + laneIn12.Width + 20, menuStrip.Height);
laneOut34.Show();
laneOut34.Start();
toolStripMenuItemSwitchLaneInOut.DisableSelected();
}
private void UpdateLaneInIn()
@ -105,6 +115,8 @@ namespace AIParkingApplication
laneIn56.Location = new Point(laneIn12.Location.X + laneIn12.Width + 20, menuStrip.Height);
laneIn56.Show();
laneIn56.Start();
toolStripMenuItemSwitchLaneInIn.DisableSelected();
}
private void UpdateLaneOutIn()
@ -118,6 +130,8 @@ namespace AIParkingApplication
laneIn56.Location = new Point(laneOut78.Location.X + laneOut78.Width + 20, menuStrip.Height);
laneIn56.Show();
laneIn56.Start();
toolStripMenuItemSwitchLaneOutIn.DisableSelected();
}
private void UpdateLaneOutOut()
@ -131,38 +145,44 @@ namespace AIParkingApplication
laneOut34.Location = new Point(laneOut78.Location.X + laneOut78.Width + 20, menuStrip.Height);
laneOut34.Show();
laneOut34.Start();
toolStripMenuItemSwitchLaneOutOut.DisableSelected();
}
private void toolStripMenuItemSwitchLaneInIn_Click(object sender, EventArgs e)
{
Util.AddOrUpdateAppSettings("CURRENT_LANE_SETTING", "IN-IN");
Util.AddOrUpdateAppSettings(CURRENT_LANE_SETTING_KEY, "IN-IN");
UpdateMenuStripItemStatus(sender as ToolStripMenuItem);
StopAllLanes();
UpdateLaneInIn();
applicationLogger.Log(LogLevel.Info, "Chuyển làn: IN-IN");
}
private void toolStripMenuItemSwitchLaneInOut_Click(object sender, EventArgs e)
{
Util.AddOrUpdateAppSettings("CURRENT_LANE_SETTING", "IN-OUT");
Util.AddOrUpdateAppSettings(CURRENT_LANE_SETTING_KEY, "IN-OUT");
UpdateMenuStripItemStatus(sender as ToolStripMenuItem);
StopAllLanes();
UpdateLaneInOut();
applicationLogger.Log(LogLevel.Info, "Chuyển làn: IN-OUT");
}
private void toolStripMenuItemSwitchLaneOutIn_Click(object sender, EventArgs e)
{
Util.AddOrUpdateAppSettings("CURRENT_LANE_SETTING", "OUT-IN");
Util.AddOrUpdateAppSettings(CURRENT_LANE_SETTING_KEY, "OUT-IN");
UpdateMenuStripItemStatus(sender as ToolStripMenuItem);
StopAllLanes();
UpdateLaneOutIn();
applicationLogger.Log(LogLevel.Info, "Chuyển làn: OUT-IN");
}
private void toolStripMenuItemSwitchLaneOutOut_Click(object sender, EventArgs e)
{
Util.AddOrUpdateAppSettings("CURRENT_LANE_SETTING", "OUT-OUT");
Util.AddOrUpdateAppSettings(CURRENT_LANE_SETTING_KEY, "OUT-OUT");
UpdateMenuStripItemStatus(sender as ToolStripMenuItem);
StopAllLanes();
UpdateLaneOutOut();
applicationLogger.Log(LogLevel.Info, "Chuyển làn: OUT-OUT");
}
private void UpdateMenuStripItemStatus(ToolStripMenuItem selectedToolStripMenuItem)
@ -204,7 +224,7 @@ namespace AIParkingApplication
{
try
{
string lanesConfig = ConfigurationManager.AppSettings["CURRENT_LANE_SETTING"];
string lanesConfig = ConfigurationManager.AppSettings[CURRENT_LANE_SETTING_KEY];
if (!string.IsNullOrEmpty(lanesConfig))
{
string[] lanes = lanesConfig.Split('-');
@ -215,32 +235,38 @@ namespace AIParkingApplication
if (lane0 == "in" && lane1 == "in")
{
UpdateLaneInIn();
applicationLogger.Log(LogLevel.Info, $"Khởi động App sử dụng lane: IN-IN");
}
if (lane0 == "in" && lane1 == "out")
{
UpdateLaneInOut();
applicationLogger.Log(LogLevel.Info, $"Khởi động App sử dụng lane: IN-OUT");
}
if (lane0 == "out" && lane1 == "in")
{
UpdateLaneOutIn();
applicationLogger.Log(LogLevel.Info, $"Khởi động App sử dụng lane: OUT-IN");
}
if (lane0 == "out" && lane1 == "out")
{
UpdateLaneOutOut();
applicationLogger.Log(LogLevel.Info, $"Khởi động App sử dụng lane: OUT-OUT");
}
}
else
{
Util.AddOrUpdateAppSettings("CURRENT_LANE_SETTING", "IN-OUT");
Util.AddOrUpdateAppSettings(CURRENT_LANE_SETTING_KEY, "IN-OUT");
UpdateLaneInOut();
applicationLogger.Log(LogLevel.Info, $"Khởi động App đọc config không đủ 2 param: IN-OUT");
}
}
}
catch (Exception ex)
{
Util.AddOrUpdateAppSettings("CURRENT_LANE_SETTING", "IN-OUT");
Util.AddOrUpdateAppSettings(CURRENT_LANE_SETTING_KEY, "IN-OUT");
UpdateLaneInOut();
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}");
}
}
@ -252,8 +278,9 @@ namespace AIParkingApplication
}
catch (Exception ex)
{
Console.WriteLine($"{DateTime.Now.GetTimeFormatted()}\tReadAccessControlDeviceIPConfiguration\t{ex.Message}");
doorAccessControlDeviceIP = string.Empty;
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}");
}
}
@ -265,6 +292,7 @@ namespace AIParkingApplication
private void AIParkingApplicationForm_FormClosing(object sender, FormClosingEventArgs e)
{
applicationLogger.Log(LogLevel.Error, $"Đóng ứng dụng");
Application.Exit();
}
}

View File

@ -2,13 +2,15 @@
{
public static class AppConstant
{
#region Application Messages
public const string APPLICATION_IS_RUNNNING = "AIParkingApplication: Ứng dụng đã chạy!";
public const string ERROR_TITLE = "Lỗi";
public const string DATETIME_FORMAT = "HH:mm:ss dd/MM/yyyy";
#endregion
public const string CAMERA_FAILED_IMAGE_PATH = @"Images\CantConnectCamera.jpg";
public const string DEFAULT_LOGO_IMAGE = @".\Images\ApplicationLogo.ico";
public const string APPLICATION_LOGGER_NAME = "ApplicationLogger";
public const string PING_SERVER_LOGGER_NAME = "PingServerLogger";
public const string PING_DOOR_DEVICE_CONTROL_ACCESS_LOGGER_NAME = "PingDoorDeviceControlAccessLogger";
}
}

View File

@ -0,0 +1,76 @@
using System;
using System.Drawing;
using System.Windows.Forms;
namespace AIParkingApplication
{
public static class ExtensitionMethods
{
public static void DisableSelected(this ToolStripMenuItem toolStripMenuItem)
{
toolStripMenuItem.Checked = true;
toolStripMenuItem.Enabled = false;
}
public static string GetTimeFormatted(this DateTime dateTime)
{
return dateTime.ToString(AppConstant.DATETIME_FORMAT);
}
public static void UpdateImage(this PictureBox pictureBox, Bitmap image)
{
if (pictureBox.IsDisposed)
{
return;
}
pictureBox.Invoke(new Action(() =>
{
pictureBox.Image?.Dispose();
pictureBox.Image = image;
}));
}
public static void UpdateLabel(this Label label, string text, Color backColor, Color foreColor)
{
if (label.IsDisposed)
{
return;
}
label.Invoke(new Action(() =>
{
label.Text = text;
label.BackColor = backColor;
label.ForeColor = foreColor;
}));
}
public static void UpdateLabel(this Label label, string text, Color backColor)
{
if (label.IsDisposed)
{
return;
}
label.Invoke(new Action(() =>
{
label.Text = text;
label.BackColor = backColor;
}));
}
public static void UpdateLabel(this Label label, string text)
{
if (label.IsDisposed)
{
return;
}
label.Invoke(new Action(() =>
{
label.Text = text;
}));
}
}
}

View File

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd"
autoReload="true"
throwExceptions="false"
internalLogLevel="Off" internalLogFile="D:\nlog-internal.log">
<variable name="logDirectory" value="${basedir}/logs"/>
<targets>
<target xsi:type="File" name="applicationLogger" fileName="${logDirectory}/${shortdate}_App.log"
layout="${uppercase:${level}} ${message} ${exception}"
maxArchiveFiles="30"
encoding="Unicode"
writeBom="true"/>
<target xsi:type="File" name="pingServerLoggingFile" fileName="${logDirectory}/${shortdate}_PingServer.log"
layout="${uppercase:${level}} ${message} ${exception}"
maxArchiveFiles="30"
encoding="Unicode"
writeBom="true"/>
<target xsi:type="File" name="pingDoorDeviceControlAccessLoggingFile" fileName="${logDirectory}/${shortdate}_PingDoorDeviceControlAccess.log"
layout="${uppercase:${level}} ${message} ${exception}"
maxArchiveFiles="30"
encoding="Unicode"
writeBom="true"/>
</targets>
<rules>
<logger name="ApplicationLogger" minlevel="Trace" writeTo="applicationLogger" />
<logger name="PingServerLogger" minlevel="Trace" writeTo="pingServerLoggingFile" />
<logger name="PingDoorDeviceControlAccessLogger" minlevel="Trace" writeTo="pingDoorDeviceControlAccessLoggingFile" />
</rules>
</nlog>

File diff suppressed because it is too large Load Diff

View File

@ -6,9 +6,7 @@ using System.Drawing;
using System.IO;
using System.Net;
using System.Net.NetworkInformation;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace AIParkingApplication
{
@ -54,62 +52,6 @@ namespace AIParkingApplication
return sf.GetMethod().Name;
}
public static void UpdateImage(this PictureBox pictureBox, Bitmap image)
{
if (pictureBox.IsDisposed)
{
return;
}
pictureBox.Invoke(new Action(() =>
{
pictureBox.Image?.Dispose();
pictureBox.Image = image;
}));
}
public static void UpdateLabel(this Label label, string text, Color backColor, Color foreColor)
{
if (label.IsDisposed)
{
return;
}
label.Invoke(new Action(() =>
{
label.Text = text;
label.BackColor = backColor;
label.ForeColor = foreColor;
}));
}
public static void UpdateLabel(this Label label, string text, Color backColor)
{
if (label.IsDisposed)
{
return;
}
label.Invoke(new Action(() =>
{
label.Text = text;
label.BackColor = backColor;
}));
}
public static void UpdateLabel(this Label label, string text)
{
if (label.IsDisposed)
{
return;
}
label.Invoke(new Action(() =>
{
label.Text = text;
}));
}
public static Bitmap ConvertFromBase64Image(string base64ImageString)
{
byte[] imageData = Convert.FromBase64String(base64ImageString);
@ -120,11 +62,6 @@ namespace AIParkingApplication
}
}
public static string GetTimeFormatted(this DateTime dateTime)
{
return dateTime.ToString(AppConstant.DATETIME_FORMAT);
}
public static void ExecuteCommand(string command)
{
var processInfo = new ProcessStartInfo("cmd.exe", "/c " + command);

View File

@ -2,6 +2,9 @@
<packages>
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.7" targetFramework="net461" />
<package id="Newtonsoft.Json" version="12.0.3" targetFramework="net461" />
<package id="NLog" version="4.7.2" targetFramework="net461" />
<package id="NLog.Config" version="4.7.2" targetFramework="net461" />
<package id="NLog.Schema" version="4.7.2" targetFramework="net461" />
<package id="OpenCvSharp4" version="4.3.0.20200524" targetFramework="net461" />
<package id="OpenCvSharp4.runtime.win" version="4.3.0.20200524" targetFramework="net461" />
<package id="OpenCvSharp4.Windows" version="4.3.0.20200524" targetFramework="net461" />

BIN
packages/NLog.4.7.2/.signature.p7s vendored Normal file

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff

BIN
packages/NLog.4.7.2/lib/net35/NLog.dll vendored Normal file

Binary file not shown.

29160
packages/NLog.4.7.2/lib/net35/NLog.xml vendored Normal file

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

BIN
packages/NLog.4.7.2/lib/net45/NLog.dll vendored Normal file

Binary file not shown.

29589
packages/NLog.4.7.2/lib/net45/NLog.xml vendored Normal file

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

BIN
packages/NLog.4.7.2/lib/sl4/NLog.dll vendored Normal file

Binary file not shown.

21873
packages/NLog.4.7.2/lib/sl4/NLog.xml vendored Normal file

File diff suppressed because it is too large Load Diff

BIN
packages/NLog.4.7.2/lib/sl5/NLog.dll vendored Normal file

Binary file not shown.

22039
packages/NLog.4.7.2/lib/sl5/NLog.xml vendored Normal file

File diff suppressed because it is too large Load Diff

BIN
packages/NLog.4.7.2/lib/wp8/NLog.dll vendored Normal file

Binary file not shown.

21215
packages/NLog.4.7.2/lib/wp8/NLog.xml vendored Normal file

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

View File

@ -0,0 +1,41 @@
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd"
autoReload="true"
throwExceptions="false"
internalLogLevel="Off" internalLogFile="c:\temp\nlog-internal.log">
<!-- optional, add some variables
https://github.com/nlog/NLog/wiki/Configuration-file#variables
-->
<variable name="myvar" value="myvalue"/>
<!--
See https://github.com/nlog/nlog/wiki/Configuration-file
for information on customizing logging rules and outputs.
-->
<targets>
<!--
add your targets here
See https://github.com/nlog/NLog/wiki/Targets for possible targets.
See https://github.com/nlog/NLog/wiki/Layout-Renderers for the possible layout renderers.
-->
<!--
Write events to a file with the date in the filename.
<target xsi:type="File" name="f" fileName="${basedir}/logs/${shortdate}.log"
layout="${longdate} ${uppercase:${level}} ${message}" />
-->
</targets>
<rules>
<!-- add your logging rules here -->
<!--
Write all events with minimal level of Debug (So Debug, Info, Warn, Error and Fatal, but not Trace) to "f"
<logger name="*" minlevel="Debug" writeTo="f" />
-->
</rules>
</nlog>

View File

@ -0,0 +1,41 @@
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd"
autoReload="true"
throwExceptions="false"
internalLogLevel="Off" internalLogFile="c:\temp\nlog-internal.log">
<!-- optional, add some variables
https://github.com/nlog/NLog/wiki/Configuration-file#variables
-->
<variable name="myvar" value="myvalue"/>
<!--
See https://github.com/nlog/nlog/wiki/Configuration-file
for information on customizing logging rules and outputs.
-->
<targets>
<!--
add your targets here
See https://github.com/nlog/NLog/wiki/Targets for possible targets.
See https://github.com/nlog/NLog/wiki/Layout-Renderers for the possible layout renderers.
-->
<!--
Write events to a file with the date in the filename.
<target xsi:type="File" name="f" fileName="${basedir}/logs/${shortdate}.log"
layout="${longdate} ${uppercase:${level}} ${message}" />
-->
</targets>
<rules>
<!-- add your logging rules here -->
<!--
Write all events with minimal level of Debug (So Debug, Info, Warn, Error and Fatal, but not Trace) to "f"
<logger name="*" minlevel="Debug" writeTo="f" />
-->
</rules>
</nlog>

View File

@ -0,0 +1,12 @@
param($installPath, $toolsPath, $package, $project)
$configItem = $project.ProjectItems.Item("NLog.config")
# set 'Copy To Output Directory' to 'Copy if newer'
$copyToOutput = $configItem.Properties.Item("CopyToOutputDirectory")
$copyToOutput.Value = 2
# set 'Build Action' to 'Content'
$buildAction = $configItem.Properties.Item("BuildAction")
$buildAction.Value = 2

Binary file not shown.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff