Example #1
0
        public byte[] DownloadPackage(NuGetRepository repo, NuGetPackageVersion version)
        {
            var isHttps = repo.BaseUrl.Contains("https");

            string url = version.Id.
                         Replace("https://", "http://")
                         .Replace(repo.BaseUrl.Replace("https://", "http://"), "");

            if (isHttps)
            {
                url = url.Replace("http://", "https://");
            }

            var client  = GetRestClient(repo.BaseUrl);
            var request = new RestRequest(url, Method.GET);
            var result  = client.Execute <NuGetPackageVersionRegistration>(request);

            if (result.ErrorException != null)
            {
                throw result.ErrorException;
            }

            var registration = result.Data;

            WebClient req = new WebClient();

            if (UserAgent != null)
            {
                req.Headers.Add("user-agent", UserAgent);
            }

            return(req.DownloadData(registration.PackageContent));
        }
Example #2
0
        public byte[] DownloadPackage(NuGetRepository repo, NuGetPackageVersion version)
        {
            var isHttps = repo.BaseUrl.Contains("https");

            string url = version.Id.
                         Replace("https://", "http://")
                         .Replace(repo.BaseUrl.Replace("https://", "http://"), "");

            if (isHttps)
            {
                url = url.Replace("http://", "https://");
            }

            if (!url.Contains("http://") && !url.Contains("https://"))
            {
                url = repo.BaseUrl + url;
            }

            var client  = GetRestClient(url);
            var request = new RestRequest(Method.GET);
            var result  = client.Execute <NuGetPackageVersionRegistration>(request);

            if (result.ErrorException != null)
            {
                var response = Encoding.UTF8.GetString(result.RawBytes);

                var logger = container.Resolve <ILogger>();
                logger.LogDebug("Failed to parse response: ");
                logger.LogDebug(response);
                throw result.ErrorException;
            }

            var registration = result.Data;

            WebClient req = new WebClient();

            if (UserAgent != null)
            {
                req.Headers.Add("user-agent", UserAgent);
            }

            return(req.DownloadData(registration.PackageContent));
        }