WriteResponseAsync() public method

public WriteResponseAsync ( IOwinContext context, ClientException e ) : System.Threading.Tasks.Task
context IOwinContext
e NuGet.Indexing.ClientException
return System.Threading.Tasks.Task
 public static async Task RankingsAsync(IOwinContext context, NuGetSearcherManager searcherManager, ResponseWriter responseWriter)
 {
     await responseWriter.WriteResponseAsync(
         context,
         HttpStatusCode.OK,
         jsonWriter => ServiceInfoImpl.Rankings(jsonWriter, searcherManager));
 }
 public static async Task Stats(IOwinContext context, NuGetSearcherManager searcherManager, ResponseWriter responseWriter)
 {
     await responseWriter.WriteResponseAsync(
         context,
         HttpStatusCode.OK,
         jsonWriter => ServiceInfoImpl.Stats(jsonWriter, searcherManager));
 }
        public static async Task FindAsync(IOwinContext context, NuGetSearcherManager searcherManager, ResponseWriter responseWriter)
        {
            var id = context.Request.Query["id"] ?? string.Empty;
            var scheme = context.Request.Uri.Scheme;

            await responseWriter.WriteResponseAsync(
                context,
                HttpStatusCode.OK,
                jsonWriter => ServiceImpl.Find(jsonWriter, searcherManager, id, scheme));
        }
        public static async Task V3SearchAsync(IOwinContext context, NuGetSearcherManager searcherManager, ResponseWriter responseWriter)
        {
            var skip = GetSkip(context);
            var take = GetTake(context);
            var includePrerelease = GetIncludePrerelease(context);
            bool includeExplanation = GetBool(context, nameof(includeExplanation));

            var q = context.Request.Query["q"] ?? string.Empty;
            var feed = context.Request.Query["feed"];
            var scheme = context.Request.Uri.Scheme;

            await responseWriter.WriteResponseAsync(
                context,
                HttpStatusCode.OK,
                jsonWriter => ServiceImpl.Search(jsonWriter, searcherManager, scheme, q, includePrerelease, skip, take, feed, includeExplanation));
        }
        public static async Task V3SearchAsync(IOwinContext context, NuGetSearcherManager searcherManager, ResponseWriter responseWriter)
        {
            var  skip = GetSkip(context);
            var  take = GetTake(context);
            var  includePrerelease  = GetIncludePrerelease(context);
            var  semVerLevel        = GetSemVerLevel(context);
            bool includeExplanation = GetBool(context, nameof(includeExplanation));

            var q      = context.Request.Query["q"] ?? string.Empty;
            var feed   = context.Request.Query["feed"];
            var scheme = context.Request.Uri.Scheme;

            await responseWriter.WriteResponseAsync(
                context,
                HttpStatusCode.OK,
                jsonWriter => ServiceImpl.Search(jsonWriter, searcherManager, scheme, q, includePrerelease, semVerLevel, skip, take, feed, includeExplanation));
        }
        public static async Task V2SearchAsync(IOwinContext context, NuGetSearcherManager searcherManager, ResponseWriter responseWriter)
        {
            var skip = GetSkip(context);
            var take = GetTake(context);
            var ignoreFilter = GetIgnoreFilter(context);
            var countOnly = GetCountOnly(context);
            var includePrerelease = GetIncludePrerelease(context);

            var q = context.Request.Query["q"] ?? string.Empty;
            var sortBy = context.Request.Query["sortBy"] ?? string.Empty;
            var feed = context.Request.Query["feed"];

            var luceneQuery = GetLuceneQuery(context);

            await responseWriter.WriteResponseAsync(
                context,
                HttpStatusCode.OK,
                jsonWriter => GalleryServiceImpl.Search(jsonWriter, searcherManager, q, countOnly, includePrerelease, sortBy, skip, take, feed, ignoreFilter, luceneQuery));
        }
        public static async Task AutoCompleteAsync(IOwinContext context, NuGetSearcherManager searcherManager, ResponseWriter responseWriter)
        {
            var skip = GetSkip(context);
            var take = GetTake(context);
            var includePrerelease = GetIncludePrerelease(context);
            bool explanation = GetBool(context, nameof(explanation));

            var q = context.Request.Query["q"];
            var id = context.Request.Query["id"];
            if (q == null && id == null)
            {
                q = string.Empty;
            }

            await responseWriter.WriteResponseAsync(
                context,
                HttpStatusCode.OK,
                jsonWriter => ServiceImpl.AutoComplete(jsonWriter, searcherManager, q, id, includePrerelease, skip, take, explanation));
        }
        public static async Task V2SearchAsync(IOwinContext context, NuGetSearcherManager searcherManager, ResponseWriter responseWriter)
        {
            var skip              = GetSkip(context);
            var take              = GetTake(context);
            var ignoreFilter      = GetIgnoreFilter(context);
            var countOnly         = GetCountOnly(context);
            var includePrerelease = GetIncludePrerelease(context);
            var semVerLevel       = GetSemVerLevel(context);

            var q      = context.Request.Query["q"] ?? string.Empty;
            var sortBy = context.Request.Query["sortBy"] ?? string.Empty;
            var feed   = context.Request.Query["feed"];

            var luceneQuery = GetLuceneQuery(context);

            await responseWriter.WriteResponseAsync(
                context,
                HttpStatusCode.OK,
                jsonWriter => GalleryServiceImpl.Search(jsonWriter, searcherManager, q, countOnly, includePrerelease, semVerLevel, sortBy, skip, take, feed, ignoreFilter, luceneQuery));
        }
        public static async Task AutoCompleteAsync(IOwinContext context, NuGetSearcherManager searcherManager, ResponseWriter responseWriter)
        {
            var  skip = GetSkip(context);
            var  take = GetTake(context);
            var  includePrerelease = GetIncludePrerelease(context);
            var  semVerLevel       = GetSemVerLevel(context);
            bool explanation       = GetBool(context, nameof(explanation));

            var q  = context.Request.Query["q"];
            var id = context.Request.Query["id"];

            if (q == null && id == null)
            {
                q = string.Empty;
            }

            await responseWriter.WriteResponseAsync(
                context,
                HttpStatusCode.OK,
                jsonWriter => ServiceImpl.AutoComplete(jsonWriter, searcherManager, q, id, includePrerelease, semVerLevel, skip, take, explanation));
        }
示例#10
0
        public async Task InvokeAsync(IOwinContext context)
        {
            try
            {
                if (_searcherManager == null)
                {
                    _logger.LogInformation(LogMessages.SearcherManagerNotInitialized);
                    _searchTelemetryClient.TrackMetric(SearchTelemetryClient.MetricName.SearcherManagerNotInitialized, 1);

                    context.Response.StatusCode = (int)HttpStatusCode.ServiceUnavailable;
                    await context.Response.WriteAsync("UNINITIALIZED");
                }
                else
                {
                    switch (context.Request.Path.Value)
                    {
                    case "/":
                        context.Response.StatusCode = (int)HttpStatusCode.OK;
                        await context.Response.WriteAsync("READY");

                        break;

                    case "/query":
                        await ServiceEndpoints.V3SearchAsync(context, _searcherManager, _responseWriter);

                        break;

                    case "/autocomplete":
                        await ServiceEndpoints.AutoCompleteAsync(context, _searcherManager, _responseWriter);

                        break;

                    case "/search/query":
                        await ServiceEndpoints.V2SearchAsync(context, _searcherManager, _responseWriter);

                        break;

                    case "/search/diag":
                        await ServiceEndpoints.Stats(context, _searcherManager, _responseWriter);

                        break;

                    default:
                        context.Response.StatusCode = (int)HttpStatusCode.NotFound;
                        await context.Response.WriteAsync("UNRECOGNIZED");

                        break;
                    }
                }
            }
            catch (ClientException e)
            {
                await _responseWriter.WriteResponseAsync(context, e);
            }
            catch (Exception e)
            {
                await _responseWriter.WriteResponseAsync(context, e, _logger);

                throw;
            }
        }