Пример #1
0
        /// <summary>
        /// Called when the package is started.
        /// </summary>
        public override void OnStart()
        {
            this.computer = new Computer();
            var updateVisitor = new UpdateVisitor();
            var wmiProvider   = new WmiProvider(computer);

            this.computer.HardwareAdded   += new HardwareEventHandler(computer_HardwareAdded);
            this.computer.HardwareRemoved += new HardwareEventHandler(computer_HardwareRemoved);

            this.computer.Open();

            this.computer.MainboardEnabled     = true;
            this.computer.CPUEnabled           = true;
            this.computer.FanControllerEnabled = true;
            this.computer.GPUEnabled           = true;
            this.computer.HDDEnabled           = true;
            this.computer.MainboardEnabled     = true;
            this.computer.RAMEnabled           = true;

            this.pushHardwareListOnChange = true;
            this.PushHardwaresList();

            while (PackageHost.IsRunning)
            {
                Thread.Sleep(PackageHost.GetSettingValue <int>("Interval"));

                this.computer.Accept(updateVisitor);
                if (wmiProvider != null)
                {
                    wmiProvider.Update();
                }

                foreach (var hardware in computer.Hardware)
                {
                    this.PushHardware(hardware);
                }
            }
        }
Пример #2
0
        static SensorInfo[] CPUTemp(Computer computer, UpdateVisitor updateVisitor)
        {
            computer.Open();
            SensorInfo[] sensorInfos = new SensorInfo[4];
            computer.Accept(updateVisitor);


            foreach (IHardware hardware in computer.Hardware)
            {
                if (hardware.HardwareType == HardwareType.CPU)
                {
                    int coreCounter = 0;
                    foreach (ISensor sensor in hardware.Sensors)
                    {
                        if (sensor.SensorType == SensorType.Temperature)
                        {
                            if (coreCounter == sensorInfos.Length)
                            {
                                return(sensorInfos);
                            }


                            SensorInfo coreInfo = new SensorInfo();
                            coreInfo.sensorName  = sensor.Name.ToString();
                            coreInfo.sensorValue = sensor.Value;

                            sensorInfos[coreCounter] = coreInfo;

                            coreCounter++;
                        }
                    }
                }
            }
            computer.Close();
            return(sensorInfos);
        }