private void EditConfigEntry_Load(object sender, EventArgs e) { if (SelectedEntry != null) { WMIQueryCollectorConfigEntry selectedEntry = (WMIQueryCollectorConfigEntry)SelectedEntry; txtName.Text = selectedEntry.Name; txtNamespace.Text = selectedEntry.Namespace == null ? "root\\CIMV2" : selectedEntry.Namespace; txtMachines.Text = selectedEntry.Machinename == null ? "." : selectedEntry.Machinename; txtStateQuery.Text = selectedEntry.StateQuery; //chkIsReturnValueInt.Checked = selectedEntry.ReturnValueIsInt; //chkReturnValueNotInverted.Checked = !selectedEntry.ReturnValueInverted; chkUseRowCountAsValue.Checked = selectedEntry.UseRowCountAsValue; cboReturnCheckSequence.SelectedIndex = (int)selectedEntry.ReturnCheckSequence; txtSuccess.Text = selectedEntry.GoodValue; cboSuccessMatchType.SelectedIndex = (int)selectedEntry.GoodResultMatchType; txtWarning.Text = selectedEntry.WarningValue; cboWarningMatchType.SelectedIndex = (int)selectedEntry.WarningResultMatchType; txtError.Text = selectedEntry.ErrorValue; cboErrorMatchType.SelectedIndex = (int)selectedEntry.ErrorResultMatchType; txtDetailQuery.Text = selectedEntry.DetailQuery; txtColumnNames.Text = selectedEntry.ColumnNames.ToCSVString(); cboOutputValueUnit.Text = selectedEntry.OutputValueUnit; } }
private void lblColumnNameSequence_DoubleClick(object sender, EventArgs e) { try { WMIQueryCollectorConfigEntry tmpWMIConfig = new WMIQueryCollectorConfigEntry(); tmpWMIConfig.Name = txtName.Text; tmpWMIConfig.Namespace = txtNamespace.Text; tmpWMIConfig.Machinename = txtMachines.Text; tmpWMIConfig.StateQuery = txtStateQuery.Text; //tmpWMIConfig.ReturnValueIsInt = chkIsReturnValueInt.Checked; //tmpWMIConfig.ReturnValueInverted = !chkReturnValueNotInverted.Checked; tmpWMIConfig.UseRowCountAsValue = chkUseRowCountAsValue.Checked; tmpWMIConfig.ReturnCheckSequence = (CollectorAgentReturnValueCheckSequence)cboReturnCheckSequence.SelectedIndex; tmpWMIConfig.GoodValue = txtSuccess.Text; tmpWMIConfig.GoodResultMatchType = (CollectorAgentReturnValueCompareMatchType)cboSuccessMatchType.SelectedIndex; tmpWMIConfig.WarningValue = txtWarning.Text; tmpWMIConfig.WarningResultMatchType = (CollectorAgentReturnValueCompareMatchType)cboWarningMatchType.SelectedIndex; tmpWMIConfig.ErrorValue = txtError.Text; tmpWMIConfig.ErrorResultMatchType = (CollectorAgentReturnValueCompareMatchType)cboErrorMatchType.SelectedIndex; tmpWMIConfig.DetailQuery = txtDetailQuery.Text; tmpWMIConfig.ColumnNames = txtColumnNames.Text.ToListFromCSVString(); // tmpWMIConfig.KeyColumn = (int)keyColumnNumericUpDown.Value; List <DataColumn> columns = tmpWMIConfig.GetDetailQueryColumns(); txtColumnNames.Text = ""; columns.ForEach(c => txtColumnNames.Text += c.ColumnName + ", "); txtColumnNames.Text = txtColumnNames.Text.TrimEnd(' ', ','); } catch { } }
private void cmdOK_Click(object sender, EventArgs e) { if (DoValidate()) { if (SelectedEntry == null) { SelectedEntry = new WMIQueryCollectorConfigEntry(); } WMIQueryCollectorConfigEntry selectedEntry = (WMIQueryCollectorConfigEntry)SelectedEntry; selectedEntry.Name = txtName.Text; selectedEntry.Namespace = txtNamespace.Text; selectedEntry.Machinename = txtMachines.Text; selectedEntry.StateQuery = txtStateQuery.Text; //selectedEntry.ReturnValueIsInt = chkIsReturnValueInt.Checked; //selectedEntry.ReturnValueInverted = !chkReturnValueNotInverted.Checked; selectedEntry.UseRowCountAsValue = chkUseRowCountAsValue.Checked; selectedEntry.ReturnCheckSequence = (CollectorAgentReturnValueCheckSequence)cboReturnCheckSequence.SelectedIndex; selectedEntry.GoodValue = txtSuccess.Text; selectedEntry.GoodResultMatchType = (CollectorAgentReturnValueCompareMatchType)cboSuccessMatchType.SelectedIndex; selectedEntry.WarningValue = txtWarning.Text; selectedEntry.WarningResultMatchType = (CollectorAgentReturnValueCompareMatchType)cboWarningMatchType.SelectedIndex; selectedEntry.ErrorValue = txtError.Text; selectedEntry.ErrorResultMatchType = (CollectorAgentReturnValueCompareMatchType)cboErrorMatchType.SelectedIndex; selectedEntry.DetailQuery = txtDetailQuery.Text; selectedEntry.ColumnNames = txtColumnNames.Text.ToListFromCSVString(); selectedEntry.OutputValueUnit = cboOutputValueUnit.Text; SelectedEntry = selectedEntry; //WmiIConfig.KeyColumn = (int)keyColumnNumericUpDown.Value; DialogResult = System.Windows.Forms.DialogResult.OK; Close(); } }
private void cmdOK_Click(object sender, EventArgs e) { if (DoValidate()) { if (SelectedEntry == null) { SelectedEntry = new WMIQueryCollectorConfigEntry(); } WMIQueryCollectorConfigEntry selectedEntry = (WMIQueryCollectorConfigEntry)SelectedEntry; selectedEntry.Name = txtName.Text; selectedEntry.Namespace = txtNamespace.Text; selectedEntry.Machinename = txtMachines.Text; selectedEntry.StateQuery = txtStateQuery.Text; selectedEntry.UseRowCountAsValue = chkUseRowCountAsValue.Checked; selectedEntry.ReturnCheckSequence = (CollectorAgentReturnValueCheckSequence)cboReturnCheckSequence.SelectedIndex; selectedEntry.GoodValue = txtSuccess.Text; selectedEntry.GoodResultMatchType = (CollectorAgentReturnValueCompareMatchType)cboSuccessMatchType.SelectedIndex; selectedEntry.WarningValue = txtWarning.Text; selectedEntry.WarningResultMatchType = (CollectorAgentReturnValueCompareMatchType)cboWarningMatchType.SelectedIndex; selectedEntry.ErrorValue = txtError.Text; selectedEntry.ErrorResultMatchType = (CollectorAgentReturnValueCompareMatchType)cboErrorMatchType.SelectedIndex; selectedEntry.OutputValueUnit = cboOutputValueUnit.Text; SelectedEntry = selectedEntry; DialogResult = System.Windows.Forms.DialogResult.OK; Close(); } }
private void cmdTestDB_Click(object sender, EventArgs e) { if (DoValidate()) { string lastStep = "Initialize values"; string columnWarningText = ""; try { WMIQueryCollectorConfigEntry tmpWMIConfig = new WMIQueryCollectorConfigEntry(); tmpWMIConfig.Name = txtName.Text; tmpWMIConfig.Namespace = txtNamespace.Text; tmpWMIConfig.Machinename = txtMachines.Text; tmpWMIConfig.StateQuery = txtStateQuery.Text; //tmpWMIConfig.ReturnValueIsInt = chkIsReturnValueInt.Checked; //tmpWMIConfig.ReturnValueInverted = !chkReturnValueNotInverted.Checked; tmpWMIConfig.UseRowCountAsValue = chkUseRowCountAsValue.Checked; tmpWMIConfig.ReturnCheckSequence = (CollectorAgentReturnValueCheckSequence)cboReturnCheckSequence.SelectedIndex; tmpWMIConfig.GoodValue = txtSuccess.Text; tmpWMIConfig.GoodResultMatchType = (CollectorAgentReturnValueCompareMatchType)cboSuccessMatchType.SelectedIndex; tmpWMIConfig.WarningValue = txtWarning.Text; tmpWMIConfig.WarningResultMatchType = (CollectorAgentReturnValueCompareMatchType)cboWarningMatchType.SelectedIndex; tmpWMIConfig.ErrorValue = txtError.Text; tmpWMIConfig.ErrorResultMatchType = (CollectorAgentReturnValueCompareMatchType)cboErrorMatchType.SelectedIndex; tmpWMIConfig.DetailQuery = txtDetailQuery.Text; tmpWMIConfig.ColumnNames = txtColumnNames.Text.ToListFromCSVString(); tmpWMIConfig.OutputValueUnit = cboOutputValueUnit.Text; //tmpWMIConfig.KeyColumn = (int)keyColumnNumericUpDown.Value; lastStep = "Run GetCurrentState"; MonitorState testState = tmpWMIConfig.GetCurrentState(); //object returnValue = null; //if (tmpWMIConfig.UseRowCountAsValue) //{ // lastStep = "Run summary query (row count as value)"; // returnValue = tmpWMIConfig.RunQueryWithCountResult(); //} //else //{ // lastStep = "Run summary query"; // if (returnValue.IsIntegerTypeNumber()) // { // object currentValue = null; // currentValue = tmpWMIConfig.RunQueryWithSingleResult(); // if (currentValue.IsNumber()) // returnValue = (decimal)currentValue; // else // throw new Exception(string.Format("Return value is not an integer!\r\nValue returned: {0}", returnValue)); // } // else // returnValue = tmpWMIConfig.RunQueryWithSingleResult(); //} //if (tmpWMIConfig.ReturnValueIsInt) //{ // lastStep = "Test return value is an Integer"; // if (!returnValue.IsIntegerTypeNumber()) // throw new Exception(string.Format("Return value is not an integer!\r\nValue returned: {0}", returnValue)); //} //testing detail query lastStep = "Testing detail query - Getting column names"; List <DataColumn> columns = tmpWMIConfig.GetDetailQueryColumns(); lastStep = "Testing detail query - Custom column name sequence check"; StringBuilder sbColumns = new StringBuilder(); for (int i = 1; i < columns.Count; i++) { sbColumns.AppendLine(columns[i].ColumnName); } foreach (string columnName in tmpWMIConfig.ColumnNames) { if ((from c in columns where c.ColumnName.ToUpper() == columnName.ToUpper() select c).Count() != 1) { columnWarningText += columnName + ", "; } } if (chkCopyColumnNames.Checked) { Clipboard.SetText(sbColumns.ToString()); } lastStep = "Testing detail query"; DataSet ds = tmpWMIConfig.RunDetailQuery(); if (columnWarningText.Length == 0) { MessageBox.Show(string.Format("{0}!\r\nSummary value return: {1}\r\nDetail row count: {2}\r\nDetail columns: {3}", testState.State, tmpWMIConfig.CurrentAgentValue, ds.Tables[0].Rows.Count, columns.ToCSVString()), "Test", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show(string.Format("{0} (with warning)!\r\nSummary value return: {1}\r\nDetail row count: {2}\r\nDetail columns returned: {3}\r\nColumns not found: {4}", testState.State, tmpWMIConfig.CurrentAgentValue, ds.Tables[0].Rows.Count, columns.ToCSVString(), columnWarningText), "Test", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } catch (Exception ex) { MessageBox.Show(string.Format("Failed!\r\nLast step: {0}\r\n{1}", lastStep, ex.Message), "Test", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } }
public WMIQueryCollectorEditEntry() { InitializeComponent(); SelectedEntry = new WMIQueryCollectorConfigEntry(); }
//private void cmdEditMachineNames_Click(object sender, EventArgs e) //{ // CSVEditor csvEditor = new CSVEditor(); // csvEditor.Text = "Machine names"; // csvEditor.ItemDescription = "Machine"; // csvEditor.CSVData = txtMachines.Text; // if (csvEditor.ShowDialog() == System.Windows.Forms.DialogResult.OK) // { // txtMachines.Text = csvEditor.CSVData; // } //} //private void cmdEditColumnNames_Click(object sender, EventArgs e) //{ // CSVEditor csvEditor = new CSVEditor(); // csvEditor.Text = "Column names"; // csvEditor.ItemDescription = "Column"; // csvEditor.Sorted = false; // csvEditor.CSVData = txtColumnNames.Text; // if (csvEditor.ShowDialog() == System.Windows.Forms.DialogResult.OK) // { // txtColumnNames.Text = csvEditor.CSVData; // } //} private void cmdTestDB_Click(object sender, EventArgs e) { if (DoValidate()) { string lastStep = "Initialize values"; try { WMIQueryCollectorConfigEntry tmpWMIConfig = new WMIQueryCollectorConfigEntry(); string name = ApplyConfigVarsOnField(txtName.Text); string namespaceName = ApplyConfigVarsOnField(txtNamespace.Text); string machineName = ApplyConfigVarsOnField(txtMachines.Text); string testScript = ApplyConfigVarsOnField(txtStateQuery.Text); string successVal = ApplyConfigVarsOnField(txtSuccess.Text); string warningVal = ApplyConfigVarsOnField(txtWarning.Text); string errorVal = ApplyConfigVarsOnField(txtError.Text); tmpWMIConfig.Name = name; tmpWMIConfig.Namespace = namespaceName; tmpWMIConfig.Machinename = machineName; tmpWMIConfig.StateQuery = testScript; tmpWMIConfig.UseRowCountAsValue = chkUseRowCountAsValue.Checked; tmpWMIConfig.ReturnCheckSequence = (CollectorAgentReturnValueCheckSequence)cboReturnCheckSequence.SelectedIndex; tmpWMIConfig.GoodValue = successVal; tmpWMIConfig.GoodResultMatchType = (CollectorAgentReturnValueCompareMatchType)cboSuccessMatchType.SelectedIndex; tmpWMIConfig.WarningValue = warningVal; tmpWMIConfig.WarningResultMatchType = (CollectorAgentReturnValueCompareMatchType)cboWarningMatchType.SelectedIndex; tmpWMIConfig.ErrorValue = errorVal; tmpWMIConfig.ErrorResultMatchType = (CollectorAgentReturnValueCompareMatchType)cboErrorMatchType.SelectedIndex; tmpWMIConfig.OutputValueUnit = cboOutputValueUnit.Text; lastStep = "Run GetCurrentState"; MonitorState testState = tmpWMIConfig.GetCurrentState(); //testing detail query //lastStep = "Testing detail query - Getting column names"; //List<DataColumn> columns = tmpWMIConfig.GetDetailQueryColumns(); //lastStep = "Testing detail query - Custom column name sequence check"; //StringBuilder sbColumns = new StringBuilder(); //for (int i = 1; i < columns.Count; i++) // sbColumns.AppendLine(columns[i].ColumnName); //foreach (string columnName in tmpWMIConfig.ColumnNames) //{ // if ((from c in columns // where c.ColumnName.ToUpper() == columnName.ToUpper() // select c).Count() != 1) // { // columnWarningText += columnName + ", "; // } //} //if (chkCopyColumnNames.Checked) //{ // Clipboard.SetText(sbColumns.ToString()); //} //lastStep = "Testing detail query"; //DataSet ds = tmpWMIConfig.RunDetailQuery(); //if (columnWarningText.Length == 0) // MessageBox.Show(string.Format("{0}!\r\nSummary value return: {1}\r\nDetail row count: {2}\r\nDetail columns: {3}", testState.State, tmpWMIConfig.CurrentAgentValue, ds.Tables[0].Rows.Count, columns.ToCSVString()), "Test", MessageBoxButtons.OK, MessageBoxIcon.Information); //else // MessageBox.Show(string.Format("{0} (with warning)!\r\nSummary value return: {1}\r\nDetail row count: {2}\r\nDetail columns returned: {3}\r\nColumns not found: {4}", testState.State, tmpWMIConfig.CurrentAgentValue, ds.Tables[0].Rows.Count, columns.ToCSVString(), columnWarningText), "Test", MessageBoxButtons.OK, MessageBoxIcon.Warning); MessageBox.Show(string.Format("{0}!\r\nValue return: {1}", testState.State, testState.CurrentValue), "Test", MessageBoxButtons.OK, testState.State == CollectorState.Good ? MessageBoxIcon.Information : testState.State == CollectorState.Warning ? MessageBoxIcon.Warning : 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); } } }