private void DownloadPackage(
            string packageId,
            IVersion version,
            Uri feedUri,
            ICredentials feedCredentials,
            string cacheDirectory,
            int maxDownloadAttempts,
            TimeSpan downloadAttemptBackoff,
            out LocalNuGetPackage downloaded,
            out string downloadedTo)
        {
            Log.Info("Downloading NuGet package {0} {1} from feed: '{2}'", packageId, version, feedUri);
            Log.VerboseFormat("Downloaded package will be stored in: '{0}'", cacheDirectory);
            fileSystem.EnsureDirectoryExists(cacheDirectory);
            fileSystem.EnsureDiskHasEnoughFreeSpace(cacheDirectory);

            var fullPathToDownloadTo = GetFilePathToDownloadPackageTo(cacheDirectory, packageId, version.ToString());

            var downloader = new NuGet.NuGetPackageDownloader(fileSystem);

            downloader.DownloadPackage(packageId, version, feedUri, feedCredentials, fullPathToDownloadTo,
                                       maxDownloadAttempts, downloadAttemptBackoff);

            downloaded   = new LocalNuGetPackage(fullPathToDownloadTo);
            downloadedTo = fullPathToDownloadTo;
            CheckWhetherThePackageHasDependencies(downloaded.Metadata);
        }
Exemplo n.º 2
0
        private void AttemptToDownload(string packageId, SemanticVersion version, Uri feedUri, string cacheDirectory, out string downloadedTo, out IPackage downloaded)
        {
            Console.WriteLine("Downloading NuGet package {0} {1} from feed: '{2}'", packageId, version, feedUri);

            Log.VerboseFormat("Downloaded package will be stored in: '{0}'", cacheDirectory);
            fileSystem.EnsureDirectoryExists(cacheDirectory);
            fileSystem.EnsureDiskHasEnoughFreeSpace(cacheDirectory);

            downloaded   = null;
            downloadedTo = null;
            Exception downloadException = null;

            for (var i = 1; i <= NumberOfTimesToAttemptToDownloadPackage; i++)
            {
                try
                {
                    AttemptToFindAndDownloadPackage(i, packageId, version.ToString(), feedUri.ToString(), cacheDirectory,
                                                    out downloaded, out downloadedTo);
                    break;
                }
                catch (Exception dataException)
                {
                    Log.VerboseFormat("Attempt {0} of {1}: Unable to download package: {2}", i,
                                      NumberOfTimesToAttemptToDownloadPackage, dataException.Message);
                    downloadException = dataException;
                    Thread.Sleep(i * 1000);
                }
            }

            if (downloaded == null || downloadedTo == null)
            {
                if (downloadException != null)
                {
                    Log.ErrorFormat("Unable to download package: {0}", downloadException.Message);
                }
                throw new Exception(
                          "The package could not be downloaded from NuGet. If you are getting a package verification error, try switching to a Windows File Share package repository to see if that helps.");
            }

            if (downloaded.Version != version)
            {
                throw new Exception(string.Format(
                                        "Octopus requested version {0} of {1}, but the NuGet server returned a package with version {2}",
                                        version, packageId, downloaded.Version));
            }

            CheckWhetherThePackageHasDependencies(downloaded);
        }
Exemplo n.º 3
0
        PackagePhysicalFileMetadata DownloadPackage(
            string packageId,
            IVersion version,
            Uri feedUri,
            ICredentials feedCredentials,
            string cacheDirectory,
            int maxDownloadAttempts,
            TimeSpan downloadAttemptBackoff)
        {
            Log.Info("Downloading GitHub package {0} v{1} from feed: '{2}'", packageId, version, feedUri);
            Log.VerboseFormat("Downloaded package will be stored in: '{0}'", cacheDirectory);
            fileSystem.EnsureDirectoryExists(cacheDirectory);
            fileSystem.EnsureDiskHasEnoughFreeSpace(cacheDirectory);

            SplitPackageId(packageId, out string owner, out string repository);
            if (string.IsNullOrWhiteSpace(owner) || string.IsNullOrWhiteSpace(repository))
            {
                throw new InvalidOperationException(
                          "Invalid PackageId for GitHub feed. Expecting format `<owner>/<repo>`");
            }

            var    page = 0;
            JArray req  = null;

            while (req == null || (req.Count != 0 && req.Count < 1000))
            {
                var uri = feedUri.AbsoluteUri + $"repos/{Uri.EscapeUriString(owner)}/{Uri.EscapeUriString(repository)}/tags?page={++page}&per_page=1000";
                req = PerformRequest(feedCredentials, uri) as JArray;
                if (req == null)
                {
                    break;
                }

                foreach (var tag in req)
                {
                    if (!TryParseVersion((string)tag["name"], out IVersion v) || !version.Equals(v))
                    {
                        continue;
                    }

                    var zipball = (string)tag["zipball_url"];
                    return(DownloadFile(zipball, cacheDirectory, packageId, version, feedCredentials, maxDownloadAttempts, downloadAttemptBackoff));
                }
            }

            throw new Exception("Unable to find package {0} v{1} from feed: '{2}'");
        }
Exemplo n.º 4
0
        private PackagePhysicalFileMetadata DownloadPackage(
            string packageId,
            IVersion version,
            Uri feedUri,
            ICredentials feedCredentials,
            string cacheDirectory,
            int maxDownloadAttempts,
            TimeSpan downloadAttemptBackoff)
        {
            Log.Info("Downloading NuGet package {0} v{1} from feed: '{2}'", packageId, version, feedUri);
            Log.VerboseFormat("Downloaded package will be stored in: '{0}'", cacheDirectory);
            fileSystem.EnsureDiskHasEnoughFreeSpace(cacheDirectory);

            var fullPathToDownloadTo = Path.Combine(cacheDirectory, PackageName.ToCachedFileName(packageId, version, ".nupkg"));

            var downloader = new InternalNuGetPackageDownloader(fileSystem);

            downloader.DownloadPackage(packageId, version, feedUri, feedCredentials, fullPathToDownloadTo, maxDownloadAttempts, downloadAttemptBackoff);

            var pkg = PackagePhysicalFileMetadata.Build(fullPathToDownloadTo);

            CheckWhetherThePackageHasDependencies(pkg);
            return(pkg);
        }