public override Task <DownloadResourceResult> GetDownloadResourceResultAsync( PackageIdentity identity, ISettings settings, ILogger logger, CancellationToken token) { // Find the package from the local folder LocalPackageInfo packageInfo = null; var sourcePackage = identity as SourcePackageDependencyInfo; if (sourcePackage?.DownloadUri != null) { // Get the package directly if the full path is known packageInfo = _localResource.GetPackage(sourcePackage.DownloadUri, logger, token); } else { // Search for the local package packageInfo = _localResource.GetPackage(identity, logger, token); } if (packageInfo != null) { var stream = File.OpenRead(packageInfo.Path); return(Task.FromResult(new DownloadResourceResult(stream, packageInfo.GetReader()))); } else { return(Task.FromResult(new DownloadResourceResult(DownloadResourceResultStatus.NotFound))); } }
public override Task <DownloadResourceResult> GetDownloadResourceResultAsync( PackageIdentity identity, PackageDownloadContext downloadContext, string globalPackagesFolder, ILogger logger, CancellationToken token) { if (identity == null) { throw new ArgumentNullException(nameof(identity)); } if (logger == null) { throw new ArgumentNullException(nameof(logger)); } var stopwatch = Stopwatch.StartNew(); try { // Find the package from the local folder LocalPackageInfo packageInfo = null; var sourcePackage = identity as SourcePackageDependencyInfo; if (sourcePackage?.DownloadUri != null) { // Get the package directly if the full path is known packageInfo = _localResource.GetPackage(sourcePackage.DownloadUri, logger, token); } else { // Search for the local package packageInfo = _localResource.GetPackage(identity, logger, token); } if (packageInfo != null) { var stream = File.OpenRead(packageInfo.Path); return(Task.FromResult(new DownloadResourceResult(stream, packageInfo.GetReader(), _localResource.Root))); } else { return(Task.FromResult(new DownloadResourceResult(DownloadResourceResultStatus.NotFound))); } } finally { ProtocolDiagnostics.RaiseEvent(new ProtocolDiagnosticResourceEvent( _source, resourceType: nameof(DownloadResource), type: nameof(LocalDownloadResource), method: nameof(GetDownloadResourceResultAsync), stopwatch.Elapsed)); } }
public override Task <DownloadResourceResult> GetDownloadResourceResultAsync( PackageIdentity identity, PackageDownloadContext downloadContext, string globalPackagesFolder, ILogger logger, CancellationToken token) { if (identity == null) { throw new ArgumentNullException(nameof(identity)); } if (logger == null) { throw new ArgumentNullException(nameof(logger)); } // Find the package from the local folder LocalPackageInfo packageInfo = null; var sourcePackage = identity as SourcePackageDependencyInfo; if (sourcePackage?.DownloadUri != null) { // Get the package directly if the full path is known packageInfo = _localResource.GetPackage(sourcePackage.DownloadUri, logger, token); } else { // Search for the local package packageInfo = _localResource.GetPackage(identity, logger, token); } if (packageInfo != null) { var stream = File.OpenRead(packageInfo.Path); return(Task.FromResult(new DownloadResourceResult(stream, packageInfo.GetReader(), _localResource.Root))); } else { return(Task.FromResult(new DownloadResourceResult(DownloadResourceResultStatus.NotFound))); } }
public override Task <IPackageSearchMetadata> GetMetadataAsync( PackageIdentity package, ILogger log, CancellationToken token) { return(Task.Run <IPackageSearchMetadata>(() => { var packageInfo = _localResource.GetPackage(package, log, token); if (packageInfo != null) { return GetPackageMetadata(packageInfo); } return null; }, token)); }
/// <summary> /// Retrieve dependency info for a single package. /// </summary> /// <param name="package">package id and version</param> /// <param name="projectFramework">project target framework. This is used for finding the dependency group</param> /// <param name="token">cancellation token</param> public override Task <SourcePackageDependencyInfo> ResolvePackage( PackageIdentity package, NuGetFramework projectFramework, SourceCacheContext sourceCacheContext, ILogger log, CancellationToken token) { if (package == null) { throw new ArgumentNullException(null, nameof(package)); } if (projectFramework == null) { throw new ArgumentNullException(nameof(projectFramework)); } SourcePackageDependencyInfo result = null; try { // Retrieve all packages var repoPackage = _localResource.GetPackage(package, log, token); if (repoPackage != null) { // convert to v3 type result = CreateDependencyInfo(repoPackage, projectFramework); } } catch (Exception ex) { // Wrap exceptions coming from the server with a user friendly message var error = string.Format(CultureInfo.CurrentUICulture, Strings.Protocol_PackageMetadataError, package, _localResource.Root); throw new FatalProtocolException(error, ex); } return(Task.FromResult(result)); }