public void CommonRepopulate(IMonitor common) { PerformanceCounterCategory hddUsageCategories = new PerformanceCounterCategory("LogicalDisk", IpOrHostName); CommonPopulateHddUsage(hddUsageCategories.GetInstanceNames()); ServiceController[] services = ServiceController.GetServices(IpOrHostName); String[] servicesList = new String[services.Length]; Int32 count = 0; foreach (ServiceController sc in services) { servicesList[count++] = sc.DisplayName; } CommonPopulateServiceState(servicesList); PerformanceCounterCategory processStateCategories = new PerformanceCounterCategory("Process", IpOrHostName); CommonPopulateProcessState(processStateCategories.GetInstanceNames()); switch(common.Type) { case FullMonitorType.PerformanceCounter: try { PfcMonitor pfc = (PfcMonitor) common; if (_commonPfcCounter == null) { _commonPfcCounter = new PerformanceCounter { CategoryName = pfc.Category, CounterName = pfc.Counter, InstanceName = pfc.Instance, MachineName = pfc.Server }; } else { _commonPfcCounter.Dispose(); _commonPfcCounter = new PerformanceCounter { CategoryName = pfc.Category, CounterName = pfc.Counter, InstanceName = pfc.Instance, MachineName = pfc.Server }; } switch (pfc.Category) { case "Processor": _commonType = CommonMonitorType.CpuUsage; commonCpuUsageTypeDdl.Text = pfc.Counter; commonCpuCriticalTextBox.Text = pfc.ThresholdPanic; commonCpuWarningTextBox.Text = pfc.ThresholdWarning; commonCpuGroupBox.BackColor = Color.LightGray; commonCpuSelected.Checked = true; break; case "LogicalDisk": _commonType = CommonMonitorType.HddUsage; commonHddDriveLetterDdl.Text = pfc.Instance; commonHddCriticalTextBox.Text = pfc.ThresholdPanic; commonHddWarningTextBox.Text = pfc.ThresholdWarning; commonHddGroupBox.BackColor = Color.LightGray; commonHddSelected.Checked = true; break; case "Process": _commonType = CommonMonitorType.ProcessState; commonProcessStateUsageTypeDdl.Text = pfc.Counter; commonProcessStateProcessDd.Text = pfc.Instance; commonProcessStateCriticalTextBox.Text = pfc.ThresholdPanic; commonProcessStateWarningTextBox.Text = pfc.ThresholdWarning; commonProcessGroupBox.BackColor = Color.LightGray; commonProcessSelected.Checked = true; break; case "Paging File": _commonType = CommonMonitorType.SwapFileUsage; commonSwapFileUsageTypeDdl.Text = pfc.Counter; commonSwapFileCriticalTextBox.Text = pfc.ThresholdPanic; commonSwapFileWarningTextBox.Text = pfc.ThresholdWarning; commonSwapFileGroupBox.BackColor = Color.LightGray; commonSwapFileSelected.Checked = true; break; } } catch(Exception ex) { Logger.Instance.LogException(this.GetType(), ex); } break; case FullMonitorType.Service: ServiceMonitor service = (ServiceMonitor) common; _commonServiceState = new ServiceController(service.Services[0].ServiceName, service.Server); _commonType = CommonMonitorType.ServiceState; commonServiceServicesChoiceDdl.Text = service.Services[0].ServiceName; //NOTE: there is only one service in Common tab commonServiceGroupBox.BackColor = Color.LightGray; commonServiceSelected.Checked = true; break; case FullMonitorType.Wmi: WmiMonitor wmi = (WmiMonitor) common; _commonType = CommonMonitorType.MemoryUsage; //NOTE: % In Use == WmiType.MemoryUsage //NOTE: Available == WmiType.MemoryFree switch(wmi.WmiType) { case WmiType.MemoryFree: commonMemoryUsageTypeDdl.Text = "Available"; break; case WmiType.MemoryUsage: commonMemoryUsageTypeDdl.Text = "% In Use"; break; } commonMemoryWarningTextBox.Text = wmi.ThresholdWarning; commonMemoryCriticalTextBox.Text = wmi.ThresholdPanic; commonMemoryGroupBox.BackColor = Color.LightGray; commonMemorySelected.Checked = true; break; } commonMonitorTestDataUpdateFreqTextBox.Text = common.UpdateFrequency.ToString(); addServerValidIpIpTextBox2.Text = common.Server; addServerValidIpMonitorName2.Text = common.FriendlyName; alreadyPopulated = true; }
private void CommonMonitorGroupBoxEnter(object sender, EventArgs e) { GroupBox groupBox = (GroupBox)sender; groupBox.BackColor = Color.LightGray; //NOTE: uncheck boxes foreach (Control control in this.commonChooserGroupBox.Controls) { if (control.GetType() == typeof(GroupBox)) { if (control.Name != groupBox.Name) { control.BackColor = Color.Transparent; foreach (Control childcontrol in control.Controls) { if (childcontrol.Name.EndsWith("Selected") && childcontrol.GetType() == typeof(CheckBox)) { ((CheckBox)childcontrol).CheckState = CheckState.Unchecked; break; } } } } } foreach (Control control in groupBox.Controls) { if (control.GetType() == typeof(CheckBox)) { if (control.Name.EndsWith("Selected")) { ((CheckBox)control).Checked = true; _commonType = (CommonMonitorType)control.Tag;//(CommonMonitorType)Enum.Parse(typeof(CommonMonitorType), control.Tag.ToString()); break; } } } }