public void HandleTransaction(ManosApp app, IHttpTransaction con) { bool end = false; if (con == null) throw new ArgumentNullException ("con"); OnPreProcessRequest (this, con); if (con.Aborted) goto cleanup; var ctx = new ManosContext (con); var handler = OnPreProcessTarget (ctx); if (handler == null) handler = Routes.Find (con.Request); if (handler == null) { Console.WriteLine ("no handler found for: '{0}'", ctx.Request.LocalPath); con.Response.StatusCode = 404; con.Response.End (); return; } con.Response.StatusCode = 200; OnPostProcessTarget (ctx, handler); try { handler.Invoke (app, new ManosContext (con)); } catch (Exception e) { Console.Error.WriteLine ("Exception in transaction handler:"); Console.Error.WriteLine (e); con.Response.StatusCode = 500; // // TODO: Maybe the cleanest thing to do is // have a HandleError, HandleException thing // on HttpTransaction, along with an UnhandledException // method/event on ManosModule. // end = true; } if (con.Response.StatusCode == 404) con.Response.End (); cleanup: OnPostProcessRequest (this, con); if (end) con.Response.End (); }
private void Execute() { step = PipelineStep.WaitingForEnd; ctx = new ManosContext(transaction); var handler = app.Routes.Find(transaction.Request); PipePreProcessTarget((newHandler) => { if (newHandler != handler) { handler = newHandler; } }); if (handler == null) { ctx.Response.StatusCode = 404; ctx.Response.End(app.Get404Response()); return; } ctx.Response.StatusCode = 200; try { handler.Invoke(app, ctx); } catch (Exception e) { Console.Error.WriteLine("Exception in transaction handler:"); Console.Error.WriteLine(e); ctx.Response.StatusCode = 500; ctx.Response.End(app.Get500Response()); // // TODO: Maybe the cleanest thing to do is // have a HandleError, HandleException thing // on HttpTransaction, along with an UnhandledException // method/event on ManosModule. // // end = true; } PipePostProcessTarget(handler); if (ctx.Response.StatusCode == 404) { step = PipelineStep.WaitingForEnd; ctx.Response.End(); return; } }
public static void RenderTemplate(ManosContext ctx, string template, object data) { TemplateEngine.RenderToStream (template, ctx.Response.Writer, data); }
public void HandleTransaction(ManosApp app, IHttpTransaction con) { bool end = false; if (con == null) { throw new ArgumentNullException("con"); } OnPreProcessRequest(this, con); if (con.Aborted) { goto cleanup; } var ctx = new ManosContext(con); var handler = OnPreProcessTarget(ctx); if (handler == null) { handler = Routes.Find(con.Request); } if (handler == null) { Console.WriteLine("no handler found for: '{0}'", ctx.Request.Path); con.Response.StatusCode = 404; con.Response.End(); return; } con.Response.StatusCode = 200; OnPostProcessTarget(ctx, handler); try { handler.Invoke(app, new ManosContext(con)); } catch (Exception e) { Console.Error.WriteLine("Exception in transaction handler:"); Console.Error.WriteLine(e); con.Response.StatusCode = 500; // // TODO: Maybe the cleanest thing to do is // have a HandleError, HandleException thing // on HttpTransaction, along with an UnhandledException // method/event on ManosModule. // end = true; } if (con.Response.StatusCode == 404) { con.Response.End(); } cleanup: OnPostProcessRequest(this, con); if (end) { con.Response.End(); } }
public static void RenderTemplate(ManosContext ctx, string template, object data) { TemplateEngine.RenderToStream(template, ctx.Response.Writer, data); }
public static void RenderTemplate(ManosContext context, string template, object data) { MemoryStream stream = new MemoryStream (); using (StreamWriter writer = new StreamWriter (stream)) { Manos.Templates.Engine.RenderToStream (template, writer, data); writer.Flush (); } context.Response.Write (stream.GetBuffer ()); }
private void Execute() { step = PipelineStep.WaitingForEnd; ctx = new ManosContext (transaction); var handler = app.Routes.Find (transaction.Request); PipePreProcessTarget((newHandler) => { if(newHandler != handler) { handler = newHandler; } }); if (handler == null) { ctx.Response.StatusCode = 404; ctx.Response.End (app.Get404Response()); return; } ctx.Response.StatusCode = 200; try { handler.Invoke (app, ctx); } catch (Exception e) { Console.Error.WriteLine ("Exception in transaction handler:"); Console.Error.WriteLine (e); ctx.Response.StatusCode = 500; ctx.Response.End (app.Get500Response()); // // TODO: Maybe the cleanest thing to do is // have a HandleError, HandleException thing // on HttpTransaction, along with an UnhandledException // method/event on ManosModule. // // end = true; } PipePostProcessTarget(handler); if (ctx.Response.StatusCode == 404) { step = PipelineStep.WaitingForEnd; ctx.Response.End (); return; } }