Пример #1
0
        private async Task <dynamic> GetAsyncInternal(string key, IList <string> providers)
        {
            var srn = new Srn {
                Namespace = _nameSpace, Key = key
            };

            // System namespace forces the JSON provider
            if (_nameSpace == "system" && key != null && !key.StartsWith("security"))
            {
                return(await _repository.GetProvider("json").GetAsync(srn));
            }

            // If we're not looking for all just return a specific result.
            if (providers.Count == 1 && providers.SingleOrDefault() != "any")
            {
                return(await _repository.GetProvider(providers.SingleOrDefault()).GetAsync(srn));
            }

            if (!srn.HasNamespace() || !srn.HasKey())
            {
                throw new SrnException("Bulk queries support fully qualified SRNs only.");
            }

            // This is the code that merges results together from all providers into one result.
            // The code will always return the first instance of a result. Duplicates are ignored.
            foreach (var(k, v) in _repository.GetProviders())
            {
                // allow only whitelisted providers
                if (!providers.Contains(k))
                {
                    continue;
                }

                var result = await v.GetAsync(srn);

                if (result != null)
                {
                    return(result);
                }
            }

            // No match found in any provider :(
            return(null);
        }
Пример #2
0
 internal Srn(Srn value)
 {
     Version   = value.Version;
     Namespace = value.Namespace;
     Key       = value.Key;
 }