GladNet.Message.RequestMessage.ExportRoutingDataTo C# (CSharp) Method

ExportRoutingDataTo() public method

public ExportRoutingDataTo ( IRoutableMessage message ) : void
message IRoutableMessage
return void
		public void ExportRoutingDataTo(IRoutableMessage message)
		{
			//So, this is sorta a hack but it's a good one
			//for preformance
			if (message is RequestMessage)
			{
				RequestMessage castedMessage = message as RequestMessage;
				lock (syncObj)
				{
					//No reason to copy null stack
					if (_routingCodeStack != null)
						//We should transfer the routing stack but also preserve the other routing stack
						//We probably won't need it but just in case the user wants to do something with it still
						castedMessage._routingCodeStack = new Stack<int>(_routingCodeStack.Reverse()); //We must create a reverse copy of the stack:http://stackoverflow.com/questions/7391348/c-sharp-clone-a-stack
				}
			}
			else
			{
				if (message is ResponseMessage)
				{
					ResponseMessage castedMessage = message as ResponseMessage;
					lock (syncObj)
					{
						//No reason to copy null stack
						if (_routingCodeStack != null)
							//We should transfer the routing stack but also preserve the other routing stack
							//We probably won't need it but just in case the user wants to do something with it still
							castedMessage._routingCodeStack = new Stack<int>(_routingCodeStack.Reverse()); //We must create a reverse copy of the stack:http://stackoverflow.com/questions/7391348/c-sharp-clone-a-stack
					}
				}
			}

		}
#endif

Usage Example

Ejemplo n.º 1
0
        public static void Test_Event_Message_Routing_Stack_Can_Export_To_Other_Message()
        {
            //arrange
            Mock<PacketPayload> packet = new Mock<PacketPayload>(MockBehavior.Strict);
            RequestMessage message = new RequestMessage(packet.Object);

            //act
            message.Push(5);
            message.Push(4);
            message.Push(3);

            ResponseMessage rMessage = new ResponseMessage(packet.Object);

            //export routing stack
            message.ExportRoutingDataTo(rMessage);

            List<IRoutableMessage> Messages = new List<IRoutableMessage>() { rMessage, message };

            foreach (IRoutableMessage m in Messages)
            {
                Assert.NotNull(m.Peek());
                Assert.True(m.isMessageRoutable);

                Assert.AreEqual(3, m.Pop());
                Assert.AreEqual(4, m.Pop());
                Assert.AreEqual(5, m.Pop());

                Assert.IsNull(m.Peek());
                Assert.IsFalse(m.isMessageRoutable);
            }
        }