private bool IsSingleEndpointAvailable(NuGetServiceInfo endpoint, RequestWrapper request)
        {
            HttpClient          client   = request.GetClient();
            HttpResponseMessage response = PathUtility.GetHttpResponse(client, endpoint.Url, (() => request.IsCanceled()),
                                                                       ((msg, num) => request.Verbose(Resources.Messages.RetryingDownload, msg, num)), (msg) => request.Verbose(msg), (msg) => request.Debug(msg));

            if (response != null)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        public bool IsAvailable(RequestWrapper request)
        {
            bool       valid    = false;
            HttpClient client   = request.GetClient();
            string     queryUri = Constants.DummyPackageId.MakeFindPackageByIdQuery(PathUtility.UriCombine(this.baseUrl, NuGetConstant.FindPackagesById));

            HttpResponseMessage response = PathUtility.GetHttpResponse(client, queryUri, (() => request.IsCanceled()),
                                                                       ((msg, num) => request.Verbose(Resources.Messages.RetryingDownload, msg, num)), (msg) => request.Verbose(msg), (msg) => request.Debug(msg));

            // The link is not valid
            if (response != null && response.IsSuccessStatusCode)
            {
                valid = true;
            }

            return(valid);
        }
Esempio n. 3
0
        private static INuGetResourceCollection GetResourcesImpl(string baseUrl, RequestWrapper request)
        {
            INuGetResourceCollection res = null;
            HttpClient          client   = request.GetClient();
            HttpResponseMessage response = PathUtility.GetHttpResponse(client, baseUrl, (() => request.IsCanceled()),
                                                                       ((msg, num) => request.Verbose(Resources.Messages.RetryingDownload, msg, num)), (msg) => request.Verbose(msg), (msg) => request.Debug(msg));

            if (!response.IsSuccessStatusCode)
            {
                throw new Exception(Resources.Messages.NuGetEndpointDiscoveryFailed);
            }

            string content = new StreamReader(NuGetClient.DownloadDataToStream(baseUrl, request)).ReadToEnd();

            // If the response starts with the magic XML header, it's v2
            if (content.StartsWith(Constants.XmlStartContent))
            {
                res = NuGetResourceCollection2.Make(baseUrl);
            }
            else
            {
                try
                {
                    dynamic root    = DynamicJsonParser.Parse(content);
                    string  version = root.version;
                    if (version != null && version.StartsWith("3."))
                    {
                        // v3 feed
                        res = NuGetResourceCollection3.Make(root, baseUrl, request);
                    }
                }
                catch (Exception ex)
                {
                    Exception discoveryException = new Exception(Resources.Messages.NuGetEndpointDiscoveryFailed, ex);
                    throw discoveryException;
                }
            }

            if (res == null)
            {
                // Couldn't figure out what this is
                throw new Exception(Resources.Messages.NuGetEndpointDiscoveryFailed);
            }

            return(res);
        }