Пример #1
0
        public override void ProcessData(BaseData data)
        {
            BRBaseParam param = data.Param as BRBaseParam;
            BRData      bd    = data as BRData;

            var handle = HandleFactory.CreateHandle(param.HandleType);

            handle.Process(bd);
        }
 public void BindHandle_MinusOneAsHandle_ThrowsArgumentException()
 {
     using (SafeHandle handle = HandleFactory.CreateHandle(new IntPtr(-1)))
     {
         AssertExtensions.Throws <ArgumentException>("handle", () =>
         {
             ThreadPoolBoundHandle.BindHandle(handle);
         });
     }
 }
Пример #3
0
 public void BindHandle_ZeroAsHandle_ThrowsArgumentException()
 {
     using (SafeHandle handle = HandleFactory.CreateHandle(IntPtr.Zero))
     {
         Assert.Throws <ArgumentException>("handle", () =>
         {
             ThreadPoolBoundHandle.BindHandle(handle);
         });
     }
 }
        private void _server_DataReceived(object sender, Message e)
        {
            Console.WriteLine("Packet Weight : " + e.Data.Count() + " bytes");
            Thread thread = new Thread(delegate()
            {
                var tmp    = SimpleTcpAdapter.Convert(e.TcpClient);
                var packet = new BasicPacket();
                if (!packet.Parse(e.Data))
                {
                    var packets = SplitPacket(e.Data);
                    foreach (var pk in packets)
                    {
                        Thread.Sleep(500);
                        Thread t = new Thread(delegate()
                        {
                            var pack = new BasicPacket();
                            if (!pack.Parse(pk))
                            {
                                return;
                            }
                            var ptc = ProtocolFactory.CreateProtocol(pack.Opcode);
                            if (!ptc.Parse(Encoding.Unicode.GetString(pack.Data)))
                            {
                                return;
                            }
                            var handling  = HandleFactory.CreateHandle(pack.Opcode);
                            string toview = handling.Handling(ptc, tmp);
                            if (OnNewMessage != null)
                            {
                                OnNewMessage.Invoke(tmp, toview);
                            }
                        });
                        t.Start();
                    }

                    return;
                }
                var protocol = ProtocolFactory.CreateProtocol(packet.Opcode);
                if (!protocol.Parse(Encoding.Unicode.GetString(packet.Data)))
                {
                    return;
                }
                var handle    = HandleFactory.CreateHandle(packet.Opcode);
                string toView = handle.Handling(protocol, tmp);
                if (OnNewMessage != null)
                {
                    OnNewMessage.Invoke(tmp, toView);
                }
            });

            thread.Priority = ThreadPriority.Highest;
            thread.Start();
        }
Пример #5
0
 private void AssignHandleProcess(ITakeData data)
 {
     try
     {
         var handle = HandleFactory.CreateHandle(data.DataType);
         if (handle == null)
         {
             logger.Error("Cannot create handle , DataType = " + data.DataType);
             return;
         }
         handle.ProcessData(data);
     }
     catch (Exception e)
     {
         logger.Error(e.ToString());
     }
 }
Пример #6
0
        public void NewRecieve(byte[] data, EndPoint endpoint)
        {
            StreamPacket packet = new StreamPacket();

            if (!packet.Parse(data))
            {
                return;
            }
            var protocol = ProtocolFactory.CreateProtocol(packet.Opcode);

            if (!protocol.Parse(packet.Data))
            {
                return;
            }
            var handle = HandleFactory.CreateHandle(packet.Opcode);
            var toview = handle.Handling(protocol, endpoint, UDPSocketAdapter.Convert(_socket));

            if (OnReceive != null)
            {
                OnReceive.Invoke(toview);
            }
        }