コード例 #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());
            }
        }
コード例 #2
0
 /// <summary>
 /// Sets the source address of the message to be send.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="context">The context.</param>
 /// <param name="uriString">The URI string.</param>
 public static void SetSourceAddress <T>(this ISendContext <T> context, [NotNull] string uriString)
     where T : class
 {
     if (uriString == null)
     {
         throw new ArgumentNullException("uriString");
     }
     context.SetSourceAddress(uriString.ToUri());
 }
コード例 #3
0
        public void ApplyContext(ISendContext <TRequest> context, Uri responseAddress)
        {
            context.SetRequestId(_requestId);
            context.SetSourceAddress(responseAddress);
            context.SendResponseTo(responseAddress);
            context.SendFaultTo(responseAddress);

            _contextActions.Each(x => x(context));
        }
コード例 #4
0
        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);
            }
        }
コード例 #5
0
 public static void SetSourceAddress <T>(this ISendContext <T> context, string uriString)
     where T : class
 {
     context.SetSourceAddress(uriString.ToUri());
 }
コード例 #6
0
 void SetSendContext <T>(ISendContext <T> context)
     where T : class
 {
     context.SetNetwork(_network);
     context.SetSourceAddress(_peerUri);
 }