Example #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);
        }
Example #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;
     });
 }
Example #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);
        }
Example #5
0
 public override Representation GetRepresentation(HttpContextEx context)
 {
     return(new AdHocRepresentation(ctx =>
     {
         ctx.Response.Write("Authorization Required.");
         ctx.Response.StatusCode = 401;
     }));
 }
Example #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"));
            }
        }
Example #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"));
        }
Example #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);
        }
Example #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;
                }
            }
        }
Example #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);
            }
Example #11
0
 public override IHttpHandler GetRepresentation(HttpContextEx context)
 {
     return get_handler(context);
 }
Example #12
0
 public Message(string text, HttpContextEx context) : this(context)
 {
     Text = text;
 }
Example #13
0
 public static Formlet <double> GetDouble(this HttpContextEx ctx, string name)
 {
     return(GetNonNull <double>(ctx, name, try_parse_dbl));
 }
Example #14
0
 public abstract IHttpHandler GetRepresentation(HttpContextEx context);
Example #15
0
 public override Representation GetRepresentation(HttpContextEx context)
 {
     return(redirect);
 }
Example #16
0
 public static Formlet <DateTime> GetDateTime(this HttpContextEx ctx, string name)
 {
     return(GetNonNull <DateTime>(ctx, name, try_parse_dt));
 }
Example #17
0
 protected virtual RouteVerdict GetRouteVerdict(HttpContextEx context)
 {
     return new DefaultRouteVerdict(context);
 }
Example #18
0
 protected virtual AppState TranslateNull(HttpContextEx context)
 {
     return new ResourceNotFound();
 }
Example #19
0
 public override Representation GetRepresentation(HttpContextEx context)
 {
     return(new AdHocHttpHandler(c => { c.Response.Write("not found."); c.Response.StatusCode = 404; }));
 }
Example #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;
            }
Example #21
0
 public static Formlet <long> GetInt64(this HttpContextEx ctx, string name)
 {
     return(GetNonNull <long>(ctx, name, try_parse_long));
 }
Example #22
0
 public static Formlet <Guid> GetGuid(this HttpContextEx ctx, string name)
 {
     return(GetNonNull <Guid>(ctx, name, try_parse_guid));
 }
Example #23
0
 public static Formlet <float> GetFloat(this HttpContextEx ctx, string name)
 {
     return(GetNonNull <float>(ctx, name, try_parse_float));
 }
Example #24
0
 public static Formlet <decimal> GetDecimal(this HttpContextEx ctx, string name)
 {
     return(GetNonNull <decimal>(ctx, name, try_parse_dec));
 }
Example #25
0
 public System.Web.IHttpHandler GetRepresentation(HttpContextEx context)
 {
     return this;
 }
Example #26
0
 protected abstract AppState GetRoot(HttpContextEx context);
Example #27
0
 public Message(string message, HttpContextEx context)
 {
     this.message = message;
     this.Context = context;
 }
Example #28
0
 protected abstract AppState GetRoot(HttpContextEx context);
Example #29
0
 public Message(HttpContextEx context)
 {
     this.context = context;
     paths        = context.Request.Url.Segments;
 }
Example #30
0
 public override Representation GetRepresentation(HttpContextEx context)
 {
     return(Representation.Create(this));
 }
Example #31
0
 public abstract Representation GetRepresentation(HttpContextEx context);
Example #32
0
 internal Message(HttpContextEx context)
 {
     this.Context = context;
 }
 public override IHttpHandler GetRepresentation(HttpContextEx context)
 {
     return this;
 }
Example #34
0
 public static Formlet <int> GetInt32(this HttpContextEx ctx, string name)
 {
     return(GetNonNull <int>(ctx, name, try_parse_int));
 }
 public abstract IHttpHandler GetHandler(HttpContextEx context);