Example #1
0
        public async Task <RegistrationIndex> GetIndexOrNullAsync(string indexUrl)
        {
            var result = await _simpleHttpClient.DeserializeUrlAsync <RegistrationIndex>(indexUrl);

            if (result.StatusCode == HttpStatusCode.NotFound)
            {
                return(null);
            }

            return(result.GetResultOrThrow());
        }
Example #2
0
        private async Task CopyUrlAsync(ICloudBlobContainer container, string oldBaseUrl, string newBaseUrl, string oldUrl, bool gzip)
        {
            await Throttle.WaitAsync();

            try
            {
                _logger.LogInformation("Copying {OldUrl}...", oldUrl);

                var result = await _simpleHttpClient.DeserializeUrlAsync <JToken>(oldUrl);

                var json      = result.GetResultOrThrow();
                var fixedJson = FixUrls(oldBaseUrl, newBaseUrl, json);

                if (!TryGetPath(oldBaseUrl, oldUrl, out var path))
                {
                    throw new InvalidOperationException("The URL does not start with the base URL.");
                }

                var blob = container.GetBlobReference(path);

                blob.Properties.ContentType = "application/json";
                var jsonString = fixedJson.ToString(Formatting.None);
                var bytes      = Encoding.UTF8.GetBytes(jsonString);

                if (gzip)
                {
                    blob.Properties.ContentEncoding = "gzip";
                    using (var compressedStream = new MemoryStream())
                    {
                        using (var gzipStream = new GZipStream(compressedStream, CompressionLevel.Optimal, leaveOpen: true))
                        {
                            gzipStream.Write(bytes, 0, bytes.Length);
                        }

                        bytes = compressedStream.ToArray();
                    }
                }

                using (var memoryStream = new MemoryStream(bytes))
                {
                    await blob.UploadFromStreamAsync(memoryStream, overwrite : true);
                }
            }
            finally
            {
                Throttle.Release();
            }
        }
Example #3
0
        private async Task <bool> DoesPackageExistAsync(string url, string id, NuGetVersion version)
        {
            await Task.Yield();

            ResponseAndResult <V3SearchResponse> result;

            try
            {
                result = await _simpleHttpClient.DeserializeUrlAsync <V3SearchResponse>(url);
            }
            catch (HttpRequestException)
            {
                return(false);
            }

            var response = result.GetResultOrThrow();

            if (!response.Data.Any())
            {
                return(false);
            }

            var idMatch = response
                          .Data
                          .FirstOrDefault(x => StringComparer.OrdinalIgnoreCase.Equals(id, x.Id));

            if (idMatch == null)
            {
                return(false);
            }

            var versionMatch = idMatch
                               .Versions
                               .FirstOrDefault(x => NuGetVersion.Parse(x.Version) == version);

            if (versionMatch == null)
            {
                return(false);
            }

            return(true);
        }
Example #4
0
        public async Task <CatalogIndex> GetIndexAsync(string indexUrl)
        {
            var result = await _jsonClient.DeserializeUrlAsync <CatalogIndex>(indexUrl);

            return(result.GetResultOrThrow());
        }