JsonSubCommand.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using SuperSocket.SocketBase.Command;
  6. using SuperSocket.SocketBase.Protocol;
  7. namespace SuperWebSocket.SubProtocol
  8. {
  9. /// <summary>
  10. /// JsonSubCommand
  11. /// </summary>
  12. /// <typeparam name="TJsonCommandInfo">The type of the json command info.</typeparam>
  13. public abstract class JsonSubCommand<TJsonCommandInfo> : JsonSubCommand<WebSocketSession, TJsonCommandInfo>
  14. {
  15. }
  16. /// <summary>
  17. /// JsonSubCommand
  18. /// </summary>
  19. /// <typeparam name="TWebSocketSession">The type of the web socket session.</typeparam>
  20. /// <typeparam name="TJsonCommandInfo">The type of the json command info.</typeparam>
  21. public abstract class JsonSubCommand<TWebSocketSession, TJsonCommandInfo> : JsonSubCommandBase<TWebSocketSession, TJsonCommandInfo>
  22. where TWebSocketSession : WebSocketSession<TWebSocketSession>, new()
  23. {
  24. /// <summary>
  25. /// Gets the json message.
  26. /// </summary>
  27. /// <param name="session">The session.</param>
  28. /// <param name="content">The content.</param>
  29. /// <returns></returns>
  30. protected string GetJsonMessage(TWebSocketSession session, object content)
  31. {
  32. return GetJsonMessage(session, Name, content);
  33. }
  34. /// <summary>
  35. /// Gets the json message.
  36. /// </summary>
  37. /// <param name="session">The session.</param>
  38. /// <param name="name">The name.</param>
  39. /// <param name="content">The content.</param>
  40. /// <returns></returns>
  41. protected string GetJsonMessage(TWebSocketSession session, string name, object content)
  42. {
  43. return GetJsonMessage(session, name, session.CurrentToken, content);
  44. }
  45. /// <summary>
  46. /// Sends the json message.
  47. /// </summary>
  48. /// <param name="session">The session.</param>
  49. /// <param name="content">The content.</param>
  50. protected void SendJsonMessage(TWebSocketSession session, object content)
  51. {
  52. session.Send(GetJsonMessage(session, content));
  53. }
  54. /// <summary>
  55. /// Sends the json message.
  56. /// </summary>
  57. /// <param name="session">The session.</param>
  58. /// <param name="name">The name.</param>
  59. /// <param name="content">The content.</param>
  60. protected void SendJsonMessage(TWebSocketSession session, string name, object content)
  61. {
  62. session.Send(GetJsonMessage(session, name, content));
  63. }
  64. }
  65. }