65 lines
2.0 KiB
C#
65 lines
2.0 KiB
C#
using NLog;
|
|
using System.Collections.Generic;
|
|
using System.Configuration;
|
|
using System.Windows.Forms;
|
|
|
|
namespace PingTool
|
|
{
|
|
public partial class PingToolForm : Form
|
|
{
|
|
private List<string> destinationIPList;
|
|
private string thisPcIP;
|
|
public PingToolForm()
|
|
{
|
|
InitializeComponent();
|
|
|
|
Logger pingLogger = LogManager.GetLogger(Constant.PING_LOGGER_FILE_NAME);
|
|
pingLogger.Log(LogLevel.Info, $"-------------------------------Chạy ứng dụng {System.DateTime.Now.ToString(Constant.DATETIME_FORMAT)} --------------------------------------");
|
|
destinationIPList = new List<string>();
|
|
timerPing.Tick += TimerPingTickEvent;
|
|
Init();
|
|
}
|
|
|
|
private void Init()
|
|
{
|
|
var listIP = ConfigurationManager.AppSettings[Constant.PING_TO_CONFIGURATION_KEY].Replace(" ", "").Split(',');
|
|
foreach (string ip in listIP)
|
|
{
|
|
destinationIPList.Add(ip);
|
|
}
|
|
thisPcIP = Util.GetLocalIPAddress();
|
|
lblThisPcIP.Text = $"IP máy hiện tại: {thisPcIP}";
|
|
lblDestinationPcIPs.Text = $"Ping đến các máy:\t{string.Join(", ", listIP)}";
|
|
}
|
|
|
|
private void TimerPingTickEvent(object sender, System.EventArgs e)
|
|
{
|
|
foreach (string ip in destinationIPList)
|
|
{
|
|
Util.IsPingable(thisPcIP, ip);
|
|
}
|
|
}
|
|
|
|
private void PingToolForm_FormClosing(object sender, FormClosingEventArgs e)
|
|
{
|
|
HideForm();
|
|
e.Cancel = true;
|
|
}
|
|
|
|
private void PingToolForm_Resize(object sender, System.EventArgs e)
|
|
{
|
|
if (WindowState == FormWindowState.Minimized)
|
|
{
|
|
HideForm();
|
|
}
|
|
}
|
|
|
|
private void HideForm()
|
|
{
|
|
this.WindowState = FormWindowState.Minimized;
|
|
this.ShowInTaskbar = false;
|
|
this.Hide();
|
|
}
|
|
}
|
|
}
|