commit 30473ed1ddb21b0c3c17db2c2849ccb62dcf371b Author: DucDangAnh Date: Mon Jun 15 15:29:50 2020 +0700 Init Commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ee255d2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,261 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ + +# Visual Studio 2015 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# DNX +project.lock.json +project.fragment.lock.json +artifacts/ + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# TODO: Comment the next line if you want to checkin your web deploy settings +# but database connection strings (with potential passwords) will be unencrypted +#*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +#**/packages/* +# except build/, which is used as an MSBuild target. +#!**/packages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/packages/repositories.config +# NuGet v3's project.json files produces more ignoreable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +node_modules/ +orleans.codegen.cs + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# JetBrains Rider +.idea/ +*.sln.iml + +# CodeRush +.cr/ + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc \ No newline at end of file diff --git a/AIParkingApplication.sln b/AIParkingApplication.sln new file mode 100644 index 0000000..9ee5f5a --- /dev/null +++ b/AIParkingApplication.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30104.148 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AIParkingApplication", "AIParkingApplication\AIParkingApplication.csproj", "{AAB88B46-4AAC-4BE6-8847-E7E4C37AEB6D}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {AAB88B46-4AAC-4BE6-8847-E7E4C37AEB6D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AAB88B46-4AAC-4BE6-8847-E7E4C37AEB6D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AAB88B46-4AAC-4BE6-8847-E7E4C37AEB6D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AAB88B46-4AAC-4BE6-8847-E7E4C37AEB6D}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {E59F5B80-E86A-481E-891C-00ECDB489D8E} + EndGlobalSection +EndGlobal diff --git a/AIParkingApplication/AIParkingApplication.csproj b/AIParkingApplication/AIParkingApplication.csproj new file mode 100644 index 0000000..a8128a3 --- /dev/null +++ b/AIParkingApplication/AIParkingApplication.csproj @@ -0,0 +1,89 @@ + + + + + Debug + AnyCPU + {AAB88B46-4AAC-4BE6-8847-E7E4C37AEB6D} + WinExe + AIParkingApplication + AIParkingApplication + v4.6 + 512 + true + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + Form + + + AIParkingApplicationForm.cs + + + + + + + + + + AIParkingApplicationForm.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + + + \ No newline at end of file diff --git a/AIParkingApplication/AIParkingApplicationForm.Designer.cs b/AIParkingApplication/AIParkingApplicationForm.Designer.cs new file mode 100644 index 0000000..7344900 --- /dev/null +++ b/AIParkingApplication/AIParkingApplicationForm.Designer.cs @@ -0,0 +1,48 @@ +namespace AIParkingApplication +{ + partial class AIParkingApplicationForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.SuspendLayout(); + // + // AIParkingApplicationForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(1350, 729); + this.MinimumSize = new System.Drawing.Size(1366, 768); + this.Name = "AIParkingApplicationForm"; + this.Text = "AIParking Application"; + this.ResumeLayout(false); + + } + + #endregion + } +} + diff --git a/AIParkingApplication/AIParkingApplicationForm.cs b/AIParkingApplication/AIParkingApplicationForm.cs new file mode 100644 index 0000000..10a59e8 --- /dev/null +++ b/AIParkingApplication/AIParkingApplicationForm.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace AIParkingApplication +{ + public partial class AIParkingApplicationForm : Form + { + public AIParkingApplicationForm() + { + InitializeComponent(); + } + } +} diff --git a/AIParkingApplication/AIParkingApplicationForm.resx b/AIParkingApplication/AIParkingApplicationForm.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/AIParkingApplication/AIParkingApplicationForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/AIParkingApplication/ActionResult.cs b/AIParkingApplication/ActionResult.cs new file mode 100644 index 0000000..eafaf03 --- /dev/null +++ b/AIParkingApplication/ActionResult.cs @@ -0,0 +1,9 @@ +namespace AIParkingApplication +{ + public class ActionResult + { + public bool HasError { get; set; } + public string Message { get; set; } + public object Data { get; set; } + } +} \ No newline at end of file diff --git a/AIParkingApplication/App.config b/AIParkingApplication/App.config new file mode 100644 index 0000000..8324aa6 --- /dev/null +++ b/AIParkingApplication/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/AIParkingApplication/AppConstant.cs b/AIParkingApplication/AppConstant.cs new file mode 100644 index 0000000..d189532 --- /dev/null +++ b/AIParkingApplication/AppConstant.cs @@ -0,0 +1,11 @@ +namespace AIParkingApplication +{ + 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 + } +} diff --git a/AIParkingApplication/C3DeviceController.cs b/AIParkingApplication/C3DeviceController.cs new file mode 100644 index 0000000..9f8c2e2 --- /dev/null +++ b/AIParkingApplication/C3DeviceController.cs @@ -0,0 +1,253 @@ +using System; +using System.Runtime.InteropServices; +using System.Text; + +namespace AIParkingApplication +{ + public delegate void C3EventHandler(ActionResult actionResult); + public delegate void C3RTLogEventHandler(ActionResult actionResult, int doorId, string cardNumber); + + public class C3DeviceController + { + public string IPAddress { get; } + private int port; + private IntPtr oneTimeConnectedParamHandler; + private string connectionString; + private bool isReconnected; + public event C3EventHandler OnConnected; + public event C3EventHandler OnConnectFailed; + public event C3EventHandler OnReconnect; + public event C3EventHandler OnDoorOpenned; + public event C3EventHandler OnDoorOpenFailed; + public event C3EventHandler OnPingFailed; + public event C3EventHandler OnDisconnected; + public event C3RTLogEventHandler OnGetRTLog; + public event C3EventHandler OnGetRTLogFailed; + private int reconnectCounter; + + public C3DeviceController(string ipAddress, int port = C3Constant.DEFAULT_C3_PORT) + { + IPAddress = ipAddress; + this.port = port; + connectionString = $"protocol=TCP,ipaddress={this.IPAddress},port={this.port},timeout=2000,passwd="; + oneTimeConnectedParamHandler = IntPtr.Zero; + isReconnected = true; + reconnectCounter = 0; + } + + ~C3DeviceController() + { + Disconnect(); + } + + [DllImport(C3Constant.PLCOMMPRO_DLL, EntryPoint = C3Constant.ENTRY_POINT_CONNECT)] + public static extern IntPtr Connect(string Parameters); + + [DllImport(C3Constant.PLCOMMPRO_DLL, EntryPoint = C3Constant.ENTRY_POINT_PULL_LAST_ERROR)] + public static extern int PullLastError(); + + [DllImport(C3Constant.PLCOMMPRO_DLL, EntryPoint = C3Constant.ENTRY_POINT_DISCONNECT)] + public static extern void Disconnect(IntPtr h); + + [DllImport(C3Constant.PLCOMMPRO_DLL, EntryPoint = C3Constant.ENTRY_POINT_CONTROL_DEVICE)] + public static extern int ControlDevice(IntPtr h, int operationid, int param1, int param2, int param3, int param4, string options); + + [DllImport(C3Constant.PLCOMMPRO_DLL, EntryPoint = C3Constant.ENTRY_POINT_GET_RT_LOG)] + public static extern int GetRTLog(IntPtr h, ref byte buffer, int buffersize); + + public ActionResult Connect() + { + if (Util.IsPingable(IPAddress)) + { + oneTimeConnectedParamHandler = Connect(connectionString); + if (oneTimeConnectedParamHandler != IntPtr.Zero) + { + var result = new ActionResult + { + HasError = false, + Message = string.Format(C3Constant.CONNECTED_SUCCESSFULLY, DateTime.Now.ToString(AppConstant.DATETIME_FORMAT), IPAddress) + }; + OnConnected?.Invoke(result); + return result; + } + else + { + var result = new ActionResult + { + HasError = true, + Message = string.Format(C3Constant.FAILED_TO_CONNECT, DateTime.Now.ToString(AppConstant.DATETIME_FORMAT), IPAddress, PullLastError()) + }; + OnConnectFailed?.Invoke(result); + return result; + } + } + else + { + var result = new ActionResult + { + HasError = true, + Message = string.Format(C3Constant.FAILED_TO_PING, DateTime.Now.ToString(AppConstant.DATETIME_FORMAT), IPAddress) + }; + OnPingFailed?.Invoke(result); + OnConnectFailed?.Invoke(result); + return result; + } + } + + public ActionResult OpenDoor(int doorId) + { + if (oneTimeConnectedParamHandler != IntPtr.Zero) + { + int controlDeviceResult = ControlDevice(oneTimeConnectedParamHandler, 1, doorId, 1, 1, 0, ""); + if (controlDeviceResult >= 0) + { + var result = new ActionResult + { + HasError = false, + Message = string.Format(C3Constant.OPENNED_DOOR_SUCCESSFULLY, DateTime.Now.ToString(AppConstant.DATETIME_FORMAT), IPAddress) + }; + OnDoorOpenned?.Invoke(result); + return result; + } + else + { + var result = new ActionResult + { + HasError = true, + Message = string.Format(C3Constant.FAILED_TO_OPEN_DOOR, DateTime.Now.ToString(AppConstant.DATETIME_FORMAT), IPAddress) + }; + OnDoorOpenFailed?.Invoke(result); + return result; + } + } + else + { + var result = new ActionResult + { + HasError = true, + Message = string.Format(C3Constant.NOT_CONNECTTED, DateTime.Now.ToString(AppConstant.DATETIME_FORMAT), IPAddress) + }; + OnDoorOpenFailed?.Invoke(result); + return result; + } + } + + public ActionResult GetRTLog(out int doorId, out string cardNumber) + { + doorId = C3Constant.DEFAULT_DOOR_ID; + cardNumber = C3Constant.DEFAULT_CARD_NUMBER; + + if (!Util.IsPingable(IPAddress)) + { + isReconnected = false; + var result = new ActionResult + { + HasError = true, + Message = string.Format(C3Constant.FAILED_TO_PING, DateTime.Now.ToString(AppConstant.DATETIME_FORMAT), IPAddress) + }; + OnPingFailed?.Invoke(result); + return result; + } + + try + { + int buffersize = 256; + byte[] buffer = new byte[buffersize]; + int resultRTLog = GetRTLog(oneTimeConnectedParamHandler, ref buffer[0], buffersize); + + if (resultRTLog >= 0) + { + string bufferString = Encoding.Default.GetString(buffer); + string[] data = bufferString.Split(','); + + reconnectCounter = 0; + cardNumber = data[2]; + int.TryParse(data[3], out doorId); + var result = new ActionResult + { + HasError = false + }; + OnGetRTLog?.Invoke(result, doorId, cardNumber); + return result; + } + else + { + reconnectCounter += 1; + if (!isReconnected && reconnectCounter >= C3Constant.MAX_TIME_GET_LOG_BEFORE_RECONNECT) + { + ActionResult reconnectResult = Connect(); + if (!reconnectResult.HasError) + { + isReconnected = true; + reconnectCounter = 0; + reconnectResult.Message = string.Format(C3Constant.RECONNECTED_SUCCESSFULLY, DateTime.Now.ToString(AppConstant.DATETIME_FORMAT), IPAddress); + } + OnReconnect?.Invoke(reconnectResult); + return reconnectResult; + } + + var result = new ActionResult + { + HasError = true, + Message = string.Format(C3Constant.FAILED_TO_READ_LOG, DateTime.Now.ToString(AppConstant.DATETIME_FORMAT), IPAddress) + }; + OnGetRTLogFailed?.Invoke(result); + return result; + } + } + catch (Exception ex) + { + doorId = C3Constant.DEFAULT_DOOR_ID; + cardNumber = C3Constant.DEFAULT_CARD_NUMBER; + var result = new ActionResult + { + HasError = true, + Message = string.Format(C3Constant.WRONG_FORMAT_DATA, DateTime.Now.ToString(AppConstant.DATETIME_FORMAT), IPAddress, ex.Message) + }; + OnGetRTLogFailed?.Invoke(result); + return result; + } + } + + public ActionResult Disconnect() + { + Disconnect(oneTimeConnectedParamHandler); + oneTimeConnectedParamHandler = IntPtr.Zero; + var result = new ActionResult + { + HasError = false, + Message = string.Format(C3Constant.DISCONNECTED_SUCCESSFULLY, DateTime.Now.ToString(AppConstant.DATETIME_FORMAT), IPAddress) + }; + OnDisconnected?.Invoke(result); + return result; + } + } + + public static class C3Constant + { + #region DLL Entry Point + public const string PLCOMMPRO_DLL = "plcommpro.dll"; + public const string ENTRY_POINT_CONNECT = "Connect"; + public const string ENTRY_POINT_PULL_LAST_ERROR = "PullLastError"; + public const string ENTRY_POINT_DISCONNECT = "Disconnect"; + public const string ENTRY_POINT_CONTROL_DEVICE = "ControlDevice"; + public const string ENTRY_POINT_GET_RT_LOG = "GetRTLog"; + #endregion + + public const int DEFAULT_C3_PORT = 4370; + public const string CONNECTED_SUCCESSFULLY = "{0}\t{1}\tKết nối thành công hệ thống đóng mở cửa"; + public const string FAILED_TO_CONNECT = "{0}\t{1}\tKhông thể kết nối tới thiết bị C3\tError Code: {2}"; + public const string NOT_CONNECTTED = "{0}\t{1}\tChưa kết nối tới thiết bị C3"; + public const string FAILED_TO_PING = "{0}\t{1}\tKhông thể PING tới thiết bị C3"; + public const string DISCONNECTED_SUCCESSFULLY = "{0}\t{1}\tĐã ngắt kết nối thành công tới thiết bị C3"; + public const string OPENNED_DOOR_SUCCESSFULLY = "{0}\t{1}\tMở cửa thành công!"; + public const string FAILED_TO_OPEN_DOOR = "{0}\t{1}\tKhông thể mở cửa!"; + public const string WRONG_FORMAT_DATA = "{0}\t{1}\tĐịnh dạng dữ liệu đọc từ thiết bị sai!\tErrorMessage:{2}"; + public const string FAILED_TO_READ_LOG = "{0}\t{1}\tKhông đọc được dữ liệu RTLog từ thiết bị C3"; + public const string RECONNECTED_SUCCESSFULLY = "{0}\t{1}\tĐã kết nối lại tới thiết bị C3"; + public const string DEFAULT_CARD_NUMBER = "0"; + public const int DEFAULT_DOOR_ID = 0; + public const string DATETIME_FORMAT = "HH:mm:ss dd/MM/yyyy"; + public const int MAX_TIME_GET_LOG_BEFORE_RECONNECT = 5; + } +} diff --git a/AIParkingApplication/Camera.cs b/AIParkingApplication/Camera.cs new file mode 100644 index 0000000..79de1d5 --- /dev/null +++ b/AIParkingApplication/Camera.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AIParkingApplication +{ + public class Camera + { + private string videoStream; + private CameraType cameraType; + public Camera(CameraType cameraType, string videoStream) + { + this.cameraType = cameraType; + this.videoStream = videoStream; + } + + public void CaptureFrame() + { + + } + + public void ShowFrame() + { + + } + } + + public enum CameraType + { + Vehicle, + Plate + } +} diff --git a/AIParkingApplication/Lane.cs b/AIParkingApplication/Lane.cs new file mode 100644 index 0000000..da99593 --- /dev/null +++ b/AIParkingApplication/Lane.cs @@ -0,0 +1,22 @@ +namespace AIParkingApplication +{ + public class Lane + { + private LaneType laneType; + private string vehicleVideoStream; + private string plateVideoStream; + + public Lane(LaneType laneType, string vehicleVideoStream, string plateVideoStream) + { + this.laneType = laneType; + this.vehicleVideoStream = vehicleVideoStream; + this.plateVideoStream = plateVideoStream; + } + } + + public enum LaneType + { + IN, + OUT + } +} diff --git a/AIParkingApplication/Program.cs b/AIParkingApplication/Program.cs new file mode 100644 index 0000000..75fb36a --- /dev/null +++ b/AIParkingApplication/Program.cs @@ -0,0 +1,36 @@ +using System; +using System.Diagnostics; +using System.Threading; +using System.Windows.Forms; + +namespace AIParkingApplication +{ + public static class Program + { + [STAThread] + public static void Main() + { + using (Mutex mutex = new Mutex(true, "AIParkingApplication", out bool isAppCreatedNew)) + { + if (isAppCreatedNew) + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new AIParkingApplicationForm()); + } + else + { + Process currentProcess = Process.GetCurrentProcess(); + foreach (Process process in Process.GetProcessesByName(currentProcess.ProcessName)) + { + if (process.Id != currentProcess.Id) + { + MessageBox.Show(AppConstant.APPLICATION_IS_RUNNNING, AppConstant.ERROR_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Error); + break; + } + } + } + } + } + } +} diff --git a/AIParkingApplication/Properties/AssemblyInfo.cs b/AIParkingApplication/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..d11a5d1 --- /dev/null +++ b/AIParkingApplication/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("AIParkingApplication")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("AIParkingApplication")] +[assembly: AssemblyCopyright("Copyright © 2020")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("aab88b46-4aac-4be6-8847-e7e4c37aeb6d")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/AIParkingApplication/Properties/Resources.Designer.cs b/AIParkingApplication/Properties/Resources.Designer.cs new file mode 100644 index 0000000..e2c8409 --- /dev/null +++ b/AIParkingApplication/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace AIParkingApplication.Properties +{ + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources + { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() + { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("AIParkingApplication.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture + { + get + { + return resourceCulture; + } + set + { + resourceCulture = value; + } + } + } +} diff --git a/AIParkingApplication/Properties/Resources.resx b/AIParkingApplication/Properties/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/AIParkingApplication/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/AIParkingApplication/Properties/Settings.Designer.cs b/AIParkingApplication/Properties/Settings.Designer.cs new file mode 100644 index 0000000..728846a --- /dev/null +++ b/AIParkingApplication/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace AIParkingApplication.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/AIParkingApplication/Properties/Settings.settings b/AIParkingApplication/Properties/Settings.settings new file mode 100644 index 0000000..3964565 --- /dev/null +++ b/AIParkingApplication/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/AIParkingApplication/Util.cs b/AIParkingApplication/Util.cs new file mode 100644 index 0000000..9cef324 --- /dev/null +++ b/AIParkingApplication/Util.cs @@ -0,0 +1,43 @@ +using System; +using System.Net.NetworkInformation; +using System.Threading.Tasks; + +namespace AIParkingApplication +{ + public static class Util + { + public static bool IsPingable(string destinationIPAddress, int timeOut = UtilConstant.PING_TIMEOUT_MS) + { + var pingTask = Task.Factory.StartNew(async () => + { + bool isPingable = false; + Ping pinger = new Ping(); + try + { + PingReply reply = await pinger.SendPingAsync(destinationIPAddress, timeOut); + isPingable = reply.Status == IPStatus.Success; + if (!isPingable) + { + // Logging + } + } + catch (Exception) + { + isPingable = false; + } + finally + { + pinger.Dispose(); + } + return isPingable; + }); + + return pingTask.Result.Result; + } + } + + public static class UtilConstant + { + public const int PING_TIMEOUT_MS = 500; + } +}