Пример #1
0
        public IEnumerable <Common.ISerializable> Parse(CommandSerializer cs)
        {
            if (data == null)
            {
                yield break;
            }
            var packages = new List <ArraySegment <byte> >();

            using (var stream = new MemoryStream(data))
            {
                var ps = new PackageSerializer();
                ps.Package += (s, e) => packages.Add(e.Data);
                ps.Run(stream);
            }

            foreach (var p in packages)
            {
                using (var mem = new MemoryStream(p.Array, p.Offset, p.Count, false))
                {
                    var cmd = cs.DeserializeCommand(mem);
                    if (cmd != null)
                    {
                        yield return(cmd);
                    }
                }
            }
        }
Пример #2
0
        private void m_server_ReceivedFull(object sender, TcpReceivedEventArgs e)
        {
            Command command = null;

            try
            {
                command = CommandSerializer.DeserializeCommand(e.Data);
            }
            catch (EncoderFallbackException ex)
            {
                if (OnCommandError != null)
                {
                    OnCommandError(this, new TcpErrorEventArgs(e.Client, ex));
                }

                return;
            }

            if (OnCommandReceived != null)
            {
                OnCommandReceived(this, new CommandReceivedArgs(command, (User)e.Client.Tag));
            }

            SendCommand(command);
        }