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(); CollectorState state = testQueryInstance.EvaluateValue(returnValue); if (state == CollectorState.Good) { MessageBox.Show(string.Format("Success!\r\nValue return: {0}", FormatUtils.FormatArrayToString(returnValue)), "Test", MessageBoxButtons.OK, MessageBoxIcon.Information); } else if (state == CollectorState.Warning) { MessageBox.Show(string.Format("Warning!\r\nValue return: {0}", FormatUtils.FormatArrayToString(returnValue)), "Test", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { MessageBox.Show(string.Format("Error!\r\nValue return: {0}", FormatUtils.FormatArrayToString(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; } } }
public override void RefreshDisplayData() { try { lvwEntries.BeginUpdate(); if (Collector != null && Collector.AgentConfig != null) { foreach (ListViewItem lvi in lvwEntries.Items) { if (lvi.Tag is RegistryQueryInstance) { RegistryQueryInstance rq = (RegistryQueryInstance)lvi.Tag; try { object value = rq.GetValue(); CollectorState currentState = rq.EvaluateValue(value); if (value == null) { lvi.SubItems[2].Text = "Null"; } else { lvi.SubItems[2].Text = value.ToString(); } if (currentState == CollectorState.Good) { lvi.ImageIndex = 0; lvi.BackColor = SystemColors.Window; } else if (currentState == CollectorState.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 { lvwEntries.EndUpdate(); toolStripStatusLabelDetails.Text = "Last updated " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); } }