public List <float> GetCpuTemps() { var myComputer = new Computer(); myComputer.Open(); myComputer.CPUEnabled = true; var temps = (from hardwareItem in myComputer.Hardware where hardwareItem.HardwareType == HardwareType.CPU from sensor in hardwareItem.Sensors where sensor.SensorType == SensorType.Temperature let value = sensor.Value where value != null where value != null select(float) value).ToList(); if (temps.Count != 0) { return(temps); } var tempTemps = new List <float>(); var procCount = Environment.ProcessorCount; for (int i = 0; i < procCount; i++) { tempTemps.Add(-1); } return(tempTemps); }
protected async override void OnStartup(StartupEventArgs e) { base.OnStartup(e); // SETTINGS CheckSettings(); // TRAY ICON TrayIcon = (TaskbarIcon)FindResource("TrayIcon"); TrayIcon.ToolTipText = Assembly.GetExecutingAssembly().GetName().Name; TrayIcon.Visibility = Visibility.Visible; // OHM COMPUTER _computer = new Computer() { CPUEnabled = true, FanControllerEnabled = true, GPUEnabled = true, HDDEnabled = false, MainboardEnabled = true, RAMEnabled = true }; _computer.Open(); // CHECK FOR UPDATES if (SidebarDiagnostics.Properties.Settings.Default.CheckForUpdates) { await UpdateManager.Check(false); } }
private CpuSensorsFilter() { _computer = new Computer() { CPUEnabled = true }; _computer.Open(); }
private SystemDiagnostics() { mCpuCounter.CategoryName = "Processor"; mCpuCounter.CounterName = "% Processor Time"; mCpuCounter.InstanceName = "_Total"; computer = new OpenHardwareMonitor.Hardware.Computer(); computer.CPUEnabled = true; computer.Open(); }
private ROCInfo(int _updatePeriod) { updatePeriod = _updatePeriod; ROC = new Computer(); ROC.CPUEnabled = true; ROC.GPUEnabled = true; ROC.RAMEnabled = true; ROC.Open(); updateTimer = new Timer(updateData, null, 100, updatePeriod); }
public static void Monitor() { running = true; UpdateVisitor updateVisitor = new UpdateVisitor(); Computer computer = new Computer(); computer.Open(); while (running) { computer.Accept(updateVisitor); MonitoringInfo currentInfo = new MonitoringInfo(); foreach (IHardware hardware in computer.Hardware) { if (hardware.HardwareType == HardwareType.CPU) { CPU cpu = new CPU(); AddCPUInfo(hardware.Sensors, cpu); currentInfo.CPUs.Add(cpu); } else if (hardware.HardwareType == HardwareType.GpuAti) { GPU gpu = new GPU(); gpu.GPUTempMax = 100; // assume max gpu temp is 100 *C AddGPUInfo(hardware.Sensors, gpu); currentInfo.GPUs.Add(gpu); } else if (hardware.HardwareType == HardwareType.GpuNvidia) { GPU gpu = new GPU(); gpu.GPUTempMax = 100; // assume max gpu temp is 100 *C AddGPUInfo(hardware.Sensors, gpu); currentInfo.GPUs.Add(gpu); } } RAM ram = new RAM(); MEMORYSTATUSEX memoryUsage = new MEMORYSTATUSEX(); if (GlobalMemoryStatusEx(memoryUsage)) { ram.FreeMemory = (int)(memoryUsage.ullAvailPhys / (1024 * 1024)); // in MB ram.TotalMemory = (int)(memoryUsage.ullTotalPhys / (1024 * 1024)); // in MB } currentInfo.RAM = ram; Info = currentInfo; Thread.Sleep(1000); } }
private OpenHardwareMonitor.Hardware.Computer thisComputer; //set 'thisComputer' as the name of the instance for the dll public GnatStatsProtocol() { thisComputer = new OpenHardwareMonitor.Hardware.Computer() { //initialise the dll instance as a new one CPUEnabled = true, //enable the datafield to be gathered GPUEnabled = true, HDDEnabled = true, MainboardEnabled = true, RAMEnabled = true, }; thisComputer.Open(); }
public OpenHardwareMonitorMetricRetriever() { _computer = new Computer(); _computer.Open(); // Enable sensors _computer.HDDEnabled = true; _computer.RAMEnabled = true; _computer.GPUEnabled = true; _computer.MainboardEnabled = true; _computer.CPUEnabled = true; }
private CPUsTemperatureMonitor() { _computer = new Computer() { CPUEnabled = true }; _computer.Open(); RetriveTemperatureSensors(); }
static void Main(string[] args) { cp = new Computer(); cp.Open(); cp.CPUEnabled = true; mainTImer = new Timer(1000); mainTImer.Elapsed += new ElapsedEventHandler(ShowCPUInfo); mainTImer.Enabled = true; Console.ReadLine(); }
private void Initialize() { Gpus = new MtObservableCollection <Gpu>(); for (var i = 0; i < GetTotalNumberOfGpus(); i++) { var id = i; id++; Gpus.Add(new Gpu { Identifier = id }); } var gpuVisibility = new[] { UserSettings.GlobalSettings.VisibilitySystemGpuTemp, UserSettings.GlobalSettings.VisibilitySystemGpuLoad }; _computer = new Computer { CPUEnabled = UserSettings.GlobalSettings.VisibilitySystemCpuTemp, GPUEnabled = BooleanExtensions.ExceedsThreshold(0, gpuVisibility) }; _computer.Open(); // Cpu timer var timerCpu = new Timer { Interval = UserSettings.GlobalSettings.PollingRateCpu }; timerCpu.Elapsed += timerCpu_Elapsed; timerCpu.Start(); // Ram timer var timerRam = new Timer { Interval = UserSettings.GlobalSettings.PollingRateRam }; timerRam.Elapsed += timerRam_Elapsed; timerRam.Start(); // Temp timer var timerTemp = new Timer { Interval = UserSettings.GlobalSettings.PollingRateTemps }; timerTemp.Elapsed += timerTemp_Elapsed; timerTemp.Start(); // Get the value at init EventExtensions.FireEvent(timerCpu, "onIntervalElapsed", this, null); EventExtensions.FireEvent(timerRam, "onIntervalElapsed", this, null); EventExtensions.FireEvent(timerTemp, "onIntervalElapsed", this, null); }
public List <float> GetCpuTemps() { var myComputer = new Computer(); myComputer.Open(); myComputer.CPUEnabled = true; return((from hardwareItem in myComputer.Hardware where hardwareItem.HardwareType == HardwareType.CPU from sensor in hardwareItem.Sensors where sensor.SensorType == SensorType.Temperature where sensor.Value != null select(float) sensor.Value).ToList()); }
public List<float> GetCpuTemps() { var myComputer = new Computer(); myComputer.Open(); myComputer.CPUEnabled = true; return (from hardwareItem in myComputer.Hardware where hardwareItem.HardwareType == HardwareType.CPU from sensor in hardwareItem.Sensors where sensor.SensorType == SensorType.Temperature let value = sensor.Value where value != null where value != null select (float) value).ToList(); }
public TemperatureWorker(int duration) { _updateVisitor = new UpdateVisitor(); _computer = new Computer(); _computer.CPUEnabled = true; _wmiProvider = new WmiProvider(_computer); _computer.Open(); _hardware = _computer.Hardware[0]; _hardware.Accept(_updateVisitor); //Timer TimerInt = new Timer(); //TimerInt.Interval = duration; //TimerInt.Tick += new EventHandler(tw_tick); //TimerInt.Start(); }
public ContextMenuStrip Create() { thisComputer = new OpenHardwareMonitor.Hardware.Computer() { }; thisComputer.CPUEnabled = true; thisComputer.GPUEnabled = true; thisComputer.HDDEnabled = true; thisComputer.MainboardEnabled = true; thisComputer.RAMEnabled = true; thisComputer.Open(); menu = new ContextMenuStrip(); CreateMenuItems(); return menu; }
protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); // NOTIFY ICON MenuItem _settingsMenuItem = new MenuItem() { Header = "Settings" }; _settingsMenuItem.Click += SettingsMenuItem_Click; MenuItem _showMenuItem = new MenuItem() { Header = "Show" }; _showMenuItem.Click += ShowMenuItem_Click; MenuItem _closeMenuItem = new MenuItem() { Header = "Close" }; _closeMenuItem.Click += CloseMenuItem_Click; ContextMenu _contextMenu = new ContextMenu(); _contextMenu.Items.Add(_settingsMenuItem); _contextMenu.Items.Add(_showMenuItem); _contextMenu.Items.Add(_closeMenuItem); _taskbarIcon = new TaskbarIcon() { Icon = SidebarDiagnostics.Properties.Resources.TrayIcon, ToolTipText = Assembly.GetExecutingAssembly().GetName().Name, ContextMenu = _contextMenu, LeftClickCommand = new ShowAppBarCommand() }; // OHM COMPUTER _computer = new Computer() { CPUEnabled = true, FanControllerEnabled = true, GPUEnabled = true, HDDEnabled = false, MainboardEnabled = true, RAMEnabled = true }; _computer.Open(); }
public DataProvider() { _computer = new Computer (); // enable everything except for GPU which we can't monitor in a service anyway (keyword: session 0 isolation) _computer.CPUEnabled = _computer.FanControllerEnabled = _computer.HDDEnabled = _computer.RAMEnabled = _computer.MainboardEnabled = true; _computer.Open (); _wmiProvider = new WmiProvider (_computer); _wmiProvider.Update (); _visitor = new UpdateVisitor (); // tick once per second _timer = new Timer (1000.0); _timer.Elapsed += updateTick; _timer.AutoReset = true; _timer.Enabled = true; }
public HWMonitor() { this.computer = new Computer { CPUEnabled = true, GPUEnabled = true, RAMEnabled = true }; computer.Open(); this.cpu_count = _GetCPUCount(); this.cpu_usages = new float[cpu_count]; this.cpu_temperatures = new float[cpu_count]; this.memory_total = (long)new ComputerInfo().TotalPhysicalMemory; this.drives = DriveInfo.GetDrives(); this.drive_usages = new float[drives.Length]; }
public void init() { _computer = new Computer() { CPUEnabled = true, FanControllerEnabled = true, GPUEnabled = true, HDDEnabled = true, MainboardEnabled = true, RAMEnabled = true }; _computer.Open(); monitorManager = new MonitorManager(_computer); monitorManager.Update(); }
public void Configuration(IAppBuilder app) { myComputer = new Computer() { MainboardEnabled = false, CPUEnabled = true, RAMEnabled = false, GPUEnabled = false, FanControllerEnabled = false, HDDEnabled = false }; myComputer.Open(); app.Run(context => { return context.Response.WriteAsync(GetSensorInfo()); }); }
public ContextMenuStrip Create() { thisComputer = new OpenHardwareMonitor.Hardware.Computer() { }; thisComputer.CPUEnabled = true; thisComputer.GPUEnabled = true; thisComputer.HDDEnabled = true; thisComputer.MainboardEnabled = true; thisComputer.RAMEnabled = true; thisComputer.Open(); menu = new ContextMenuStrip(); CreateMenuItems(); return(menu); }
public HardwareMonitor() { WindowsIdentity identity = WindowsIdentity.GetCurrent(); WindowsPrincipal principal = new WindowsPrincipal(identity); isElevated = principal.IsInRole(WindowsBuiltInRole.Administrator); if (isElevated) { MySettings settings = new MySettings(new Dictionary<string, string> { { "/intelcpu/0/temperature/0/values", "H4sIAAAAAAAEAOy9B2AcSZYlJi9tynt/SvVK1+B0oQiAYBMk2JBAEOzBiM3mkuwdaUcjKasqgcplVmVdZhZAzO2dvPfee++999577733ujudTif33/8/XGZkAWz2zkrayZ4hgKrIHz9+fB8/Iu6//MH37x79i9/+NX6N3/TJm9/5f/01fw1+fosnv+A/+OlfS37/jZ/s/Lpv9fff6Ml/NTef/yZPnozc5679b+i193//TQZ+/w2Dd+P9/sZeX/67v/GTf/b3iP3u4/ObBL//73+i+f039+D8Zk/+xz/e/P6beu2TQZju8yH8f6OgzcvPv/U3/Rb8+z/0f/9b/+yfaOn8079X6fr6Cws7ln/iHzNwflPv99/wyS/+xY4+v/evcJ+733+jJ5//Cw7/4ndy9Im3+U2e/Fbnrk31C93vrt/fyPvdb+N//hsF7/4/AQAA//9NLZZ8WAIAAA==" }, { "/intelcpu/0/load/0/values", "H4sIAAAAAAAEAOy9B2AcSZYlJi9tynt/SvVK1+B0oQiAYBMk2JBAEOzBiM3mkuwdaUcjKasqgcplVmVdZhZAzO2dvPfee++999577733ujudTif33/8/XGZkAWz2zkrayZ4hgKrIHz9+fB8/Iu6//MH37x79i9++mpwcv/md/9df89egZ/xX/ym/5y/4D37618Lv7ya//u+58+u+5d9/z7/5t/w9/6u5fP5bH/6av+eTkXyefXxp26ONaf/v/dG/sf39D/rvnv4e5vc/0IP56/waK/vuHzf5I38P8/tv+mv8Rbb9f0pwTF9/zr/1X9vP/8I//+/6Pf7Z30N+/zdf/HX29zd/859q4aCNP5b//U+U3/+7f+zXOjZwfqvDX/V7/o9/vPz+a1G/pv0f+fGlhfk7eZ//N3/0v28//5X0u/n8Cxq7+f1X/tHft20A5x8a/W5/02+BP36Nf+j/nv8XfzrT+c2//Ob4p3+vktvUhNs/+xcWikP6e/4T/5jS5M8/sL8vP/5ff49f/Ivl9//sHzv6PX/vXyG//9R/94/9HuZ34P/5vyC//3W/5e/1exa/k+Bw4bUBnU2bP4Xg/1bn0uafeTH6PatfKL//N3/0t2y/gG9+/8+IzqYNxmU+/+jwX7afY67/nwAAAP//GYSA31gCAAA=" }, }); _computer = new Computer(settings) { CPUEnabled = true }; _computer.GPUEnabled = true; _computer.Open(); } }
// // /Commands // public MainViewModel() { _displayHardwareValuesTimer = new DispatcherTimer(); _clearDisplayTimer = new DispatcherTimer(); _myComputer = new Computer { GPUEnabled = true, CPUEnabled = true }; _myComputer.Open(); ConfigureComponents(); ResetSerialPort(); GetGpuTemps(); GetCpuTemps(); }
public void Start() { Computer = new Computer() { CPUEnabled = true, FanControllerEnabled = true, GPUEnabled = true, HDDEnabled = true, MainboardEnabled = true, RAMEnabled = true }; Computer.Open(); _timer = new Timer(60000); _timer.Elapsed += Update; Update(null, null); _timer.Start(); }
private int _GetCPUCount() { int cpu_count = 0; Computer computer = new Computer { CPUEnabled = true }; computer.Open(); foreach (var hardwareItem in computer.Hardware) { foreach (var sensor in hardwareItem.Sensors) { if (sensor.SensorType == SensorType.Load) { cpu_count++; } } } return(cpu_count); }
private float? GetGpuTemp(string gpuName) { var myComputer = new Computer(); myComputer.Open(); //possible fix for gpu temps on laptops myComputer.GPUEnabled = true; foreach (var hardwareItem in myComputer.Hardware) { hardwareItem.Update(); switch (hardwareItem.HardwareType) { case HardwareType.GpuNvidia: foreach ( var sensor in hardwareItem.Sensors.Where( sensor => sensor.SensorType == SensorType.Temperature && hardwareItem.Name.Contains(gpuName))) { return sensor.Value; } break; case HardwareType.GpuAti: foreach ( var sensor in hardwareItem.Sensors.Where( sensor => sensor.SensorType == SensorType.Temperature && hardwareItem.Name.Contains(gpuName))) { return sensor.Value; } break; default: throw new ArgumentOutOfRangeException(); } } return -1; }
public Form1() { InitializeComponent(); pc = new Computer() { CPUEnabled = true }; pc.Open(); //Makes the window non resizeable this.FormBorderStyle = FormBorderStyle.None; this.MaximizeBox = false; //calls the makeTalk method, which is the Microsoft Voice Synthesizer //makeTalk("Welcome" + SystemInformation.UserName); //Displays the welcome message to the user when they open the program label3.Text = ("Welcome, " + SystemInformation.UserName); //Displays the primary monitor resolution of the user maskedTextBox1.Text = (Convert.ToString(SystemInformation.PrimaryMonitorSize)); maskedTextBox1.Enabled = false; //Displays current time timer1.Start(); //Gets the CPU temp timer2.Start(); //Tells the user how man monitors they have (lol) int monitorCount = SystemInformation.MonitorCount; //tells user the amount of monitors they have label6.Text = "Amount of Monitors: "; maskedTextBox2.Text = Convert.ToString(monitorCount); maskedTextBox2.Enabled = false; //Adds PC name to the form maskedTextBox4.Enabled = false; maskedTextBox4.Text = System.Environment.MachineName; }
private void CheckGPU() { string name = string.Empty; string gpuType = string.Empty; string sensortype = string.Empty; string tempvalue = string.Empty; string fanvalue = string.Empty; int x, y; int hardwareCount; int sensorcount; computerHardware.FanControllerEnabled = true; computerHardware.GPUEnabled = true; computerHardware.Open(); hardwareCount = computerHardware.Hardware.Count(); for (x = 0; x < hardwareCount; x++) { name = computerHardware.Hardware[x].Name; gpuType = computerHardware.Hardware[x].HardwareType.ToString();//判断是A卡还是N卡条件 sensorcount = computerHardware.Hardware[x].Sensors.Count(); if (sensorcount > 0) { for (y = 0; y < sensorcount; y++) { if (computerHardware.Hardware[x].Sensors[y].SensorType.ToString() == "Temperature") { tempvalue = computerHardware.Hardware[x].Sensors[y].Value.ToString(); } if (computerHardware.Hardware[x].Sensors[y].SensorType.ToString() == "Fan") { fanvalue = computerHardware.Hardware[x].Sensors[y].Value.ToString(); } } } GPUinfo(name, gpuType, tempvalue, fanvalue); } }
private float? GetGpuTemp(string gpuName) { var myComputer = new Computer(); myComputer.Open(); myComputer.GPUEnabled = true; var gpuTemps = new List<Object>(); foreach (var hardwareItem in myComputer.Hardware) { switch (hardwareItem.HardwareType) { case HardwareType.GpuNvidia: foreach ( var sensor in hardwareItem.Sensors.Where( sensor => sensor.SensorType == SensorType.Temperature && hardwareItem.Name.Contains(gpuName))) { return sensor.Value; } break; case HardwareType.GpuAti: foreach ( var sensor in hardwareItem.Sensors.Where( sensor => sensor.SensorType == SensorType.Temperature && hardwareItem.Name.Contains(gpuName))) { return sensor.Value; } break; } } return -1; }
private void frmMain_Load(object sender, EventArgs e) { string strError = string.Empty; ScheduleTask.CreateNewTask(); //ScheduleTask.RunTask(); //Initialize Calls and data settingsCall = new SettingCall(); settings = new Settings(); devices = new DevicesCall(); comp = new Computer(); miner = new MinerCall(); if (miner.IsMinersRunning()) if (MessageBox.Show("CUDA Administrator detected that there are CPU or GPU miners already running. Do you want to shutdown these miners now?", "Miners Running", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes) miner.ShutdownMiners(); bool isNewVersion = settingsCall.IsNewVersionAvailable(ref strError); if (!string.IsNullOrEmpty(strError)) { UserMessage.ShowMessage(this, UserMessage.MessageType.Error, "There was an error while trying to check for the latest version of CUDA Administrator. Error: " + strError); strError = string.Empty; } else { if (isNewVersion) if (MessageBox.Show("A new version of CUDA Administrator is available. Would you like to go to the subreddit?", "Verion Check", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes) Process.Start("http://www.reddit.com/r/CudaAdministrator"); } this.Icon = settingsCall.GetApplicationIcon(); comp.Open(); comp.CPUEnabled = true; //Set UI data AddMinersToDataGridViews(); //Setup everything required to run CUDA Admin settingsCall.CreateFolders(ref strError); if (!string.IsNullOrEmpty(strError)) { MessageBox.Show(strError, "Folder Creation", MessageBoxButtons.OK, MessageBoxIcon.Error); Environment.Exit(Environment.ExitCode); } if (!File.Exists(FileManager.CudaMinerPath + "cudaminer.exe") || !File.Exists(FileManager.CudaMinerPath + "pthreadVC2.dll") || !(File.Exists(FileManager.CudaMinerPath + "cudart64_55.dll") || File.Exists(FileManager.CudaMinerPath + "cudart32_55.dll"))) UserMessage.ShowMessage(this, UserMessage.MessageType.Warning, "GPU Miner disabled. Either it or some/all of it's dependencies couldn't be located"); if (!File.Exists(FileManager.CpuMinerPath + "minerd.exe") || !File.Exists(FileManager.CpuMinerPath + "libwinpthread-1.dll") || !(File.Exists(FileManager.CpuMinerPath + "libcurl.dll") || File.Exists(FileManager.CpuMinerPath + "libcurl-4.dll"))) UserMessage.ShowMessage(this, UserMessage.MessageType.Warning, "CPU Miner disabled. Either it or some/all of it's dependencies couldn't be located"); settings = settingsCall.GetSettings(ref strError); if (!string.IsNullOrEmpty(strError)) UserMessage.ShowMessage(this, UserMessage.MessageType.Error, "An error occurred while trying to get the settings data. Error: " + strError); string[] args = Environment.GetCommandLineArgs(); if (args.Contains("--autorun")) btnMinerAutomation.PerformClick(); }
public MainForm() { InitializeComponent(); // check if the OpenHardwareMonitorLib assembly has the correct version if (Assembly.GetAssembly(typeof(Computer)).GetName().Version != Assembly.GetExecutingAssembly().GetName().Version) { MessageBox.Show( "The version of the file OpenHardwareMonitorLib.dll is incompatible.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); Environment.Exit(0); } this.settings = new PersistentSettings(); this.settings.Load(Path.ChangeExtension( Application.ExecutablePath, ".config")); this.unitManager = new UnitManager(settings); // make sure the buffers used for double buffering are not disposed // after each draw call BufferedGraphicsManager.Current.MaximumBuffer = Screen.PrimaryScreen.Bounds.Size; // set the DockStyle here, to avoid conflicts with the MainMenu this.splitContainer.Dock = DockStyle.Fill; this.Font = SystemFonts.MessageBoxFont; treeView.Font = SystemFonts.MessageBoxFont; plotPanel = new PlotPanel(settings, unitManager); plotPanel.Font = SystemFonts.MessageBoxFont; plotPanel.Dock = DockStyle.Fill; nodeCheckBox.IsVisibleValueNeeded += nodeCheckBox_IsVisibleValueNeeded; nodeTextBoxText.DrawText += nodeTextBoxText_DrawText; nodeTextBoxValue.DrawText += nodeTextBoxText_DrawText; nodeTextBoxMin.DrawText += nodeTextBoxText_DrawText; nodeTextBoxMax.DrawText += nodeTextBoxText_DrawText; nodeTextBoxText.EditorShowing += nodeTextBoxText_EditorShowing; foreach (TreeColumn column in treeView.Columns) column.Width = Math.Max(20, Math.Min(400, settings.GetValue("treeView.Columns." + column.Header + ".Width", column.Width))); treeModel = new TreeModel(); root = new Node(System.Environment.MachineName); root.Image = Utilities.EmbeddedResources.GetImage("computer.png"); treeModel.Nodes.Add(root); treeView.Model = treeModel; this.computer = new Computer(settings); systemTray = new SystemTray(computer, settings, unitManager); systemTray.HideShowCommand += hideShowClick; systemTray.ExitCommand += exitClick; int p = (int)Environment.OSVersion.Platform; if ((p == 4) || (p == 128)) { // Unix treeView.RowHeight = Math.Max(treeView.RowHeight, 18); splitContainer.BorderStyle = BorderStyle.None; splitContainer.Border3DStyle = Border3DStyle.Adjust; splitContainer.SplitterWidth = 4; treeView.BorderStyle = BorderStyle.Fixed3D; plotPanel.BorderStyle = BorderStyle.Fixed3D; gadgetMenuItem.Visible = false; minCloseMenuItem.Visible = false; minTrayMenuItem.Visible = false; startMinMenuItem.Visible = false; } else { // Windows treeView.RowHeight = Math.Max(treeView.Font.Height + 1, 18); gadget = new SensorGadget(computer, settings, unitManager); gadget.HideShowCommand += hideShowClick; wmiProvider = new WmiProvider(computer); } logger = new Logger(computer); plotColorPalette = new Color[13]; plotColorPalette[0] = Color.Blue; plotColorPalette[1] = Color.OrangeRed; plotColorPalette[2] = Color.Green; plotColorPalette[3] = Color.LightSeaGreen; plotColorPalette[4] = Color.Goldenrod; plotColorPalette[5] = Color.DarkViolet; plotColorPalette[6] = Color.YellowGreen; plotColorPalette[7] = Color.SaddleBrown; plotColorPalette[8] = Color.RoyalBlue; plotColorPalette[9] = Color.DeepPink; plotColorPalette[10] = Color.MediumSeaGreen; plotColorPalette[11] = Color.Olive; plotColorPalette[12] = Color.Firebrick; computer.HardwareAdded += new HardwareEventHandler(HardwareAdded); computer.HardwareRemoved += new HardwareEventHandler(HardwareRemoved); computer.Open(); timer.Enabled = true; showHiddenSensors = new UserOption("hiddenMenuItem", false, hiddenMenuItem, settings); showHiddenSensors.Changed += delegate(object sender, EventArgs e) { treeModel.ForceVisible = showHiddenSensors.Value; }; showValue = new UserOption("valueMenuItem", true, valueMenuItem, settings); showValue.Changed += delegate(object sender, EventArgs e) { treeView.Columns[1].IsVisible = showValue.Value; }; showMin = new UserOption("minMenuItem", false, minMenuItem, settings); showMin.Changed += delegate(object sender, EventArgs e) { treeView.Columns[2].IsVisible = showMin.Value; }; showMax = new UserOption("maxMenuItem", true, maxMenuItem, settings); showMax.Changed += delegate(object sender, EventArgs e) { treeView.Columns[3].IsVisible = showMax.Value; }; startMinimized = new UserOption("startMinMenuItem", false, startMinMenuItem, settings); minimizeToTray = new UserOption("minTrayMenuItem", true, minTrayMenuItem, settings); minimizeToTray.Changed += delegate(object sender, EventArgs e) { systemTray.IsMainIconEnabled = minimizeToTray.Value; }; minimizeOnClose = new UserOption("minCloseMenuItem", false, minCloseMenuItem, settings); autoStart = new UserOption(null, startupManager.Startup, startupMenuItem, settings); autoStart.Changed += delegate(object sender, EventArgs e) { try { startupManager.Startup = autoStart.Value; } catch (InvalidOperationException) { MessageBox.Show("Updating the auto-startup option failed.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); autoStart.Value = startupManager.Startup; } }; readMainboardSensors = new UserOption("mainboardMenuItem", true, mainboardMenuItem, settings); readMainboardSensors.Changed += delegate(object sender, EventArgs e) { computer.MainboardEnabled = readMainboardSensors.Value; }; readCpuSensors = new UserOption("cpuMenuItem", true, cpuMenuItem, settings); readCpuSensors.Changed += delegate(object sender, EventArgs e) { computer.CPUEnabled = readCpuSensors.Value; }; readRamSensors = new UserOption("ramMenuItem", true, ramMenuItem, settings); readRamSensors.Changed += delegate(object sender, EventArgs e) { computer.RAMEnabled = readRamSensors.Value; }; readGpuSensors = new UserOption("gpuMenuItem", true, gpuMenuItem, settings); readGpuSensors.Changed += delegate(object sender, EventArgs e) { computer.GPUEnabled = readGpuSensors.Value; }; readFanControllersSensors = new UserOption("fanControllerMenuItem", true, fanControllerMenuItem, settings); readFanControllersSensors.Changed += delegate(object sender, EventArgs e) { computer.FanControllerEnabled = readFanControllersSensors.Value; }; readHddSensors = new UserOption("hddMenuItem", true, hddMenuItem, settings); readHddSensors.Changed += delegate(object sender, EventArgs e) { computer.HDDEnabled = readHddSensors.Value; }; showGadget = new UserOption("gadgetMenuItem", false, gadgetMenuItem, settings); showGadget.Changed += delegate(object sender, EventArgs e) { if (gadget != null) gadget.Visible = showGadget.Value; }; celsiusMenuItem.Checked = unitManager.TemperatureUnit == TemperatureUnit.Celsius; fahrenheitMenuItem.Checked = !celsiusMenuItem.Checked; server = new HttpServer(root, this.settings.GetValue("listenerPort", 8085)); if (server.PlatformNotSupported) { webMenuItemSeparator.Visible = false; webMenuItem.Visible = false; } runWebServer = new UserOption("runWebServerMenuItem", false, runWebServerMenuItem, settings); runWebServer.Changed += delegate(object sender, EventArgs e) { if (runWebServer.Value) server.StartHTTPListener(); else server.StopHTTPListener(); }; logSensors = new UserOption("logSensorsMenuItem", false, logSensorsMenuItem, settings); loggingInterval = new UserRadioGroup("loggingInterval", 0, new[] { log1sMenuItem, log2sMenuItem, log5sMenuItem, log10sMenuItem, log30sMenuItem, log1minMenuItem, log2minMenuItem, log5minMenuItem, log10minMenuItem, log30minMenuItem, log1hMenuItem, log2hMenuItem, log6hMenuItem}, settings); loggingInterval.Changed += (sender, e) => { switch (loggingInterval.Value) { case 0: logger.LoggingInterval = new TimeSpan(0, 0, 1); break; case 1: logger.LoggingInterval = new TimeSpan(0, 0, 2); break; case 2: logger.LoggingInterval = new TimeSpan(0, 0, 5); break; case 3: logger.LoggingInterval = new TimeSpan(0, 0, 10); break; case 4: logger.LoggingInterval = new TimeSpan(0, 0, 30); break; case 5: logger.LoggingInterval = new TimeSpan(0, 1, 0); break; case 6: logger.LoggingInterval = new TimeSpan(0, 2, 0); break; case 7: logger.LoggingInterval = new TimeSpan(0, 5, 0); break; case 8: logger.LoggingInterval = new TimeSpan(0, 10, 0); break; case 9: logger.LoggingInterval = new TimeSpan(0, 30, 0); break; case 10: logger.LoggingInterval = new TimeSpan(1, 0, 0); break; case 11: logger.LoggingInterval = new TimeSpan(2, 0, 0); break; case 12: logger.LoggingInterval = new TimeSpan(6, 0, 0); break; } }; InitializePlotForm(); startupMenuItem.Visible = startupManager.IsAvailable; if (startMinMenuItem.Checked) { if (!minTrayMenuItem.Checked) { WindowState = FormWindowState.Minimized; Show(); } } else { Show(); } // Create a handle, otherwise calling Close() does not fire FormClosed IntPtr handle = Handle; // Make sure the settings are saved when the user logs off Microsoft.Win32.SystemEvents.SessionEnded += delegate { computer.Close(); SaveConfiguration(); if (runWebServer.Value) server.Quit(); }; }
public TrayApplicationContext() { _components = new System.ComponentModel.Container(); // Clean old files if they exist if (File.Exists("settings.dat")) { File.Delete("settings.dat"); MessageBox.Show("All stored preferences were cleared during the update.\nPlease set your preferences again by right-clicking the tray icon and selecting settings."); } if (File.Exists("devices.dat")) File.Delete("devices.dat"); // Load settings Boolean first_time = false; if (File.Exists("settings.json")) { try { _settings = JsonConvert.DeserializeObject<Settings>(File.ReadAllText("settings.json")); } catch (Exception e) { MessageBox.Show("Could not load settings. Default values will be used."); _settings = new Settings(); File.WriteAllText("settings.json", JsonConvert.SerializeObject(_settings)); } } else { _settings = new Settings(); _settings.Save(); first_time = true; } // Create history directory if needed if (!Directory.Exists("History")) { Directory.CreateDirectory("History"); } // Load devices _deviceManager = new DeviceManager(_settings); _deviceManager.SaveData(); // Prepare notification system _notificationManager = new NotificationManager(_settings.ComputerName); // Create the icon _notifyIcon = new NotifyIcon(this._components); _notifyIcon.Icon = Resources.icon_app; _notifyIcon.Text = "Icy Monitor Server"; _notifyIcon.DoubleClick += mSettings_Click; _notifyIcon.Visible = true; // Prepare context menu PrepareContextMenu(); // Create computer object for data _computer = new Computer(); _visitor = new UpdateVisitor(); _computer.CPUEnabled = true; _computer.FanControllerEnabled = true; _computer.GPUEnabled = true; _computer.MainboardEnabled = true; _computer.HDDEnabled = true; _computer.Open(); _computer.Accept(_visitor); // Collect sensors (for history and notifications) CollectSensors(); // Create notifications timer StartNotificationsTimer(); // Create history timer if (_settings.History) StartHistoryTimer(); // Create server CreateServer(); // Create the multicast timer if (_settings.Multicast) { try { StartMulticasting(); } catch (SocketException e) { MessageBox.Show("Could not open socket for multicasting. Autodetection will be disabled.\n(Is another copy of Icy Monitor running?)"); } } if (first_time) { DialogResult dialogResult = MessageBox.Show("It is essential that you open a port for the server to use, would you want to open the preferences window?\n\nYou can do this at any moment by double-clicking the tray icon.", "Icy Monitor Server", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { mSettings_Click(null, null); } } // Start the server if (_server.Start() == false) { if (_multicastSocket != null) _multicastSocket.Close(); base.ExitThreadCore(); } }
public static void InitComp(Computer cmp) { cmp.Open(); cmp.CPUEnabled = true; cmp.GPUEnabled = true; }
public List<float> GetCpuTemps() { var myComputer = new Computer(); myComputer.Open(); myComputer.CPUEnabled = true; var temps = (from hardwareItem in myComputer.Hardware where hardwareItem.HardwareType == HardwareType.CPU from sensor in hardwareItem.Sensors where sensor.SensorType == SensorType.Temperature let value = sensor.Value where value != null where value != null select (float) value).ToList(); if (temps.Count != 0) return temps; var tempTemps = new List<float>(); var procCount = Environment.ProcessorCount; for (int i = 0; i < procCount; i++) { tempTemps.Add(-1); } return tempTemps; }
// UPDATE OHM DATA private void UpdateOHM() { string s = String.Empty; string name = string.Empty; string type = string.Empty; string value = string.Empty; int x, y, z, yy, zz; int hardwareCount; int subcount; int sensorcount; int moresubhardwarecount; int moresensorcount; ReportItems.Clear(); computerHardware.MainboardEnabled = true; computerHardware.FanControllerEnabled = true; computerHardware.CPUEnabled = true; computerHardware.GPUEnabled = true; computerHardware.RAMEnabled = true; computerHardware.HDDEnabled = true; computerHardware.Open(); hardwareCount = computerHardware.Hardware.Count(); for (x = 0; x < hardwareCount; x++) { name = computerHardware.Hardware[x].Name; type = computerHardware.Hardware[x].HardwareType.ToString(); value = ""; // no value for non-sensors; AddReportItem(name, type, value); subcount = computerHardware.Hardware[x].SubHardware.Count(); // ADDED 07-28-2016 // NEED Update to view Subhardware for (y = 0; y < subcount; y++) { computerHardware.Hardware[x].SubHardware[y].Update(); if (computerHardware.Hardware[x].SubHardware[y].SubHardware.Count() > 0) { yy = computerHardware.Hardware[x].SubHardware[y].SubHardware.Count(); for (zz = 0; zz < yy; zz++) { computerHardware.Hardware[x].SubHardware[y].SubHardware[zz].Update(); } } } if (subcount > 0) { for (y = 0; y < subcount; y++) { sensorcount = computerHardware.Hardware[x].SubHardware[y].Sensors.Count(); // REV 08-06-2016 moresubhardwarecount = computerHardware.Hardware[x].SubHardware[y].SubHardware.Count(); // END REV name = computerHardware.Hardware[x].SubHardware[y].Name; type = computerHardware.Hardware[x].SubHardware[y].HardwareType.ToString(); value = ""; AddReportItem(name, type, value); if (sensorcount > 0) { for (z = 0; z < sensorcount; z++) { name = computerHardware.Hardware[x].SubHardware[y].Sensors[z].Name; type = computerHardware.Hardware[x].SubHardware[y].Sensors[z].SensorType.ToString(); value = computerHardware.Hardware[x].SubHardware[y].Sensors[z].Value.ToString(); AddReportItem(name, type, value); } } // REV 08-06-2016 for (yy = 0; yy < moresubhardwarecount; yy++) { computerHardware.Hardware[x].SubHardware[y].SubHardware[yy].Update(); moresensorcount = computerHardware.Hardware[x].SubHardware[y].SubHardware[yy].Sensors.Count(); name = computerHardware.Hardware[x].SubHardware[y].SubHardware[yy].Name; type = computerHardware.Hardware[x].SubHardware[y].SubHardware[yy].HardwareType.ToString(); value = ""; AddReportItem(name, type, value); if (sensorcount > 0) { for (zz = 0; zz < sensorcount; zz++) { name = computerHardware.Hardware[x].SubHardware[y].SubHardware[yy].Sensors[zz].Name; type = computerHardware.Hardware[x].SubHardware[y].SubHardware[yy].Sensors[zz].SensorType.ToString(); value = computerHardware.Hardware[x].SubHardware[y].SubHardware[yy].Sensors[zz].Value.ToString(); AddReportItem(name, type, value); } } } // END REV } } sensorcount = computerHardware.Hardware[x].Sensors.Count(); if (sensorcount > 0) { for (z = 0; z < sensorcount; z++) { name = computerHardware.Hardware[x].Sensors[z].Name; type = computerHardware.Hardware[x].Sensors[z].SensorType.ToString(); value = computerHardware.Hardware[x].Sensors[z].Value.ToString(); AddReportItem(name, type, value); } } } computerHardware.Close(); }
public void getCpuTemp() { Computer thisComputer = new Computer() { CPUEnabled = true }; thisComputer.Open(); string temp = ""; foreach (var hardwareItem in thisComputer.Hardware) { if (hardwareItem.HardwareType == HardwareType.CPU) { hardwareItem.Update(); foreach (IHardware subHardware in hardwareItem.SubHardware) { subHardware.Update(); } foreach (var sensor in hardwareItem.Sensors) { if (sensor.SensorType == SensorType.Temperature) { temp += (string.Format("{0} Temperature = {1} \r\n", sensor.Name, sensor.Value.HasValue ? sensor.Value.Value.ToString() : "no value")); } } } } }
private void statusTime_Elapsed(object sender, EventArgs e) { var myComputer = new Computer(); string cpuNum = "", cpuClickedNum = ""; myComputer.CPUEnabled = true; myComputer.Open(); int numOfCpus = 0; App.Current.Dispatcher.Invoke((Action)delegate { foreach (var hardwareItem in myComputer.Hardware) { foreach (var sensor in hardwareItem.Sensors) { if (sensor.SensorType == SensorType.Temperature) { if (sensor.Name == "CPU Core #1") { CPU0Temp.Content = sensor.Value + " °C"; if(cpuClicked == "CPU0Temp") { if (isClicked == true) { cpuClickedNum = cpuClicked.Substring(3, 1); cpuClickedNum = (int.Parse(cpuClickedNum) + 1).ToString(); cpuNum = sensor.Name.Substring(10, 1); } if (cpuClickedNum == cpuNum) { TempGauge.Scales[0].Pointers[0].Value = double.Parse(sensor.Value.ToString()); } isClicked = false; } setMin(CPU0TempMin, sensor.Value, sensor.Index); setMax(CPU0TempMax, sensor.Value, sensor.Index); } else if (sensor.Name == "CPU Core #2") { CPU1Temp.Content = sensor.Value + " °C"; if (cpuClicked == "CPU1Temp") { if (isClicked == true) { cpuClickedNum = cpuClicked.Substring(3, 1); cpuClickedNum = (int.Parse(cpuClickedNum) + 1).ToString(); cpuNum = sensor.Name.Substring(10, 1); } if (cpuClickedNum == cpuNum) { TempGauge.Scales[0].Pointers[0].Value = double.Parse(sensor.Value.ToString()); } isClicked = false; } setMin(CPU1TempMin, sensor.Value, sensor.Index); setMax(CPU1TempMax, sensor.Value, sensor.Index); } else if (sensor.Name == "CPU Core #3") { CPU2Temp.Content = sensor.Value + " °C"; if (cpuClicked == "CPU2Temp") { if (isClicked == true) { cpuClickedNum = cpuClicked.Substring(3, 1); cpuClickedNum = (int.Parse(cpuClickedNum) + 1).ToString(); cpuNum = sensor.Name.Substring(10, 1); } if (cpuClickedNum == cpuNum) { TempGauge.Scales[0].Pointers[0].Value = double.Parse(sensor.Value.ToString()); } isClicked = false; } setMin(CPU2TempMin, sensor.Value, sensor.Index); setMax(CPU2TempMax, sensor.Value, sensor.Index); } else if (sensor.Name == "CPU Core #4") { CPU3Temp.Content = sensor.Value + " °C"; if (cpuClicked == "CPU3Temp") { if (isClicked == true) { cpuClickedNum = cpuClicked.Substring(3, 1); cpuClickedNum = (int.Parse(cpuClickedNum) + 1).ToString(); cpuNum = sensor.Name.Substring(10, 1); } if (cpuClickedNum == cpuNum) { TempGauge.Scales[0].Pointers[0].Value = double.Parse(sensor.Value.ToString()); } isClicked = false; } setMin(CPU3TempMin, sensor.Value, sensor.Index); setMax(CPU3TempMax, sensor.Value, sensor.Index); } else if (sensor.Name == "CPU Core #5") { CPU4Temp.Content = sensor.Value + " °C"; if (cpuClicked == "CPU4Temp") { if (isClicked == true) { cpuClickedNum = cpuClicked.Substring(3, 1); cpuClickedNum = (int.Parse(cpuClickedNum) + 1).ToString(); cpuNum = sensor.Name.Substring(10, 1); } if (cpuClickedNum == cpuNum) { TempGauge.Scales[0].Pointers[0].Value = double.Parse(sensor.Value.ToString()); } isClicked = false; } setMin(CPU4TempMin, sensor.Value, sensor.Index); setMax(CPU4TempMax, sensor.Value, sensor.Index); } else if (sensor.Name == "CPU Core #6") { CPU5Temp.Content = sensor.Value + " °C"; if (cpuClicked == "CPU5Temp") { if (isClicked == true) { cpuClickedNum = cpuClicked.Substring(3, 1); cpuClickedNum = (int.Parse(cpuClickedNum) + 1).ToString(); cpuNum = sensor.Name.Substring(10, 1); } if (cpuClickedNum == cpuNum) { TempGauge.Scales[0].Pointers[0].Value = double.Parse(sensor.Value.ToString()); } isClicked = false; } setMin(CPU5TempMin, sensor.Value, sensor.Index); setMax(CPU5TempMax, sensor.Value, sensor.Index); } else if (sensor.Name == "CPU Core #7") { CPU6Temp.Content = sensor.Value + " °C"; if (cpuClicked == "CPU6Temp") { if (isClicked == true) { cpuClickedNum = cpuClicked.Substring(3, 1); cpuClickedNum = (int.Parse(cpuClickedNum) + 1).ToString(); cpuNum = sensor.Name.Substring(10, 1); } if (cpuClickedNum == cpuNum) { TempGauge.Scales[0].Pointers[0].Value = double.Parse(sensor.Value.ToString()); } isClicked = false; } setMin(CPU6TempMin, sensor.Value, sensor.Index); setMax(CPU6TempMax, sensor.Value, sensor.Index); } else if (sensor.Name == "CPU Core #8") { CPU7Temp.Content = sensor.Value + " °C"; if (cpuClicked == "CPU7Temp") { if (isClicked == true) { cpuClickedNum = cpuClicked.Substring(3, 1); cpuClickedNum = (int.Parse(cpuClickedNum) + 1).ToString(); cpuNum = sensor.Name.Substring(10, 1); } if (cpuClickedNum == cpuNum) { TempGauge.Scales[0].Pointers[0].Value = double.Parse(sensor.Value.ToString()); } isClicked = false; } setMin(CPU7TempMin, sensor.Value, sensor.Index); setMax(CPU7TempMax, sensor.Value, sensor.Index); } else if (sensor.Name == "CPU Core #9") { CPU8Temp.Content = sensor.Value + " °C"; if (cpuClicked == "CPU8Temp") { if (isClicked == true) { cpuClickedNum = cpuClicked.Substring(3, 1); cpuClickedNum = (int.Parse(cpuClickedNum) + 1).ToString(); cpuNum = sensor.Name.Substring(10, 1); } if (cpuClickedNum == cpuNum) { TempGauge.Scales[0].Pointers[0].Value = double.Parse(sensor.Value.ToString()); } isClicked = false; } setMin(CPU8TempMin, sensor.Value, sensor.Index); setMax(CPU8TempMax, sensor.Value, sensor.Index); } else if (sensor.Name == "CPU Core #10") { CPU9Temp.Content = sensor.Value + " °C"; if (cpuClicked == "CPU9Temp") { if (isClicked == true) { cpuClickedNum = cpuClicked.Substring(3, 1); cpuClickedNum = (int.Parse(cpuClickedNum) + 1).ToString(); cpuNum = sensor.Name.Substring(10, 1); } if (cpuClickedNum == cpuNum) { TempGauge.Scales[0].Pointers[0].Value = double.Parse(sensor.Value.ToString()); } isClicked = false; } setMin(CPU9TempMin, sensor.Value, sensor.Index); setMax(CPU9TempMax, sensor.Value, sensor.Index); } else if (sensor.Name == "CPU Core #11") { CPU10Temp.Content = sensor.Value + " °C"; if (cpuClicked == "CPU10Temp") { if (isClicked == true) { cpuClickedNum = cpuClicked.Substring(3, 1); cpuClickedNum = (int.Parse(cpuClickedNum) + 1).ToString(); cpuNum = sensor.Name.Substring(10, 1); } if (cpuClickedNum == cpuNum) { TempGauge.Scales[0].Pointers[0].Value = double.Parse(sensor.Value.ToString()); } isClicked = false; } setMin(CPU10TempMin, sensor.Value, sensor.Index); setMax(CPU10TempMax, sensor.Value, sensor.Index); } else if (sensor.Name == "CPU Core #12") { CPU11Temp.Content = sensor.Value + " °C"; if (cpuClicked == "CPU11Temp") { if (isClicked == true) { cpuClickedNum = cpuClicked.Substring(3, 1); cpuClickedNum = (int.Parse(cpuClickedNum) + 1).ToString(); cpuNum = sensor.Name.Substring(10, 1); } if (cpuClickedNum == cpuNum) { TempGauge.Scales[0].Pointers[0].Value = double.Parse(sensor.Value.ToString()); } isClicked = false; } setMin(CPU11TempMin, sensor.Value, sensor.Index); setMax(CPU11TempMax, sensor.Value, sensor.Index); } else if (sensor.Name == "CPU Package") { numOfCpus = sensor.Index; if (cpuClicked == "CPUPackageTemp") { if (isClicked == true) { cpuClickedNum = cpuClicked.Substring(3, 7); cpuNum = sensor.Name.Substring(4, 7); } if (cpuClickedNum == cpuNum) { TempGauge.Scales[0].Pointers[0].Value = double.Parse(sensor.Value.ToString()); } isClicked = false; } //if (!isClicked) //{ // TempGauge.Scales[0].Pointers[0].Value = double.Parse(sensor.Value.ToString()); //} //Application.Current.MainWindow.Resources.Remove("temperature"); //Application.Current.MainWindow.Resources.Add("temperature", double.Parse(sensor.Value.ToString())); CPUPackageTemp.Content = sensor.Value + " °C"; resizeWindow(numOfCpus); setMin(CPUPackageTempMin, sensor.Value, numOfCpus); setMax(CPUPackageTempMax, sensor.Value, numOfCpus); } } } } }); }
public MainWindow() { InitializeComponent(); /*double size = GetHDDFreeSpace("C"); ManagementScope scope = new ManagementScope("\\\\.\\ROOT\\CIMV2"); //create object query ObjectQuery query = new ObjectQuery("SELECT * FROM Win32_Fan"); //create object searcher ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query); //get a collection of WMI objects ManagementObjectCollection queryCollection = searcher.Get(); //enumerate the collection. foreach (ManagementObject m in queryCollection) { // access properties of the WMI object double speed = Convert.ToDouble(m["DesiredSpeed"]); Console.WriteLine("ActiveCooling : {0}", m["ActiveCooling"]); }*/ //AreaSeries.StrokeThickness = 2; //AreaSeries.Stroke = new SolidColorBrush(Color.FromArgb(255, 27, 161, 226)); //AreaSeries.Interior = new SolidColorBrush(Color.FromArgb(120, 27, 161, 226)); var myComputer = new Computer(); myComputer.CPUEnabled = true; //myComputer.FanControllerEnabled = true; //myComputer.GPUEnabled = true; myComputer.MainboardEnabled = true; myComputer.Open(); foreach (var hardwareItem in myComputer.Hardware) { hardwareItem.Update(); hardwareItem.GetReport(); Console.WriteLine(hardwareItem.GetReport()); Label[] cpuLabels = { CPU0, CPU1, CPU2, CPU3, CPU4, CPU5, CPU6, CPU7, CPU8, CPU9, CPU10, CPU11 }; foreach(Label cpuVisibility in cpuLabels) { cpuVisibility.Visibility = Visibility.Collapsed; } foreach (var subhardware in hardwareItem.SubHardware) { // This will be in the SuperIO subhardware.Update(); if (subhardware.Sensors.Length > 0) // Index out of bounds check { foreach (var sensor in subhardware.Sensors) { // Look for the main fan sensor if (sensor.Name == "Fan #1") { } } } } int numOfCpus = 0, cpuClassifier = 0; foreach (var sensor in hardwareItem.Sensors) { if (sensor.Name == "CPU Package" && cpuClassifier == 0) { numberOfCpus = sensor.Index; cpuClassifier++; } } foreach (var sensor in hardwareItem.Sensors) { if (sensor.SensorType == SensorType.Temperature) { if (sensor.Name == "CPU Core #1") { CPU0.Visibility = Visibility.Visible; cpu[0] = (int)sensor.Value; CPU0Temp.Content = sensor.Value + " °C"; setMin(CPU0TempMin, sensor.Value, sensor.Index); setMax(CPU0TempMax, sensor.Value, sensor.Index); } else if (sensor.Name == "CPU Core #2") { CPU1.Visibility = Visibility.Visible; cpu[1] = (int)sensor.Value; CPU1Temp.Content = sensor.Value + " °C"; setMin(CPU1TempMin, sensor.Value, sensor.Index); setMax(CPU1TempMax, sensor.Value, sensor.Index); } else if (sensor.Name == "CPU Core #3") { CPU2.Visibility = Visibility.Visible; cpu[2] = (int)sensor.Value; CPU2Temp.Content = sensor.Value + " °C"; setMin(CPU2TempMin, sensor.Value, sensor.Index); setMax(CPU2TempMax, sensor.Value, sensor.Index); } else if (sensor.Name == "CPU Core #4") { CPU3.Visibility = Visibility.Visible; cpu[3] = (int)sensor.Value; CPU3Temp.Content = sensor.Value + " °C"; setMin(CPU3TempMin, sensor.Value, sensor.Index); setMax(CPU3TempMax, sensor.Value, sensor.Index); } else if (sensor.Name == "CPU Core #5") { CPU4.Visibility = Visibility.Visible; cpu[4] = (int)sensor.Value; CPU4Temp.Content = sensor.Value + " °C"; setMin(CPU4TempMin, sensor.Value, sensor.Index); setMax(CPU4TempMax, sensor.Value, sensor.Index); } else if (sensor.Name == "CPU Core #6") { CPU5.Visibility = Visibility.Visible; cpu[5] = (int)sensor.Value; CPU5Temp.Content = sensor.Value + " °C"; setMin(CPU5TempMin, sensor.Value, sensor.Index); setMax(CPU5TempMax, sensor.Value, sensor.Index); } else if (sensor.Name == "CPU Core #7") { CPU6.Visibility = Visibility.Visible; cpu[6] = (int)sensor.Value; CPU6Temp.Content = sensor.Value + " °C"; setMin(CPU6TempMin, sensor.Value, sensor.Index); setMax(CPU6TempMax, sensor.Value, sensor.Index); } else if (sensor.Name == "CPU Core #8") { CPU7.Visibility = Visibility.Visible; cpu[7] = (int)sensor.Value; CPU7Temp.Content = sensor.Value + " °C"; setMin(CPU7TempMin, sensor.Value, sensor.Index); setMax(CPU8TempMax, sensor.Value, sensor.Index); } else if (sensor.Name == "CPU Core #9") { CPU8.Visibility = Visibility.Visible; cpu[8] = (int)sensor.Value; CPU8Temp.Content = sensor.Value + " °C"; setMin(CPU8TempMin, sensor.Value, sensor.Index); setMax(CPU8TempMax, sensor.Value, sensor.Index); } else if (sensor.Name == "CPU Core #10") { CPU9.Visibility = Visibility.Visible; cpu[9] = (int)sensor.Value; CPU9Temp.Content = sensor.Value + " °C"; setMin(CPU8TempMin, sensor.Value, sensor.Index); setMax(CPU8TempMax, sensor.Value, sensor.Index); } else if (sensor.Name == "CPU Core #11") { CPU10.Visibility = Visibility.Visible; cpu[10] = (int)sensor.Value; CPU10Temp.Content = sensor.Value + " °C"; setMin(CPU9TempMin, sensor.Value, sensor.Index); setMax(CPU9TempMax, sensor.Value, sensor.Index); } else if (sensor.Name == "CPU Core #12") { CPU11.Visibility = Visibility.Visible; cpu[11] = (int)sensor.Value; CPU11Temp.Content = sensor.Value + " °C"; setMin(CPU10TempMin, sensor.Value, sensor.Index); setMax(CPU10TempMax, sensor.Value, sensor.Index); } else if (sensor.Name == "CPU Package") { numOfCpus = sensor.Index; TempGauge.Scales[0].Pointers[0].Value = double.Parse(sensor.Value.ToString()); //Application.Current.MainWindow.Resources.Add("temperature", double.Parse(sensor.Value.ToString())); CPUPackageTemp.Content = sensor.Value + " °C"; setMin(CPUPackageTempMin, sensor.Value, numOfCpus); setMax(CPUPackageTempMax, sensor.Value, numOfCpus); resizeWindow(numOfCpus); } } } int count; for (count = 0; count < cpu.Length; count++) { cpu[count] = cpu[count].HasValue ? cpu[count] : 0; } /*cpu_0 = cpu_0.HasValue ? cpu_0 : 0; cpu_1 = cpu_0.HasValue ? cpu_1 : 0; cpu_2 = cpu_0.HasValue ? cpu_2 : 0; cpu_3 = cpu_0.HasValue ? cpu_3 : 0; cpu_4 = cpu_0.HasValue ? cpu_4 : 0; cpu_5 = cpu_0.HasValue ? cpu_5 : 0; cpu_6 = cpu_0.HasValue ? cpu_6 : 0; cpu_7 = cpu_0.HasValue ? cpu_7 : 0; cpu_8 = cpu_0.HasValue ? cpu_8 : 0; cpu_9 = cpu_0.HasValue ? cpu_9 : 0; cpu_10 = cpu_0.HasValue ? cpu_10 : 0; cpu_11 = cpu_0.HasValue ? cpu_11 : 0;*/ /*char[] charsToTrim = { ' ', '°', 'C' }; cpu_0 = Int32.Parse(CPU0Temp.Content.ToString()) ? cpu_0 = Int32.Parse(CPU0Temp.Content.ToString().TrimEnd(charsToTrim)) : cpu_0 = 0; cpu_1 = Int32.Parse(CPU1Temp.Content.ToString().TrimEnd(charsToTrim)); cpu_2 = Int32.Parse(CPU2Temp.Content.ToString().TrimEnd(charsToTrim)); cpu_3 = Int32.Parse(CPU3Temp.Content.ToString().TrimEnd(charsToTrim)); cpu_4 = Int32.Parse(CPU4Temp.Content.ToString().TrimEnd(charsToTrim)); cpu_5 = Int32.Parse(CPU5Temp.Content.ToString().TrimEnd(charsToTrim)); cpu_6 = Int32.Parse(CPU6Temp.Content.ToString().TrimEnd(charsToTrim)); cpu_7 = Int32.Parse(CPU7Temp.Content.ToString().TrimEnd(charsToTrim)); cpu_8 = Int32.Parse(CPU8Temp.Content.ToString().TrimEnd(charsToTrim)); cpu_9 = Int32.Parse(CPU9Temp.Content.ToString().TrimEnd(charsToTrim)); cpu_10 = Int32.Parse(CPU10Temp.Content.ToString().TrimEnd(charsToTrim)); cpu_11 = Int32.Parse(CPU11Temp.Content.ToString().TrimEnd(charsToTrim)); */ string sql = "INSERT INTO pc_info (cpu_0, cpu_1, cpu_2, cpu_3, cpu_4, cpu_5, cpu_6, cpu_7, cpu_8, cpu_9, " + "cpu_10, cpu_11) VALUES (@cpu_0, @cpu_1, @cpu_2, @cpu_3, @cpu_4, @cpu_5, @cpu_6, @cpu_7, " + "@cpu_8, @cpu_9, @cpu_10, @cpu_11)"; //try //{ // conn.Open(); // MySqlCommand cmd = new MySqlCommand(sql, conn); // cmd.CommandType = CommandType.Text; // for (count = 0; count < cpu.Length; count++) // { // cpu[count] = cpu[count].HasValue ? cpu[count] : 0; // cmd.Parameters.AddWithValue("cpu_" + count, cpu[count]); // } // /*cmd.Parameters.AddWithValue("cpu_0", cpu_0); // cmd.Parameters.AddWithValue("cpu_1", cpu_1); // cmd.Parameters.AddWithValue("cpu_2", cpu_2); // cmd.Parameters.AddWithValue("cpu_3", cpu_3); // cmd.Parameters.AddWithValue("cpu_4", cpu_4); // cmd.Parameters.AddWithValue("cpu_5", cpu_5); // cmd.Parameters.AddWithValue("cpu_6", cpu_6); // cmd.Parameters.AddWithValue("cpu_7", cpu_7); // cmd.Parameters.AddWithValue("cpu_8", cpu_8); // cmd.Parameters.AddWithValue("cpu_9", cpu_9); // cmd.Parameters.AddWithValue("cpu_10", cpu_10); // cmd.Parameters.AddWithValue("cpu_11", cpu_11);*/ // cmd.ExecuteNonQuery(); // if(HardwareMonitor.Properties.Settings.Default.isIdSet == false) // { // saveId(); // } //} //catch (Exception error) //{ // Console.WriteLine("Error inserting data:\n %s", error); //} //finally //{ // conn.Close(); //} } //System.Windows.Threading.DispatcherTimer dispatcherTimer = new System.Windows.Threading.DispatcherTimer(); //dispatcherTimer.Tick += dispatcherTimer_Tick; //dispatcherTimer.Interval = new TimeSpan(0,0,1); //dispatcherTimer.Start(); System.Timers.Timer statusTime = new System.Timers.Timer(); statusTime.Interval = 1000; statusTime.Elapsed += new System.Timers.ElapsedEventHandler(statusTime_Elapsed); statusTime.Enabled = true; //main = this; }