/// <summary>
        /// Asynchronously gets dependency information for a specific package.
        /// </summary>
        /// <param name="id">A package id.</param>
        /// <param name="version">A package version.</param>
        /// <param name="cacheContext">A source cache context.</param>
        /// <param name="logger">A logger.</param>
        /// <param name="cancellationToken">A cancellation token.</param>
        /// <returns>A task that represents the asynchronous operation.
        /// The task result (<see cref="Task{TResult}.Result" />) returns an
        /// <see cref="IEnumerable{NuGetVersion}" />.</returns>
        /// <exception cref="ArgumentException">Thrown if <paramref name="id" />
        /// is either <c>null</c> or an empty string.</exception>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="version" /> <c>null</c>.</exception>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="cacheContext" /> <c>null</c>.</exception>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="logger" /> <c>null</c>.</exception>
        /// <exception cref="OperationCanceledException">Thrown if <paramref name="cancellationToken" />
        /// is cancelled.</exception>
        public override async Task <FindPackageByIdDependencyInfo> GetDependencyInfoAsync(
            string id,
            NuGetVersion version,
            SourceCacheContext cacheContext,
            ILogger logger,
            CancellationToken cancellationToken)
        {
            if (string.IsNullOrEmpty(id))
            {
                throw new ArgumentException(Strings.ArgumentCannotBeNullOrEmpty, nameof(id));
            }

            if (version == null)
            {
                throw new ArgumentNullException(nameof(version));
            }

            if (cacheContext == null)
            {
                throw new ArgumentNullException(nameof(cacheContext));
            }

            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }

            var stopwatch = Stopwatch.StartNew();

            try
            {
                cancellationToken.ThrowIfCancellationRequested();

                var packageInfos = await EnsurePackagesAsync(id, cacheContext, logger, cancellationToken);

                PackageInfo packageInfo;

                if (packageInfos.TryGetValue(version, out packageInfo))
                {
                    AddOrUpdateLogger(_plugin, logger);

                    await _utilities.DoOncePerPluginLifetimeAsync(
                        MessageMethod.SetLogLevel.ToString(),
                        () => SetLogLevelAsync(logger, cancellationToken),
                        cancellationToken);

                    var response = await _plugin.Connection.SendRequestAndReceiveResponseAsync <PrefetchPackageRequest, PrefetchPackageResponse>(
                        MessageMethod.PrefetchPackage,
                        new PrefetchPackageRequest(
                            _packageSource.Source,
                            packageInfo.Identity.Id,
                            packageInfo.Identity.Version.ToNormalizedString()),
                        cancellationToken);

                    if (response != null && response.ResponseCode == MessageResponseCode.Success)
                    {
                        using (var packageReader = new PluginPackageReader(_plugin, packageInfo.Identity, _packageSource.Source))
                        {
                            var nuspecReader = await packageReader.GetNuspecReaderAsync(cancellationToken);

                            return(GetDependencyInfo(nuspecReader));
                        }
                    }
                }

                return(null);
            }
            finally
            {
                ProtocolDiagnostics.RaiseEvent(new ProtocolDiagnosticResourceEvent(
                                                   _packageSource.Source,
                                                   ResourceTypeName,
                                                   ThisTypeName,
                                                   nameof(GetDependencyInfoAsync),
                                                   stopwatch.Elapsed));
            }
        }
 /// <summary>
 /// Asynchronously gets all package versions for a package ID.
 /// </summary>
 /// <param name="id">A package ID.</param>
 /// <param name="cacheContext">A source cache context.</param>
 /// <param name="logger">A logger.</param>
 /// <param name="cancellationToken">A cancellation token.</param>
 /// <returns>A task that represents the asynchronous operation.
 /// The task result (<see cref="Task{TResult}.Result" />) returns an
 /// <see cref="IEnumerable{NuGetVersion}" />.</returns>
 /// <exception cref="ArgumentException">Thrown if <paramref name="id" />
 /// is either <c>null</c> or an empty string.</exception>
 /// <exception cref="ArgumentNullException">Thrown if <paramref name="cacheContext" /> <c>null</c>.</exception>
 /// <exception cref="ArgumentNullException">Thrown if <paramref name="logger" /> <c>null</c>.</exception>
 /// <exception cref="OperationCanceledException">Thrown if <paramref name="cancellationToken" />
 /// is cancelled.</exception>
 public abstract Task <IEnumerable <NuGetVersion> > GetAllVersionsAsync(
     string id,
     SourceCacheContext cacheContext,
     ILogger logger,
     CancellationToken cancellationToken);
 /// <summary>
 /// Asynchronously gets dependency information for a specific package.
 /// </summary>
 /// <param name="id">A package id.</param>
 /// <param name="version">A package version.</param>
 /// <param name="cacheContext">A source cache context.</param>
 /// <param name="logger">A logger.</param>
 /// <param name="cancellationToken">A cancellation token.</param>
 /// <returns>A task that represents the asynchronous operation.
 /// The task result (<see cref="Task{TResult}.Result" />) returns an
 /// <see cref="IEnumerable{NuGetVersion}" />.</returns>
 /// <exception cref="ArgumentException">Thrown if <paramref name="id" />
 /// is either <c>null</c> or an empty string.</exception>
 /// <exception cref="ArgumentNullException">Thrown if <paramref name="version" /> <c>null</c>.</exception>
 /// <exception cref="ArgumentNullException">Thrown if <paramref name="cacheContext" /> <c>null</c>.</exception>
 /// <exception cref="ArgumentNullException">Thrown if <paramref name="logger" /> <c>null</c>.</exception>
 /// <exception cref="OperationCanceledException">Thrown if <paramref name="cancellationToken" />
 /// is cancelled.</exception>
 public abstract Task <FindPackageByIdDependencyInfo> GetDependencyInfoAsync(
     string id,
     NuGetVersion version,
     SourceCacheContext cacheContext,
     ILogger logger,
     CancellationToken cancellationToken);
 /// <summary>
 /// Asynchronously gets a package downloader for a package identity.
 /// </summary>
 /// <param name="packageIdentity">A package identity.</param>
 /// <param name="cacheContext">A source cache context.</param>
 /// <param name="logger">A logger.</param>
 /// <param name="cancellationToken">A cancellation token.</param>
 /// <returns>A task that represents the asynchronous operation.
 /// The task result (<see cref="Task{TResult}.Result" />) returns an <see cref="IPackageDownloader" />.</returns>
 /// <exception cref="ArgumentNullException">Thrown if <paramref name="packageIdentity" /> <c>null</c>.</exception>
 /// <exception cref="ArgumentNullException">Thrown if <paramref name="cacheContext" /> <c>null</c>.</exception>
 /// <exception cref="ArgumentNullException">Thrown if <paramref name="logger" /> <c>null</c>.</exception>
 /// <exception cref="OperationCanceledException">Thrown if <paramref name="cancellationToken" />
 /// is cancelled.</exception>
 public abstract Task <IPackageDownloader> GetPackageDownloaderAsync(
     PackageIdentity packageIdentity,
     SourceCacheContext cacheContext,
     ILogger logger,
     CancellationToken cancellationToken);
 /// <summary>
 /// Asynchronously check if exact package (id/version) exists at this source.
 /// </summary>
 /// <param name="id">A package id.</param>
 /// <param name="version">A package version.</param>
 /// <param name="cacheContext">A source cache context.</param>
 /// <param name="logger">A logger.</param>
 /// <param name="cancellationToken">A cancellation token.</param>
 /// <returns>A task that represents the asynchronous operation.
 /// The task result (<see cref="Task{TResult}.Result" />) returns an
 /// <see cref="IEnumerable{NuGetVersion}" />.</returns>
 /// <exception cref="ArgumentException">Thrown if <paramref name="id" />
 /// is either <c>null</c> or an empty string.</exception>
 /// <exception cref="ArgumentNullException">Thrown if <paramref name="version" /> <c>null</c>.</exception>
 /// <exception cref="ArgumentNullException">Thrown if <paramref name="cacheContext" /> <c>null</c>.</exception>
 /// <exception cref="ArgumentNullException">Thrown if <paramref name="logger" /> <c>null</c>.</exception>
 /// <exception cref="OperationCanceledException">Thrown if <paramref name="cancellationToken" />
 /// is cancelled.</exception>
 public abstract Task <bool> DoesPackageExistAsync(
     string id,
     NuGetVersion version,
     SourceCacheContext cacheContext,
     ILogger logger,
     CancellationToken cancellationToken);
示例#6
0
        public async Task <NuGetVersion> GetLatestVersion(string packageId, bool includePrerelease, bool includeUnlisted, SourceCacheContext sourceCacheContext, Common.ILogger log, CancellationToken token)
        {
            var results = await GetLatestVersions(new string[] { packageId }, includePrerelease, includeUnlisted, sourceCacheContext, log, token);

            var result = results.SingleOrDefault();

            if (!result.Equals(default(KeyValuePair <string, bool>)))
            {
                return(result.Value);
            }

            return(null);
        }
示例#7
0
        private HttpSourceCacheContext(string rootTempFolder, TimeSpan maxAge, bool directDownload, SourceCacheContext cacheContext)
        {
            if (maxAge <= TimeSpan.Zero)
            {
                if (rootTempFolder == null)
                {
                    throw new ArgumentNullException(nameof(rootTempFolder));
                }
            }
            else
            {
                Debug.Assert(
                    rootTempFolder == null,
                    $"{nameof(rootTempFolder)} should be null when {nameof(maxAge)} is not zero.");
            }

            RootTempFolder     = rootTempFolder;
            MaxAge             = maxAge;
            DirectDownload     = directDownload;
            SourceCacheContext = cacheContext ?? throw new ArgumentNullException(nameof(cacheContext));
        }
示例#8
0
 public abstract Task <bool> Exists(string packageId, bool includePrerelease, bool includeUnlisted, SourceCacheContext sourceCacheContext, Common.ILogger log, CancellationToken token);
示例#9
0
 public abstract Task <IEnumerable <KeyValuePair <string, NuGetVersion> > > GetLatestVersions(IEnumerable <string> packageIds, bool includePrerelease, bool includeUnlisted, SourceCacheContext sourceCacheContext, Common.ILogger log, CancellationToken token);
示例#10
0
 /// <summary>
 /// True if the package exists in the source
 /// </summary>
 public abstract Task <bool> Exists(PackageIdentity identity, bool includeUnlisted, SourceCacheContext sourceCacheContext, Common.ILogger log, CancellationToken token);
示例#11
0
 public async Task <bool> Exists(string packageId, SourceCacheContext sourceCacheContext, Common.ILogger log, CancellationToken token)
 {
     return(await Exists(packageId, true, false, sourceCacheContext, log, token));
 }
示例#12
0
 /// <summary>
 /// True if the package exists in the source
 /// Includes unlisted.
 /// </summary>
 public async Task <bool> Exists(PackageIdentity identity, SourceCacheContext sourceCacheContext, Common.ILogger log, CancellationToken token)
 {
     return(await Exists(identity, true, sourceCacheContext, log, token));
 }
示例#13
0
 /// <summary>
 /// Get all versions of a package
 /// </summary>
 public abstract Task <IEnumerable <NuGetVersion> > GetVersions(string packageId, bool includePrerelease, bool includeUnlisted, SourceCacheContext sourceCacheContext, Common.ILogger log, CancellationToken token);
示例#14
0
 /// <summary>
 /// Get all versions of a package
 /// </summary>
 public async Task <IEnumerable <NuGetVersion> > GetVersions(string packageId, SourceCacheContext sourceCacheContext, Common.ILogger log, CancellationToken token)
 {
     return(await GetVersions(packageId, true, false, sourceCacheContext, log, token));
 }
示例#15
0
 public static HttpSourceCacheContext Create(SourceCacheContext cacheContext, int retryCount)
 {
     return(Create(cacheContext, retryCount == 0));
 }
 public PackageDownloadContext(SourceCacheContext sourceCacheContext) : this(
         sourceCacheContext,
         directDownloadDirectory : null,
         directDownload : false)
 {
 }