コード例 #1
0
        public void Compare(DirectTestMessage from)
        {
            Assert.AreEqual(SomeValue, from.SomeValue);
            Assert.AreEqual(Data.Length, from.Data.Length);

            for (var i = 0; i < Data.Length; i++)
            {
                Assert.AreEqual(Data[i], from.Data[i]);
            }
        }
コード例 #2
0
        public void MultipleCommunication()
        {
            var server          = new DirectTest();
            var waitReceiveAll  = new ManualResetEvent(false);
            var checkReciveLock = new object();

            var clients = Enumerable.Range(0, 2000)
                          .Select(i => new MultipleCommunicationStruct
            {
                Client      = new DirectTest(),
                Message     = DirectTestMessage.Generate(),
                IsCompleted = false
            })
                          .ToList();

            server.OnMessage += delegate(DirectTestMessage messageReceived)
            {
                var client = clients.First(c => c.Message.Index == messageReceived.Index);
                client.IsCompleted = true;
                client.Message.Compare(messageReceived);

                lock (checkReciveLock)
                {
                    var notCompleted = clients.Where(c => c.IsCompleted);
                    if (!notCompleted.Any())
                    {
                        waitReceiveAll.Set();
                    }
                }
            };

            clients.ForEach(m => m.Client.OnSend += delegate(byte[] bytes)
            {
                server.Receive(bytes, bytes.Length);
            });

            Parallel.ForEach(clients, (client) =>
            {
                client.Client.Send(client.Message);
            });

            waitReceiveAll.WaitOne();
        }
コード例 #3
0
        public void SingleCommunication()
        {
            var client      = new DirectTest();
            var server      = new DirectTest();
            var waitReceive = new ManualResetEvent(false);

            var message = DirectTestMessage.Generate();

            server.OnMessage += delegate(DirectTestMessage messageReceived)
            {
                message.Compare(messageReceived);

                waitReceive.Set();
            };

            client.OnSend += delegate(byte[] bytes)
            {
                server.Receive(bytes, bytes.Length);
            };

            client.Send(message);

            waitReceive.WaitOne();
        }
コード例 #4
0
        public void Send(DirectTestMessage message)
        {
            var bytes = _serializeType.Serialize(message);

            Send(bytes);
        }