Пример #1
0
        /// <summary>
        /// url 必须没有后缀名
        /// </summary>
        /// <param name="cleanUrl">必须没有后缀名</param>
        /// <returns></returns>
        public static Route RecognizePath( String cleanUrl ) {

            if (strUtil.IsNullOrEmpty( cleanUrl ) || cleanUrl.ToLower().Equals( "default" )) {
                cleanUrl = "default";
            }

            logger.Info( "RecognizePath begin, clearnUrl=" + cleanUrl );

            Route x = LinkMap.Parse( cleanUrl );
            if (x != null) return x;

            if (cleanUrl.StartsWith( "/" )) cleanUrl = strUtil.TrimStart( cleanUrl, "/" );

            String[] arrPathRow = cleanUrl.Split( Separator );

            foreach (RouteSetting route in RouteTable.GetRoutes()) {

                if (!isMatched( route, arrPathRow )) continue;


                RouteParseInfo routeInfo = new RouteParseInfo( MemberPath.getOwnerInfo( arrPathRow ), arrPathRow );
                processOwnerNamespaceAppId( routeInfo, route );

                Route result = getResult( route, routeInfo );

                if (result == null) continue;

                setRouteInfo( result, routeInfo, cleanUrl );

                return result;
            }

            return null;
        }
Пример #2
0
        /// <summary>
        /// url 必须没有后缀名
        /// </summary>
        /// <param name="cleanUrl">必须没有后缀名</param>
        /// <returns></returns>
        public static Route RecognizePath( String cleanUrl )
        {
            if (strUtil.IsNullOrEmpty( cleanUrl ) || cleanUrl.ToLower().Equals( "default" )) {
                cleanUrl = "default";
            }

            if (cleanUrl.StartsWith( "/" )) cleanUrl = strUtil.TrimStart( cleanUrl, "/" );

            String[] arrPathRow = cleanUrl.Split( Separator );

            foreach (RouteSetting route in RouteTable.GetRoutes()) {

                if (!isMatched( route, arrPathRow )) continue;

                RouteParseInfo routeInfo = new RouteParseInfo( MemberPath.getOwnerInfo( arrPathRow ), arrPathRow );
                processOwnerNamespaceAppId( routeInfo, route );

                Route result = getResult( route, routeInfo );

                if (result == null) continue;

                setRouteInfo( result, routeInfo, cleanUrl );

                return result;
            }

            throw new MvcException( HttpStatus.NotFound_404, "can't find matching route : Url=" + cleanUrl );
        }
Пример #3
0
        //----------------------------------------------------------------------------------------------------------------------

        private static void setRouteInfo( Route result, RouteParseInfo routeInfo, String cleanUrl ) {

            if (strUtil.IsNullOrEmpty( result.ns ))
                result.setNs( routeInfo.getNamespace().ToString() );
            if (result.ns.Equals( "_" ))
                result.setNs( "" );

            if (routeInfo.getAppId() > 0) {
                result.setItem( "appid", routeInfo.getAppId() );
            }

            if (routeInfo.getOwnerInfo() != null) {
                result.setItem( "owner", routeInfo.getOwnerInfo().Owner );
                result.setItem( "ownertype", routeInfo.getOwnerInfo().OwnerType );
            }

            result.setCleanUrl( cleanUrl );
            setStrongTypeValue( result );
            setDefaultAction( result );
        }
Пример #4
0
        private static Route getResult( RouteSetting setting, RouteParseInfo routeInfo ) {

            Route result = setting.getRouteWithDefaultValue();
            List<PathItem> items = setting.GetNamedItem();


            for (int i = 0; i < items.Count; i++) {

                String[] arrValue = routeInfo.getPathArray();

                if (i > arrValue.Length - 1) break;

                PathItem item = items[i];
                if (item.isNamed() == false) continue;

                String val = arrValue[i];
                if (strUtil.IsNullOrEmpty( val )) continue;

                // 如果条件不符合,跳过此条route
                if (setting.getRequirements().match( item.getName(), val ) == false) return null;

                result.setItem( item.getName(), val );
            }

            return result;
        }
Пример #5
0
        private static void processOwnerNamespaceAppId( RouteParseInfo routeInfo, RouteSetting route ) {

            String[] arrPathRow = routeInfo.getRowPathArray();

            int count = route.GetNamedItem().Count;
            if (count == 0) {
                routeInfo.setPathArray( arrPathRow );
                return;
            }

            String[] arrTemp;

            // 首先前面剔除掉 owner
            if (routeInfo.getOwnerInfo() != null) {
                arrTemp = new String[arrPathRow.Length - 2];
                for (int i = 2; i < arrPathRow.Length; i++) {
                    arrTemp[i - 2] = arrPathRow[i];
                }
            }
            else {
                arrTemp = arrPathRow;
            }


            if (arrTemp.Length <= count) {
                routeInfo.setPathArray( arrTemp );
                return;
            }

            // 然后末尾剔除掉 controller/action/id
            String[] arrPath = new String[count];
            int x = 0;
            for (int i = arrTemp.Length - count; i < arrTemp.Length; i++) {
                arrPath[x] = arrTemp[i];
                x++;
            }

            // 得到 ns
            StringBuilder ns = new StringBuilder();
            int end = arrTemp.Length - count;
            for (int i = 0; i < end; i++) {

                if (i > 0) ns.Append( "." );

                if (i == 0 && isEndsWithInt( arrTemp[i] )) {
                    routeInfo.setAppId( strUtil.GetEndNumber( arrTemp[i] ) );

                    ns.Append( strUtil.TrimEnd( arrTemp[i], routeInfo.getAppId().ToString() ) );

                }
                else
                    ns.Append( arrTemp[i] );
            }


            routeInfo.setPathArray( arrPath );
            routeInfo.setNamespace( ns );

        }