Exemple #1
0
        public void Set(string key, object value, bool overwrite)
        {
            if (key == null)
            {
                throw new ArgumentNullException(nameof(key));
            }

            if (value == null)
            {
                _properties.Remove(key);
            }
            else if (overwrite)
            {
                _properties[key] = value;
            }
            else if (!_properties.Contains(key))
            {
                _properties[key] = value;
            }
        }
Exemple #2
0
        protected void AddInterceptor(string key, Interceptor interceptor)
        {
            bool updated = false;

            if (!interceptors.ContainsKey(key))
            {
                this.interceptors.Add(key, interceptor);
            }
            else
            {
                // this allows subs classes to override base classes.
                this.interceptors[key] = interceptor;
                updated = true;
            }
            if (properties.Contains(key) || updated)
            {
                SetProperty(key, properties[key]);
                properties.Remove(key);
            }
        }
Exemple #3
0
        public void TestUnmarshalPrimitiveMap()
        {
            XmlPrimitiveMapMarshaler marshaler = new XmlPrimitiveMapMarshaler();

            byte[] rawBytes = Encoding.UTF8.GetBytes(xmlString);

            IPrimitiveMap result = marshaler.Unmarshal(rawBytes);

            Assert.IsNotNull(result);

            Assert.IsTrue(result.Contains("BOOL"));
            Assert.IsTrue(result.Contains("BYTES"));
            Assert.IsTrue(result.Contains("STRING"));
            Assert.IsTrue(result.Contains("LONG"));
            Assert.IsTrue(result.Contains("FLOAT"));
            Assert.IsTrue(result.Contains("INT"));
            Assert.IsTrue(result.Contains("BYTE"));
            Assert.IsTrue(result.Contains("SHORT"));
            Assert.IsTrue(result.Contains("DOUBLE"));
            Assert.IsTrue(result.Contains("CHAR"));
        }
        public bool TryGetHeader(string key, out object value)
        {
            var found = _properties.Contains(key);

            if (found)
            {
                value = _properties[key];
                return(true);
            }

            value = null;
            return(false);
        }
Exemple #5
0
        public bool TryGetHeader(string key, out object value)
        {
            var found = _properties.Contains(key);

            if (found)
            {
                value = _properties[key];

                if (value is byte[])
                {
                    value = Encoding.UTF8.GetString((byte[])value);
                }
            }

            value = null;
            return(false);
        }
Exemple #6
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);
                }
            }
        }
 public bool Contains(object key)
 {
     return(_original.Contains(key));
 }