83 lines
2.9 KiB
C#
83 lines
2.9 KiB
C#
using System;
|
|
using System.Drawing;
|
|
using System.Threading;
|
|
using System.Windows.Forms;
|
|
|
|
namespace AIParkingApplication
|
|
{
|
|
public partial class StatusBar : UserControl
|
|
{
|
|
private string webServerIP;
|
|
private string doorAccessControlDeviceIP;
|
|
private TimeSpan updateInterval;
|
|
|
|
public StatusBar(string webServerIP, string doorAccessControlDeviceIP, TimeSpan updateInterval)
|
|
{
|
|
InitializeComponent();
|
|
this.webServerIP = webServerIP;
|
|
this.doorAccessControlDeviceIP = doorAccessControlDeviceIP;
|
|
this.updateInterval = updateInterval;
|
|
Thread thrStatus = new Thread(new ThreadStart(UpdateStatus));
|
|
thrStatus.IsBackground = true;
|
|
thrStatus.Start();
|
|
}
|
|
|
|
private void UpdateStatus()
|
|
{
|
|
while (true)
|
|
{
|
|
if (IsHandleCreated)
|
|
{
|
|
lblDateTime.UpdateLabel(DateTime.Now.ToString(AppConstant.DATETIME_FORMAT));
|
|
|
|
PingResult pingDoorAccessControlResult = GetPingStatus(doorAccessControlDeviceIP);
|
|
lblPingTimeC3.UpdateLabel($"{pingDoorAccessControlResult.ReplyTime} ms", pingDoorAccessControlResult.BackColor, pingDoorAccessControlResult.ForeColor);
|
|
|
|
PingResult pingWebServerResult = GetPingStatus(webServerIP);
|
|
lblPingTimeServer.UpdateLabel($"{pingWebServerResult.ReplyTime} ms", pingWebServerResult.BackColor, pingWebServerResult.ForeColor);
|
|
}
|
|
Thread.Sleep(updateInterval);
|
|
}
|
|
}
|
|
|
|
private PingResult GetPingStatus(string ipAddress)
|
|
{
|
|
PingResult pingResult = new PingResult();
|
|
bool isPingable;
|
|
isPingable = Util.IsPingable(ipAddress, out long replyTime);
|
|
if (isPingable)
|
|
{
|
|
switch (replyTime)
|
|
{
|
|
case long n when (n >= 0 && n < 1):
|
|
pingResult.ReplyTime = 1;
|
|
pingResult.BackColor = Color.Green;
|
|
break;
|
|
case long n when (n >= 1 && n < 50):
|
|
pingResult.ReplyTime = replyTime;
|
|
pingResult.BackColor = Color.Green;
|
|
break;
|
|
case long n when (n >= 50):
|
|
pingResult.ReplyTime = replyTime;
|
|
pingResult.BackColor = Color.Red;
|
|
break;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
pingResult.ReplyTime = 0;
|
|
pingResult.BackColor = Color.Gray;
|
|
}
|
|
return pingResult;
|
|
}
|
|
|
|
private class PingResult
|
|
{
|
|
public long ReplyTime { get; set; }
|
|
public Color BackColor { get; set; }
|
|
public Color ForeColor { get; set; }
|
|
}
|
|
}
|
|
}
|
|
|