PageRenderTime 36ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/QuickMon3/QuickMonCommonAgents/Collectors/SoapWebServicePingCollector/SoapWebServicePingCollector.cs

#
C# | 106 lines | 97 code | 8 blank | 1 comment | 8 complexity | e0f5d02f4fe9b7d656aa2395c3ec732f MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Linq;
  5. using System.Text;
  6. namespace QuickMon.Collectors
  7. {
  8. [Description("Soap Web Service Query Collector [Deprecated]"), Category("Web Service"), Obsolete]
  9. public class SoapWebServicePingCollector : CollectorBase
  10. {
  11. public SoapWebServicePingCollector()
  12. {
  13. AgentConfig = new SoapWebServicePingCollectorConfig();
  14. }
  15. public override MonitorState GetState()
  16. {
  17. MonitorState returnState = new MonitorState();
  18. StringBuilder plainTextDetails = new StringBuilder();
  19. StringBuilder htmlTextTextDetails = new StringBuilder();
  20. string lastAction = "";
  21. int errors = 0;
  22. int success = 0;
  23. try
  24. {
  25. SoapWebServicePingCollectorConfig config = (SoapWebServicePingCollectorConfig)AgentConfig;
  26. plainTextDetails.AppendLine(string.Format("Calling {0} web service(s)", config.Entries.Count));
  27. htmlTextTextDetails.AppendLine(string.Format("<b>Calling {0} web service(s)</b>", config.Entries.Count));
  28. htmlTextTextDetails.AppendLine("<ul>");
  29. foreach (SoapWebServicePingConfigEntry soapWebServicePingConfigEntry in config.Entries)
  30. {
  31. plainTextDetails.Append(string.Format("\t\t{0} - ", soapWebServicePingConfigEntry.ServiceBaseURL));
  32. htmlTextTextDetails.Append(string.Format("<li>{0} - ", soapWebServicePingConfigEntry.ServiceBaseURL));
  33. object val = soapWebServicePingConfigEntry.ExecuteMethod();
  34. string formattedVal = "";
  35. bool checkResultMatch = soapWebServicePingConfigEntry.CheckResultMatch(val, soapWebServicePingConfigEntry.ResultType, soapWebServicePingConfigEntry.CustomValue1, soapWebServicePingConfigEntry.CustomValue2, out formattedVal);
  36. //LastDetailMsg.LastValue = formattedVal;
  37. if (checkResultMatch)
  38. {
  39. success++;
  40. plainTextDetails.Append("Success - ");
  41. htmlTextTextDetails.Append("<b>Success</b> - ");
  42. }
  43. else
  44. {
  45. errors++;
  46. plainTextDetails.Append("Failure - ");
  47. htmlTextTextDetails.Append("<b>Failure</b> - ");
  48. }
  49. switch (soapWebServicePingConfigEntry.ResultType)
  50. {
  51. case SoapWebServicePingResult.CheckAvailabilityOnly:
  52. plainTextDetails.Append("Available");
  53. htmlTextTextDetails.Append("Available");
  54. break;
  55. case SoapWebServicePingResult.NoValueOnly:
  56. plainTextDetails.Append("No value returned");
  57. htmlTextTextDetails.Append("No value returned");
  58. break;
  59. default:
  60. plainTextDetails.Append(string.Format("Value:{0}", formattedVal));
  61. htmlTextTextDetails.Append(string.Format("Value:{0}", formattedVal));
  62. break;
  63. }
  64. plainTextDetails.AppendLine();
  65. htmlTextTextDetails.AppendLine("</li>");
  66. }
  67. htmlTextTextDetails.AppendLine("</ul>");
  68. if (errors > 0 && success == 0) //are all errors
  69. returnState.State = CollectorState.Error;
  70. else if (errors > 0 && success > 0) //mixture
  71. returnState.State = CollectorState.Warning;
  72. else
  73. returnState.State = CollectorState.Good;
  74. returnState.RawDetails = plainTextDetails.ToString().TrimEnd('\r', '\n');
  75. returnState.HtmlDetails = htmlTextTextDetails.ToString();
  76. }
  77. catch (Exception ex)
  78. {
  79. returnState.RawDetails = ex.Message;
  80. returnState.HtmlDetails = string.Format("<p><b>Last action:</b> {0}</p><blockquote>{1}</blockquote>", lastAction, ex.Message);
  81. returnState.State = CollectorState.Error;
  82. }
  83. return returnState;
  84. }
  85. public override ICollectorDetailView GetCollectorDetailView()
  86. {
  87. return new SoapWebServicePingCollectorShowDetails();
  88. }
  89. public override string GetDefaultOrEmptyConfigString()
  90. {
  91. return Properties.Resources.SoapWebServicePingCollectorDefaultConfig;
  92. }
  93. public override IEditConfigEntryWindow GetEditConfigEntryWindow()
  94. {
  95. return new SoapWebServicePingCollectorEditEntry();
  96. }
  97. }
  98. }