public ConsulState UpdateKVNode(KeyValueNode kvNode) { if (TryUpdateKVNode(kvNode, out var updatedState)) { return(updatedState); } return(this); }
public bool TryUpdateKVNode(KeyValueNode kvNode, out ConsulState updatedState) { if (_kvStore.TryUpdate(kvNode, out var updatedKvStore)) { updatedState = new ConsulState(_services, updatedKvStore, _missingKeyPrefixes); return(true); } updatedState = null; return(false); }
public bool TryUpdate(KeyValueNode kvNode, out KeyValueStore updatedStore) { if (_leaves.TryGetValue(kvNode.FullKey, out var existingNode) && existingNode.Equals(kvNode)) { updatedStore = null; return(false); } updatedStore = new KeyValueStore(_leaves.SetItem(kvNode.FullKey, kvNode)); return(true); }
public static IReadOnlyList <KeyValueNode> ParseConfig(this KeyValueNode node, IConfigurationParser parser) { if (node.FullKey == null) { throw new ArgumentException("Key is empty"); } if (string.IsNullOrWhiteSpace(node.Value)) { return(new [] { new KeyValueNode(node.FullKey, null as string) }); } var config = node.GetValueAsDictionary(parser); var result = config.Select(x => new KeyValueNode(ConfigurationPath.Combine(node.FullKey, x.Key), x.Value)).ToList(); return(result); }
public static Dictionary <string, string> GetValueAsDictionary(this KeyValueNode node, IConfigurationParser parser) { if (node.FullKey == null) { throw new ArgumentException("Key is empty"); } if (string.IsNullOrWhiteSpace(node.Value)) { return(new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase) { { node.FullKey, null } }); } using (var configStream = new MemoryStream(node.RawValue)) { return(new Dictionary <string, string>( parser.Parse(configStream), StringComparer.OrdinalIgnoreCase)); } }
protected bool Equals(KeyValueNode other) { return(string.Equals(FullKey, other.FullKey) && string.Equals(Value, other.Value)); }