Exemple #1
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.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 ();
        }
Exemple #2
0
        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;
            }
        }
Exemple #3
0
 public static void RenderTemplate(ManosContext ctx, string template, object data)
 {
     TemplateEngine.RenderToStream (template, ctx.Response.Writer, data);
 }
Exemple #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();
            }
        }
Exemple #5
0
 public static void RenderTemplate(ManosContext ctx, string template, object data)
 {
     TemplateEngine.RenderToStream(template, ctx.Response.Writer, data);
 }
Exemple #6
0
        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 ());
        }
Exemple #7
0
        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;
            }
        }