private IEnumerable <IPackage> SearchPackagesWithBackup(string baseUrl, HttpQueryBuilder qb, RequestWrapper request, NuGetSearchContext searchContext, NuGetSearchTerm searchTerm)
        {
            // First execute the actual search
            HashSet <string> foundPackageIds = new HashSet <string>();

            return(NuGetWebUtility.GetResults <dynamic, PackageBase>(request, (dynamic root) =>
            {
                long res = -1;
                if (root.HasProperty("totalhits"))
                {
                    res = root.totalhits;
                    request.Debug(Resources.Messages.TotalPackagesDiscovered, res);
                }
                else
                {
                    request.Warning(Resources.Messages.JsonSchemaMismatch, "totalhits");
                    request.Debug(Resources.Messages.JsonObjectDump, DynamicJsonParser.Serialize(root));
                }

                return res;
            }, (dynamic root) => GetPackageCollectionsForSearchResult(root, searchContext, searchTerm, foundPackageIds, request), (long packagesToSkip) =>
            {
                if (packagesToSkip > 0)
                {
                    HttpQueryBuilder currentQb = qb.CloneAdd(Constants.SkipQueryParam, packagesToSkip.ToString());
                    return currentQb.AddQueryString(baseUrl);
                }

                return qb.AddQueryString(baseUrl);
            }, (string content) =>
            {
                return DynamicJsonParser.Parse(content);
            }, Constants.SearchPageCountInt));
        }
        public IEnumerable <string> Autocomplete(NuGetSearchTerm autocompleteSearchTerm, RequestWrapper request, WildcardPattern acceptedPattern, bool allowPrerelease)
        {
            try
            {
                request.Debug(Messages.DebugInfoCallMethod3, "NuGetAutoCompleteFeed3", "Autocomplete", autocompleteSearchTerm.ToString());
                return(base.Execute <IEnumerable <string> >((baseUrl) =>
                {
                    HttpQueryBuilder qb = new HttpQueryBuilder();
                    if (autocompleteSearchTerm.Term == NuGetSearchTerm.NuGetSearchTermType.Id)
                    {
                        qb.Add(Constants.PackageIdQueryParam, autocompleteSearchTerm.Text);
                    }
                    else if (autocompleteSearchTerm.Term == NuGetSearchTerm.NuGetSearchTermType.AutoComplete)
                    {
                        qb.Add(Constants.QueryQueryParam, autocompleteSearchTerm.Text);
                    }

                    if (allowPrerelease)
                    {
                        qb.Add(Constants.PrereleaseQueryParam, "true");
                    }

                    qb.Add(Constants.TakeQueryParam, Constants.SearchPageCount)
                    .Add(Constants.SemVerLevelQueryParam, Constants.SemVerLevel2);

                    return NuGetWebUtility.GetResults <dynamic, string>(request, (dynamic root) =>
                    {
                        long res = -1;
                        if (root.HasProperty("totalhits"))
                        {
                            res = root.totalhits;
                            request.Debug(Resources.Messages.TotalPackagesDiscovered, res);
                        }
                        else
                        {
                            request.Warning(Resources.Messages.JsonSchemaMismatch, "totalhits");
                            request.Debug(Resources.Messages.JsonObjectDump, DynamicJsonParser.Serialize(root));
                        }

                        return res;
                    }, (dynamic root) => GetAutoCompleteResults(root, autocompleteSearchTerm, acceptedPattern), (long resultsToSkip) =>
                    {
                        if (resultsToSkip > 0)
                        {
                            HttpQueryBuilder currentQb = qb.CloneAdd(Constants.SkipQueryParam, resultsToSkip.ToString());
                            return currentQb.AddQueryString(baseUrl);
                        }

                        return qb.AddQueryString(baseUrl);
                    }, (string content) =>
                    {
                        return DynamicJsonParser.Parse(content);
                    }, Constants.SearchPageCountInt);
                }));
            }
            finally
            {
                request.Debug(Messages.DebugInfoReturnCall, "NuGetAutoCompleteFeed3", "Autocomplete");
            }
        }