public MainForm() { InitializeComponent(); _settings = new PersistentSettings(); _settings.Load(Path.ChangeExtension(Application.ExecutablePath, ".config")); _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 splitContainer.Dock = DockStyle.Fill; Font = SystemFonts.MessageBoxFont; treeView.Font = SystemFonts.MessageBoxFont; // Set the bounds immediately, so that our child components can be // properly placed. Bounds = new Rectangle { X = _settings.GetValue("mainForm.Location.X", Location.X), Y = _settings.GetValue("mainForm.Location.Y", Location.Y), Width = _settings.GetValue("mainForm.Width", 470), Height = _settings.GetValue("mainForm.Height", 640) }; _plotPanel = new PlotPanel(_settings, _unitManager) { Font = SystemFonts.MessageBoxFont, 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 treeModel = new TreeModel(); _root = new Node(Environment.MachineName) { Image = EmbeddedResources.GetImage("computer.png") }; treeModel.Nodes.Add(_root); treeView.Model = treeModel; _computer = new Computer(_settings); _systemTray = new SystemTray(_computer, _settings, _unitManager); _systemTray.HideShowCommand += HideShowClick; _systemTray.ExitCommand += ExitClick; if (Software.OperatingSystem.IsUnix) { // 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 += HardwareAdded; _computer.HardwareRemoved += HardwareRemoved; _computer.Open(); timer.Enabled = true; UserOption showHiddenSensors = new UserOption("hiddenMenuItem", false, hiddenMenuItem, _settings); showHiddenSensors.Changed += delegate { treeModel.ForceVisible = showHiddenSensors.Value; }; UserOption showValue = new UserOption("valueMenuItem", true, valueMenuItem, _settings); showValue.Changed += delegate { treeView.Columns[1].IsVisible = showValue.Value; }; UserOption showMin = new UserOption("minMenuItem", false, minMenuItem, _settings); showMin.Changed += delegate { treeView.Columns[2].IsVisible = showMin.Value; }; UserOption showMax = new UserOption("maxMenuItem", true, maxMenuItem, _settings); showMax.Changed += delegate { treeView.Columns[3].IsVisible = showMax.Value; }; var _ = new UserOption("startMinMenuItem", false, startMinMenuItem, _settings); _minimizeToTray = new UserOption("minTrayMenuItem", true, minTrayMenuItem, _settings); _minimizeToTray.Changed += delegate { _systemTray.IsMainIconEnabled = _minimizeToTray.Value; }; _minimizeOnClose = new UserOption("minCloseMenuItem", false, minCloseMenuItem, _settings); _autoStart = new UserOption(null, _startupManager.Startup, startupMenuItem, _settings); _autoStart.Changed += delegate { 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 { _computer.IsMotherboardEnabled = _readMainboardSensors.Value; }; _readCpuSensors = new UserOption("cpuMenuItem", true, cpuMenuItem, _settings); _readCpuSensors.Changed += delegate { _computer.IsCpuEnabled = _readCpuSensors.Value; }; _readRamSensors = new UserOption("ramMenuItem", true, ramMenuItem, _settings); _readRamSensors.Changed += delegate { _computer.IsMemoryEnabled = _readRamSensors.Value; }; _readGpuSensors = new UserOption("gpuMenuItem", true, gpuMenuItem, _settings); _readGpuSensors.Changed += delegate { _computer.IsGpuEnabled = _readGpuSensors.Value; }; _readFanControllersSensors = new UserOption("fanControllerMenuItem", true, fanControllerMenuItem, _settings); _readFanControllersSensors.Changed += delegate { _computer.IsControllerEnabled = _readFanControllersSensors.Value; }; _readHddSensors = new UserOption("hddMenuItem", true, hddMenuItem, _settings); _readHddSensors.Changed += delegate { _computer.IsStorageEnabled = _readHddSensors.Value; }; _readNicSensors = new UserOption("nicMenuItem", true, nicMenuItem, _settings); _readNicSensors.Changed += delegate { _computer.IsNetworkEnabled = _readNicSensors.Value; }; _showGadget = new UserOption("gadgetMenuItem", false, gadgetMenuItem, _settings); _showGadget.Changed += delegate { if (_gadget != null) { _gadget.Visible = _showGadget.Value; } }; celsiusMenuItem.Checked = _unitManager.TemperatureUnit == TemperatureUnit.Celsius; fahrenheitMenuItem.Checked = !celsiusMenuItem.Checked; Server = new HttpServer(_root, _settings.GetValue("listenerPort", 8085), _settings.GetValue("authenticationEnabled", false), _settings.GetValue("authenticationUserName", ""), _settings.GetValue("authenticationPassword", "")); if (Server.PlatformNotSupported) { webMenuItemSeparator.Visible = false; webMenuItem.Visible = false; } _runWebServer = new UserOption("runWebServerMenuItem", false, runWebServerMenuItem, _settings); _runWebServer.Changed += delegate { if (_runWebServer.Value) { Server.StartHttpListener(); } else { Server.StopHttpListener(); } }; authWebServerMenuItem.Checked = _settings.GetValue("authenticationEnabled", false); _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; } }; _sensorValuesTimeWindow = new UserRadioGroup("sensorValuesTimeWindow", 10, new[] { timeWindow30sMenuItem, timeWindow1minMenuItem, timeWindow2minMenuItem, timeWindow5minMenuItem, timeWindow10minMenuItem, timeWindow30minMenuItem, timeWindow1hMenuItem, timeWindow2hMenuItem, timeWindow6hMenuItem, timeWindow12hMenuItem, timeWindow24hMenuItem }, _settings); _sensorValuesTimeWindow.Changed += (sender, e) => { TimeSpan timeWindow = TimeSpan.Zero; switch (_sensorValuesTimeWindow.Value) { case 0: timeWindow = new TimeSpan(0, 0, 30); break; case 1: timeWindow = new TimeSpan(0, 1, 0); break; case 2: timeWindow = new TimeSpan(0, 2, 0); break; case 3: timeWindow = new TimeSpan(0, 5, 0); break; case 4: timeWindow = new TimeSpan(0, 10, 0); break; case 5: timeWindow = new TimeSpan(0, 30, 0); break; case 6: timeWindow = new TimeSpan(1, 0, 0); break; case 7: timeWindow = new TimeSpan(2, 0, 0); break; case 8: timeWindow = new TimeSpan(6, 0, 0); break; case 9: timeWindow = new TimeSpan(12, 0, 0); break; case 10: timeWindow = new TimeSpan(24, 0, 0); break; } _computer.Accept(new SensorVisitor(delegate(ISensor sensor) { sensor.ValuesTimeWindow = timeWindow; })); }; InitializePlotForm(); InitializeSplitter(); 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 // Make sure the settings are saved when the user logs off Microsoft.Win32.SystemEvents.SessionEnded += delegate { _computer.Close(); SaveConfiguration(); if (_runWebServer.Value) { Server.Quit(); } }; Microsoft.Win32.SystemEvents.PowerModeChanged += PowerModeChanged; }
public TypeNode(SensorType sensorType) { SensorType = sensorType; switch (sensorType) { case SensorType.Voltage: Image = EmbeddedResources.GetImage("voltage.png"); Text = "Voltages"; break; case SensorType.Clock: Image = EmbeddedResources.GetImage("clock.png"); Text = "Clocks"; break; case SensorType.Load: Image = EmbeddedResources.GetImage("load.png"); Text = "Load"; break; case SensorType.Temperature: Image = EmbeddedResources.GetImage("temperature.png"); Text = "Temperatures"; break; case SensorType.Fan: Image = EmbeddedResources.GetImage("fan.png"); Text = "Fans"; break; case SensorType.Flow: Image = EmbeddedResources.GetImage("flow.png"); Text = "Flows"; break; case SensorType.Control: Image = EmbeddedResources.GetImage("control.png"); Text = "Controls"; break; case SensorType.Level: Image = EmbeddedResources.GetImage("level.png"); Text = "Levels"; break; case SensorType.Power: Image = EmbeddedResources.GetImage("power.png"); Text = "Powers"; break; case SensorType.Data: Image = EmbeddedResources.GetImage("data.png"); Text = "Data"; break; case SensorType.Factor: Image = EmbeddedResources.GetImage("factor.png"); Text = "Factors"; break; } NodeAdded += TypeNode_NodeAdded; NodeRemoved += TypeNode_NodeRemoved; }