예제 #1
0
        private void ckStartup_CheckedChanged(object sender, EventArgs e)
        {
            Configuration _config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

            _config.AppSettings.Settings["startTray"].Value = ckStartup.Checked.ToString();
            _config.Save();
            using (TaskService ts = new TaskService())
            {
                TaskDefinition td = ts.NewTask();
                td.RegistrationInfo.Description = "HardwareMonitorLite";
                td.Principal.RunLevel           = TaskRunLevel.Highest;
                td.Triggers.AddNew(TaskTriggerType.Logon);
                td.Actions.Add(new ExecAction(Application.ExecutablePath, null));
                if (ckStartup.Checked == true)
                {
                    ts.RootFolder.RegisterTaskDefinition("HardwareMonitorLite", td);
                    AppIcon.ShowBalloonTip(500, "Khởi động cùng windows !", "Start with windows ! ", ToolTipIcon.Info);
                }
                else
                {
                    ts.RootFolder.DeleteTask("HardwareMonitorLite");
                    AppIcon.ShowBalloonTip(500, "Không khởi động cùng windows!", "Does not start with windows ! ", ToolTipIcon.Info);
                }
            }
        }
예제 #2
0
 private void btnWired_Click(object sender, EventArgs e)
 {
     try
     {
         if (!serialPort1.IsOpen)
         {
             serialPort1.PortName = cbbCom.Text;
             Configuration _config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
             _config.AppSettings.Settings["port"].Value = cbbCom.Text;
             _config.Save();
             serialPort1.Open();
             btnWired.Text            = "Disconnect";
             btnWired.ForeColor       = Color.Red;
             lblStatusWired.Text      = "Connected";
             lblStatusWired.ForeColor = Color.Green;
             AppIcon.ShowBalloonTip(5000, "Kết nối thành công ", "Connection Successful", ToolTipIcon.Info);
         }
         else
         {
             serialPort1.Close();
             btnWired.Text            = "Connect";
             btnWired.ForeColor       = Color.Green;
             lblStatusWired.Text      = "Disconnect";
             lblStatusWired.ForeColor = Color.Red;
             AppIcon.ShowBalloonTip(5000, "Đã ngắt kết nối ", "Disconnected", ToolTipIcon.Warning);
         }
     }
     catch
     {
         AppIcon.ShowBalloonTip(5000, "Lỗi kêt nối", "Không tìm thấy COM", ToolTipIcon.Warning);
     }
 }
        private void btnWired_Click(object sender, EventArgs e)
        {
            Thread threadWired = new Thread(() =>
            {
                MethodInvoker method = delegate
                {
                    try
                    {
                        if (!serialPort1.IsOpen)
                        {
                            serialPort1.PortName  = cbbCom.Text;
                            Configuration _config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                            _config.AppSettings.Settings["port"].Value = cbbCom.Text;
                            _config.Save();
                            serialPort1.Open();
                            btnWired.Text            = "Disconnect";
                            btnWired.ForeColor       = Color.Red;
                            lblStatusWired.Text      = "Connected";
                            lblStatusWired.ForeColor = Color.Green;
                            AppIcon.ShowBalloonTip(2000, "Kết nối thành công ", "Connection Successful", ToolTipIcon.Info);
                            cbbCom.Enabled    = false;
                            btnReload.Enabled = false;
                        }
                        else
                        {
                            serialPort1.Close();
                            btnWired.Text            = "Connect";
                            btnWired.ForeColor       = Color.Black;
                            lblStatusWired.Text      = "Disconnect";
                            lblStatusWired.ForeColor = Color.Red;
                            AppIcon.ShowBalloonTip(2000, "Đã ngắt kết nối ", "Disconnected", ToolTipIcon.Warning);
                            cbbCom.Enabled    = true;
                            btnReload.Enabled = true;
                        }
                    }
                    catch
                    {
                        btnWired.Text            = "Connect";
                        btnWired.ForeColor       = Color.Black;
                        lblStatusWired.Text      = "Disconnect";
                        lblStatusWired.ForeColor = Color.Red;
                        AppIcon.ShowBalloonTip(2000, "Lỗi kêt nối", "Không tìm thấy PORT", ToolTipIcon.Warning);
                        cbbCom.Enabled = true;
                    }
                };

                if (InvokeRequired)
                {
                    BeginInvoke(method);
                }
                else
                {
                    method.Invoke();
                }
            });

            threadWired.IsBackground = true;
            threadWired.Start();
        }
예제 #4
0
        private void btnConnectWIFI_Click(object sender, EventArgs e)
        {
            if (btnConnectWIFI.Text == "Connect")
            {
                lblWIFIStatus.Text      = "Connecting...";
                lblWIFIStatus.ForeColor = Color.Black;
                btnConnectWIFI.Enabled  = false;

                try
                {
                    client.ConnectAsync(txtIP.Text, 80).Wait(5000);
                }
                catch
                {
                    AppIcon.ShowBalloonTip(5000, "Lỗi kêt nối", "Địa Chỉ IP không đúng !!", ToolTipIcon.Warning);
                    lblWIFIStatus.Text      = "Disconnected";
                    lblWIFIStatus.ForeColor = Color.Red;
                }
                if (client.Connected)
                {
                    txtIP.Enabled            = false;
                    btnConnectWIFI.Text      = "Disconnect";
                    btnConnectWIFI.ForeColor = Color.Red;
                    lblWIFIStatus.Text       = "Connected";
                    lblWIFIStatus.ForeColor  = Color.Green;
                    AppIcon.ShowBalloonTip(5000, "Kết nối thành công ", "Connection Successful", ToolTipIcon.Info);
                    Configuration _config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                    _config.AppSettings.Settings["ip"].Value = txtIP.Text;
                    _config.Save();
                }
                else
                {
                    AppIcon.ShowBalloonTip(5000, "Lỗi kêt nối", "Không tìm thấy server", ToolTipIcon.Warning);
                    lblWIFIStatus.Text      = "Disconnect";
                    lblWIFIStatus.ForeColor = Color.Red;
                    client.Close();
                    client = new TcpClient();
                }
            }
            else
            {
                txtIP.Enabled            = true;
                btnConnectWIFI.Text      = "Connect";
                btnConnectWIFI.ForeColor = Color.Black;
                lblWIFIStatus.Text       = "Disconnect";
                lblWIFIStatus.ForeColor  = Color.Red;
                client.Close();
                client = new TcpClient();
            }
            btnConnectWIFI.Enabled = true;
        }
예제 #5
0
        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            Configuration _config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

            _config.AppSettings.Settings["startTray"].Value = checkBox1.Checked.ToString();
            _config.Save();
            if (checkBox1.Checked)
            {
                AppIcon.ShowBalloonTip(500, "Sẽ chạy cùng Windows ", "Will run with Windows", ToolTipIcon.Info);
            }
            else
            {
                AppIcon.ShowBalloonTip(500, "Sẽ không chạy cùng Windows", "Will not run with Windows", ToolTipIcon.Info);
            }
        }
예제 #6
0
 private void Home_Resize(object sender, EventArgs e)
 {
     if (this.WindowState != FormWindowState.Normal)
     {
         this.Hide();
         AppIcon.ShowBalloonTip(500, "Đang Chạy Thu Nhỏ !", "Minimize to tray!", ToolTipIcon.Info);
     }
     else
     {
         //this.Visible = true;
         this.Show();
         this.WindowState = FormWindowState.Normal;
         this.Activate();
         this.Focus();
         this.ShowInTaskbar = true;
     }
 }
예제 #7
0
        public Main()
        {
            InitializeComponent();
            base.WindowState   = FormWindowState.Minimized;         // Thu nhỏ của sổ ngay từ lúc đầu mở ra
            base.ShowInTaskbar = false;                             // Không hiển thị trên thanh Taskbar
            base.Visible       = true;                              // Ẩn chương trình
            base.Hide();
            AddMenu();                                              // Tạo menu
            this.thisComputer.CPUEnabled       = true;
            this.thisComputer.GPUEnabled       = true;
            this.thisComputer.HDDEnabled       = true;
            this.thisComputer.MainboardEnabled = true;
            this.thisComputer.RAMEnabled       = true;
            this.thisComputer.Open();
            XmlDocument file = new XmlDocument();                   // Đọc địa chỉ từ file xml

            file.Load("ipAddress.xml");
            XmlNode ip = file.SelectNodes("/data/Address")[0];      // Chọn node Address

            if (ip.InnerText == "")                                 // Chưa có địa chỉ IP trong file
            {
                AppIcon.ShowBalloonTip(5000, "Lỗi kêt nối", "Không có địa chỉ IP để kết nối\r\nYêu cầu nhập địa chỉ IP của server", ToolTipIcon.Warning);
            }
            else
            {
                IPAddr.Text = ip.InnerText;                             // Đọc địa chỉ
                client.ConnectAsync(ip.InnerText, 80).Wait(3000);       // Thử kết nối với server, timeout 5000ms
                if (client.Connected)
                {
                    IPAddr.ReadOnly    = true;
                    connectButton.Text = "Disconnect";
                    status.Text        = "Connected";
                    status.ForeColor   = Color.Green;
                    timer.Enabled      = true;
                }
                else
                {
                    AppIcon.ShowBalloonTip(5000, "Lỗi kêt nối", "Không tìm thấy server", ToolTipIcon.Warning);
                    client.Close();
                    client = new TcpClient();
                }
            }
        }
예제 #8
0
        /*--------------------------------------------------------------------------------------*/

        private void connectButton_Click(object sender, EventArgs e)
        {
            if (connectButton.Text == "Connect")
            {
                status.Text           = "Connecting...";
                status.ForeColor      = Color.Black;
                connectButton.Enabled = false;
                client.ConnectAsync(IPAddr.Text, 80).Wait(5000);       // Thử kết nối với server, timeout 5000ms
                if (client.Connected)
                {
                    IPAddr.Enabled     = false;
                    connectButton.Text = "Disconnect";
                    status.Text        = "Connected";
                    status.ForeColor   = Color.Green;
                    XmlDocument file = new XmlDocument();                   // Load file XML
                    file.Load("ipAddress.xml");
                    XmlNode ip = file.SelectNodes("/data/Address")[0];      // Chọn node Address
                    ip.InnerText = IPAddr.Text;                             // Thay đổi địa chỉ
                    file.Save("ipAddress.xml");                             // Lưu địa chỉ IP
                    timer.Enabled = true;
                }
                else
                {
                    AppIcon.ShowBalloonTip(5000, "Lỗi kêt nối", "Không tìm thấy server", ToolTipIcon.Warning);
                    status.Text      = "Disconnected";
                    status.ForeColor = Color.Red;
                    client.Close();
                    client = new TcpClient();
                }
            }
            else
            {
                IPAddr.Enabled     = true;
                timer.Enabled      = false;
                connectButton.Text = "Connect";
                status.Text        = "Disconnected";
                status.ForeColor   = Color.Red;
                client.Close();
                client = new TcpClient();
            }
            connectButton.Enabled = true;
        }
예제 #9
0
        public Home()
        {
            InitializeComponent();
            timer.Interval = 1000;
            timer.Start();

            AddMenu();
            this.thisComputer.IsCpuEnabled         = true;
            this.thisComputer.IsGpuEnabled         = true;
            this.thisComputer.IsStorageEnabled     = true;
            this.thisComputer.IsMotherboardEnabled = true;
            this.thisComputer.IsMemoryEnabled      = true;
            this.thisComputer.IsNetworkEnabled     = true;
            this.thisComputer.Open();
            /*AUTO*/
            if (ConfigurationManager.AppSettings["autoConnectWifi"].ToString().ToLower().Equals("true"))
            {
                swWifiAuto.Value = true;
            }
            else
            {
                swWifiAuto.Value = false;
            }
            if (ConfigurationManager.AppSettings["autoConnectWired"].ToString().ToLower().Equals("true"))
            {
                swWiredAuto.Value = true;
            }
            else
            {
                swWiredAuto.Value = false;
            }
            if (ConfigurationManager.AppSettings["startTray"].ToString().ToLower().Equals("true"))
            {
                checkBox1.Checked = true;
            }
            if (ConfigurationManager.AppSettings["state"].ToString().ToLower().Equals("true"))
            {
                base.WindowState   = FormWindowState.Minimized;
                base.ShowInTaskbar = false;
                checkBox2.Checked  = true;
            }
            else
            {
                base.WindowState   = FormWindowState.Normal;
                base.ShowInTaskbar = true;
                checkBox2.Checked  = false;
            }
            /*WIRED*/
            serialPort1.BaudRate  = 9600;
            serialPort1.Parity    = Parity.None;
            serialPort1.StopBits  = StopBits.One;
            serialPort1.DataBits  = 8;
            serialPort1.Handshake = Handshake.None;
            serialPort1.RtsEnable = true;
            string[] ports = SerialPort.GetPortNames();
            foreach (string port in ports)
            {
                cbbCom.Items.Add(port);
            }
            cbbCom.SelectedIndex = cbbCom.Items.IndexOf(ConfigurationManager.AppSettings["port"].ToString());
            if (swWiredAuto.Value == true)
            {
                if (cbbCom.Text != "")
                {
                    try
                    {
                        serialPort1.PortName = cbbCom.Text;
                        if (!serialPort1.IsOpen)
                        {
                            serialPort1.Open();
                            btnWired.Text            = "Disconnect";
                            btnWired.ForeColor       = Color.Red;
                            lblStatusWired.Text      = "Connected";
                            lblStatusWired.ForeColor = Color.Green;
                            AppIcon.ShowBalloonTip(5000, "Kết nối thành công ", "Connection Successful", ToolTipIcon.Info);
                        }
                    }
                    catch
                    {
                        AppIcon.ShowBalloonTip(5000, "Lỗi kêt nối", "Không tìm thấy Port", ToolTipIcon.Warning);
                        lblStatusWired.Text      = "Disconnected";
                        lblStatusWired.ForeColor = Color.Red;
                    }
                }
            }
            /*WIFI*/
            string ip = ConfigurationManager.AppSettings["ip"].ToString();

            if (ip != "")
            {
                txtIP.Text = ip;
            }
            if (swWifiAuto.Value == true)
            {
                if (ip == "")
                {
                    AppIcon.ShowBalloonTip(5000, "Lỗi kêt nối", "Không có địa chỉ IP để kết nối\r\nYêu cầu nhập địa chỉ IP của server", ToolTipIcon.Warning);
                }
                else
                {
                    client.ConnectAsync(ip, 80).Wait(3000);
                    if (client.Connected)
                    {
                        txtIP.Enabled       = false;
                        btnConnectWIFI.Text = "Disconnect";
                        //btnConnectWIFI.BackColor = Color.Red;
                        lblStatusWifi.Text      = "Connected";
                        lblStatusWifi.ForeColor = Color.Green;
                        AppIcon.ShowBalloonTip(5000, "Kết nối thành công ", "Connection Successful", ToolTipIcon.Info);
                    }
                    else
                    {
                        AppIcon.ShowBalloonTip(5000, "Lỗi kêt nối", "Không tìm thấy server", ToolTipIcon.Warning);
                        client.Close();
                        lblStatusWifi.Text      = "Disconnected";
                        lblStatusWifi.ForeColor = Color.Red;
                        client = new TcpClient();
                    }
                }
            }
        }
예제 #10
0
        private void timer_Tick(object sender, EventArgs e)
        {
            string cpuName = "", gpuName = "";
            float  cpuLoad = 0, cpuTemp = 0;
            float  gpuLoad = 0, gpuTemp = 0, gpuFan = 0, gpuFanLoad = 0;
            float  ramLoad = 0, ramUse = 0, totalRam = 0, x, y;

            /*-------------------------------------Read Info-------------------------------------*/
            foreach (var hardware in thisComputer.Hardware)
            {
                hardware.Update();
                /*---------------------------------CPU---------------------------------*/
                if (hardware.HardwareType == HardwareType.Cpu)
                {
                    cpuName         = hardware.Name;
                    lblCPUName.Text = cpuName;
                    foreach (var sensor in hardware.Sensors)
                    {
                        if (sensor.SensorType == SensorType.Load && sensor.Name == "CPU Total")
                        {
                            cpuLoad = sensor.Value.Value;
                            int load = (int)cpuLoad;
                            psCPULoad.Value = load;
                            lblCPULoad.Text = load.ToString();
                        }

                        if (sensor.SensorType == SensorType.Temperature && sensor.Name == "CPU Package")
                        {
                            cpuTemp = sensor.Value.GetValueOrDefault();
                            int temp = (int)cpuTemp;
                            psCPUTemp.Value = temp;
                            lblCpuTemp.Text = temp.ToString();
                        }
                    }
                }

                /*---------------------------------RAM---------------------------------*/
                if (hardware.HardwareType == HardwareType.Memory)
                {
                    foreach (var sensor in hardware.Sensors)
                    {
                        if (sensor.SensorType == SensorType.Load && sensor.Name == "Memory")
                        {
                            ramLoad = sensor.Value.Value;
                            int load = (int)ramLoad;
                            psRamLoad.Value = load;
                            lblRamLoad.Text = load.ToString();
                        }
                        if (sensor.SensorType == SensorType.Data && sensor.Name == "Memory Used")
                        {
                            ramUse = sensor.Value.GetValueOrDefault();
                            double ram = Math.Round(ramUse, 2);
                            lblRamUse.Text = ram.ToString();
                        }
                        if (sensor.SensorType == SensorType.Data && sensor.Name == "Memory Available")
                        {
                            float ramAva = sensor.Value.GetValueOrDefault();
                            totalRam = ramAva + ramUse;
                            double ram = Math.Round(totalRam);
                            lblRamTotal.Text = ram.ToString() + " GB";
                        }
                    }
                }

                /*---------------------------------GPU---------------------------------*/
                if (hardware.HardwareType == HardwareType.GpuAmd || hardware.HardwareType == HardwareType.GpuNvidia)
                {
                    gpuName         = hardware.Name;
                    lblGPUName.Text = gpuName;
                    foreach (var sensor in hardware.Sensors)
                    {
                        if (sensor.SensorType == SensorType.Load && sensor.Name == "GPU Core")
                        {
                            gpuLoad = sensor.Value.Value;
                            int load = (int)gpuLoad;
                            psGPULoad.Value = load;
                            lblGPULoad.Text = load.ToString();
                        }

                        if (sensor.SensorType == SensorType.Temperature && sensor.Name == "GPU Core")
                        {
                            gpuTemp         = sensor.Value.GetValueOrDefault();
                            psGPUTemp.Value = (int)gpuTemp;
                            lblGPUTemp.Text = gpuTemp.ToString();
                        }
                        if (sensor.SensorType == SensorType.Fan && sensor.Name == "GPU Fan")
                        {
                            gpuFan         = sensor.Value.GetValueOrDefault();
                            lblGPUFan.Text = ((int)gpuFan).ToString();
                        }
                        if (sensor.SensorType == SensorType.Control && sensor.Name == "GPU Fan")
                        {
                            gpuFanLoad = sensor.Value.GetValueOrDefault();
                            int fanLoad = (int)gpuFanLoad;
                            psGPUFanLoad.Value = fanLoad;
                        }
                    }
                }
            }
            foreach (NetworkInterface inf in interfaces)
            {
                if (inf.OperationalStatus == OperationalStatus.Up &&
                    inf.NetworkInterfaceType != NetworkInterfaceType.Loopback &&
                    inf.NetworkInterfaceType != NetworkInterfaceType.Tunnel &&
                    inf.NetworkInterfaceType != NetworkInterfaceType.Unknown && !inf.IsReceiveOnly)
                {
                    byteRec  = inf.GetIPv4Statistics().BytesReceived;
                    byteSent = inf.GetIPv4Statistics().BytesSent;
                }
            }
            x       = byteRec - oldRec;
            y       = byteSent - oldSent;
            oldRec  = byteRec;
            oldSent = byteSent;
            string strNw = (x / 1048576).ToString("F2") + "/" + (y / 1048576).ToString("F2");

            if (strNw.Length > 10)
            {
                strNw = "Connecting...";
            }
            else
            {
                lblNet.Text = strNw + " Mb/s";
            }

            Processor dataCPU = new Processor
            {
                Name = cpuName,
                Load = Math.Round(cpuLoad, 1),
                Temp = Math.Round(cpuTemp, 1)
            };
            Graphic dataGPU = new Graphic
            {
                Name    = gpuName,
                Load    = Math.Round(gpuLoad, 1),
                Temp    = Math.Round(gpuTemp, 1),
                FanLoad = Math.Round(gpuFan, 1),
                Fan     = Math.Round(gpuFanLoad, 1)
            };
            Ram dataRam = new Ram
            {
                Total = Math.Round(totalRam),
                Use   = Math.Round(ramUse, 1),
                Load  = Math.Round(ramLoad, 1)
            };
            Net dataNet = new Net
            {
                net = strNw
            };
            Infomation info = new Infomation
            {
                CPU = dataCPU,
                GPU = dataGPU,
                RAM = dataRam,
                Net = dataNet
            };
            string obj = JsonConvert.SerializeObject(info);

            /*---------------------------------Send DATA---------------------------------*/
            if (lblStatusWifi.Text == "Connected")
            {
                try
                {
                    NetworkStream stream = client.GetStream();
                    byte[]        data   = Encoding.ASCII.GetBytes(obj + "\r\n");
                    stream.Write(data, 0, data.Length);
                }
                catch (Exception)
                {
                    AppIcon.ShowBalloonTip(5000, "Mất kêt nối", "Kiểm tra lại server", ToolTipIcon.Warning);
                    txtIP.Enabled           = true;
                    timer.Enabled           = false;
                    btnConnectWIFI.Text     = "Connect";
                    lblStatusWifi.Text      = "Disconnected";
                    lblStatusWifi.ForeColor = Color.Red;
                    client.Close();
                    client.Close();
                    client = new TcpClient();
                }
            }
            if (lblStatusWired.Text == "Connected")
            {
                serialPort1.Write(obj);
            }
        }
예제 #11
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            foreach (var hardware in thisComputer.Hardware)
            {
                hardware.Update();
                /*---------------------------------CPU---------------------------------*/
                if (hardware.HardwareType == HardwareType.Cpu)
                {
                    cpuName = hardware.Name;
                    foreach (var sensor in hardware.Sensors)
                    {
                        if (sensor.SensorType == SensorType.Load && sensor.Name == "CPU Total")
                        {
                            cpuLoad = sensor.Value.Value;
                        }

                        if (sensor.SensorType == SensorType.Temperature && sensor.Name == "CPU Package")
                        {
                            cpuTemp = sensor.Value.GetValueOrDefault();
                        }
                    }
                }
                /*---------------------------------GPU---------------------------------*/
                if (hardware.HardwareType == HardwareType.GpuAmd || hardware.HardwareType == HardwareType.GpuNvidia)
                {
                    gpuName = hardware.Name;
                    foreach (var sensor in hardware.Sensors)
                    {
                        if (sensor.SensorType == SensorType.Load && sensor.Name == "GPU Core")
                        {
                            gpuLoad = sensor.Value.Value;
                        }

                        if (sensor.SensorType == SensorType.Temperature && sensor.Name == "GPU Core")
                        {
                            gpuTemp = sensor.Value.GetValueOrDefault();
                        }
                        if (sensor.SensorType == SensorType.Fan && sensor.Name == "GPU Fan")
                        {
                            gpuFan = sensor.Value.GetValueOrDefault();
                        }
                        if (sensor.SensorType == SensorType.Control && sensor.Name == "GPU Fan")
                        {
                            gpuFanLoad = sensor.Value.GetValueOrDefault();
                        }
                    }
                }
                /*---------------------------------RAM---------------------------------*/
                if (hardware.HardwareType == HardwareType.Memory)
                {
                    foreach (var sensor in hardware.Sensors)
                    {
                        if (sensor.SensorType == SensorType.Load && sensor.Name == "Memory")
                        {
                            ramLoad = sensor.Value.Value;
                        }
                        if (sensor.SensorType == SensorType.Data && sensor.Name == "Memory Used")
                        {
                            ramUse = sensor.Value.GetValueOrDefault();
                        }
                        if (sensor.SensorType == SensorType.Data && sensor.Name == "Memory Available")
                        {
                            float ramAva = sensor.Value.GetValueOrDefault();
                            totalRam = ramAva + ramUse;
                        }
                    }
                }
                /*---------------------------------Connection---------------------------------*/
                if (hardware.HardwareType == HardwareType.Network)
                {
                    foreach (var sensor in hardware.Sensors)
                    {
                        if (sensor.SensorType == SensorType.Throughput && sensor.Name == "Upload Speed")
                        {
                            upload = (sensor.Value.GetValueOrDefault()) * 8 / 1048576;
                        }
                        if (sensor.SensorType == SensorType.Throughput && sensor.Name == "Download Speed")
                        {
                            download = (sensor.Value.GetValueOrDefault()) * 8 / 1048576;
                        }
                        strNw = Math.Round(download, 2).ToString("F2") + "/" + Math.Round(upload, 2).ToString("F2");
                        if (strNw.Length > 10)
                        {
                            strNw = "Connecting...";
                        }
                    }
                }
                /*---------------------------------Drive---------------------------------*/
                if (hardware.Name == "WDC WD10EZEX-00WN4A0")
                {
                    foreach (var sensor in hardware.Sensors)
                    {
                        hdd = hardware.Name;
                        if (sensor.SensorType == SensorType.Load && sensor.Name == "Total Activity")
                        {
                            hddLoad = sensor.Value.Value;
                        }
                        if (sensor.SensorType == SensorType.Temperature && sensor.Name == "Temperature")
                        {
                            hddTemp = sensor.Value.GetValueOrDefault();
                        }
                        if (sensor.SensorType == SensorType.Load && sensor.Name == "Used Space")
                        {
                            hddUse = sensor.Value.GetValueOrDefault();
                        }
                    }
                }

                if (hardware.Name == "Samsung SSD 960 EVO 250GB")
                {
                    foreach (var sensor in hardware.Sensors)
                    {
                        ssd = hardware.Name.Substring(0, 19);
                        if (sensor.SensorType == SensorType.Load && sensor.Name == "Total Activity")
                        {
                            ssdLoad = sensor.Value.Value;
                        }
                        if (sensor.SensorType == SensorType.Temperature && sensor.Name == "Temperature")
                        {
                            ssdTemp = sensor.Value.GetValueOrDefault();
                        }
                        if (sensor.SensorType == SensorType.Load && sensor.Name == "Used Space")
                        {
                            ssdUse = sensor.Value.GetValueOrDefault();
                        }
                    }
                }

                if (hardware.HardwareType == HardwareType.Heatmaster)
                {
                    foreach (var sensor in hardware.Sensors)
                    {
                        if (sensor.SensorType == SensorType.Load && sensor.Name == "CPU Total")
                        {
                            cpuLoad = sensor.Value.Value;
                        }

                        if (sensor.SensorType == SensorType.Temperature && sensor.Name == "CPU Package")
                        {
                            cpuTemp = sensor.Value.GetValueOrDefault();
                        }
                    }
                }
                /*---------------------------------Display---------------------------------*/
                grCPU.Text      = cpuName;
                txtLoadCPU.Text = Math.Round(cpuLoad).ToString() + " %";
                txtTempCPU.Text = Math.Round(cpuTemp).ToString() + " °C";

                grGPU.Text      = gpuName;
                txtLoadGPU.Text = Math.Round(gpuLoad).ToString() + " %";
                txtTempGPU.Text = Math.Round(gpuTemp).ToString() + " °C";
                txtFanGPU.Text  = Math.Round(gpuFan).ToString() + " RPM";

                txtTotalRam.Text = Math.Round(totalRam).ToString() + " GB";
                txtRamUse.Text   = Math.Round(ramUse).ToString() + " GB";
                txtRamLoad.Text  = Math.Round(ramLoad).ToString() + " %";

                txtDown.Text = Math.Round(download, 2).ToString("F2") + " MB/s";
                txtUp.Text   = Math.Round(upload, 2).ToString("F2") + " MB/s";

                grHDD.Text      = hdd;
                txtHddLoad.Text = Math.Round(hddLoad).ToString() + " %";
                txtHddUse.Text  = Math.Round(hddUse).ToString() + " %";
                txtHddTemp.Text = Math.Round(hddTemp).ToString() + " °C";

                grSSD.Text      = ssd;
                txtSsdLoad.Text = Math.Round(ssdLoad).ToString() + " %";
                txtSsdUse.Text  = Math.Round(ssdUse).ToString() + " %";
                txtSsdTemp.Text = Math.Round(ssdTemp).ToString() + " °C";
                /*---------------------------------Send DATA---------------------------------*/
            }
            Processor dataCPU = new Processor
            {
                Name = cpuName,
                Load = Math.Round(cpuLoad, 1),
                Temp = Math.Round(cpuTemp, 1)
            };
            Graphic dataGPU = new Graphic
            {
                Name = gpuName,
                Load = Math.Round(gpuLoad, 1),
                Temp = Math.Round(gpuTemp, 1),
            };
            Ram dataRam = new Ram
            {
                Use = Math.Round(ramUse).ToString() + "/" + Math.Round(totalRam).ToString()
            };
            Connection dataNet = new Connection
            {
                Speed = strNw
            };
            HDD infoHDD = new HDD
            {
                Name = hdd,
                Use  = Math.Round(hddUse),
                Load = Math.Round(hddLoad),
                Temp = Math.Round(hddTemp)
            };
            SSD infoSSD = new SSD
            {
                Name = ssd,
                Use  = Math.Round(ssdUse),
                Load = Math.Round(ssdLoad),
                Temp = Math.Round(ssdTemp)
            };
            Infomation info = new Infomation
            {
                CPU      = dataCPU,
                GPU      = dataGPU,
                RAM      = dataRam,
                Net      = dataNet,
                hddDrive = infoHDD,
                ssdDrive = infoSSD
            };
            string obj = JsonConvert.SerializeObject(info);

            if (lblWIFIStatus.Text == "Connected")
            {
                try
                {
                    NetworkStream stream = client.GetStream();
                    byte[]        data   = Encoding.ASCII.GetBytes(obj + "\r\n");
                    stream.Write(data, 0, data.Length);
                }
                catch (Exception)
                {
                    AppIcon.ShowBalloonTip(5000, "Mất kêt nối", "Kiểm tra lại server", ToolTipIcon.Warning);
                    txtIP.Enabled           = true;
                    timer1.Enabled          = false;
                    btnConnectWIFI.Text     = "Connect";
                    lblWIFIStatus.Text      = "Disconnected";
                    lblWIFIStatus.ForeColor = Color.Red;
                    client.Close();
                    client = new TcpClient();
                }
            }
            if (lblStatusWired.Text == "Connected")
            {
                a = dataCPU.Name + "," + dataCPU.Load + "," + dataCPU.Temp + "," + dataGPU.Name + "," + dataGPU.Load + "," + dataGPU.Temp + "," + dataRam.Use + "," + dataNet.Speed + "," + infoHDD.Name + "," + infoHDD.Use + "," + infoHDD.Load + "," + infoHDD.Temp + "," + infoSSD.Name + "," + infoSSD.Use + "," + infoSSD.Load + "," + infoSSD.Temp + "*";
                serialPort1.Write(a);
            }
        }
예제 #12
0
        private void timer_Tick(object sender, EventArgs e)
        {
            /*-------------------------------------Đọc thông số-------------------------------------*/
            String cpuName = "", gpuName = "";
            float  cpuLoad = 0, cpuTemp = 0, ramLoad = 0, gpuLoad = 0, gpuTemp = 0;

            foreach (var hardware in thisComputer.Hardware)
            {
                hardware.Update();
                /*---------------------------------CPU---------------------------------*/
                if (hardware.HardwareType == HardwareType.CPU)
                {
                    cpuName = hardware.Name;
                    foreach (var sensor in hardware.Sensors)
                    {
                        if (sensor.SensorType == SensorType.Load)
                        {
                            cpuLoad = sensor.Value.Value;
                        }
                        if (sensor.SensorType == SensorType.Temperature)
                        {
                            cpuTemp = sensor.Value.GetValueOrDefault();
                        }
                    }
                }

                /*---------------------------------RAM---------------------------------*/
                if (hardware.HardwareType == HardwareType.RAM)
                {
                    foreach (var sensor in hardware.Sensors)
                    {
                        if (sensor.SensorType == SensorType.Load)
                        {
                            ramLoad = sensor.Value.Value;
                        }
                    }
                }

                /*---------------------------------GPU---------------------------------*/
                if (hardware.HardwareType == HardwareType.GpuAti || hardware.HardwareType == HardwareType.GpuNvidia)
                {
                    gpuName = hardware.Name;
                    foreach (var sensor in hardware.Sensors)
                    {
                        if (sensor.SensorType == SensorType.Load && sensor.Name == "GPU Core")
                        {
                            gpuLoad = sensor.Value.Value;
                        }
                        if (sensor.SensorType == SensorType.Temperature)
                        {
                            gpuTemp = sensor.Value.GetValueOrDefault();
                        }
                    }
                }
            }
            /*------------------------------Serialize------------------------------*/
            Processor dataCPU = new Processor
            {
                Name = cpuName,
                Load = Math.Round(cpuLoad, 1),
                Temp = Math.Round(cpuTemp, 1)
            };
            Graphic dataGPU = new Graphic
            {
                Name = gpuName,
                Load = Math.Round(gpuLoad, 1),
                Temp = Math.Round(gpuTemp, 1)
            };
            Infomation info = new Infomation
            {
                CPU = dataCPU,
                RAM = Math.Round(ramLoad, 1),
                GPU = dataGPU
            };
            string obj = JsonConvert.SerializeObject(info);

            /*---------------------------------------------------------------------------------------*/
            try
            {
                NetworkStream stream = client.GetStream();
                byte[]        data   = Encoding.ASCII.GetBytes(obj + "\r\n");
                stream.Write(data, 0, data.Length);
            }
            catch (Exception)
            {
                AppIcon.ShowBalloonTip(5000, "Mất kêt nối", "Kiểm tra lại server", ToolTipIcon.Warning);
                IPAddr.Enabled     = true;
                timer.Enabled      = false;
                connectButton.Text = "Connect";
                status.Text        = "Disconnected";
                status.ForeColor   = Color.Red;
                client.Close();
                client = new TcpClient();
            }
        }
        private void btnConnectWIFI_Click(object sender, EventArgs e)
        {
            Thread threadWIFI = new Thread(() =>
            {
                MethodInvoker method = delegate
                {
                    if (btnConnectWIFI.Text == "Connect")
                    {
                        lblWIFIStatus.Text      = "Connecting...";
                        lblWIFIStatus.ForeColor = Color.Black;
                        btnConnectWIFI.Enabled  = false;
                        try
                        {
                            client.ConnectAsync(txtIP.Text, 80).Wait(3000);
                            if (client.Connected)
                            {
                                txtIP.Enabled            = false;
                                btnConnectWIFI.Text      = "Disconnect";
                                btnConnectWIFI.ForeColor = Color.Red;
                                lblWIFIStatus.Text       = "Connected";
                                lblWIFIStatus.ForeColor  = Color.Green;
                                AppIcon.ShowBalloonTip(5000, "Kết nối thành công ", "Connection Successful", ToolTipIcon.Info);
                                Configuration _config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                                _config.AppSettings.Settings["ip"].Value = txtIP.Text;
                                _config.Save();
                            }
                            else
                            {
                                AppIcon.ShowBalloonTip(5000, "Lỗi kêt nối", "Địa Chỉ IP không đúng !!", ToolTipIcon.Warning);
                                lblWIFIStatus.Text      = "Disconnected";
                                lblWIFIStatus.ForeColor = Color.Red;
                                client.Close();
                                client = new TcpClient();
                            }
                        }
                        catch
                        {
                            AppIcon.ShowBalloonTip(5000, "Lỗi kêt nối", "Địa Chỉ IP không đúng !!", ToolTipIcon.Warning);
                            lblWIFIStatus.Text      = "Disconnected";
                            lblWIFIStatus.ForeColor = Color.Red;
                            client.Close();
                            client = new TcpClient();
                        }
                    }
                    else
                    {
                        txtIP.Enabled            = true;
                        btnConnectWIFI.Text      = "Connect";
                        btnConnectWIFI.ForeColor = Color.Black;
                        lblWIFIStatus.Text       = "Disconnect";
                        lblWIFIStatus.ForeColor  = Color.Red;
                        client.Close();
                        client = new TcpClient();
                    }
                    btnConnectWIFI.Enabled = true;
                };

                if (InvokeRequired)
                {
                    BeginInvoke(method);
                }
                else
                {
                    method.Invoke();
                }
            });

            threadWIFI.IsBackground = true;
            threadWIFI.Start();
        }
        private void timer1_Tick(object sender, EventArgs e)
        {
            var ListDisk          = new List <diskDrive>();
            var dataCpu           = new Processor();
            var dataGpu           = new Graphic();
            var dataRam           = new Ram();
            var dataInternetSpeed = new InternetSpeed();

            foreach (var hardware in thisComputer.Hardware)
            {
                hardware.Update();
                /*---------------------------------CPU---------------------------------*/
                if (hardware.HardwareType == HardwareType.Cpu)
                {
                    dataCpu.Name = hardware.Name;
                    foreach (var sensor in hardware.Sensors)
                    {
                        if (sensor.SensorType == SensorType.Load && sensor.Name == "CPU Total")
                        {
                            dataCpu.Load = Convert.ToInt32(sensor.Value.Value);
                        }

                        if (sensor.SensorType == SensorType.Temperature && sensor.Name == "CPU Package")
                        {
                            dataCpu.Temp = Convert.ToInt32(sensor.Value.Value);
                        }
                    }
                }
                /*---------------------------------GPU---------------------------------*/
                if (hardware.HardwareType == HardwareType.GpuAmd || hardware.HardwareType == HardwareType.GpuNvidia)
                {
                    dataGpu.Name = hardware.Name;
                    foreach (var sensor in hardware.Sensors)
                    {
                        if (sensor.SensorType == SensorType.Load && sensor.Name == "GPU Core")
                        {
                            dataGpu.Load = Convert.ToInt32(sensor.Value.Value);
                        }
                        if (sensor.SensorType == SensorType.Temperature && sensor.Name == "GPU Core")
                        {
                            dataGpu.Temp = Convert.ToInt32(sensor.Value.Value);
                        }
                        if (sensor.SensorType == SensorType.Fan && sensor.Name == "GPU Fan")
                        {
                            dataGpu.Fan = Convert.ToInt32(sensor.Value.Value);
                        }
                        if (sensor.SensorType == SensorType.Control && sensor.Name == "GPU Fan")
                        {
                            dataGpu.FanLoad = Convert.ToInt32(sensor.Value.Value);
                        }
                    }
                }
                /*---------------------------------RAM---------------------------------*/
                if (hardware.HardwareType == HardwareType.Memory)
                {
                    foreach (var sensor in hardware.Sensors)
                    {
                        if (sensor.SensorType == SensorType.Load && sensor.Name == "Memory")
                        {
                            dataRam.RamLoad = Convert.ToInt32(sensor.Value.Value);
                        }
                        if (sensor.SensorType == SensorType.Data && sensor.Name == "Memory Used")
                        {
                            dataRam.RamUse = Convert.ToInt32(sensor.Value.Value);
                        }
                        if (sensor.SensorType == SensorType.Data && sensor.Name == "Memory Available")
                        {
                            int ramAva = Convert.ToInt32(sensor.Value.Value);
                            dataRam.RamTotal = ramAva + dataRam.RamUse;
                        }
                    }
                }
                /*---------------------------------Connection---------------------------------*/
                if (hardware.HardwareType == HardwareType.Network)
                {
                    foreach (var sensor in hardware.Sensors)
                    {
                        if (sensor.SensorType == SensorType.Throughput && sensor.Name == "Upload Speed")
                        {
                            dataInternetSpeed.UpSpeed = Math.Round(sensor.Value.Value, 1) / 1048576;
                        }
                        if (sensor.SensorType == SensorType.Throughput && sensor.Name == "Download Speed")
                        {
                            dataInternetSpeed.DownloadSpeed = Math.Round(sensor.Value.Value, 1) / 1048576;
                        }
                    }
                }
                /*---------------------------------DISK---------------------------------*/
                if (hardware.HardwareType == HardwareType.Storage)
                {
                    int use = 0, load = 0, temp = 0;
                    foreach (ISensor sensor in hardware.Sensors)
                    {
                        if (sensor.SensorType == SensorType.Load && sensor.Name == "Used Space")
                        {
                            use = Convert.ToInt32(sensor.Value.GetValueOrDefault());
                        }
                        if (sensor.SensorType == SensorType.Load && sensor.Name == "Total Activity")
                        {
                            load = Convert.ToInt32(sensor.Value.GetValueOrDefault());
                        }
                        if (sensor.SensorType == SensorType.Temperature && sensor.Name == "Temperature")
                        {
                            temp = Convert.ToInt32(sensor.Value.GetValueOrDefault());
                        }
                    }
                    var disk = new diskDrive();
                    disk.Name = hardware.Name;
                    disk.Use  = use;
                    disk.Load = load;
                    disk.Temp = temp;
                    ListDisk.Add(disk);
                }
                /*---------------------------------Display---------------------------------*/
                grCPU.Text      = dataCpu.Name;
                txtLoadCPU.Text = dataCpu.Load.ToString() + " %";
                txtTempCPU.Text = dataCpu.Temp.ToString() + " °C";

                grGPU.Text      = dataGpu.Name;
                txtLoadGPU.Text = dataGpu.Load.ToString() + " %";
                txtTempGPU.Text = dataGpu.Temp.ToString() + " °C";
                txtFanGPU.Text  = dataGpu.Fan.ToString() + " RPM";

                txtTotalRam.Text = dataRam.RamTotal.ToString() + " GB";
                txtRamUse.Text   = dataRam.RamUse.ToString() + " GB";
                txtRamLoad.Text  = dataRam.RamLoad.ToString() + " %";

                txtDown.Text = dataInternetSpeed.DownloadSpeed.ToString("F1") + " MB/s";
                txtUp.Text   = dataInternetSpeed.UpSpeed.ToString("F1") + " MB/s";
                //int i = 1;
                //foreach(var item in ListDisk)
                //{
                //    i++;
                //    int Index = KiemTraTonTai(tabControl2, item[i].Name);
                //    if (Index >= 0)
                //    {
                //        break;
                //    }
                //    else
                //    {
                //        TabPage TabPage = new TabPage { Text = item.Name };
                //        tabControl2.TabPages.Add(TabPage);
                //      //  tabControl2.SelectedTab = TabPage;
                //    }
                //}
                for (int i = 0; i < ListDisk.Count; i++)
                {
                    bool Index = KiemTraTonTai(tabControl2, ListDisk[i].Name);
                    if (Index)
                    {
                        // break;
                    }
                    else
                    {
                        TabPage TabPageDisk = new TabPage {
                            Text = ListDisk[i].Name
                        };
                        Label diskName = new Label();
                        diskName.Width = 200;
                        // diskName.BackColor(Color.Red);
                        diskName.Text = ListDisk[i].Name;
                        TabPageDisk.Controls.Add(diskName);

                        tabControl2.TabPages.Add(TabPageDisk);
                        //  tabControl2.SelectedTab = TabPage;
                        //tabControl2.Dock = DockStyle.;
                    }
                }
                /*---------------------------------Send DATA---------------------------------*/
            }
            Infomation info = new Infomation
            {
                CPU   = dataCpu,
                GPU   = dataGpu,
                RAM   = dataRam,
                Speed = dataInternetSpeed,
                disk  = ListDisk
            };
            string obj = JsonConvert.SerializeObject(info);

            if (lblWIFIStatus.Text == "Connected")
            {
                try
                {
                    NetworkStream stream = client.GetStream();
                    byte[]        data   = Encoding.ASCII.GetBytes(obj + "\r\n");
                    stream.Write(data, 0, data.Length);
                }
                catch (Exception)
                {
                    AppIcon.ShowBalloonTip(5000, "Mất kêt nối", "Kiểm tra lại server", ToolTipIcon.Warning);
                    txtIP.Enabled           = true;
                    timer1.Enabled          = false;
                    btnConnectWIFI.Text     = "Connect";
                    lblWIFIStatus.Text      = "Disconnected";
                    lblWIFIStatus.ForeColor = Color.Red;
                    client.Close();
                    client = new TcpClient();
                }
            }
            if (lblStatusWired.Text == "Connected")
            {
                //a = dataCPU.Name + "," + dataCPU.Load + "," + dataCPU.Temp + "," + dataGPU.Name + "," + dataGPU.Load + "," + dataGPU.Temp + "," + dataRam.Use + "," + dataNet.Speed + "*";
                serialPort1.Write(a);
                serialPort1.DataReceived += new System.IO.Ports.SerialDataReceivedEventHandler(Data);
            }
        }