void ProcessMessage(ref string message) { var data = message.Split(new char[] { ',' }, 4); uint version = 0; if (!uint.TryParse(data[0], out version)) { throw new Exception("Message error"); } int msgType; if (!Int32.TryParse(data[1], out msgType)) { throw new Exception("Message error"); } IControlLayer MsgClass = null; switch ((_ControlLayerBase.messageType)msgType) { case _ControlLayerBase.messageType.BroadcastMessage: MsgClass = new BroadcastMessage(ref data); BroadcastMessage?.Invoke(this, (BroadcastMessage)MsgClass); break; case _ControlLayerBase.messageType.UnicastMessage: // MsgClass = new UnicastMessage(ref data); // break; case _ControlLayerBase.messageType.SubscribeResponse: MsgClass = JsonConvert.DeserializeObject <SubscribeRequest>(data[3]); break; case _ControlLayerBase.messageType.UnsubscribeResponse: MsgClass = JsonConvert.DeserializeObject <UnsubscribeResponse>(data[3]); break; // case _ControlLayerBase.messageType.ResendResponseResending: // MsgClass = new ResendResponseResending(ref data); // break; // case _ControlLayerBase.messageType.ResendResponseResent: // MsgClass = new ResendResponseResent(ref data); // break; // case _ControlLayerBase.messageType.ResendResponseNoResend: // MsgClass = new ResendResponseNoResend(ref data); // break; case _ControlLayerBase.messageType.ErrorResponse: MsgClass = new ErrorResponse(ref data); break; // case _ControlLayerBase.messageType.PublishRequest: // MsgClass = new PublishRequest(ref data); // break; case _ControlLayerBase.messageType.SubscribeRequest: MsgClass = JsonConvert.DeserializeObject <SubscribeRequest>(data[3]); break; case _ControlLayerBase.messageType.UnsubscribeRequest: MsgClass = JsonConvert.DeserializeObject <UnsubscribeRequest>(data[3]); break; // case _ControlLayerBase.messageType.ResendLastRequest: // MsgClass = new ResendLastRequest(ref data); // break; // case _ControlLayerBase.messageType.ResendFromRequest: // MsgClass = new ResendFromRequest(ref data); // break; // case _ControlLayerBase.messageType.ResendRangeRequest: // MsgClass = new ResendRangeRequest(ref data); // break; default: Console.WriteLine($"Unsupported message: {(_ControlLayerBase.messageType)msgType} {message}"); break; } MsgClass.Version = version; NetworkMessage?.Invoke(this, MsgClass); }
public void Send(IControlLayer messageClass, string Sender = "sender", SessionToken token = null) { websocketClient.Send(messageClass.ToMessage(token ?? sessionToken, RequestID)); }
public WrapperMessage(IControlLayer controlLayer, string sender) : base(messageType.WrapperMessage) { ControlLayer = controlLayer; Sender = sender; }