// V3 implementation - called directly from the integrated Visual Studio client
        public static void WriteSearchResult(
            JsonWriter jsonWriter,
            NuGetIndexSearcher searcher,
            string scheme,
            TopDocs topDocs,
            int skip,
            int take,
            bool includePrerelease,
            bool includeExplanation,
            NuGetVersion semVerLevel,
            Query query)
        {
            Uri baseAddress;
            var useSemVer2Registration = SemVerHelpers.ShouldIncludeSemVer2Results(semVerLevel);
            RegistrationBaseAddresses registrationAddresses = searcher.Manager.RegistrationBaseAddresses;

            switch (scheme)
            {
            case "https":
                baseAddress = (useSemVer2Registration ? registrationAddresses.SemVer2Https : registrationAddresses.LegacyHttps);
                break;

            case "http":
            default:
                // if scheme specified is invalid, fall back to using as much information as we can
                baseAddress = (useSemVer2Registration ? registrationAddresses.SemVer2Http : registrationAddresses.LegacyHttp);
                break;
            }

            jsonWriter.WriteStartObject();
            WriteInfo(jsonWriter, baseAddress, searcher, topDocs);
            WriteData(jsonWriter, searcher, topDocs, skip, take, baseAddress, includePrerelease, includeExplanation, semVerLevel, query);
            jsonWriter.WriteEndObject();
        }
示例#2
0
        public NuGetSearcherManager(FrameworkLogger logger,
                                    IIndexDirectoryProvider indexProvider,
                                    ILoader loader,
                                    int auxiliaryDataRefreshRateSec,
                                    int indexReloadRateSec)
        {
            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }

            _logger = logger;

            RegistrationBaseAddresses = new RegistrationBaseAddresses();

            _indexProvider = indexProvider;
            _loader        = loader;

            AuxiliaryFiles = new AuxiliaryFiles(_loader);

            _indexReloadRate          = TimeSpan.FromSeconds(indexReloadRateSec);
            _auxiliaryDataRefreshRate = TimeSpan.FromSeconds(auxiliaryDataRefreshRateSec);
        }