Exemple #1
0
 public override void RefreshDisplayData()
 {
     try
     {
         CollectorState currentState = ((LoopbackCollector)Collector).GetState().State;
         lblDisplayedState.Text = currentState.ToString() + " - " + DateTime.Now.ToString("HH:mm:ss");
         if (currentState == CollectorState.Error)
         {
             lblDisplayedState.BackColor = Color.LightSalmon;
         }
         else if (currentState == CollectorState.Warning)
         {
             lblDisplayedState.BackColor = Color.Yellow;
         }
         else if (currentState == CollectorState.Good)
         {
             lblDisplayedState.BackColor = Color.LightGreen;
         }
         else
         {
             lblDisplayedState.BackColor = Color.Silver;
         }
     }
     catch (Exception ex)
     {
         lblDisplayedState.BackColor = Color.LightSalmon;
         lblDisplayedState.Text      = ex.Message + " - " + DateTime.Now.ToString("HH:mm:ss");
     }
 }
        private void cmdTestService_Click(object sender, EventArgs e)
        {
            if (txtServiceURL.Text.Trim().Length > 0)
            {
                string lastStep = "Creating entry";
                try
                {
                    DynamicWSCollectorConfigEntry textEntry = new DynamicWSCollectorConfigEntry();
                    textEntry.ServiceBaseURL     = txtServiceURL.Text;
                    textEntry.ServiceBindingName = cboEndPoint.Text;
                    textEntry.MethodName         = cboMethodName.Text;
                    textEntry.ParametersFromString(txtParameters.Text);
                    textEntry.ResultIsSuccess         = !chkResultXOr.Checked;
                    textEntry.ValueExpectedReturnType = (WebServiceValueExpectedReturnTypeEnum)cboExpectedValueType.SelectedIndex;
                    if (cboValueFormatMacro.SelectedIndex == -1 || !(cboValueFormatMacro.SelectedItem is ValueFormatMacroDisplay))
                    {
                        textEntry.MacroFormatType = WebServiceMacroFormatTypeEnum.None;
                    }
                    else
                    {
                        textEntry.MacroFormatType = ((ValueFormatMacroDisplay)cboValueFormatMacro.SelectedItem).MacroFormatType;
                    }
                    textEntry.CheckValueArrayIndex  = (int)indexOrRowNumericUpDown.Value;
                    textEntry.CheckValueColumnIndex = (int)dataSetColumnNumericUpDown.Value;
                    textEntry.CheckValueOrMacro     = cboValueOrMacro.Text;
                    textEntry.UseRegEx = chkUseRegEx.Checked;

                    lastStep = "Running method";
                    object returnValue = textEntry.RunMethod();
                    lastStep = "Evaluating return value";
                    CollectorState state = textEntry.GetState(returnValue);
                    MessageBox.Show("Returned state: " + state.ToString() + "\r\nValue: " + textEntry.LastFormattedValue, "Test", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch (Exception ex)
                {
                    if (ex.Message.Contains("Specified web service invalid or not available"))
                    {
                        MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        MessageBox.Show("Last step: " + lastStep + "\r\n" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }