예제 #1
0
        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);
        }
예제 #2
0
 public void Send(IControlLayer messageClass, string Sender = "sender", SessionToken token = null)
 {
     websocketClient.Send(messageClass.ToMessage(token ?? sessionToken, RequestID));
 }
예제 #3
0
 public WrapperMessage(IControlLayer controlLayer, string sender) : base(messageType.WrapperMessage)
 {
     ControlLayer = controlLayer;
     Sender       = sender;
 }