Пример #1
0
        public static IDictionary <string, string> ParseDimensions(string dimensions)
        {
            var dimensionsMap            = new SortedDictionary <string, string>();
            var commaSeparatedDimensions = dimensions.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

            foreach (var commaSeparated in commaSeparatedDimensions)
            {
                var keyValues = commaSeparated.Split(new[] { '=' }, StringSplitOptions.RemoveEmptyEntries);

                if (keyValues.Length != 2)
                {
                    MetricsManager.ReportError("Invalid dimension key=value pair format");
                    return(new Dictionary <string, string>());
                }

                var key = keyValues[0].Trim().ToLower();
                var val = keyValues[1].Trim();

                if (IsValidName(key) && IsValidName(val))
                {
                    dimensionsMap.AddOrUpdate(key, val);
                }
                else
                {
                    MetricsManager.ReportError("Invalid dimension key or value pair " + key + "=" + val);
                    return(new Dictionary <string, string>());
                }
            }

            return(dimensionsMap);
        }
Пример #2
0
        public static void AddOrUpdateRange <T, S>(this SortedDictionary <T, S> source, IDictionary <T, S> collection)
        {
            if (collection == null)
            {
                throw new ArgumentNullException("Collection is null");
            }

            foreach (var item in collection)
            {
                source.AddOrUpdate(item.Key, item.Value, (k, v) => v = item.Value);
            }
        }
Пример #3
0
 /// <summary>
 /// 设置某个字段的值
 /// </summary>
 /// <param name="key">字段名</param>
 /// <param name="value">字段值</param>
 public void SetValue(string key, object value)
 {
     m_values.AddOrUpdate(key, value);
 }