Example #1
0
        internal static IList <KeyValue> ToKeyValueList(IDictionary <string, string> metadata)
        {
            if (metadata == null || metadata.Count == 0)
            {
                return(Array.Empty <KeyValue>());
            }

            return(HashMapHelper.SetOfKeyValuePairs(metadata).Select(e => new KeyValueBuilder().SetKey(e.Key).SetValue(e.Value).Build()).ToList());
        }
Example #2
0
        // If all messageId in map are same Size, and all bigger/smaller than the other, return valid value.
        public int CompareTo(IMessageId o)
        {
            if (!(o is MultiMessageId))
            {
                throw new ArgumentException("expected MultiMessageId object. Got instance of " + o.GetType().FullName);
            }

            var other    = (MultiMessageId)o;
            var otherMap = other.Map;

            if ((Map == null || Map.Count == 0) && (otherMap == null || otherMap.Count == 0))
            {
                return(0);
            }

            if (otherMap == null || Map == null || otherMap.Count != Map.Count)
            {
                throw new ArgumentException("Current Size and other Size not equals");
            }

            var result = 0;

            foreach (var entry in HashMapHelper.SetOfKeyValuePairs(Map))
            {
                if (!otherMap.TryGetValue(entry.Key, out var otherMessage))
                {
                    throw new ArgumentException("Other MessageId not have topic " + entry.Key);
                }

                var currentResult = entry.Value.CompareTo(otherMessage);
                if (result == 0)
                {
                    result = currentResult;
                }
                else if (currentResult == 0)
                {
                    continue;
                }
                else if (result != currentResult)
                {
                    throw new ArgumentException("Different MessageId in Map get different compare result");
                }
                else
                {
                    continue;
                }
            }

            return(result);
        }
Example #3
0
        public static void ValidateMetadata(IDictionary <string, string> metadata)
        {
            if (metadata == null)
            {
                return;
            }

            var size = 0;

            foreach (var e in HashMapHelper.SetOfKeyValuePairs(metadata))
            {
                size += (e.Key.Length + e.Value.Length);
                if (size > MaxMetadataSize)
                {
                    throw new System.ArgumentException(ErrorMessage);
                }
            }
        }
 public ConsumerConfigBuilder <T> Properties(IDictionary <string, string> properties)
 {
     if (properties.Count == 0)
     {
         throw new ArgumentException("properties cannot be empty");
     }
     HashMapHelper.SetOfKeyValuePairs(properties).ToList().ForEach(entry =>
     {
         if (entry.Key == null || entry.Value == null)
         {
             throw new ArgumentException("properties' key/value cannot be blank");
         }
         if (string.IsNullOrWhiteSpace(entry.Key) || string.IsNullOrWhiteSpace(entry.Value))
         {
             throw new ArgumentException("properties' key/value cannot be blank");
         }
         _conf.Properties.Add(entry.Key, entry.Value);
     });
     return(this);
 }