public PSAutoCompleteResourceV3(DataClient client, ServiceIndexResourceV3 serviceIndex, RegistrationResourceV3 regResource) : base() { _regResource = regResource; _serviceIndex = serviceIndex; _client = client; }
public SearchLatestResourceV3Provider(DataClient client) : base(typeof(SearchLatestResource), nameof(SearchLatestResourceV3Provider), "SearchLatestResourceV2Provider") { _client = client; }
public UIMetadataResourceV3(DataClient client, RegistrationResourceV3 regResource, ReportAbuseResourceV3 reportAbuseResource) : base() { _regResource = regResource; _client = client; _reportAbuseResource = reportAbuseResource; }
/// <summary> /// Creates a new stats resource. /// </summary> /// <param name="client">DataClient that can be used for accessing resource URLs</param> /// <param name="resourceUrl">Resource URL</param> /// <exception cref="ArgumentNullException">Thrown when client or resourceUrl are not specified</exception> public V3TotalsStatsResource(DataClient client, Uri resourceUrl) { if (client == null) throw new ArgumentNullException("client"); if (resourceUrl == null) throw new ArgumentNullException("resourceUrl"); _client = client; _resourceUrl = resourceUrl; }
public override async Task<Tuple<bool, INuGetResource>> TryCreate(SourceRepository source, CancellationToken token) { MetadataResourceV3 curResource = null; RegistrationResourceV3 regResource = await source.GetResourceAsync<RegistrationResourceV3>(token); if (regResource != null) { var messageHandlerResource = await source.GetResourceAsync<HttpHandlerResource>(token); DataClient client = new DataClient(messageHandlerResource.MessageHandler); curResource = new MetadataResourceV3(client, regResource); } return new Tuple<bool, INuGetResource>(curResource != null, curResource); }
public RawSearchResourceV3(HttpMessageHandler handler, IEnumerable<Uri> searchEndpoints) { if (handler == null) { throw new ArgumentNullException("handler"); } if (searchEndpoints == null) { throw new ArgumentNullException("searchEndpoints"); } _client = new DataClient(handler); _searchEndpoints = searchEndpoints.ToArray(); }
public override async Task<Tuple<bool, INuGetResource>> TryCreate(SourceRepository source, CancellationToken token) { DependencyInfoResource curResource = null; if (await source.GetResourceAsync<ServiceIndexResourceV3>(token) != null) { var messageHandlerResource = await source.GetResourceAsync<HttpHandlerResource>(token); var client = new DataClient(messageHandlerResource.MessageHandler); var regResource = await source.GetResourceAsync<RegistrationResourceV3>(token); // construct a new resource curResource = new DependencyInfoResourceV3(client, regResource, source); } return new Tuple<bool, INuGetResource>(curResource != null, curResource); }
public override async Task<Tuple<bool, INuGetResource>> TryCreate(SourceRepository source, CancellationToken token) { RegistrationResourceV3 regResource = null; var serviceIndex = await source.GetResourceAsync<ServiceIndexResourceV3>(token); if (serviceIndex != null) { Uri baseUrl = serviceIndex[ServiceTypes.RegistrationsBaseUrl].FirstOrDefault(); var messageHandlerResource = await source.GetResourceAsync<HttpHandlerResource>(token); DataClient client = new DataClient(messageHandlerResource.MessageHandler); // construct a new resource regResource = new RegistrationResourceV3(client, baseUrl); } return new Tuple<bool, INuGetResource>(regResource != null, regResource); }
// TODO: refresh the file when it gets old public override async Task<Tuple<bool, INuGetResource>> TryCreate(SourceRepository source, CancellationToken token) { ServiceIndexResourceV3 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)) { var messageHandlerResource = await source.GetResourceAsync<HttpHandlerResource>(token); DataClient client = new DataClient(messageHandlerResource.MessageHandler); JObject json = await client.GetJObjectAsync(new Uri(url), token); 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 ServiceIndexResourceV3(json, DateTime.UtcNow); } } } } // cache the value even if it is null to avoid checking it again later _cache.TryAdd(url, index); } return new Tuple<bool, INuGetResource>(index != null, index); }
public override async Task<Tuple<bool, INuGetResource>> TryCreate(SourceRepository source, CancellationToken token) { DownloadResource curResource = null; var serviceIndex = await source.GetResourceAsync<ServiceIndexResourceV3>(token); if (serviceIndex != null) { if (!_cache.TryGetValue(source.PackageSource, out curResource)) { var registrationResource = await source.GetResourceAsync<RegistrationResourceV3>(token); var messageHandlerResource = await source.GetResourceAsync<HttpHandlerResource>(token); DataClient client = new DataClient(messageHandlerResource.MessageHandler); curResource = new DownloadResourceV3(client, registrationResource); _cache.TryAdd(source.PackageSource, curResource); } } return new Tuple<bool, INuGetResource>(curResource != null, curResource); }
public UIMetadataResourceV3Provider(DataClient client) : base(typeof(UIMetadataResource), "UIMetadataResourceV3Provider", "UIMetadataResourceV2Provider") { _client = client; }
public async Task DataClient_Basic_NoCache() { int count = 0; TestHandler handler = new TestHandler((request) => { count++; var response = new HttpResponseMessage(HttpStatusCode.OK); response.Content = new TestContent(TestJson.BasicGraph); return response; }); using (var client = new DataClient(handler)) { var json = await client.GetJObjectAsync(new Uri("http://test/doc")); json = await client.GetJObjectAsync(new Uri("http://test/doc")); json = await client.GetJObjectAsync(new Uri("http://test/doc")); Assert.Equal(3, count); } }
public PSAutoCompleteResourceV3Provider(DataClient client) : base(typeof(PSAutoCompleteResource), "PSAutoCompleteResourceV3Provider", "V2PSAutoCompleteResourceProvider") { _client = client; }
// TODO: refresh the file when it gets old public override async Task<Tuple<bool, INuGetResource>> TryCreate(SourceRepository source, CancellationToken token) { ServiceIndexResourceV3 index = null; var url = source.PackageSource.Source; // the file type can easily rule out if we need to request the url if (source.PackageSource.ProtocolVersion == 3 || (source.PackageSource.IsHttp && url.EndsWith(".json", StringComparison.OrdinalIgnoreCase))) { ServiceIndexCacheInfo cacheInfo; // check the cache before downloading the file if (!_cache.TryGetValue(url, out cacheInfo) || UtcNow - cacheInfo.CachedTime > MaxCacheDuration) { var messageHandlerResource = await source.GetResourceAsync<HttpHandlerResource>(token); var client = new DataClient(messageHandlerResource.MessageHandler); JObject json; try { json = await client.GetJObjectAsync(new Uri(url), token); } catch (JsonReaderException) { _cache.TryAdd(url, new ServiceIndexCacheInfo { CachedTime = UtcNow }); return new Tuple<bool, INuGetResource>(false, null); } catch (HttpRequestException) { _cache.TryAdd(url, new ServiceIndexCacheInfo { CachedTime = UtcNow }); return new Tuple<bool, INuGetResource>(false, null); } if (json != null) { // Use SemVer instead of NuGetVersion, the service index should always be // in strict SemVer format SemanticVersion version; JToken versionToken; if (json.TryGetValue("version", out versionToken) && versionToken.Type == JTokenType.String && SemanticVersion.TryParse((string)versionToken, out version) && version.Major == 3) { index = new ServiceIndexResourceV3(json, UtcNow); } } } else { index = cacheInfo.Index; } // cache the value even if it is null to avoid checking it again later _cache.TryAdd(url, new ServiceIndexCacheInfo { CachedTime = UtcNow, Index = index }); } return new Tuple<bool, INuGetResource>(index != null, index); }
public async Task DataClient_Basic() { TestHandler handler = new TestHandler((request) => { var response = new HttpResponseMessage(HttpStatusCode.OK); response.Content = new TestContent(TestJson.BasicGraph); return response; }); using (var client = new DataClient(handler)) { var json = await client.GetJObjectAsync(new Uri("http://test/doc")); Assert.Equal("test", json["name"].ToString()); } }
public UISearchResourceV3Provider(DataClient client) : base(typeof(UISearchResource), nameof(UISearchResourceV3Provider), "UISearchResourceV2Provider") { _client = client; }
public async Task DataClient_GetFile_404() { int count = 0; TestHandler handler = new TestHandler((request) => { count++; var response = new HttpResponseMessage(HttpStatusCode.NotFound); response.Content = new TestContent(TestJson.BasicGraph); return response; }); RetryHandler retryHandler = new RetryHandler(handler, 2); using (var client = new DataClient(retryHandler)) { var json = await client.GetJObjectAsync(new Uri("http://test/doc")); Assert.Equal(2, count); } }