SamplesHeaderExceptionHelper.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. // Copyright (C) 2007 Cognos ULC, an IBM Company. All rights reserved.
  9. // Cognos (R) is a trademark of Cognos ULC, (formerly Cognos Incorporated).
  10. // sn_dg_sdk_headerexception_start_1
  11. using System;
  12. using System.Text;
  13. using cognosdotnet_10_2;
  14. namespace SamplesCommon
  15. {
  16. /// <summary>
  17. /// Extract the interesting bits from a biBusHeader after a biBusHeader
  18. /// fault.
  19. /// </summary>
  20. public class HeaderExceptionHelper
  21. {
  22. private CAMException _exception = null;
  23. /// <summary>
  24. /// Create a HeaderExceptionHelper object.
  25. /// </summary>
  26. /// <param name="crn">The contentManagerService1 object in use during the last exception.</param>
  27. public HeaderExceptionHelper( contentManagerService1 cmService )
  28. {
  29. // Pull the CAM exception out of the biBusHeader.
  30. _exception = cmService.biBusHeaderValue.CAM.exception;
  31. }
  32. /// <summary>
  33. /// Get the Severity string from this biBusHeader exception.
  34. /// </summary>
  35. public string Severity {
  36. get {
  37. return _exception.severity.ToString();
  38. }
  39. }
  40. /// <summary>
  41. /// Get the errorCode string from this biBusHeader exception.
  42. /// </summary>
  43. public string ErrorCode {
  44. get {
  45. return _exception.errorCodeString;
  46. }
  47. }
  48. /// <summary>
  49. /// Get the details (messageString) from this biBusHeader exception.
  50. /// </summary>
  51. public string[] Details {
  52. get {
  53. string[] retval = new string[_exception.messages.Length];
  54. for( int idx = 0; idx < _exception.messages.Length; idx++ ) {
  55. retval[idx] = _exception.messages[idx].messageString;
  56. }
  57. return retval;
  58. }
  59. }
  60. /// <summary>
  61. /// Get the promptInfo (and useful captions/displayObjects inside) to
  62. /// facilitate prompting the user, if this is a recoverable exception.
  63. /// </summary>
  64. public promptInfo PromptInfo {
  65. get {
  66. return _exception.promptInfo;
  67. }
  68. }
  69. /// <summary>
  70. /// Convert this biBusHeader exception into a string for printing.
  71. /// </summary>
  72. /// <returns>A string representation of the biBusHeader exception.</returns>
  73. public override string ToString() {
  74. StringBuilder str = new StringBuilder();
  75. str.AppendFormat( "Severity: {0}\n", Severity );
  76. str.AppendFormat( "ErrorCode: {0}\n", ErrorCode );
  77. str.AppendFormat( "Details:\n" );
  78. foreach( string s in Details ) {
  79. str.AppendFormat( "\t{0}\n", s );
  80. }
  81. return str.ToString();
  82. }
  83. /// <summary>
  84. /// Convert a biBusHeader exception into a string.
  85. ///
  86. /// This is the same as creating a HeaderExceptionHelper and calling
  87. /// its ToString() method.
  88. /// </summary>
  89. /// <param name="ex">The Service object that threw the exception.</param>
  90. /// <returns>A string representation of the biBusHeader exception.</returns>
  91. static public string ConvertToString( contentManagerService1 cmService ) {
  92. HeaderExceptionHelper exception = new HeaderExceptionHelper( cmService );
  93. return exception.ToString();
  94. }
  95. }
  96. }
  97. // sn_dg_sdk_headerexception_end_1