public static void Set(this IDictionary <string, object> dictionary, IEnumerable <HeaderValue> headerValues)
 {
     foreach (HeaderValue header in headerValues)
     {
         _adapter.Set(dictionary, header);
     }
 }
コード例 #2
0
        /// <summary>
        /// Set the host headers on the SendContext (for error, dead-letter, etc.)
        /// </summary>
        /// <param name="adapter"></param>
        /// <param name="headers"></param>
        /// <param name="exceptionContext"></param>
        public static void SetExceptionHeaders <T>(this ITransportSetHeaderAdapter <T> adapter, IDictionary <string, T> headers, ExceptionReceiveContext
                                                   exceptionContext)
        {
            var exception = exceptionContext.Exception.GetBaseException() ?? exceptionContext.Exception;

            var exceptionMessage = ExceptionUtil.GetMessage(exception);

            adapter.Set(headers, MessageHeaders.Reason, "fault");

            adapter.Set(headers, MessageHeaders.FaultExceptionType, TypeMetadataCache.GetShortName(exception.GetType()));
            adapter.Set(headers, MessageHeaders.FaultMessage, exceptionMessage);
            adapter.Set(headers, MessageHeaders.FaultTimestamp, exceptionContext.ExceptionTimestamp);
            adapter.Set(headers, MessageHeaders.FaultStackTrace, ExceptionUtil.GetStackTrace(exception));

            if (exceptionContext.TryGetPayload(out ConsumerFaultInfo info))
            {
                adapter.Set(headers, MessageHeaders.FaultConsumerType, info.ConsumerType);
                adapter.Set(headers, MessageHeaders.FaultMessageType, info.MessageType);
            }

            if (exceptionContext.TryGetPayload(out RetryContext retryContext) && retryContext.RetryCount > 0)
            {
                adapter.Set(headers, MessageHeaders.FaultRetryCount, retryContext.RetryCount);
            }
        }
 public static void Set <TValueType>(this ITransportSetHeaderAdapter <TValueType> adapter, IDictionary <string, TValueType> dictionary,
                                     IEnumerable <HeaderValue> headerValues)
 {
     foreach (HeaderValue header in headerValues)
     {
         adapter.Set(dictionary, header);
     }
 }
 public static void Set <TValueType>(this ITransportSetHeaderAdapter <TValueType> adapter, IDictionary <string, TValueType> dictionary, string key,
                                     DateTime?value, Func <DateTime, string> formatter)
 {
     if (value.HasValue)
     {
         adapter.Set(dictionary, new HeaderValue <string>(key, formatter(value.Value)));
     }
 }
 public static void Set <TValueType>(this ITransportSetHeaderAdapter <TValueType> adapter, IDictionary <string, TValueType> dictionary, string key,
                                     TimeSpan?value)
 {
     if (value.HasValue)
     {
         adapter.Set(dictionary, new HeaderValue <string>(key, ToString(value.Value)));
     }
 }
 public static void Set <TValueType>(this ITransportSetHeaderAdapter <TValueType> adapter, IDictionary <string, TValueType> dictionary, string key,
                                     string value)
 {
     if (!string.IsNullOrWhiteSpace(value))
     {
         adapter.Set(dictionary, new HeaderValue <string>(key, value));
     }
 }
コード例 #7
0
 /// <summary>
 /// Set the host headers on the SendContext (for error, dead-letter, etc.)
 /// </summary>
 /// <param name="adapter"></param>
 /// <param name="dictionary"></param>
 public static void SetHostHeaders <T>(this ITransportSetHeaderAdapter <T> adapter, IDictionary <string, T> dictionary)
 {
     adapter.Set(dictionary, MessageHeaders.Host.MachineName, HostMetadataCache.Host.MachineName);
     adapter.Set(dictionary, MessageHeaders.Host.ProcessName, HostMetadataCache.Host.ProcessName);
     adapter.Set(dictionary, MessageHeaders.Host.ProcessId, HostMetadataCache.Host.ProcessId);
     adapter.Set(dictionary, MessageHeaders.Host.Assembly, HostMetadataCache.Host.Assembly);
     adapter.Set(dictionary, MessageHeaders.Host.AssemblyVersion, HostMetadataCache.Host.AssemblyVersion);
     adapter.Set(dictionary, MessageHeaders.Host.MassTransitVersion, HostMetadataCache.Host.MassTransitVersion);
     adapter.Set(dictionary, MessageHeaders.Host.FrameworkVersion, HostMetadataCache.Host.FrameworkVersion);
     adapter.Set(dictionary, MessageHeaders.Host.OperatingSystemVersion, HostMetadataCache.Host.OperatingSystemVersion);
 }
コード例 #8
0
            public Headers Serialize(SendContext context)
            {
                var dictionary = new Dictionary <string, Header>();

                if (context.MessageId.HasValue)
                {
                    _adapter.Set(dictionary, nameof(MessageContext.MessageId), context.MessageId.Value);
                }

                if (context.CorrelationId.HasValue)
                {
                    _adapter.Set(dictionary, nameof(MessageContext.CorrelationId), context.CorrelationId.Value);
                }

                if (context.ConversationId.HasValue)
                {
                    _adapter.Set(dictionary, nameof(MessageContext.ConversationId), context.ConversationId.Value);
                }

                if (context.InitiatorId.HasValue)
                {
                    _adapter.Set(dictionary, nameof(MessageContext.InitiatorId), context.InitiatorId.Value);
                }

                if (context.DestinationAddress != null)
                {
                    _adapter.Set(dictionary, nameof(MessageContext.DestinationAddress), context.DestinationAddress.ToString());
                }

                if (context.SourceAddress != null)
                {
                    _adapter.Set(dictionary, nameof(MessageContext.SourceAddress), context.SourceAddress.ToString());
                }

                if (context.ContentType != null)
                {
                    _adapter.Set(dictionary, MessageHeaders.ContentType, context.ContentType.MediaType);
                }

                foreach (var headerValue in context.Headers)
                {
                    _adapter.Set(dictionary, headerValue);
                }

                var headers = new Headers();

                foreach (var value in dictionary.Values)
                {
                    headers.Add(value);
                }

                return(headers);
            }