示例#1
0
        public static void SetTextHeaders <T>(this IDictionary <string, T> dictionary, SendHeaders headers, Func <string, string, T> converter)
        {
            foreach (var header in headers.GetAll())
            {
                if (header.Value == null)
                {
                    if (dictionary.ContainsKey(header.Key))
                    {
                        dictionary.Remove(header.Key);
                    }

                    continue;
                }

                if (dictionary.ContainsKey(header.Key))
                {
                    continue;
                }

                if (header.Value is string stringValue)
                {
                    dictionary[header.Key] = converter(header.Key, stringValue);
                }
                else if (header.Value is IFormattable formatValue && formatValue.GetType().IsValueType)
                {
                    dictionary.Add(header.Key, converter(header.Key, formatValue.ToString()));
                }
            }
        }
示例#2
0
        public IEnumerable <KeyValuePair <string, object> > GetAll()
        {
            yield return(new KeyValuePair <string, object>(nameof(_message.MessageId), _message.MessageId));

            foreach (var header in _adapter.GetAll())
            {
                yield return(header);
            }
        }
示例#3
0
        static void SetHeaders(IDictionary <string, object> dictionary, SendHeaders headers)
        {
            foreach (KeyValuePair <string, object> header in headers.GetAll())
            {
                if (header.Value == null)
                {
                    if (dictionary.ContainsKey(header.Key))
                    {
                        dictionary.Remove(header.Key);
                    }

                    continue;
                }

                if (dictionary.ContainsKey(header.Key))
                {
                    continue;
                }

                switch (header.Value)
                {
                case DateTimeOffset value:
                    if (_dateTimeOffsetConverter.TryConvert(value, out string text))
                    {
                        dictionary[header.Key] = text;
                    }
                    break;

                case DateTime value:
                    if (_dateTimeConverter.TryConvert(value, out text))
                    {
                        dictionary[header.Key] = text;
                    }
                    break;

                case string value:
                    dictionary[header.Key] = value;
                    break;

                case bool value when value:
                    dictionary[header.Key] = bool.TrueString;
                    break;

                case IFormattable formatValue:
                    if (header.Value.GetType().IsValueType)
                    {
                        dictionary[header.Key] = header.Value;
                    }
                    else
                    {
                        dictionary[header.Key] = formatValue.ToString();
                    }
                    break;
                }
            }
        }
            void SetHeaders(IDictionary<string, object> dictionary, SendHeaders headers)
            {
                foreach (var header in headers.GetAll())
                {
                    if (header.Value == null)
                    {
                        if (dictionary.ContainsKey(header.Key))
                            dictionary.Remove(header.Key);

                        continue;
                    }

                    if (dictionary.ContainsKey(header.Key))
                        continue;

                    switch (header.Value)
                    {
                        case DateTimeOffset value:
                            if (_dateTimeOffsetConverter.TryConvert(value, out long result))
                                dictionary[header.Key] = new AmqpTimestamp(result);
                            else if (_dateTimeOffsetConverter.TryConvert(value, out string text))
                                dictionary[header.Key] = text;

                            break;

                        case DateTime value:
                            if (_dateTimeConverter.TryConvert(value, out result))
                                dictionary[header.Key] = new AmqpTimestamp(result);
                            else if (_dateTimeConverter.TryConvert(value, out string text))
                                dictionary[header.Key] = text;

                            break;

                        case string value:
                            dictionary[header.Key] = value;
                            break;

                        case IFormattable formatValue:
                            if (header.Value.GetType().IsValueType)
                                dictionary[header.Key] = header.Value;
                            else
                                dictionary[header.Key] = formatValue.ToString();

                            break;
                    }
                }
            }
示例#5
0
        public static void SetTextHeaders(this IPrimitiveMap dictionary, SendHeaders headers)
        {
            foreach (KeyValuePair <string, object> header in headers.GetAll())
            {
                if (header.Value == null)
                {
                    continue;
                }

                if (dictionary.Contains(header.Key))
                {
                    continue;
                }

                if (header.Value is string stringValue)
                {
                    dictionary[header.Key] = stringValue;
                }
                else if (header.Value is IFormattable formatValue && formatValue.GetType().IsValueType)
                {
                    dictionary[header.Key] = formatValue.ToString();
                }
            }
        }
        public static void SetHeaders(this IPrimitiveMap dictionary, SendHeaders headers)
        {
            foreach (KeyValuePair <string, object> header in headers.GetAll())
            {
                if (header.Value == null)
                {
                    if (dictionary.Contains(header.Key))
                    {
                        dictionary.Remove(header.Key);
                    }

                    continue;
                }

                if (dictionary.Contains(header.Key))
                {
                    continue;
                }

                switch (header.Value)
                {
                case DateTimeOffset dateTimeOffset:
                    if (_dateTimeOffsetConverter.TryConvert(dateTimeOffset, out long result))
                    {
                        dictionary[header.Key] = result;
                    }
                    else if (_dateTimeOffsetConverter.TryConvert(dateTimeOffset, out string text))
                    {
                        dictionary[header.Key] = text;
                    }

                    break;

                case DateTime dateTime:
                    if (_dateTimeConverter.TryConvert(dateTime, out result))
                    {
                        dictionary[header.Key] = result;
                    }
                    else if (_dateTimeConverter.TryConvert(dateTime, out string text))
                    {
                        dictionary[header.Key] = text;
                    }

                    break;

                case string s:
                    dictionary[header.Key] = s;
                    break;

                case bool boolValue when boolValue:
                    dictionary[header.Key] = bool.TrueString;
                    break;

                case IFormattable formatValue:
                    if (header.Value.GetType().IsValueType)
                    {
                        dictionary[header.Key] = header.Value;
                    }
                    else
                    {
                        dictionary[header.Key] = formatValue.ToString();
                    }
                    break;
                }

                if (header.Key == "AMQ_SCHEDULED_DELAY")
                {
                    headers.Set(header.Key, null);
                }
            }
        }
            static void SetHeaders(IDictionary <string, object> dictionary, SendHeaders headers)
            {
                foreach (KeyValuePair <string, object> header in headers.GetAll())
                {
                    if (header.Value == null)
                    {
                        if (dictionary.ContainsKey(header.Key))
                        {
                            dictionary.Remove(header.Key);
                        }

                        continue;
                    }

                    if (dictionary.ContainsKey(header.Key))
                    {
                        continue;
                    }

                    switch (header.Value)
                    {
                    case DateTimeOffset value:
                        if (_dateTimeOffsetConverter.TryConvert(value, out long result))
                        {
                            dictionary[header.Key] = new AmqpTimestamp(result);
                        }
                        else if (_dateTimeOffsetConverter.TryConvert(value, out string text))
                        {
                            dictionary[header.Key] = text;
                        }

                        break;

                    case DateTime value:
                        if (_dateTimeConverter.TryConvert(value, out result))
                        {
                            dictionary[header.Key] = new AmqpTimestamp(result);
                        }
                        else if (_dateTimeConverter.TryConvert(value, out string text))
                        {
                            dictionary[header.Key] = text;
                        }

                        break;

                    case string value when header.Key == "CC" || header.Key == "BCC":
                        dictionary[header.Key] = new[] { value };
                        break;

                    case IEnumerable <string> strings when header.Key == "CC" || header.Key == "BCC":
                        dictionary[header.Key] = strings.ToArray();
                        break;

                    case string value:
                        dictionary[header.Key] = value;
                        break;

                    case bool value when value:
                        dictionary[header.Key] = bool.TrueString;
                        break;

                    case IFormattable formatValue:
                        if (header.Value.GetType().IsValueType)
                        {
                            dictionary[header.Key] = header.Value;
                        }
                        else
                        {
                            dictionary[header.Key] = formatValue.ToString();
                        }

                        break;
                    }
                }
            }