diff --git a/src/Project/Sucrose.Backgroundog/Helper/Specification.cs b/src/Project/Sucrose.Backgroundog/Helper/Specification.cs index 8bc7e3e96..fef149e4c 100644 --- a/src/Project/Sucrose.Backgroundog/Helper/Specification.cs +++ b/src/Project/Sucrose.Backgroundog/Helper/Specification.cs @@ -164,32 +164,40 @@ public static async Task Start() { try { - if (SSSHN.GetHostEntry()) + if (SBMI.PingManagement) { - List Hosts = SSSHN.GetHost(); + SBMI.PingManagement = false; - foreach (SSDSHS Host in Hosts) + if (SSSHN.GetHostEntry()) { - if (SMMM.PingType == Host.Name) + List Hosts = SSSHN.GetHost(); + + foreach (SSDSHS Host in Hosts) { - SBMI.NetworkData.PingData = SSEPPE.Send(Host.Address, 1000); + if (SMMM.PingType == Host.Name) + { + SBMI.NetworkData.PingData = SSEPPE.Send(Host.Address, 1000); - SBMI.NetworkData.Host = Host.Address; - SBMI.NetworkData.Ping = SBMI.NetworkData.PingData.RoundTrip; - SBMI.NetworkData.PingAddress = $"{SBMI.NetworkData.PingData.Address} ({Host.Address})"; + SBMI.NetworkData.Host = Host.Address; + SBMI.NetworkData.Ping = SBMI.NetworkData.PingData.RoundTrip; + SBMI.NetworkData.PingAddress = $"{SBMI.NetworkData.PingData.Address} ({Host.Address})"; - break; + break; + } } } - } - else - { - SBMI.NetworkData.Ping = 0; - SBMI.NetworkData.PingData = new(); + else + { + SBMI.NetworkData.Ping = 0; + SBMI.NetworkData.PingData = new(); + } + + SBMI.PingManagement = true; } } catch (Exception Exception) { + SBMI.PingManagement = true; SSWW.Watch_CatchException(Exception); } }); @@ -231,14 +239,23 @@ public static async Task Start() SBMI.DownloadCounter = new("Network Interface", "Bytes Received/sec", Name); } - SBMI.NetworkData.Upload = SBMI.UploadCounter.NextValue(); - SBMI.NetworkData.Download = SBMI.DownloadCounter.NextValue(); + if (SBMI.UploadCounter != null) + { + SBMI.NetworkData.Upload = SBMI.UploadCounter.NextValue(); - SBMI.NetworkData.UploadData = SSESSE.AutoConvert(SBMI.NetworkData.Upload, SEST.Byte, SEMST.Palila); - SBMI.NetworkData.DownloadData = SSESSE.AutoConvert(SBMI.NetworkData.Download, SEST.Byte, SEMST.Palila); + SBMI.NetworkData.UploadData = SSESSE.AutoConvert(SBMI.NetworkData.Upload, SEST.Byte, SEMST.Palila); - SBMI.NetworkData.FormatUploadData = SHN.Numeral(SBMI.NetworkData.UploadData.Value, true, true, 2, '0', SECNT.None) + " " + SBMI.NetworkData.UploadData.Text; - SBMI.NetworkData.FormatDownloadData = SHN.Numeral(SBMI.NetworkData.DownloadData.Value, true, true, 2, '0', SECNT.None) + " " + SBMI.NetworkData.DownloadData.Text; + SBMI.NetworkData.FormatUploadData = SHN.Numeral(SBMI.NetworkData.UploadData.Value, true, true, 2, '0', SECNT.None) + " " + SBMI.NetworkData.UploadData.Text; + } + + if (SBMI.DownloadCounter != null) + { + SBMI.NetworkData.Download = SBMI.DownloadCounter.NextValue(); + + SBMI.NetworkData.DownloadData = SSESSE.AutoConvert(SBMI.NetworkData.Download, SEST.Byte, SEMST.Palila); + + SBMI.NetworkData.FormatDownloadData = SHN.Numeral(SBMI.NetworkData.DownloadData.Value, true, true, 2, '0', SECNT.None) + " " + SBMI.NetworkData.DownloadData.Text; + } break; } @@ -347,172 +364,222 @@ public static async Task Start() { if (Hardware.HardwareType == HardwareType.Cpu) { - Hardware.Update(); - - foreach (ISensor Sensor in Hardware.Sensors) + _ = Task.Run(() => { - if (Sensor.SensorType == SensorType.Load && Sensor.Name == "CPU Total") + try { - SBMI.CpuData.State = true; - SBMI.CpuData.Min = Sensor.Min; - SBMI.CpuData.Max = Sensor.Max; - SBMI.CpuData.Now = Sensor.Value; - SBMI.CpuData.Name = Hardware.Name; + Hardware.Update(); - break; + foreach (ISensor Sensor in Hardware.Sensors) + { + if (Sensor.SensorType == SensorType.Load && Sensor.Name == "CPU Total") + { + SBMI.CpuData.State = true; + SBMI.CpuData.Min = Sensor.Min; + SBMI.CpuData.Max = Sensor.Max; + SBMI.CpuData.Now = Sensor.Value; + SBMI.CpuData.Name = Hardware.Name; + + break; + } + } } - } + catch (Exception Exception) + { + SSWW.Watch_CatchException(Exception); + } + }); } else if (Hardware.HardwareType == HardwareType.Memory) { - Hardware.Update(); + _ = Task.Run(() => + { + try + { + Hardware.Update(); - SBMI.MemoryData.State = true; - SBMI.MemoryData.Name = Hardware.Name; + SBMI.MemoryData.State = true; + SBMI.MemoryData.Name = Hardware.Name; - foreach (ISensor Sensor in Hardware.Sensors) - { - switch (Sensor.Name) + foreach (ISensor Sensor in Hardware.Sensors) + { + switch (Sensor.Name) + { + case "Memory Used" when Sensor.SensorType == SensorType.Data: + SBMI.MemoryData.MemoryUsed = Sensor.Value; + break; + case "Memory Available" when Sensor.SensorType == SensorType.Data: + SBMI.MemoryData.MemoryAvailable = Sensor.Value; + break; + case "Memory" when Sensor.SensorType == SensorType.Load: + SBMI.MemoryData.MemoryLoad = Sensor.Value; + break; + case "Virtual Memory Used" when Sensor.SensorType == SensorType.Data: + SBMI.MemoryData.VirtualMemoryUsed = Sensor.Value; + break; + case "Virtual Memory Available" when Sensor.SensorType == SensorType.Data: + SBMI.MemoryData.VirtualMemoryAvailable = Sensor.Value; + break; + case "Virtual Memory" when Sensor.SensorType == SensorType.Load: + SBMI.MemoryData.VirtualMemoryLoad = Sensor.Value; + break; + default: + break; + } + } + } + catch (Exception Exception) { - case "Memory Used" when Sensor.SensorType == SensorType.Data: - SBMI.MemoryData.MemoryUsed = Sensor.Value; - break; - case "Memory Available" when Sensor.SensorType == SensorType.Data: - SBMI.MemoryData.MemoryAvailable = Sensor.Value; - break; - case "Memory" when Sensor.SensorType == SensorType.Load: - SBMI.MemoryData.MemoryLoad = Sensor.Value; - break; - case "Virtual Memory Used" when Sensor.SensorType == SensorType.Data: - SBMI.MemoryData.VirtualMemoryUsed = Sensor.Value; - break; - case "Virtual Memory Available" when Sensor.SensorType == SensorType.Data: - SBMI.MemoryData.VirtualMemoryAvailable = Sensor.Value; - break; - case "Virtual Memory" when Sensor.SensorType == SensorType.Load: - SBMI.MemoryData.VirtualMemoryLoad = Sensor.Value; - break; - default: - break; + SSWW.Watch_CatchException(Exception); } - } + }); } else if (Hardware.HardwareType == HardwareType.Battery) { - Hardware.Update(); - - if (Hardware.Sensors.Any()) + _ = Task.Run(() => { - SBMI.BatteryData.State = true; - SBMI.BatteryData.Name = Hardware.Name; - - foreach (ISensor Sensor in Hardware.Sensors) + try { - switch (Sensor.Name) + Hardware.Update(); + + if (Hardware.Sensors.Any()) { - case "Charge Level" when Sensor.SensorType == SensorType.Level: - SBMI.BatteryData.ChargeLevel = Sensor.Value; - break; - case "Discharge Level" when Sensor.SensorType == SensorType.Level: - SBMI.BatteryData.DischargeLevel = Sensor.Value; - break; - case "Voltage" when Sensor.SensorType == SensorType.Voltage: - SBMI.BatteryData.Voltage = Sensor.Value; - break; - case "Charge Current" when Sensor.SensorType == SensorType.Current: - SBMI.BatteryData.ChargeCurrent = Sensor.Value; - break; - case "Discharge Current" when Sensor.SensorType == SensorType.Current: - SBMI.BatteryData.DischargeCurrent = Sensor.Value; - break; - case "Charge / Discharge Current" when Sensor.SensorType == SensorType.Current: - SBMI.BatteryData.ChargeDischargeCurrent = Sensor.Value; - break; - case "Designed Capacity" when Sensor.SensorType == SensorType.Energy: - SBMI.BatteryData.DesignedCapacity = Sensor.Value; - break; - case "Full Charged Capacity" when Sensor.SensorType == SensorType.Energy: - SBMI.BatteryData.FullChargedCapacity = Sensor.Value; - break; - case "Remaining Capacity" when Sensor.SensorType == SensorType.Energy: - SBMI.BatteryData.RemainingCapacity = Sensor.Value; - break; - case "Charge Rate" when Sensor.SensorType == SensorType.Power: - SBMI.BatteryData.ChargeRate = Sensor.Value; - break; - case "Discharge Rate" when Sensor.SensorType == SensorType.Power: - SBMI.BatteryData.DischargeRate = Sensor.Value; - break; - case "Charge / Discharge Rate" when Sensor.SensorType == SensorType.Power: - SBMI.BatteryData.ChargeDischargeRate = Sensor.Value; - break; - case "Degradation Level" when Sensor.SensorType == SensorType.Level: - SBMI.BatteryData.DegradationLevel = Sensor.Value; - break; - case "Remaining Time (Estimated)" when Sensor.SensorType == SensorType.TimeSpan: - SBMI.BatteryData.RemainingTimeEstimated = Sensor.Value; - break; - default: - break; + SBMI.BatteryData.State = true; + SBMI.BatteryData.Name = Hardware.Name; + + foreach (ISensor Sensor in Hardware.Sensors) + { + switch (Sensor.Name) + { + case "Charge Level" when Sensor.SensorType == SensorType.Level: + SBMI.BatteryData.ChargeLevel = Sensor.Value; + break; + case "Discharge Level" when Sensor.SensorType == SensorType.Level: + SBMI.BatteryData.DischargeLevel = Sensor.Value; + break; + case "Voltage" when Sensor.SensorType == SensorType.Voltage: + SBMI.BatteryData.Voltage = Sensor.Value; + break; + case "Charge Current" when Sensor.SensorType == SensorType.Current: + SBMI.BatteryData.ChargeCurrent = Sensor.Value; + break; + case "Discharge Current" when Sensor.SensorType == SensorType.Current: + SBMI.BatteryData.DischargeCurrent = Sensor.Value; + break; + case "Charge / Discharge Current" when Sensor.SensorType == SensorType.Current: + SBMI.BatteryData.ChargeDischargeCurrent = Sensor.Value; + break; + case "Designed Capacity" when Sensor.SensorType == SensorType.Energy: + SBMI.BatteryData.DesignedCapacity = Sensor.Value; + break; + case "Full Charged Capacity" when Sensor.SensorType == SensorType.Energy: + SBMI.BatteryData.FullChargedCapacity = Sensor.Value; + break; + case "Remaining Capacity" when Sensor.SensorType == SensorType.Energy: + SBMI.BatteryData.RemainingCapacity = Sensor.Value; + break; + case "Charge Rate" when Sensor.SensorType == SensorType.Power: + SBMI.BatteryData.ChargeRate = Sensor.Value; + break; + case "Discharge Rate" when Sensor.SensorType == SensorType.Power: + SBMI.BatteryData.DischargeRate = Sensor.Value; + break; + case "Charge / Discharge Rate" when Sensor.SensorType == SensorType.Power: + SBMI.BatteryData.ChargeDischargeRate = Sensor.Value; + break; + case "Degradation Level" when Sensor.SensorType == SensorType.Level: + SBMI.BatteryData.DegradationLevel = Sensor.Value; + break; + case "Remaining Time (Estimated)" when Sensor.SensorType == SensorType.TimeSpan: + SBMI.BatteryData.RemainingTimeEstimated = Sensor.Value; + break; + default: + break; + } + } + } + else + { + SBMI.BatteryData.State = false; } } - } - else - { - SBMI.BatteryData.State = false; - } + catch (Exception Exception) + { + SSWW.Watch_CatchException(Exception); + } + }); } else if (Hardware.HardwareType == HardwareType.Motherboard) { - Hardware.Update(); + _ = Task.Run(() => + { + try + { + Hardware.Update(); - SBMI.MotherboardData.State = true; - SBMI.MotherboardData.Name = Hardware.Name; + SBMI.MotherboardData.State = true; + SBMI.MotherboardData.Name = Hardware.Name; + } + catch (Exception Exception) + { + SSWW.Watch_CatchException(Exception); + } + }); } else if (Hardware.HardwareType is HardwareType.GpuAmd or HardwareType.GpuIntel or HardwareType.GpuNvidia) { - Hardware.Update(); - - List Sensors = new() + _ = Task.Run(() => { - new SBSSSS + try { - Name = Hardware.Name, - Type = $"{Hardware.HardwareType}" - } - }; + Hardware.Update(); - foreach (ISensor Sensor in Hardware.Sensors) - { - Sensors.Add(new SBSSSS + List Sensors = new() { - Max = Sensor.Max, - Min = Sensor.Min, - Name = Sensor.Name, - Now = Sensor.Value, - Type = $"{Sensor.SensorType}" - }); - } + new SBSSSS + { + Name = Hardware.Name, + Type = $"{Hardware.HardwareType}" + } + }; - string Result = JsonConvert.SerializeObject(Sensors, Formatting.Indented); + foreach (ISensor Sensor in Hardware.Sensors) + { + Sensors.Add(new SBSSSS + { + Max = Sensor.Max, + Min = Sensor.Min, + Name = Sensor.Name, + Now = Sensor.Value, + Type = $"{Sensor.SensorType}" + }); + } - switch (Hardware.HardwareType) - { - case HardwareType.GpuAmd: - SBMI.GraphicData.State = true; - SBMI.GraphicData.Amd = JArray.Parse(Result); - break; - case HardwareType.GpuIntel: - SBMI.GraphicData.State = true; - SBMI.GraphicData.Intel = JArray.Parse(Result); - break; - case HardwareType.GpuNvidia: - SBMI.GraphicData.State = true; - SBMI.GraphicData.Nvidia = JArray.Parse(Result); - break; - default: - break; - } + string Result = JsonConvert.SerializeObject(Sensors, Formatting.Indented); + + switch (Hardware.HardwareType) + { + case HardwareType.GpuAmd: + SBMI.GraphicData.State = true; + SBMI.GraphicData.Amd = JArray.Parse(Result); + break; + case HardwareType.GpuIntel: + SBMI.GraphicData.State = true; + SBMI.GraphicData.Intel = JArray.Parse(Result); + break; + case HardwareType.GpuNvidia: + SBMI.GraphicData.State = true; + SBMI.GraphicData.Nvidia = JArray.Parse(Result); + break; + default: + break; + } + } + catch (Exception Exception) + { + SSWW.Watch_CatchException(Exception); + } + }); } } } diff --git a/src/Project/Sucrose.Backgroundog/Manage/Internal.cs b/src/Project/Sucrose.Backgroundog/Manage/Internal.cs index b20e94acc..84b4416cf 100644 --- a/src/Project/Sucrose.Backgroundog/Manage/Internal.cs +++ b/src/Project/Sucrose.Backgroundog/Manage/Internal.cs @@ -44,6 +44,8 @@ internal static class Internal public static bool BiosManagement = true; + public static bool PingManagement = true; + public static bool RemoteDesktop = false; public static bool AudioManagement = true;