コード例 #1
0
        public async Task Invoke(IOwinContext context)
        {
            switch (context.Request.Path.Value)
            {
            case "/":
                await context.Response.WriteAsync("OK");

                context.Response.StatusCode = (int)HttpStatusCode.OK;
                break;

            case "/find":
                await ServiceHelpers.WriteResponse(context, HttpStatusCode.OK, ServiceImpl.Find(context, _searcherManager));

                break;

            case "/query":
                await ServiceHelpers.WriteResponse(context, HttpStatusCode.OK, ServiceImpl.Query(context, _searcherManager));

                break;

            case "/autocomplete":
                await ServiceHelpers.WriteResponse(context, HttpStatusCode.OK, ServiceImpl.AutoComplete(context, _searcherManager));

                break;

            case "/targetframeworks":
                await ServiceInfoImpl.TargetFrameworks(context, _searcherManager);

                break;

            case "/segments":
                await ServiceInfoImpl.Segments(context, _searcherManager);

                break;

            case "/stats":
                await ServiceInfoImpl.Stats(context, _searcherManager);

                break;

            default:
                await context.Response.WriteAsync("unrecognized");

                context.Response.StatusCode = (int)HttpStatusCode.NotFound;
                break;
            }
        }
コード例 #2
0
        public static async Task AutoCompleteAsync(IOwinContext context, NuGetSearcherManager searcherManager)
        {
            var skip = GetSkip(context);
            var take = GetTake(context);
            var includePrerelease  = GetIncludePrerelease(context);
            var includeExplanation = GetIncludeExplanation(context);

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

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

            await ResponseHelpers.WriteResponseAsync(
                context,
                HttpStatusCode.OK,
                jsonWriter => ServiceImpl.AutoComplete(jsonWriter, searcherManager, q, id, includePrerelease, skip, take, includeExplanation));
        }