Util - add ExecuteCommand. StatusBar - Check engine status.

This commit is contained in:
DucDangAnh 2020-07-02 14:46:49 +07:00
parent 798eee42e2
commit a717b356f0
7 changed files with 106 additions and 13 deletions

View File

@ -8,13 +8,19 @@ EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
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}.Debug|x64.ActiveCfg = Debug|x64
{AAB88B46-4AAC-4BE6-8847-E7E4C37AEB6D}.Debug|x64.Build.0 = Debug|x64
{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
{AAB88B46-4AAC-4BE6-8847-E7E4C37AEB6D}.Release|x64.ActiveCfg = Release|x64
{AAB88B46-4AAC-4BE6-8847-E7E4C37AEB6D}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -36,6 +36,28 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x64\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>bin\x64\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<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>
@ -137,6 +159,9 @@
<EmbeddedResource Include="StatusBar.resx">
<DependentUpon>StatusBar.cs</DependentUpon>
</EmbeddedResource>
<None Include="engine.bat">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>

View File

@ -57,6 +57,7 @@ namespace AIParkingApplication
Mat videoFrame = new Mat();
while (true)
{
//Thread.Sleep(5);
Thread.Sleep(50); //Stream Thread Sleep
//Thread.Sleep(40); //Video Thread Sleep

View File

@ -31,9 +31,11 @@
this.lblPingTimeServer = new System.Windows.Forms.Label();
this.lblDateTime = new System.Windows.Forms.Label();
this.lblPingDoorAccessControlDevice = new System.Windows.Forms.Label();
this.lblPingTimeC3 = new System.Windows.Forms.Label();
this.lblPingTimeToDoorAccessControl = new System.Windows.Forms.Label();
this.lblConnectionStatus = new System.Windows.Forms.Label();
this.lblServer = new System.Windows.Forms.Label();
this.lblEngine = new System.Windows.Forms.Label();
this.lblEngineStatus = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// lblPingTimeServer
@ -67,20 +69,20 @@
this.lblPingDoorAccessControlDevice.Text = "Thiết bị mở cửa:";
this.lblPingDoorAccessControlDevice.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// lblPingTimeC3
// lblPingTimeToDoorAccessControl
//
this.lblPingTimeC3.Font = new System.Drawing.Font("Microsoft Sans Serif", 11F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.lblPingTimeC3.Location = new System.Drawing.Point(436, 0);
this.lblPingTimeC3.Name = "lblPingTimeC3";
this.lblPingTimeC3.Size = new System.Drawing.Size(71, 24);
this.lblPingTimeC3.TabIndex = 3;
this.lblPingTimeC3.Text = "500ms";
this.lblPingTimeC3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.lblPingTimeToDoorAccessControl.Font = new System.Drawing.Font("Microsoft Sans Serif", 11F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.lblPingTimeToDoorAccessControl.Location = new System.Drawing.Point(437, 0);
this.lblPingTimeToDoorAccessControl.Name = "lblPingTimeToDoorAccessControl";
this.lblPingTimeToDoorAccessControl.Size = new System.Drawing.Size(71, 24);
this.lblPingTimeToDoorAccessControl.TabIndex = 3;
this.lblPingTimeToDoorAccessControl.Text = "500ms";
this.lblPingTimeToDoorAccessControl.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// lblConnectionStatus
//
this.lblConnectionStatus.Font = new System.Drawing.Font("Microsoft Sans Serif", 11F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.lblConnectionStatus.Location = new System.Drawing.Point(3, 0);
this.lblConnectionStatus.Location = new System.Drawing.Point(0, 0);
this.lblConnectionStatus.Name = "lblConnectionStatus";
this.lblConnectionStatus.Size = new System.Drawing.Size(125, 24);
this.lblConnectionStatus.TabIndex = 1;
@ -97,11 +99,33 @@
this.lblServer.Text = "Server";
this.lblServer.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// lblEngine
//
this.lblEngine.Font = new System.Drawing.Font("Microsoft Sans Serif", 11F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.lblEngine.Location = new System.Drawing.Point(570, 0);
this.lblEngine.Name = "lblEngine";
this.lblEngine.Size = new System.Drawing.Size(65, 24);
this.lblEngine.TabIndex = 3;
this.lblEngine.Text = "Engine:";
this.lblEngine.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// lblEngineStatus
//
this.lblEngineStatus.Font = new System.Drawing.Font("Microsoft Sans Serif", 11F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.lblEngineStatus.Location = new System.Drawing.Point(641, 0);
this.lblEngineStatus.Name = "lblEngineStatus";
this.lblEngineStatus.Size = new System.Drawing.Size(169, 24);
this.lblEngineStatus.TabIndex = 3;
this.lblEngineStatus.Text = "ĐANG HOẠT ĐỘNG";
this.lblEngineStatus.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// StatusBar
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.lblPingTimeC3);
this.Controls.Add(this.lblEngineStatus);
this.Controls.Add(this.lblPingTimeToDoorAccessControl);
this.Controls.Add(this.lblEngine);
this.Controls.Add(this.lblPingDoorAccessControlDevice);
this.Controls.Add(this.lblDateTime);
this.Controls.Add(this.lblServer);
@ -120,8 +144,10 @@
private System.Windows.Forms.Label lblPingTimeServer;
private System.Windows.Forms.Label lblDateTime;
private System.Windows.Forms.Label lblPingDoorAccessControlDevice;
private System.Windows.Forms.Label lblPingTimeC3;
private System.Windows.Forms.Label lblPingTimeToDoorAccessControl;
private System.Windows.Forms.Label lblConnectionStatus;
private System.Windows.Forms.Label lblServer;
private System.Windows.Forms.Label lblEngine;
private System.Windows.Forms.Label lblEngineStatus;
}
}

View File

@ -1,4 +1,5 @@
using System;
using System.Diagnostics;
using System.Drawing;
using System.Threading;
using System.Windows.Forms;
@ -31,10 +32,21 @@ namespace AIParkingApplication
lblDateTime.UpdateLabel(DateTime.Now.GetTimeFormatted());
PingResult pingDoorAccessControlResult = GetPingStatus(doorAccessControlDeviceIP);
lblPingTimeC3.UpdateLabel($"{pingDoorAccessControlResult.ReplyTime} ms", pingDoorAccessControlResult.BackColor, pingDoorAccessControlResult.ForeColor);
lblPingTimeToDoorAccessControl.UpdateLabel($"{pingDoorAccessControlResult.ReplyTime} ms", pingDoorAccessControlResult.BackColor, pingDoorAccessControlResult.ForeColor);
PingResult pingWebServerResult = GetPingStatus(webServerIP);
lblPingTimeServer.UpdateLabel($"{pingWebServerResult.ReplyTime} ms", pingWebServerResult.BackColor, pingWebServerResult.ForeColor);
if (Process.GetProcessesByName("tmux").Length == 0)
{
string engineBatFilePath = Application.StartupPath + @"\engine.bat";
Util.ExecuteCommand(engineBatFilePath);
lblEngineStatus.UpdateLabel("DỪNG HOẠT ĐỘNG", Color.Red);
}
else
{
lblEngineStatus.UpdateLabel("ĐANG HOẠT ĐỘNG", Color.Green);
}
}
Thread.Sleep(updateInterval);
}

View File

@ -128,6 +128,26 @@ namespace AIParkingApplication
{
return dateTime.ToString(AppConstant.DATETIME_FORMAT);
}
public static void ExecuteCommand(string command)
{
var processInfo = new ProcessStartInfo("cmd.exe", "/c " + command);
processInfo.CreateNoWindow = true;
processInfo.UseShellExecute = false;
processInfo.RedirectStandardError = true;
processInfo.RedirectStandardOutput = true;
using (var process = Process.Start(processInfo))
{
process.OutputDataReceived += (object sender, DataReceivedEventArgs e) => Console.WriteLine("Engine Output >>" + e.Data);
process.BeginOutputReadLine();
process.ErrorDataReceived += (object sender, DataReceivedEventArgs e) => Console.WriteLine("Engine Error >>" + e.Data);
process.BeginErrorReadLine();
//process.WaitForExit();
//Console.WriteLine("ExitCode: {0}", process.ExitCode);
//process.Close();
}
}
}
public class PlateRequestEngineModel

View File

@ -0,0 +1,3 @@
@echo off
wsl bash -c "cd ~/AIParking_Engine_deploy && tmux new-session -d -s "engine" gunicorn app:app -b 0.0.0.0:8080 --workers=2"
exit