Example #1
0
        public Route SelectRoute(HttpContext context, out string[] segments)
        {
            var method    = context.Request.Method;
            var routeTree = _trees[method];

            segments = RouteTree.ToSegments(context.Request.Path);
            return(routeTree.Select(segments));
        }
Example #2
0
 public Router(RouteTree tree)
 {
     _tree = tree;
 }
Example #3
0
        public void Place(RouteTree tree)
        {
            var method = tree.ForMethod(HttpMethod);



            var count = _segments.Count;

            switch (count)
            {
            case 0:
                method.Root = this;
                break;

            case 1:
                if (HasSpread)
                {
                    method.SpreadRoute = this;
                }
                else if (HasParameters)
                {
                    method.ArgRoutes.Add(this);
                }
                else
                {
                    method.Leaves.Add(this);
                }

                break;

            default:
                RouteNode current = method;
                for (int i = 0; i < _segments.Count - 1; i++)
                {
                    var segment = _segments[i];
                    if (segment is Segment s)
                    {
                        current = current.ChildFor(s.SegmentPath);
                    }
                    else if (segment is RouteArgument)
                    {
                        current.ArgRoutes.Add(this);
                        break;
                    }
                    else
                    {
                        current.SpreadRoute = this;
                        break;
                    }
                }

                var last = _segments.Last();

                if (last is Segment)
                {
                    current.Leaves.Add(this);
                }
                else if (last is RouteArgument)
                {
                    current.ArgRoutes.Add(this);
                }
                else
                {
                    current.SpreadRoute = this;
                }

                break;
            }
        }