Beispiel #1
0
        public MyClient(string endFilter)
        {
            if (string.IsNullOrEmpty(endFilter))
            {
                this.endFilter = endFilter;
            }
            client = new EasyClient();
            client.Initialize(new MyReceiveFilter(endFilter), (request) => {
                Console.WriteLine("resposen:" + request.Body);
                //收到服务器的发送CPU状态通知
                if (request.Body.ToUpper().IndexOf("GETCPU") > -1)
                {
                    if (!cycleSend)
                    {
                        StartSend();
                    }
                }
                //收到服务器的终止发送通知
                else if (request.Body.ToUpper().IndexOf("STOPSENDING") > -1)
                {
                    cycleSend = false;
                }
            });

            cpuReader = new CpuTemperatureReader();
            hs        = cpuReader.GetTemperaturesInCelsius();
        }
Beispiel #2
0
        public string GetCpuTemperature()
        {
            hs = cpuReader.GetTemperaturesInCelsius();
            var message = String.Format("CPU Package:{0}℃ Min:{1}℃ Max:{2}℃ CPU Speed:{3}GHz Memory Load:{4}%",
                                        hs.temperature, hs.temperature_min, hs.temperature_max,
                                        hs.cpu_clock.ToString("f2"), hs.mem_load);

            Console.WriteLine(message);
            return(message);
        }
Beispiel #3
0
        public HardwareSensors GetTemperaturesInCelsius()
        {
            int i = 0;

            foreach (var hardware in _computer.Hardware)
            {
                hardware.Update(); //use hardware.Name to get CPU model
                //遍历CPU传感器
                if (hardware.HardwareType == HardwareType.CPU)
                {
                    foreach (var sensor in hardware.Sensors)
                    {
                        //温度
                        if (sensor.SensorType == SensorType.Temperature && sensor.Value.HasValue)
                        {
                            Console.WriteLine("{0}, Value={1}, Min Value={2}, Max Value={3}",
                                              sensor.Name, sensor.Value.Value, sensor.Min.Value, sensor.Max.Value);
                            if (sensor.Name.Contains("Package"))
                            {
                                temperature     = Convert.ToInt32(sensor.Value);
                                temperature_min = Convert.ToInt32(sensor.Min);
                                temperature_max = Convert.ToInt32(sensor.Max);
                            }
                        }
                        //时钟
                        if (sensor.SensorType == SensorType.Clock && sensor.Value.HasValue)
                        {
                            Console.WriteLine("{0}, Value={1}, Min Value={2}, Max Value={3}",
                                              sensor.Name, sensor.Value.Value, sensor.Min.Value, sensor.Max.Value);
                            if (!sensor.Name.Contains("Bus"))
                            {
                                i++;
                                cpu_clock += (float)sensor.Value;
                            }
                        }
                    }
                }
                //遍历内存
                if (hardware.HardwareType == HardwareType.RAM)
                {
                    foreach (var sensor in hardware.Sensors)
                    {
                        if (sensor.SensorType == SensorType.Load && sensor.Value.HasValue)
                        {
                            Console.WriteLine("{0}, Value={1}", sensor.Name, sensor.Value.Value);
                            mem_load = Convert.ToInt32(sensor.Value);
                        }
                    }
                }
            }
            cpu_clock = cpu_clock / i / 1000f;
            hs        = new HardwareSensors(temperature, temperature_min, temperature_max, cpu_clock, mem_load);
            return(hs);
        }