Esempio n. 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));
        }
Esempio n. 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));
        }
Esempio n. 3
0
        public IEnumerable <NuGetPackage> QueryPackages(NuGetRepository repository, NuGetQuery query = null)
        {
            var client  = GetRestClient(repository.BaseUrl);
            var request = new RestRequest(query == null ? "query" : "query?q={QUERY}", Method.GET);

            if (query != null)
            {
                request.AddParameter("QUERY", query.Name, ParameterType.UrlSegment);
            }

            var result = client.Execute <NuGetQueryResult>(request);

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

            return(result.Data.Data);
        }
Esempio n. 4
0
        public IEnumerable <NuGetPackage> QueryPackages(NuGetRepository repository, NuGetQuery query = null, bool isPreRelease = false)
        {
            var client           = GetRestClient(repository.BaseUrl);
            var prereleaseSuffix = isPreRelease ? (query == null ? "?" : "&") + "prerelease=true" : "";

            RestRequest request = new RestRequest(query == null ? "query" + prereleaseSuffix : "query?q={QUERY}" + prereleaseSuffix, Method.GET);

            if (query != null)
            {
                request.AddParameter("QUERY", query.Name, ParameterType.UrlSegment);
            }

            var result = client.Execute <NuGetQueryResult>(request);

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

            return(result.Data.Data);
        }
Esempio n. 5
0
        public byte[] DownloadPackage(NuGetRepository repo, NuGetPackage package)
        {
            var currentVersion = package.Version;

            return(DownloadPackage(repo, package.Versions.First(c => c.Version.Equals(currentVersion, System.StringComparison.OrdinalIgnoreCase))));
        }