Message.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #if !BESTHTTP_DISABLE_SIGNALR_CORE && !BESTHTTP_DISABLE_WEBSOCKET
  2. using System;
  3. namespace BestHTTP.SignalRCore.Messages
  4. {
  5. public enum MessageTypes : int
  6. {
  7. /// <summary>
  8. /// This is a made up message type, for easier handshake handling.
  9. /// </summary>
  10. Handshake = 0,
  11. /// <summary>
  12. /// https://github.com/aspnet/SignalR/blob/dev/specs/HubProtocol.md#invocation-message-encoding
  13. /// </summary>
  14. Invocation = 1,
  15. /// <summary>
  16. /// https://github.com/aspnet/SignalR/blob/dev/specs/HubProtocol.md#streamitem-message-encoding
  17. /// </summary>
  18. StreamItem = 2,
  19. /// <summary>
  20. /// https://github.com/aspnet/SignalR/blob/dev/specs/HubProtocol.md#completion-message-encoding
  21. /// </summary>
  22. Completion = 3,
  23. /// <summary>
  24. /// https://github.com/aspnet/SignalR/blob/dev/specs/HubProtocol.md#streaminvocation-message-encoding
  25. /// </summary>
  26. StreamInvocation = 4,
  27. /// <summary>
  28. /// https://github.com/aspnet/SignalR/blob/dev/specs/HubProtocol.md#cancelinvocation-message-encoding
  29. /// </summary>
  30. CancelInvocation = 5,
  31. /// <summary>
  32. /// https://github.com/aspnet/SignalR/blob/dev/specs/HubProtocol.md#ping-message-encoding
  33. /// </summary>
  34. Ping = 6,
  35. /// <summary>
  36. /// https://github.com/aspnet/SignalR/blob/dev/specs/HubProtocol.md#close-message-encoding
  37. /// </summary>
  38. Close = 7
  39. }
  40. public class Message
  41. {
  42. public MessageTypes type;
  43. public string invocationId;
  44. public bool nonblocking;
  45. public string target;
  46. public object[] arguments;
  47. public object item;
  48. public object result;
  49. public string error;
  50. public override string ToString()
  51. {
  52. switch (this.type)
  53. {
  54. case MessageTypes.Invocation:
  55. return string.Format("[Invocation Id: {0}, Target: '{1}', Argument count: {2}]", this.invocationId, this.target, this.arguments != null ? this.arguments.Length : 0);
  56. case MessageTypes.StreamItem:
  57. return string.Format("[StreamItem Id: {0}, Item: {1}]", this.invocationId, this.item.ToString());
  58. case MessageTypes.Completion:
  59. return string.Format("[Completion Id: {0}, Result: {1}, Error: '{2}']", this.invocationId, this.result, this.error);
  60. case MessageTypes.StreamInvocation:
  61. return string.Format("[StreamInvocation Id: {0}, Target: '{1}', Argument count: {2}]", this.invocationId, this.target, this.arguments != null ? this.arguments.Length : 0);
  62. case MessageTypes.CancelInvocation:
  63. return string.Format("[CancelInvocation Id: {0}]", this.invocationId);
  64. case MessageTypes.Ping:
  65. return "[Ping]";
  66. case MessageTypes.Close:
  67. return string.IsNullOrEmpty(this.error) ? "[Close]" : string.Format("[Close {0}]", this.error);
  68. default:
  69. return "Unknown message! Type: " + this.type;
  70. }
  71. }
  72. }
  73. }
  74. #endif