Example #1
0
        /// <summary>
        /// Download the nupkg to a folder.
        /// </summary>
        protected async Task <FileInfo> DownloadNupkgAsync(string outputDirectory, DownloadMode mode, DateTimeOffset date, CancellationToken token)
        {
            using (var stream = await GetNupkgAsync(token))
            {
                var path = new FileInfo(Path.Combine(outputDirectory, $"{FileBaseName}.nupkg"));
                await CatalogReaderUtility.DownloadFileAsync(stream, path, date, mode, token);

                return(path);
            }
        }
Example #2
0
        /// <summary>
        /// Download the nuspec to a directory.
        /// </summary>
        public async Task <FileInfo> DownloadNuspecAsync(string outputDirectory, DownloadMode mode, CancellationToken token)
        {
            using (var stream = await GetNupkgAsync(token))
            {
                var path = new FileInfo(Path.Combine(outputDirectory, $"{FileBaseName}.nuspec".ToLowerInvariant()));

                await CatalogReaderUtility.DownloadFileAsync(stream, path, CommitTimeStamp, mode, token);

                return(path);
            }
        }
        internal static Task <JObject> GetJObjectAsync(this HttpSource source, Uri uri, HttpSourceCacheContext cacheContext, ILogger log, CancellationToken token)
        {
            var cacheKey = GetHashKey(uri);

            var request = new HttpSourceCachedRequest(uri.AbsoluteUri, cacheKey, cacheContext)
            {
                EnsureValidContents = stream => CatalogReaderUtility.LoadJson(stream, true),
                IgnoreNotFounds     = false
            };

            return(source.GetAsync(request, ProcessJson, log, token));
        }
Example #4
0
        private async Task EnsureHttpSourceAsync()
        {
            if (_httpSource == null)
            {
                var handlerResource = await CatalogReaderUtility.GetHandlerAsync(_indexUri, _messageHandler);

                var packageSource = new PackageSource(_indexUri.AbsoluteUri);

                _httpSource = new HttpSource(
                    packageSource,
                    () => Task.FromResult((HttpHandlerResource)handlerResource),
                    NullThrottle.Instance);

                if (string.IsNullOrEmpty(UserAgent.UserAgentString) ||
                    new UserAgentStringBuilder().Build()
                    .Equals(UserAgent.UserAgentString, StringComparison.Ordinal))
                {
                    // Set the user agent string if it was not already set.
                    var userAgent = new UserAgentStringBuilder("NuGet.CatalogReader");
                    UserAgent.SetUserAgentString(userAgent);
                }
            }
        }
 private static Task <JObject> ProcessJson(HttpSourceResult result)
 {
     return(CatalogReaderUtility.LoadJsonAsync(result.Stream, false));
 }
Example #6
0
 /// <summary>
 /// Clear the HttpCacheFolder cache folder.
 /// Use this to free up space when downloading large numbers of packages.
 /// </summary>
 public void ClearCache()
 {
     CatalogReaderUtility.DeleteDirectoryFiles(HttpCacheFolder);
 }