Ejemplo n.º 1
0
        public Task ParseAsync(ResponseTextParser rtp)
        {
            Regex regex = new Regex("^42" + rtp.Namespace + "\\d*\\[\"([*\\s\\w-]+)\",([\\s\\S]*)\\]$");

            if (regex.IsMatch(rtp.Text))
            {
                GroupCollection groups = regex.Match(rtp.Text).Groups;
                string          index  = groups[1].Value;
                ResponseArgs    args   = new ResponseArgs()
                {
                    Text    = groups[2].Value,
                    RawText = rtp.Text
                };
                if (rtp.Socket.EventHandlers.ContainsKey(index))
                {
                    rtp.Socket.EventHandlers[index](args);
                }
                else
                {
                    rtp.Socket.InvokeUnhandledEvent(index, args);
                }
                rtp.Socket.InvokeReceivedEvent(index, args);
                return(Task.CompletedTask);
            }
            rtp.Parser = (IParser) new MessageAckParser();
            return(rtp.ParseAsync());
        }
Ejemplo n.º 2
0
        public Task ParseAsync(ResponseTextParser rtp)
        {
            var regex = new Regex($@"^43{rtp.Namespace}(\d+)\[([\s\S]*)\]$");

            if (regex.IsMatch(rtp.Text))
            {
                var groups   = regex.Match(rtp.Text).Groups;
                int packetId = int.Parse(groups[1].Value);
                if (rtp.Socket.Callbacks.ContainsKey(packetId))
                {
                    var handler = rtp.Socket.Callbacks[packetId];
                    handler(new ResponseArgs
                    {
                        Text    = groups[2].Value,
                        RawText = rtp.Text
                    });
                    rtp.Socket.Callbacks.Remove(packetId);
                }
                return(Task.CompletedTask);
            }
            else
            {
                rtp.Parser = new ErrorParser();
                return(rtp.ParseAsync());
            }
        }
Ejemplo n.º 3
0
 public Task ParseAsync(ResponseTextParser rtp)
 {
     if (rtp.Text == "41" + rtp.Namespace)
     {
         return(rtp.Socket.InvokeClosedAsync());
     }
     rtp.Parser = (IParser) new MessageEventParser();
     return(rtp.ParseAsync());
 }
Ejemplo n.º 4
0
 public Task ParseAsync(ResponseTextParser rtp)
 {
     if (rtp.Text.StartsWith("0{\"sid\":\""))
     {
         OpenedArgs args = (OpenedArgs)JsonConvert.DeserializeObject <OpenedArgs>(rtp.Text.TrimStart('0'));
         return(rtp.Socket.InvokeOpenedAsync(args));
     }
     rtp.Parser = (IParser) new ConnectedParser();
     return(rtp.ParseAsync());
 }
Ejemplo n.º 5
0
 public Task ParseAsync(ResponseTextParser rtp)
 {
     if (rtp.Text == "40" + rtp.Namespace)
     {
         return(rtp.Socket.InvokeConnectedAsync());
     }
     if (rtp.Text == "40")
     {
         return(Task.CompletedTask);
     }
     rtp.Parser = (IParser) new DisconnectedParser();
     return(rtp.ParseAsync());
 }
Ejemplo n.º 6
0
        public Task ParseAsync(ResponseTextParser rtp)
        {
            var regex = new Regex($@"^44{rtp.Namespace}([\s\S]*)$");

            if (regex.IsMatch(rtp.Text))
            {
                var groups = regex.Match(rtp.Text).Groups;
                rtp.Socket.InvokeErrorEvent(new ResponseArgs
                {
                    Text    = groups[1].Value,
                    RawText = rtp.Text
                });
            }
            return(Task.CompletedTask);
        }