Beispiel #1
0
            private static async Task ExecuteAsync(
                IDictionary <string, object> environment,
                IDictionary <string, string> keys, OwinRequest request,
                AsyncHttpRequestHandler handler)
            {
                var response = new OwinResponse(environment);

                var executor = (Func <Task <object> >)(async() =>
                {
                    var form = from w in request.HasForm()
                                         ? (IEnumerable <KeyValuePair <string, string[]> >)(await request.ReadFormAsync().ConfigureAwait(false))
                                         : EmptyForm
                               select w != null ? w[0] : null;

                    return(await handler.Executor(
                               environment,
                               keys,
                               form.ToDictionary()));
                });

                var result = await executor().ConfigureAwait(false);

                if (result != null)
                {
                    await response.WriteAsync(JsonConvert.SerializeObject(result)).ConfigureAwait(false);
                }

                response.StatusCode = handler.StatusCodeGenerator != null
                                    ? handler.StatusCodeGenerator(result)
                                    : (int)HttpStatusCode.OK;
            }