private string AddMissingDictionaryHashDefaultValues(string value, string @default)
        {
            try
            {
                if (value == null || @default == null)
                {
                    return(@default ?? value);
                }
                var values        = Config.GetDictionaryHash <string, string>(Guid.NewGuid().ToString(), value);
                var defaultValues = Config.GetDictionaryHash <string, string>(Guid.NewGuid().ToString(), @default);

                foreach (var entry in defaultValues)
                {
                    HashSet <string> hash;
                    if (!values.TryGetValue(entry.Key, out hash))
                    {
                        hash = new HashSet <string>();
                        values[entry.Key] = hash;
                    }

                    foreach (var item in entry.Value.Where(v => !hash.Contains(v)))
                    {
                        hash.Add(item);
                    }
                }

                // All missing values have been added.  Join back Values
                return(Config.ToString(values));
            }
            catch (Exception ex)
            {
                throw new Exception("Error Processing config value: " + value, ex);
            }
        }
示例#2
0
        private string AddPipeDelimitedMissingDefaultValues(string value, string @default)
        {
            try
            {
                if (value == null || @default == null)
                {
                    return(@default ?? value);
                }
                var splitValues = value.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries).Select(s => s.Trim()).ToList();
                var hash        = new HashSet <string>(splitValues);
                splitValues.AddRange(@default.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries).
                                     Where(key => !hash.Contains(key)));

                return(Config.ToString(splitValues));
            }
            catch (Exception ex)
            {
                throw new Exception("Error Processing config value: " + value, ex);
            }
        }
        private static string ConvertNonColonDelimitedDictionaryListToDictionaryHash(string oldValue)
        {
            if (oldValue == null)
            {
                return(null);
            }
            var oldValues = Config.GetList <string>(Guid.NewGuid().ToString(), oldValue);
            var newValues = new Dictionary <string, HashSet <string> >();

            foreach (var entry in oldValues)
            {
                var hash   = new HashSet <string>();
                var values = entry.Split(',');
                newValues.Add(values.First(), hash);
                foreach (var value in values.Skip(1).Where(v => !hash.Contains(v)))
                {
                    hash.Add(value);
                }
            }
            return(Config.ToString(newValues));
        }