Exemplo n.º 1
0
        private static Formlet <T> GetNonNull <T>(HttpContextEx ctx, string name, TryParse <T> try_parse)
            where T : struct
        {
            T value = default(T);

            return(try_parse(ctx[name], out value) ? (Formlet <T>)value : (MissingError)name);
        }
Exemplo n.º 2
0
        protected virtual void MapHandler(object sender, EventArgs e)
        {
            var result = new RouteAnalysis(app.Context);
            var curr   = (AppState)null;
            var ctx    = new HttpContextEx(app.Context);
            var msg    = new Message(ctx);

            if (result.IsRoutable)
            {
                try
                {
                    curr = GetRoot(ctx);

                    foreach (var path in result)
                    {
                        msg.Text = path;
                        curr     = TranslateNull(curr.Next(msg), app.Context);
                    }
                }
                catch (ArcException ex)
                {
                    if (ex.CanHandle)
                    {
                        curr = ex.AppState;
                    }
                    else
                    {
                        throw;
                    }
                }

                app.Context.RemapHandler(curr.GetRepresentation(ctx));
            }
        }
 public System.Web.IHttpHandler GetRepresentation(HttpContextEx context)
 {
     return (AdhocHttpHandler) (c =>
     {
         context.Response.Write("Not Found");
         context.Response.StatusCode = 404;
     });
 }
Exemplo n.º 4
0
        public static ModelView <T> Create(string path, T model, HttpContextEx context)
        {
            var page = (ModelView <T>)PageParser.GetCompiledPageInstance(path, context.Server.MapPath(path), HttpContext.Current);

            page.Model = model;

            return(page);
        }
Exemplo n.º 5
0
 public override Representation GetRepresentation(HttpContextEx context)
 {
     return(new AdHocRepresentation(ctx =>
     {
         ctx.Response.Write("Authorization Required.");
         ctx.Response.StatusCode = 401;
     }));
 }
Exemplo n.º 6
0
        public static Formlet <string> GetNonEmptyString(this HttpContextEx ctx, string name)
        {
            var s = ctx.Request[name];

            if (!string.IsNullOrEmpty(s))
            {
                return(s);
            }

            else
            {
                return(new Formlet <string> .Failed("Cannot find non value named '" + name + "' that is a non-empty string"));
            }
        }
Exemplo n.º 7
0
        public static Formlet <bool> GetBoolean(this HttpContextEx ctx, string name)
        {
            if (name.Equals("yes", StringComparison.OrdinalIgnoreCase) || name.Equals("true", StringComparison.OrdinalIgnoreCase))
            {
                return((Formlet <bool>)true);
            }

            if (name.Equals("no", StringComparison.OrdinalIgnoreCase) || name.Equals("false", StringComparison.OrdinalIgnoreCase))
            {
                return((Formlet <bool>)false);
            }

            return(new Formlet <bool> .Failed("Cannot find non value named '" + name + "' that is a boolean"));
        }
Exemplo n.º 8
0
        public static Formlet <bool?> MaybeGetBoolean(this HttpContextEx ctx, string name)
        {
            bool?b = null;

            if (name.Equals("yes", StringComparison.OrdinalIgnoreCase) || name.Equals("true", StringComparison.OrdinalIgnoreCase))
            {
                b = true;
            }

            if (name.Equals("no", StringComparison.OrdinalIgnoreCase) || name.Equals("false", StringComparison.OrdinalIgnoreCase))
            {
                b = false;
            }

            return(b);
        }
Exemplo n.º 9
0
        protected virtual void Route(object sender, EventArgs e)
        {
            var context = new HttpContextEx(app.Context);
            var verdict = GetRouteVerdict(context);

            if (verdict.IsRoutable)
            {
                var controlPoint = GetRoot(context);
                var message = new Message(context);

                try
                {
                    var segments = verdict.Segments;

                    if (segments.Length > 0)
                    {
                        int index = 0;

                        if (segments[0] == "x" && segments.Length > 1)
                        {
                            controlPoint = new ClosureControlPoint(segments[1]);
                            index = 1;
                        }

                        for (var i = index; i < segments.Length; i++)
                        {
                            message.message = segments[i];
                            controlPoint = controlPoint.Next(message) ?? TranslateNull(context);
                        }

                    }

                    context.RemapHandler(controlPoint.GetRepresentation(context));
                }
                catch (WebException ex)
                {
                    var handler = ex.GetHandler(context);

                    if (handler != null)
                        context.RemapHandler(handler);
                    else
                        throw;
                }
            }
        }
Exemplo n.º 10
0
            public RouteVerdict(HttpContextEx context)
            {
                this.context = context;

                var raw = context.Request.Path;

                if (raw == "/")
                    Segments = new string[0];
                else
                    Segments = raw.Substring(1).Split(separators, StringSplitOptions.RemoveEmptyEntries);
            }
Exemplo n.º 11
0
 public override IHttpHandler GetRepresentation(HttpContextEx context)
 {
     return get_handler(context);
 }
Exemplo n.º 12
0
 public Message(string text, HttpContextEx context) : this(context)
 {
     Text = text;
 }
Exemplo n.º 13
0
 public static Formlet <double> GetDouble(this HttpContextEx ctx, string name)
 {
     return(GetNonNull <double>(ctx, name, try_parse_dbl));
 }
Exemplo n.º 14
0
 public abstract IHttpHandler GetRepresentation(HttpContextEx context);
Exemplo n.º 15
0
 public override Representation GetRepresentation(HttpContextEx context)
 {
     return(redirect);
 }
Exemplo n.º 16
0
 public static Formlet <DateTime> GetDateTime(this HttpContextEx ctx, string name)
 {
     return(GetNonNull <DateTime>(ctx, name, try_parse_dt));
 }
Exemplo n.º 17
0
 protected virtual RouteVerdict GetRouteVerdict(HttpContextEx context)
 {
     return new DefaultRouteVerdict(context);
 }
Exemplo n.º 18
0
 protected virtual AppState TranslateNull(HttpContextEx context)
 {
     return new ResourceNotFound();
 }
Exemplo n.º 19
0
 public override Representation GetRepresentation(HttpContextEx context)
 {
     return(new AdHocHttpHandler(c => { c.Response.Write("not found."); c.Response.StatusCode = 404; }));
 }
Exemplo n.º 20
0
            public DefaultRouteVerdict(HttpContextEx context)
                : base(context)
            {
                string lst = null;

                if (Segments.Length > 0 && (lst = Segments[Segments.Length - 1]).Contains('.'))
                {
                    var xs = lst.Split('.');

                    var ext = xs[xs.Length - 1];

                    if (MimeMapping.GetMimeMapping('.' + ext) != "application/octet-stream")
                    {
                        IsRoutable = false;
                        return;
                    }
                }

                IsRoutable = true;
            }
Exemplo n.º 21
0
 public static Formlet <long> GetInt64(this HttpContextEx ctx, string name)
 {
     return(GetNonNull <long>(ctx, name, try_parse_long));
 }
Exemplo n.º 22
0
 public static Formlet <Guid> GetGuid(this HttpContextEx ctx, string name)
 {
     return(GetNonNull <Guid>(ctx, name, try_parse_guid));
 }
Exemplo n.º 23
0
 public static Formlet <float> GetFloat(this HttpContextEx ctx, string name)
 {
     return(GetNonNull <float>(ctx, name, try_parse_float));
 }
Exemplo n.º 24
0
 public static Formlet <decimal> GetDecimal(this HttpContextEx ctx, string name)
 {
     return(GetNonNull <decimal>(ctx, name, try_parse_dec));
 }
Exemplo n.º 25
0
 public System.Web.IHttpHandler GetRepresentation(HttpContextEx context)
 {
     return this;
 }
Exemplo n.º 26
0
 protected abstract AppState GetRoot(HttpContextEx context);
Exemplo n.º 27
0
 public Message(string message, HttpContextEx context)
 {
     this.message = message;
     this.Context = context;
 }
Exemplo n.º 28
0
 protected abstract AppState GetRoot(HttpContextEx context);
Exemplo n.º 29
0
 public Message(HttpContextEx context)
 {
     this.context = context;
     paths        = context.Request.Url.Segments;
 }
Exemplo n.º 30
0
 public override Representation GetRepresentation(HttpContextEx context)
 {
     return(Representation.Create(this));
 }
Exemplo n.º 31
0
 public abstract Representation GetRepresentation(HttpContextEx context);
Exemplo n.º 32
0
 internal Message(HttpContextEx context)
 {
     this.Context = context;
 }
Exemplo n.º 33
0
 public override IHttpHandler GetRepresentation(HttpContextEx context)
 {
     return this;
 }
Exemplo n.º 34
0
 public static Formlet <int> GetInt32(this HttpContextEx ctx, string name)
 {
     return(GetNonNull <int>(ctx, name, try_parse_int));
 }
Exemplo n.º 35
0
 public abstract IHttpHandler GetHandler(HttpContextEx context);