NetworkErrorScreen.cs 2.6 KB

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