NetworkErrorScreen.cs 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #region File Description
  2. //-----------------------------------------------------------------------------
  3. // NetworkErrorScreen.cs
  4. //
  5. // Microsoft XNA Community Game Platform
  6. // Copyright (C) Microsoft Corporation. All rights reserved.
  7. //-----------------------------------------------------------------------------
  8. #endregion
  9. #region Using Statements
  10. using System;
  11. using System.Diagnostics;
  12. using Microsoft.Xna.Framework.GamerServices;
  13. using Microsoft.Xna.Framework.Net;
  14. #endregion
  15. namespace NetworkStateManagement
  16. {
  17. /// <summary>
  18. /// Specialized message box subclass, used to display network error messages.
  19. /// </summary>
  20. class NetworkErrorScreen : MessageBoxScreen
  21. {
  22. #region Initialization
  23. /// <summary>
  24. /// Constructs an error message box from the specified exception.
  25. /// </summary>
  26. public NetworkErrorScreen(Exception exception)
  27. : base(GetErrorMessage(exception), false)
  28. { }
  29. /// <summary>
  30. /// Converts a network exception into a user friendly error message.
  31. /// </summary>
  32. static string GetErrorMessage(Exception exception)
  33. {
  34. Debug.WriteLine("Network operation threw " + exception);
  35. // Is this a GamerPrivilegeException?
  36. if (exception is GamerPrivilegeException)
  37. {
  38. if (Guide.IsTrialMode)
  39. return Resources.ErrorTrialMode;
  40. else
  41. return Resources.ErrorGamerPrivilege;
  42. }
  43. // Is it a NetworkSessionJoinException?
  44. NetworkSessionJoinException joinException = exception as
  45. NetworkSessionJoinException;
  46. if (joinException != null)
  47. {
  48. switch (joinException.JoinError)
  49. {
  50. case NetworkSessionJoinError.SessionFull:
  51. return Resources.ErrorSessionFull;
  52. case NetworkSessionJoinError.SessionNotFound:
  53. return Resources.ErrorSessionNotFound;
  54. case NetworkSessionJoinError.SessionNotJoinable:
  55. return Resources.ErrorSessionNotJoinable;
  56. }
  57. }
  58. // Is this a NetworkNotAvailableException?
  59. if (exception is NetworkNotAvailableException)
  60. {
  61. return Resources.ErrorNetworkNotAvailable;
  62. }
  63. // Is this a NetworkException?
  64. if (exception is NetworkException)
  65. {
  66. return Resources.ErrorNetwork;
  67. }
  68. // Otherwise just a generic error message.
  69. return Resources.ErrorUnknown;
  70. }
  71. #endregion
  72. }
  73. }