public static NuGetResourceCollection2 Make(string baseUrl) { NuGetResourceCollection2 collection = new NuGetResourceCollection2(); if (baseUrl != null) { collection.PackagesFeed = new NuGetPackageFeed2(baseUrl); collection.QueryFeed = new NuGetQueryFeed2(baseUrl); collection.FilesFeed = new NuGetFilesFeed2(); } collection.GetSearchQueryDelegate = (terms) => { string searchString = String.Empty; IEnumerable <NuGetSearchTerm> tagTerms = terms.Where(st => st.Term == NuGetSearchTerm.NuGetSearchTermType.Tag); NuGetSearchTerm searchTerm = terms.Where(st => st.Term == NuGetSearchTerm.NuGetSearchTermType.SearchTerm).FirstOrDefault(); if (searchTerm != null) { searchString = searchTerm.Text; } searchString = terms.Where(st => st.Term == NuGetSearchTerm.NuGetSearchTermType.Tag) .Aggregate(searchString, (current, tag) => current + " tag:" + tag.Text); return(searchString); }; return(collection); }
private static INuGetResourceCollection GetResourcesImpl(string baseUrl, RequestWrapper request) { INuGetResourceCollection res = null; HttpClient client = request.GetClientWithHeaders(); 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); }