Beispiel #1
0
        public async Task Send(SendContext context)
        {
            context.DestinationAddress = _message.Destination;
            context.SourceAddress      = _sourceAddress;

            context.ResponseAddress = ToUri(_message.ResponseAddress);
            context.FaultAddress    = ToUri(_message.FaultAddress);

            SetHeaders(context);

            context.MessageId      = ConvertIdToGuid(_message.MessageId);
            context.RequestId      = ConvertIdToGuid(_message.RequestId);
            context.CorrelationId  = ConvertIdToGuid(_message.CorrelationId);
            context.ConversationId = ConvertIdToGuid(_message.ConversationId);
            context.InitiatorId    = ConvertIdToGuid(_message.InitiatorId);

            if (!string.IsNullOrWhiteSpace(_message.ExpirationTime))
            {
                if (DateTime.TryParse(_message.ExpirationTime, null, DateTimeStyles.RoundtripKind, out var expirationTime) ||
                    DateTime.TryParse(_message.ExpirationTime, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal, out expirationTime))
                {
                    var timeToLive = expirationTime - DateTime.UtcNow;
                    context.TimeToLive = timeToLive > TimeSpan.Zero
                        ? timeToLive
                        : TimeSpan.FromSeconds(1);
                }
            }

            var bodySerializer = new StringMessageSerializer(new ContentType(_message.ContentType), _message.Body);

            if (!string.IsNullOrWhiteSpace(_message.PayloadMessageHeadersAsJson))
            {
                var headers = JObject.Parse(_message.PayloadMessageHeadersAsJson).ToObject <Dictionary <string, object> >();

                if (string.Compare(_message.ContentType, JsonMessageSerializer.JsonContentType.MediaType, StringComparison.OrdinalIgnoreCase) == 0)
                {
                    bodySerializer.UpdateJsonHeaders(headers);
                }
                else if (string.Compare(_message.ContentType, XmlMessageSerializer.XmlContentType.MediaType, StringComparison.OrdinalIgnoreCase) == 0)
                {
                    bodySerializer.UpdateXmlHeaders(headers);
                }
            }

            context.Serializer = bodySerializer;

            if (_pipe != null)
            {
                await _pipe.Send(context).ConfigureAwait(false);
            }
        }
        public async Task Send(SendContext context)
        {
            context.DestinationAddress = _message.Destination;
            context.SourceAddress      = _sourceAddress;

            context.ResponseAddress = ToUri(_message.ResponseAddress);
            context.FaultAddress    = ToUri(_message.FaultAddress);

            SetHeaders(context);

            context.MessageId      = ConvertIdToGuid(_message.MessageId);
            context.RequestId      = ConvertIdToGuid(_message.RequestId);
            context.CorrelationId  = ConvertIdToGuid(_message.CorrelationId);
            context.ConversationId = ConvertIdToGuid(_message.ConversationId);
            context.InitiatorId    = ConvertIdToGuid(_message.InitiatorId);

            if (!string.IsNullOrEmpty(_message.ExpirationTime))
            {
                context.TimeToLive = DateTime.UtcNow - DateTime.Parse(_message.ExpirationTime);
            }

            var bodySerializer = new StringMessageSerializer(new ContentType(_message.ContentType), _message.Body);

            if (!string.IsNullOrWhiteSpace(_message.PayloadMessageHeadersAsJson))
            {
                var headers = JObject.Parse(_message.PayloadMessageHeadersAsJson).ToObject <Dictionary <string, object> >();

                if (string.Compare(_message.ContentType, JsonMessageSerializer.JsonContentType.MediaType, StringComparison.OrdinalIgnoreCase) == 0)
                {
                    bodySerializer.UpdateJsonHeaders(headers);
                }
                else if (string.Compare(_message.ContentType, XmlMessageSerializer.XmlContentType.MediaType, StringComparison.OrdinalIgnoreCase) == 0)
                {
                    bodySerializer.UpdateXmlHeaders(headers);
                }
            }

            context.Serializer = bodySerializer;

            if (_pipe != null)
            {
                await _pipe.Send(context).ConfigureAwait(false);
            }
        }