using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace SuperWebSocket.SubProtocol { /// /// Async json sub command /// /// The type of the json command info. public abstract class AsyncJsonSubCommand : AsyncJsonSubCommand { } /// /// Async json sub command /// /// The type of the web socket session. /// The type of the json command info. public abstract class AsyncJsonSubCommand : JsonSubCommandBase where TWebSocketSession : WebSocketSession, new() { private Action m_AsyncJsonCommandAction; /// /// Initializes a new instance of the class. /// public AsyncJsonSubCommand() { m_AsyncJsonCommandAction = ExecuteAsyncJsonCommand; } /// /// Executes the json command. /// /// The session. /// The command info. protected override void ExecuteJsonCommand(TWebSocketSession session, TJsonCommandInfo commandInfo) { m_AsyncJsonCommandAction.BeginInvoke(session, session.CurrentToken, commandInfo, null, session); } /// /// Executes the async json command. /// /// The session. /// The token. /// The command info. protected abstract void ExecuteAsyncJsonCommand(TWebSocketSession session, string token, TJsonCommandInfo commandInfo); private void OnAsyncJsonCommandExecuted(IAsyncResult result) { var session = (TWebSocketSession)result.AsyncState; try { m_AsyncJsonCommandAction.EndInvoke(result); } catch (Exception e) { session.Logger.Error(e); } } /// /// Sends the json message. /// /// The session. /// The token. /// The content. protected void SendJsonMessage(TWebSocketSession session, string token, object content) { session.Send(GetJsonMessage(session, this.Name, token, content)); } /// /// Sends the json message. /// /// The session. /// The name. /// The token. /// The content. protected void SendJsonMessage(TWebSocketSession session, string name, string token, object content) { session.Send(GetJsonMessage(session, name, token, content)); } } }