using HSUCO_CCTV_Monitoring; using HSUCO_CCTV_Monitoring.Properties; using System; using System.Collections.Generic; using System.Threading.Tasks; using System.Windows.Forms; namespace HSUCO_Server_Monitoring { public partial class MainForm : Form { private string configPath = "config.xml"; private Config config; private List nvrStatuses = new List(); private readonly object locker = new object(); public MainForm() { InitializeComponent(); } private void MainForm_Load(object sender, EventArgs e) { if (!System.IO.File.Exists(configPath)) { MessageBox.Show("config 파일을 찾을수 없습니다"); Application.Exit(); return; } config = XmlSystem.LoadFromPath("config.xml"); InitializeNVR(); this.FormBorderStyle = FormBorderStyle.None; this.WindowState = FormWindowState.Maximized; Size = Screen.PrimaryScreen.WorkingArea.Size; tableLayoutPanelMaster.ColumnStyles[0].SizeType = SizeType.Absolute; tableLayoutPanelMaster.ColumnStyles[1].Width = 1100; tableLayoutPanelMaster.ColumnStyles[3].SizeType = SizeType.Absolute; tableLayoutPanelMaster.ColumnStyles[3].Width = 400; Task.Run(() => NVR_Runner()); Task.Run(() => CCTV_Runner()); } public void InitializeNVR() { for (int i = 0; i < config.NVR.Count; i++) { NVRStatus nvrStatus = new NVRStatus(config.NVR[i].Name, Resources.NVR_Success, Resources.NVR_Fail, Resources.NVR_Inspection); nvrStatuses.Add(nvrStatus); flowLayoutPanel.Controls.Add(nvrStatus); } } private void NVR_Runner() { Worker worker = new Worker(config); worker.UpdateMessage += UpdateMessage; worker.Start_NVR(); } private void CCTV_Runner() { Worker worker = new Worker(config); worker.UpdateMessage += UpdateMessage; worker.Start_CCTV(); } private void UpdateMessage(MessageSender sender, int from, StatusResult result) { Invoke((Action)(() => { switch (sender) { case MessageSender.NVR: nvrStatuses[from].StatusUpdate(result, DateTime.Now); if (result != StatusResult.Success) { Log.WriteLog(LogLevel.Trace, "NVR " + (result == StatusResult.Fail ? "Fail" : "Inspection") + " : " + config.NVR[from].Name + " / " + config.NVR[from].IpAddress); } break; case MessageSender.CCTV: if (result == StatusResult.Success) { listBox1.Items.Remove(config.CCTV[from].Name); listBox2.Items.Remove(config.CCTV[from].Name); } else if (result == StatusResult.Inspection) { if (!listBox1.Items.Contains((config.CCTV[from].Name))) { listBox1.Items.Add(config.CCTV[from].Name); } listBox2.Items.Remove(config.CCTV[from].Name); Log.WriteLog(LogLevel.Trace, "CCTV Inspection : " + config.CCTV[from].Name + " / " + config.CCTV[from].IpAddress); } else { listBox1.Items.Remove(config.CCTV[from].Name); if (!listBox2.Items.Contains(config.CCTV[from].Name)) { listBox2.Items.Add(config.CCTV[from].Name); } Log.WriteLog(LogLevel.Trace, "CCTV Fail : " + config.CCTV[from].Name + " / " + config.CCTV[from].IpAddress); } break; default: break; } })); } } }