コード例 #1
0
ファイル: ManosApp.cs プロジェクト: debackerl/manos
        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 ();
        }
コード例 #2
0
ファイル: Pipeline.cs プロジェクト: txdv/manos
        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;
            }
        }
コード例 #3
0
ファイル: ManosModule.cs プロジェクト: vbatz258/manos
 public static void RenderTemplate(ManosContext ctx, string template, object data)
 {
     TemplateEngine.RenderToStream (template, ctx.Response.Writer, data);
 }
コード例 #4
0
        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();
            }
        }
コード例 #5
0
 public static void RenderTemplate(ManosContext ctx, string template, object data)
 {
     TemplateEngine.RenderToStream(template, ctx.Response.Writer, data);
 }
コード例 #6
0
ファイル: ManosModule.cs プロジェクト: emiaj/manos
        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 ());
        }
コード例 #7
0
ファイル: Pipeline.cs プロジェクト: vbatz258/manos
        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;
            }
        }