public async Task <INuGetResource> Create(SourceRepository source) { V3RawSearchResource curResource = null; V3ServiceIndexResource serviceIndex = await source.GetResource <V3ServiceIndexResource>(); if (serviceIndex != null) { var endpoints = serviceIndex["SearchQueryService"].ToArray(); if (endpoints.Length > 0) { HttpHandlerResource handler = await source.GetResource <HttpHandlerResource>(); // construct a new resource curResource = new V3RawSearchResource(handler.MessageHandler, endpoints); } } return(curResource); }
// TODO: refresh the file when it gets old public async Task <INuGetResource> Create(SourceRepository source) { V3ServiceIndexResource index = null; string url = source.PackageSource.Source; // the file type can easily rule out if we need to request the url if (url.EndsWith(".json", StringComparison.OrdinalIgnoreCase)) { // check the cache before downloading the file if (!_cache.TryGetValue(url, out index)) { DataClient client = new DataClient((await source.GetResource <HttpHandlerResource>()).MessageHandler); JObject json = await client.GetJObjectAsync(new Uri(url)); if (json != null) { // Use SemVer instead of NuGetVersion, the service index should always be // in strict SemVer format SemanticVersion version = null; var status = json.Value <string>("version"); if (status != null && SemanticVersion.TryParse(status, out version)) { if (version.Major == 3) { index = new V3ServiceIndexResource(json, DateTime.UtcNow); } } } } // cache the value even if it is null to avoid checking it again later _cache.TryAdd(url, index); } return(index); }