Exemplo n.º 1
0
        private bool CheckAvailable()
        {
            if (!_checkedIfAvailable)
            {
                _checkedIfAvailable = true;
                if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && File.Exists("/sys/class/thermal/thermal_zone0/temp"))
                {
                    _isAvailable = true;
                    _windows     = false;
                }
                else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                {
                    OpenHardwareMonitor ohw = new OpenHardwareMonitor();
                    if (ohw.TryGetAverageCpuTemperature(out _))
                    {
                        _windows              = true;
                        _isAvailable          = true;
                        _hardwareMonitorInUse = ohw;
                        return(true);
                    }

                    try
                    {
                        ManagementObjectSearcher searcher = new ManagementObjectSearcher(@"root\WMI", "SELECT * FROM MSAcpi_ThermalZoneTemperature");
                        if (searcher.Get().Count > 0)
                        {
                            _managementObjectSearchers.Add(searcher);
                            _isAvailable = true;
                            _windows     = true;
                        }
                    }
                    catch (Exception x) when(x is IOException || x is UnauthorizedAccessException || x is ManagementException)
                    {
                        // Nothing to do - WMI not available for this element or missing permissions.
                        // WMI enumeration may require elevated rights.
                    }

                    try
                    {
                        ManagementObjectSearcher searcher = new ManagementObjectSearcher(@"root\WMI", "SELECT * FROM Win32_TemperatureProbe");
                        if (searcher.Get().Count > 0)
                        {
                            _managementObjectSearchers.Add(searcher);
                            _isAvailable = true;
                            _windows     = true;
                        }
                    }
                    catch (Exception x) when(x is IOException || x is UnauthorizedAccessException || x is ManagementException)
                    {
                        // Nothing to do - WMI not available for this element or missing permissions.
                        // WMI enumeration may require elevated rights.
                    }
                }
            }

            return(_isAvailable);
        }
Exemplo n.º 2
0
 /// <summary>
 /// start export plugin
 /// </summary>
 public void start_instance()
 {
     data_source = new OpenHardwareMonitor(this.unique_plugin_identifier);
 }