Esempio n. 1
0
        public static IAppBuilder UseDirect(this IAppBuilder builder, Func<Request, Response, Task> app)
        {
            return builder.Use<AppDelegate>(next => call =>
            {
                var req = new Request(call);
                var resp = new Response
                {
                    Next = () => next(call)
                };

                app.Invoke(req, resp)
                    .Then(() => resp.End())
                    .Catch(caught =>
                    {
                        resp.Error(caught.Exception);
                        return caught.Handled();
                    });
                return resp.GetResultAsync();
            });
        }
Esempio n. 2
0
        private ResultParameters HandleException(Exception ex)
        {
            // Run the adapters
            ErrorSummary details = null;
            foreach (IExceptionAnalyzer analyzer in Analyzers)
            {
                details = analyzer.Analyze(ex);
                if (details != null)
                {
                    break;
                }
            }

            if (details == null)
            {
                details = GenerateNoProcessorsError(ex);
            }

            // Generate the HTML
            ErrorPageBuilder builder = new ErrorPageBuilder(details);

            Response resp = new Response(details.StatusCode);
            resp.Start();
            resp.ReasonPhrase = details.ReasonPhrase;
            resp.ContentType = "text/html";

            StringBuilder sb = new StringBuilder();
            using (StringWriter w = new StringWriter(sb))
            {
                builder.Write(w);
            }
            resp.Write(sb.ToString());
            resp.End();
            return resp.GetResultAsync().Result; //Good idea? Probably not...
        }