예제 #1
0
        public RouteResolveResult Resolve(IOwinRequest request)
        {
            if (request.Path.IndexOf('.') > 0)
            {
                return(null);
            }

            RouteResolveResult result = null;
            var roles = routeRoles.Where(r => r.Method == HttpMethod.Both || r.Method.ToString().ToLower() == request.Method.ToLower());

            foreach (var role in roles)
            {
                var resolveResult = getRouteForUrl(request.Path, request.Method, role);
                if (resolveResult != null)
                {
                    result = resolveResult;
                    break;
                }
            }

            return(result);
        }
예제 #2
0
        private RouteResolveResult getRouteForUrl(string path, string method, RouteRole role)
        {
            RouteResolveResult result = new RouteResolveResult()
            {
                Url        = path, ControllerName = role.DefaultController,
                ActionName = role.DefalutAction
            };
            List <RouteSegment> segments = role.Segments;
            var urlSegments = path.GetUrlSegments();

            for (int index = 0; index < urlSegments.Count; index++)
            {
                if (index < segments.Count)
                {
                    switch (segments[index].SegmentType)
                    {
                    case SegmentType.Directory:
                        if (segments[index].Segment != urlSegments[index] || segments[index].Index != index)
                        {
                            result = null;
                        }
                        break;

                    case SegmentType.Role:
                        if (segments [index].Index == index)
                        {
                            var controllerOrAction = segments [index].GetSegmentValue(urlSegments [index]);
                            if (segments [index].RouteNames [0] == "controller")
                            {
                                result.ControllerName = controllerOrAction;
                            }
                            else                                                                                           //"action"
                            {
                                result.ActionName = controllerOrAction;
                            }
                        }
                        break;

                    case SegmentType.Parameter:
                        var segmentValue = urlSegments[index];
                        result.RouteValues.Add(segments[index].RouteNames[0], segmentValue);
                        break;
                    }
                }
                else
                {
                    int i = index - segments.Count;
                    result.RouteValues.Add("p" + i, urlSegments[index]);
                }

                if (result == null)
                {
                    break;
                }
            }

            if (result != null && (string.IsNullOrEmpty(result.ActionName) || string.IsNullOrEmpty(result.ControllerName)))
            {
                return(null);
            }

            return(result);
        }
예제 #3
0
 public MvcRouteHandler(RouteResolveResult result) : base(result)
 {
 }
예제 #4
0
 public RouteHandler(RouteResolveResult resolveResult)
 {
     _resolveResult = resolveResult;
 }
예제 #5
0
 public MvcRouteHandler(RouteResolveResult result):base(result) {  }