Esempio n. 1
0
        public static void ForwardUsingOriginalContext(this ISendContext target,
                                                       IConsumeContext source)
        {
            target.SetRequestId(source.RequestId);
            target.SetConversationId(source.ConversationId);
            target.SetCorrelationId(source.CorrelationId);
            target.SetSourceAddress(source.SourceAddress);
            target.SetResponseAddress(source.ResponseAddress);
            target.SetFaultAddress(source.FaultAddress);
            target.SetNetwork(source.Network);
            if (source.ExpirationTime.HasValue)
            {
                target.SetExpirationTime(source.ExpirationTime.Value);
            }
            target.SetRetryCount(source.RetryCount);

            foreach (var header in source.Headers)
            {
                target.SetHeader(header.Key, header.Value);
            }

            var inputAddress = source.InputAddress != null
                                   ? source.InputAddress.ToString()
                                   : source.DestinationAddress != null
                                         ? source.DestinationAddress.ToString()
                                         : null;

            if (!string.IsNullOrEmpty(inputAddress))
            {
                target.SetHeader("mt.forwarder.uri", source.DestinationAddress.ToString());
            }
        }
        protected void TestSerialization <T>(T message)
            where T : class
        {
            byte[] data;
            var    serializer = new TSerializer();

            _sourceUri      = new Uri("loopback://localhost/source");
            _responseUri    = new Uri("loopback://localhost/response");
            _faultUri       = new Uri("loopback://localhost/fault");
            _destinationUri = new Uri("loopback://localhost/destination");
            _retryCount     = 69;

            using (var output = new MemoryStream())
            {
                ISendContext <T> context = message.ToSendContext();
                context.SetSourceAddress(_sourceUri);
                context.SendResponseTo(_responseUri);
                context.SendFaultTo(_faultUri);
                context.SetDestinationAddress(_destinationUri);
                context.SetRetryCount(_retryCount);

                serializer.Serialize(output, context);

                data = output.ToArray();
            }

            // Trace.WriteLine(Encoding.UTF8.GetString(data));

            using (MemoryStream input = new MemoryStream(data))
            {
                IReceiveContext context = ReceiveContext.FromBodyStream(input);
                serializer.Deserialize(context);

                IConsumeContext <T> messageContext;
                context.TryGetContext <T>(out messageContext).ShouldBeTrue();

                messageContext.ShouldNotBeNull();
                message.Equals(messageContext.Message).ShouldBeTrue();
                message.ShouldNotBeTheSameAs(messageContext.Message);


                Assert.AreEqual(_retryCount, context.RetryCount);
                Assert.AreEqual(_sourceUri, context.SourceAddress);
                Assert.AreEqual(_responseUri, context.ResponseAddress);
                Assert.AreEqual(_faultUri, context.FaultAddress);
                Assert.AreEqual(_destinationUri, context.DestinationAddress);
                //			Assert.AreEqual(message.GetType().ToMessageName(), CurrentMessage.Headers.MessageType);
            }
        }
Esempio n. 3
0
        public static void ForwardUsingOriginalContext<T>(this ISendContext target,
            IConsumeContext<T> source)
            where T : class
        {
            target.SetRequestId(source.RequestId);
            target.SetConversationId(source.ConversationId);
            target.SetCorrelationId(source.CorrelationId);
            target.SetResponseAddress(source.ResponseAddress);
            target.SetFaultAddress(source.FaultAddress);
            target.SetNetwork(source.Network);
            if (source.ExpirationTime.HasValue)
                target.SetExpirationTime(source.ExpirationTime.Value);
            target.SetRetryCount(source.RetryCount);

            foreach (var header in source.Headers)
            {
                target.SetHeader(header.Key, header.Value);
            }
        }