コード例 #1
0
ファイル: ConsulState.cs プロジェクト: similarweb/consul-rx
        public ConsulState UpdateKVNode(KeyValueNode kvNode)
        {
            if (TryUpdateKVNode(kvNode, out var updatedState))
            {
                return(updatedState);
            }

            return(this);
        }
コード例 #2
0
ファイル: ConsulState.cs プロジェクト: similarweb/consul-rx
 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);
 }
コード例 #3
0
ファイル: KeyValueStore.cs プロジェクト: similarweb/consul-rx
        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);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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));
            }
        }
コード例 #6
0
 protected bool Equals(KeyValueNode other)
 {
     return(string.Equals(FullKey, other.FullKey) && string.Equals(Value, other.Value));
 }