public static ISettingsNode Convert(IDictionary configuration)
        {
            var result = null as ISettingsNode;

            foreach (DictionaryEntry entry in configuration)
            {
                var node = TreeFactory.CreateTreeByMultiLevelKey(
                    null,
                    entry.Key.ToString().Replace(" ", "").Split(Separators, StringSplitOptions.RemoveEmptyEntries),
                    entry.Value.ToString());

                result = SettingsNodeMerger.Merge(result, node, null);
            }

            return(result);
        }
        public static ISettingsNode Extract([NotNull] ClusterConfigClientState state, ClusterConfigPath path, [CanBeNull] SettingsMergeOptions mergeOptions)
        {
            mergeOptions = mergeOptions ?? DefaultMergeOptions;

            return(state.Cache.Obtain(
                       path,
                       p =>
            {
                foreach (var prefix in EnumeratePrefixes(p))
                {
                    if (state.Cache.TryGetValue(prefix, out var tree))
                    {
                        return tree.ScopeTo(path.Segments.Skip(prefix.Segments.Count()));
                    }
                }

                var remoteSettings = state.RemoteTree?.GetSettings(p);
                var localSettings = state.LocalTree?.ScopeTo(p.Segments);

                return SettingsNodeMerger.Merge(remoteSettings, localSettings, mergeOptions);
            }));
        }
        private TreeBuilder Add(ISettingsNode node)
        {
            tree = SettingsNodeMerger.Merge(tree, node, SettingsMergeOptions.Default);

            return(this);
        }
        private static ISettingsNode ParseSettings(string[] args, string defaultKey, string defaultValue)
        {
            var resultBuilder   = new ObjectNodeBuilder();
            var valueNodeIndex  = new Dictionary <string, List <ValueNode> >(StringComparer.OrdinalIgnoreCase);
            var objectNodeIndex = new Dictionary <string, ISettingsNode>(StringComparer.OrdinalIgnoreCase);

            foreach (var pair in CommandLineArgumentsParser.Parse(args ?? Array.Empty <string>()))
            {
                var key = pair.key ?? defaultKey;
                if (key == null)
                {
                    continue;
                }

                var value = pair.value ?? defaultValue;
                if (value == null)
                {
                    continue;
                }

                var node = TreeFactory.CreateTreeByMultiLevelKey(null, key.Split('.'), value).Children.Single();
                var name = node.Name ?? string.Empty;

                if (node is ObjectNode objectNode)
                {
                    var currentNode = objectNodeIndex.TryGetValue(name, out var current) ? current : null;

                    objectNodeIndex[name] = SettingsNodeMerger.Merge(currentNode, objectNode, null);
                }
                else if (node is ValueNode valueNode)
                {
                    if (!valueNodeIndex.TryGetValue(name, out var nodes))
                    {
                        valueNodeIndex[name] = nodes = new List <ValueNode>();
                    }

                    nodes.Add(valueNode);
                }
            }

            foreach (var pair in valueNodeIndex)
            {
                if (pair.Value.Count == 1)
                {
                    resultBuilder.SetChild(pair.Value.Single());
                }
                else
                {
                    resultBuilder.SetChild(new ArrayNode(pair.Key, pair.Value.Select((node, index) => new ValueNode(index.ToString(), node.Value)).ToArray()));
                }
            }

            foreach (var pair in objectNodeIndex)
            {
                resultBuilder.SetChild(pair.Value);
            }

            var result = resultBuilder.Build();

            if (result.ChildrenCount > 0)
            {
                return(result);
            }

            return(null);
        }