DownloadPackage() public method

public DownloadPackage ( IHttpClient downloadClient, byte packageHash, IPackageMetadata package ) : IPackage
downloadClient IHttpClient
packageHash byte
package IPackageMetadata
return IPackage
        public void Download(IPackage package)
        {
            try
              {
            NuGet.PackageDownloader downloader = new NuGet.PackageDownloader();

            var filename = String.Format("{0}.{1}.nupkg", package.Id, package.Version);
            var path = Path.Combine(_downloadfolder, filename);
            var stream = new System.IO.FileStream(path, FileMode.Create);

            downloader.DownloadPackage(_uri, package, stream);
            downloader.ProgressAvailable += handler;
              }
              catch (Exception ex)
              {
            throw new Exception(string.Format("Download package {0} version {1} failed", package.Id, package.Version),ex);
              }
        }
        public void Download(IPackage package)
        {
            try
            {
                NuGet.PackageDownloader downloader = new NuGet.PackageDownloader();

                var filename = String.Format("{0}.{1}.nupkg", package.Id, package.Version);
                var path     = Path.Combine(_downloadfolder, filename);
                var stream   = new System.IO.FileStream(path, FileMode.Create);

                downloader.DownloadPackage(_uri, package, stream);
                downloader.ProgressAvailable += handler;
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("Download package {0} version {1} failed", package.Id, package.Version), ex);
            }
        }
Exemplo n.º 3
0
        public static void GetPackageAndDependencies( string packageId, string packageVersion, string sourceServer, string targetFolder, bool overwriteExistingFiles, bool includePrerelease, bool allowUnlisted, DependencyVersionTypeToDownload depVersionToDownload)
        {
            log.Trace( $"Entered GetPackageAndDependencies(packageId='{packageId}', packageVersion='{packageVersion}', sourceServer='{sourceServer}', targetFolder='{targetFolder}', overwriteExistingFiles={overwriteExistingFiles}, includePrerelease={includePrerelease}, allowUnlisted={allowUnlisted}, depVersionToDownload={depVersionToDownload})" );

            var repo = PackageRepositoryFactory.Default.CreateRepository( sourceServer );
            var package = repo.FindPackage( packageId, packageVersion==null?null:new SemanticVersion(packageVersion),NullConstraintProvider.Instance, includePrerelease, allowUnlisted ) as DataServicePackage;

            if( package == null ) {
                log.Warn( $"Package '{packageId} {packageVersion}' could not be found in the repository '{sourceServer}', or it could be converted as DataServicePackage" );

                return;
            }

            var finalPackagePath = Path.Combine( targetFolder, $"{package.Id}.{package.Version}.nupkg" );

            if( File.Exists( finalPackagePath ) && !overwriteExistingFiles ) {
                log.Info( $"Skipping '{finalPackagePath}'" );
                return;
            }

            if( !Directory.Exists( targetFolder ) ) {
                Directory.CreateDirectory( targetFolder );
            }

            using( var fs = File.Open( finalPackagePath, FileMode.Create ) ) {
                log.Debug($"Downloading package '{package.Id}' from '{package.DownloadUrl}' ... ");
                var downloader = new PackageDownloader();
                downloader.DownloadPackage( package.DownloadUrl, package, fs );
                log.Info($"Package {package.Id} downloaded!");
            }

            foreach( var dset in package.DependencySets.Where( dset => dset.Dependencies.Count > 0 ) ) {
                log.Debug( $"Processing dependency set: {dset.TargetFramework?.ToString() ?? "<default set>"} " );

                foreach( var dep in dset.Dependencies ) {
                    log.Debug( $"Processing dependency '{dep.Id}'" );
                    var dependencyVersion = depVersionToDownload == DependencyVersionTypeToDownload.Max
                                                ? dep.VersionSpec?.MaxVersion?.ToString()
                                                : dep.VersionSpec?.MinVersion?.ToString();
                    GetPackageAndDependencies( dep.Id, dependencyVersion, sourceServer, targetFolder, overwriteExistingFiles, includePrerelease, allowUnlisted, depVersionToDownload );
                }
            }
            log.Trace( "Exiting GetPackageAndDependencies" );
        }
Exemplo n.º 4
0
        void DownloadPackage(IPackage package, string fullPathToDownloadTo, NuGet.PackageDownloader directDownloader)
        {
            Log.VerboseFormat("Found package {0} version {1}", package.Id, package.Version);
            Log.Verbose("Downloading to: " + fullPathToDownloadTo);

            var dsp = package as DataServicePackage;

            if (dsp != null && directDownloader != null)
            {
                Log.Verbose("A direct download is possible; bypassing the NuGet machine cache");
                using (var targetFile = new FileStream(fullPathToDownloadTo, FileMode.CreateNew))
                    directDownloader.DownloadPackage(dsp.DownloadUrl, dsp, targetFile);
                return;
            }

            var physical = new PhysicalFileSystem(Path.GetDirectoryName(fullPathToDownloadTo));
            var local    = new LocalPackageRepository(new FixedFilePathResolver(package.Id, fullPathToDownloadTo), physical);

            local.AddPackage(package);
        }