/// <summary> /// 调用此方法更新本地主机数据 /// </summary> public void Gengxin_bendi() { //获取数据 Shuju_Shebei_PC shuju_Shebei_ = Gongju.Huoqu_shebei_xinxi(); shuju_Shebei_.Shebei_shibie = Shebei_dangqian.Shuju.Shebei_shibie; shuju_Shebei_.Mingchen = App.Peizhi_.Shuju.Zhujiming; shuju_Shebei_.Weiyi_shibie = App.Peizhi_.Shuju.Weiyi_shibie; Shebei_dangqian.Shuju = shuju_Shebei_; Shebei_dangqian.Baocun(); }
/// <summary> /// 更新设备数据 /// </summary> /// <param name="shuju_xin"></param> public void Gengxin(Shuju_Shebei_PC shuju_Shebei_PC) { Shuju = shuju_Shebei_PC; }
public void Gengxin(object a) { App.Current.Dispatcher.Invoke(new Action(() => { lock (this) { try { //刷新前台数据 daima.Shuju_Shebei_PC shuju_Shebei_PC = App.Mianban_.Shebei_dangqian.Shuju as daima.Shuju_Shebei_PC; textblock0.Text = shuju_Shebei_PC.Mingchen; textblock1.Text = "处理器:" + shuju_Shebei_PC.Cpu_info; textblock2.Text = "显卡:" + shuju_Shebei_PC.Gpu_info; textblock3.Text = "内存:" + shuju_Shebei_PC.Ram_info; textblock4.Text = "系统:" + shuju_Shebei_PC.Sys_info; textblock5.Text = "CPU利用率:" + shuju_Shebei_PC.Cpu_use.ToString("0.0") + "%"; textblock6.Text = "GPU占用率:" + shuju_Shebei_PC.Gpu_use.ToString("0.0") + "%"; textblock7.Text = "内存使用率:" + shuju_Shebei_PC.Ram_use.ToString("0.0") + "%"; textblock8.Text = "磁盘活动时间比:" + shuju_Shebei_PC.Hdd_use.ToString("0.0") + "%"; textblock9.Text = "系统连续开机时间:" + shuju_Shebei_PC.Sys_time; //填充图表 //添加数据到表格中 LastHourSeries[0].Values.Add(new ObservableValue(shuju_Shebei_PC.Cpu_wendu)); LastHourSeries[1].Values.Add(new ObservableValue(shuju_Shebei_PC.Gpu_wendu)); //判断是否超过20 if (LastHourSeries[0].Values.Count >= 40) { LastHourSeries[0].Values.RemoveAt(0); } if (LastHourSeries[1].Values.Count >= 40) { LastHourSeries[1].Values.RemoveAt(0); } //循环界面列表 查找不在的控制器将其移除 foreach (var item in warp.Children) { bool shifou = false; kongjian.kongzhi kongzhi_ui = null; //判断是否是控件 if (item is kongjian.kongzhi) { kongzhi_ui = item as kongjian.kongzhi; } else { continue; } foreach (var nei in App.Mianban_.Kongzhis) { //找到则直接下一个 if (kongzhi_ui.kongzhi_.Shuju.Weiyi_shibie == nei.Shuju.Weiyi_shibie) { shifou = true; break; } } //未找到匹配的 if (shifou == false) { warp.Children.Remove((UIElement)item); } } //循环后台控制器列表 查找不在ui的将其添加 foreach (var nei in App.Mianban_.Kongzhis) { bool shifou = false; foreach (var item in warp.Children) { kongjian.kongzhi kongzhi_ui = null; //判断是否是控件 if (item is kongjian.kongzhi) { kongzhi_ui = item as kongjian.kongzhi; } else { continue; } //找到则直接下一个 if (kongzhi_ui.kongzhi_.Shuju.Weiyi_shibie == nei.Shuju.Weiyi_shibie) { shifou = true; } } if (shifou == false) { //未找到匹配的 kongjian.kongzhi linshi = new kongjian.kongzhi(nei); linshi.BoilerEventLog += Linshi_BoilerEventLog; warp.Children.Insert(0, linshi); } } } catch { } } })); }
//[DllImport("硬件检测引擎.dll")] // public static extern string Hwinfo(string 配置文件路径, string 运行目录); /// <summary> /// 获取硬件信息和占用 /// </summary> /// <returns></returns> public static Shuju_Shebei_PC Huoqu_shebei_xinxi() { if (shuju_Shebei_PC == null) { shuju_Shebei_PC = new Shuju_Shebei_PC(); } if (computer == null) { computer = new Computer(); computer.Open(); } shuju_Shebei_PC.Cpu_use = SystemInfo.CpuLoad; shuju_Shebei_PC.Ram_use = (float)(1 - (double)SystemInfo.MemoryAvailable / SystemInfo.PhysicalMemory) * 100; computer.CPUEnabled = true; computer.GPUEnabled = true; computer.RAMEnabled = true; computer.Accept(updateVisitor); float cpu_wendu = 0; int cpu_wendu_jishu = 0; float gpu_wendu = 0; int gpu_wendu_jishu = 0; float gpu_use = 0; int gpu_use_jishu = 0; for (int i = 0; i < computer.Hardware.Length; i++) { //查找硬件类型为CPU if (computer.Hardware[i].HardwareType == HardwareType.CPU) { for (int j = 0; j < computer.Hardware[i].Sensors.Length; j++) { //找到温度传感器 if (computer.Hardware[i].Sensors[j].SensorType == SensorType.Temperature) { if (computer.Hardware[i].Sensors[j].Value != null) { cpu_wendu += (float)computer.Hardware[i].Sensors[j].Value; cpu_wendu_jishu++; } } } shuju_Shebei_PC.Cpu_info = computer.Hardware[i].Name; } else//查找AMD的GPU if (computer.Hardware[i].HardwareType == HardwareType.GpuAti) { for (int j = 0; j < computer.Hardware[i].Sensors.Length; j++) { //找到温度传感器 if (computer.Hardware[i].Sensors[j].SensorType == SensorType.Temperature) { if (computer.Hardware[i].Sensors[j].Value != null) { gpu_wendu += (float)computer.Hardware[i].Sensors[j].Value; gpu_wendu_jishu++; } } else//找到占用率 if (computer.Hardware[i].Sensors[j].SensorType == SensorType.Load) { if (computer.Hardware[i].Sensors[j].Value != null) { gpu_use += (float)computer.Hardware[i].Sensors[j].Value; gpu_use_jishu++; } } } shuju_Shebei_PC.Gpu_info = computer.Hardware[i].Name; } else//查找AMD的GPU if (computer.Hardware[i].HardwareType == HardwareType.GpuNvidia) { for (int j = 0; j < computer.Hardware[i].Sensors.Length; j++) { //找到温度传感器 if (computer.Hardware[i].Sensors[j].SensorType == SensorType.Temperature) { if (computer.Hardware[i].Sensors[j].Value != null) { gpu_wendu += (float)computer.Hardware[i].Sensors[j].Value; gpu_wendu_jishu++; } } else//找到占用率 if (computer.Hardware[i].Sensors[j].SensorType == SensorType.Load) { if (computer.Hardware[i].Sensors[j].Value != null) { gpu_use += (float)computer.Hardware[i].Sensors[j].Value; gpu_use_jishu++; } } shuju_Shebei_PC.Gpu_info = computer.Hardware[i].Name; } } else//查找AMD的GPU if (computer.Hardware[i].HardwareType == HardwareType.RAM) { for (int j = 0; j < computer.Hardware[i].Sensors.Length; j++) { shuju_Shebei_PC.Ram_info = computer.Hardware[i].Name; } } } //格式化字符串 if (gpu_use_jishu != 0) { shuju_Shebei_PC.Gpu_use = (gpu_use / gpu_use_jishu); } if (cpu_wendu_jishu != 0) { shuju_Shebei_PC.Cpu_wendu = (cpu_wendu / cpu_wendu_jishu); } if (gpu_wendu_jishu != 0) { shuju_Shebei_PC.Gpu_wendu = (gpu_wendu / gpu_wendu_jishu); } shuju_Shebei_PC.Ram_info += " " + ((double)SystemInfo.PhysicalMemory / (1024 * 1024 * 1024)).ToString(".0") + " GB"; shuju_Shebei_PC.Sys_info = GetOSFriendlyName(); shuju_Shebei_PC.Sys_time = ((Environment.TickCount / 0x3e8) / 60).ToString() + "分钟"; return(shuju_Shebei_PC); }