Пример #1
0
        public static AckMessage Deserialize(string rawMessage)
        {
            AckMessage msg = new AckMessage();

            //  '6:::' [message id] '+' [data]
            //   6:::4
            //	 6:::4+["A","B"]
            msg.RawMessage = rawMessage;

            string[] args = rawMessage.Split(SPLITCHARS, 4);
            if (args.Length == 4)
            {
                msg.Endpoint = args[2];
                int      id;
                string[] parts = args[3].Split(new char[] { '+' });
                if (parts.Length > 1)
                {
                    if (int.TryParse(parts[0], out id))
                    {
                        msg.AckId       = id;
                        msg.MessageText = parts[1];
                        Match payloadMatch = reAckComplex.Match(msg.MessageText);

                        if (payloadMatch.Success)
                        {
                            msg.Json      = new JsonEncodedEventMessage();
                            msg.Json.Args = new string[]  { payloadMatch.Groups["payload"].Value };
                        }
                    }
                }
            }
            return(msg);
        }
Пример #2
0
        public static IMessage Factory(string rawMessage)
        {
            if (reMessageType.IsMatch(rawMessage))
            {
                char id = rawMessage.First();
                switch (id)
                {
                case '0':
                    return(DisconnectMessage.Deserialize(rawMessage));

                case '1':
                    return(ConnectMessage.Deserialize(rawMessage));

                case '2':
                    return(new Heartbeat());

                case '3':
                    return(TextMessage.Deserialize(rawMessage));

                case '4':
                    return(JSONMessage.Deserialize(rawMessage));

                case '5':
                    return(EventMessage.Deserialize(rawMessage));

                case '6':
                    return(AckMessage.Deserialize(rawMessage));

                case '7':
                    return(ErrorMessage.Deserialize(rawMessage));

                case '8':
                    return(new NoopMessage());

                default:
                    Debug.WriteLine(string.Format("Message.Factory undetermined message: {0}", rawMessage));
                    return(new TextMessage());
                }
            }
            else
            {
                Debug.WriteLine(string.Format("Message.Factory did not find matching message type: {0}", rawMessage));
                return(new NoopMessage());
            }
        }