SamplesException.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /**
  2. Licensed Materials - Property of IBM
  3. IBM Cognos Products: DOCS
  4. (C) Copyright IBM Corp. 2005, 2008
  5. US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with
  6. IBM Corp.
  7. */
  8. // Copyright (C) 2008 Cognos ULC, an IBM Company. All rights reserved.
  9. // Cognos (R) is a trademark of Cognos ULC, (formerly Cognos Incorporated).
  10. using System;
  11. using System.Web.Services.Protocols;
  12. using System.Text;
  13. using cognosdotnet_10_2;
  14. using System.Xml;
  15. using System.Windows.Forms;
  16. namespace SamplesCommon
  17. {
  18. /// <summary>
  19. /// Display a simple dialog box reporting an error to the user.
  20. /// </summary>
  21. public class SamplesException
  22. {
  23. /// <summary>
  24. /// You can't make this, just call the static method.
  25. /// </summary>
  26. private SamplesException()
  27. {
  28. }
  29. /// <summary>
  30. /// Turn a SoapException into a string suitable for display to a user.
  31. /// </summary>
  32. /// <param name="ex">A SoapException object.</param>
  33. /// <returns>A string representation of the exception.</returns>
  34. public static string FormatException( SoapException ex ) {
  35. return ExceptionHelper.ConvertToString( ex );
  36. }
  37. /// <summary>
  38. /// Display a SOAP exception in a simple dialog box.
  39. /// </summary>
  40. /// <param name="ex">The exception object.</param>
  41. /// <param name="gui">True if we should display a GUI, false if we shouldn't.</param>
  42. public static void ShowExceptionMessage( SoapException ex, bool gui, string title )
  43. {
  44. string error = ExceptionHelper.ConvertToString( ex );
  45. if( gui )
  46. {
  47. MessageBox.Show( error, title, MessageBoxButtons.OK, MessageBoxIcon.Error );
  48. } else
  49. {
  50. Console.WriteLine( error );
  51. }
  52. }
  53. public static string getExceptionMessage( SoapException ex)
  54. {
  55. return ExceptionHelper.ConvertToString( ex );
  56. }
  57. public static void ShowExceptionMessage( string error, bool gui, string title )
  58. {
  59. if( gui )
  60. {
  61. MessageBox.Show( error, title, MessageBoxButtons.OK, MessageBoxIcon.Error );
  62. }
  63. else
  64. {
  65. Console.WriteLine( error );
  66. }
  67. }
  68. }
  69. }