private void cmdTest_Click(object sender, EventArgs e) { if (DoValidate()) { string lastStep = "Initialize values"; try { Cursor.Current = Cursors.WaitCursor; RegistryQueryInstance testQueryInstance = new RegistryQueryInstance(); testQueryInstance.Name = txtName.Text; testQueryInstance.UseRemoteServer = chkUseRemoteServer.Checked; testQueryInstance.Server = txtServer.Text; testQueryInstance.Path = txtPath.Text; testQueryInstance.KeyName = txtKey.Text; testQueryInstance.ExpandEnvironmentNames = chkExpandEnvNames.Checked; testQueryInstance.RegistryHive = RegistryQueryInstance.GetRegistryHiveFromString(cboRegistryHive.Text); if (!chkValueIsANumber.Checked) { testQueryInstance.ReturnValueIsNumber = false; testQueryInstance.ReturnValueInARange = false; testQueryInstance.ReturnValueInverted = false; } else { testQueryInstance.ReturnValueIsNumber = true; testQueryInstance.ReturnValueInARange = chkValueIsInARange.Checked; testQueryInstance.ReturnValueInverted = !chkReturnValueNotInverted.Checked; } testQueryInstance.SuccessValue = cboSuccessValue.Text; testQueryInstance.WarningValue = cboWarningValue.Text; testQueryInstance.ErrorValue = cboErrorValue.Text; object returnValue = null; returnValue = testQueryInstance.GetValue(); MonitorStates state = testQueryInstance.EvaluateValue(returnValue); if (state == MonitorStates.Good) { MessageBox.Show(string.Format("Success!\r\nValue return: {0}", returnValue), "Test", MessageBoxButtons.OK, MessageBoxIcon.Information); } else if (state == MonitorStates.Warning) { MessageBox.Show(string.Format("Warning!\r\nValue return: {0}", returnValue), "Test", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { MessageBox.Show(string.Format("Error!\r\nValue return: {0}", returnValue), "Test", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception ex) { MessageBox.Show(string.Format("Failed!\r\nLast step: {0}\r\n{1}", lastStep, ex.Message), "Test", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } finally { Cursor.Current = Cursors.Default; } } }
private void RefreshList() { try { lvwDetails.BeginUpdate(); if (SelectedRegistryQueryConfig != null) { foreach (ListViewItem lvi in lvwDetails.Items) { if (lvi.Tag is RegistryQueryInstance) { RegistryQueryInstance rq = (RegistryQueryInstance)lvi.Tag; try { object value = rq.GetValue(); MonitorStates currentState = rq.EvaluateValue(value); if (value == null) { lvi.SubItems[2].Text = "Null"; } else { lvi.SubItems[2].Text = value.ToString(); } if (currentState == MonitorStates.Good) { lvi.ImageIndex = 0; lvi.BackColor = SystemColors.Window; } else if (currentState == MonitorStates.Warning) { lvi.ImageIndex = 1; lvi.BackColor = Color.SandyBrown; } else { lvi.ImageIndex = 2; lvi.BackColor = Color.Salmon; } } catch (Exception ex) { lvi.SubItems[2].Text = ex.Message; lvi.ImageIndex = 2; lvi.BackColor = Color.Salmon; } } } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { lvwDetails.EndUpdate(); toolStripStatusLabel1.Text = "Last updated " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); } }