CognosException.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /**
  2. Licensed Materials - Property of IBM
  3. IBM Cognos Products: DOCS
  4. (C) Copyright IBM Corp. 2005, 2007
  5. US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with
  6. IBM Corp.
  7. */
  8. using System;
  9. using System.Web.Services.Protocols;
  10. using System.Xml;
  11. using System.Text;
  12. namespace Exceptions
  13. {
  14. /// <summary>
  15. /// Simple exception object for use with IBM Cognos.
  16. /// </summary>
  17. public class CognosException
  18. {
  19. private SoapException _exception = null;
  20. /// <summary>
  21. /// Create a CognosException object.
  22. /// </summary>
  23. /// <param name="ex">A SoapException thrown by an IBM Cognos method call.</param>
  24. public CognosException( SoapException ex )
  25. {
  26. _exception = ex;
  27. }
  28. /// <summary>
  29. /// Return the exception message.
  30. /// </summary>
  31. public string Message {
  32. get {
  33. return _exception.Message;
  34. }
  35. }
  36. /// <summary>
  37. /// Return the exception severity.
  38. /// </summary>
  39. public string Severity {
  40. get {
  41. return _exception.Detail.SelectSingleNode( "//severity" ).InnerText;
  42. }
  43. }
  44. /// <summary>
  45. /// Return the exception errorCode.
  46. /// </summary>
  47. public string ErrorCode {
  48. get {
  49. return _exception.Detail.SelectSingleNode( "//errorCode" ).InnerText;
  50. }
  51. }
  52. /// <summary>
  53. /// Return the exception messageStrings.
  54. /// </summary>
  55. public string[] Details {
  56. get {
  57. XmlNodeList nodes = _exception.Detail.SelectNodes( "//messageString" );
  58. string[] retval = new string[nodes.Count];
  59. for( int idx = 0; idx < nodes.Count; idx++ ) {
  60. retval[idx] = nodes[idx].InnerText;
  61. }
  62. return retval;
  63. }
  64. }
  65. /// <summary>
  66. /// Convert this CognosException into a string for printing.
  67. /// </summary>
  68. /// <returns>A string representation of the CognosException.</returns>
  69. public override string ToString() {
  70. StringBuilder str = new StringBuilder();
  71. str.AppendFormat( "Message: {0}\n", Message );
  72. str.AppendFormat( "Severity: {0}\n", Severity );
  73. str.AppendFormat( "ErrorCode: {0}\n", ErrorCode );
  74. str.AppendFormat( "Details:\n" );
  75. foreach( string s in Details ) {
  76. str.AppendFormat( "\t{0}\n", s );
  77. }
  78. return str.ToString();
  79. }
  80. /// <summary>
  81. /// Convert a SoapException into a CognosException string.
  82. ///
  83. /// This is the same as creating a CognosException and calling
  84. /// its ToString() method.
  85. /// </summary>
  86. /// <param name="ex">The SoapException to format.</param>
  87. /// <returns>A string representation.</returns>
  88. static public string ConvertToString( SoapException ex ) {
  89. CognosException exception = new CognosException( ex );
  90. return exception.ToString();
  91. }
  92. }
  93. }