Esempio n. 1
1
        public static MvcContext GetOne( IMember objOwner, Type appType, int appId )
        {
            MvcContext ctx = getContextInit();

            // route
            Route route = new wojilu.Web.Mvc.Routes.Route();
            route.setAppId( appId ); // 为了让生成的link链接中有appId,必须设置此项
            ctx.utils.setRoute( route );

            // viewer: 某些地方需要判断viewer
            ViewerContext viewer = new ViewerContext();
            viewer.obj = new User();
            ctx.utils.setViewerContext( viewer );

            // owner
            OwnerContext owner = new OwnerContext();
            owner.Id = objOwner.Id;
            owner.obj = objOwner;
            ctx.utils.setOwnerContext( owner );

            // app
            IAppContext app = new AppContext();
            app.Id = appId;
            app.obj = ndb.findById( appType, appId );
            app.setAppType( appType ); // 如果要使用alang语言包,必须设置此项
            ctx.utils.setAppContext( app );

            return ctx;
        }
Esempio n. 2
1
        public static MvcContext GetOne( IMember objOwner )
        {
            MvcContext ctx = getContextInit();

            // route
            Route route = new wojilu.Web.Mvc.Routes.Route();
            ctx.utils.setRoute( route );

            // viewer: 某些地方需要判断viewer
            ViewerContext viewer = new ViewerContext();
            viewer.obj = new User();
            ctx.utils.setViewerContext( viewer );

            // owner
            OwnerContext owner = new OwnerContext();
            owner.Id = objOwner.Id;
            owner.obj = objOwner;
            ctx.utils.setOwnerContext( owner );

            // app
            IAppContext app = new AppContext();
            app.obj = null;
            ctx.utils.setAppContext( app );

            return ctx;
        }
Esempio n. 3
0
        public Route getRouteWithDefaultValue()
        {
            Route route = new Route();

            route.setOwnerType ( _default.getOwnerType());
            route.setOwner ( _default.getOwner());
            route.setNs( _default.getNs() );
            route.setController ( _default.getController());
            route.setAction ( _default.getAction());
            route.setQuery ( _default.getQuery());
            route.setId( _default.getId() );
            route.setAppId( _default.getAppId() );
            route.setPage( _default.getPage() );

            route.setItem( "ownertype", route.ownerType );
            route.setItem( "owner", route.owner );
            route.setItem( "namespace", route.ns );
            route.setItem( "controller", route.controller );
            route.setItem( "action", route.action );
            route.setItem( "query", route.query );
            route.setItem( "id", route.id );
            route.setItem( "appId", route.appId );
            route.setItem( "page", route.page );

            return route;
        }
Esempio n. 4
0
 private Boolean isSiteAdmin(Route route)
 {
     String ns = route.ns;
     if (strUtil.IsNullOrEmpty(ns)) return false;
     if (ns.StartsWith("Admin.") || ns.Equals("Admin")) return true;
     return false;
 }
Esempio n. 5
0
        public static MvcContext GetOne( IMember objOwner, int appId )
        {
            IWebContext webContext = MockWebContext.New( 1, "http://localhost/", new System.IO.StringWriter() );

            MvcContext ctx = new MvcContext( webContext );

            // route
            Route route = new wojilu.Web.Mvc.Routes.Route();
            route.setAppId( appId ); // 为了让生成的link链接中有appId,必须设置此项
            ctx.utils.setRoute( route );

            // viewer: 某些地方需要判断viewer
            ViewerContext viewer = new ViewerContext();
            viewer.obj = new User();
            ctx.utils.setViewerContext( viewer );

            // owner
            OwnerContext owner = new OwnerContext();
            owner.Id = objOwner.Id;
            owner.obj = objOwner;
            ctx.utils.setOwnerContext( owner );

            // app
            IAppContext app = new AppContext();
            app.Id = appId;
            app.obj = BlogApp.findById( appId );
            app.setAppType( typeof( BlogApp ) ); // 如果要使用alang语言包,必须设置此项
            ctx.utils.setAppContext( app );

            return ctx;
        }
Esempio n. 6
0
        public static MvcContext GetOne(IMember objOwner, int appId)
        {
            IWebContext webContext = MockWebContext.New(1, "http://localhost/", new System.IO.StringWriter());

            MvcContext ctx = new MvcContext(webContext);

            // route
            Route route = new wojilu.Web.Mvc.Routes.Route();

            route.setAppId(appId);   // 为了让生成的link链接中有appId,必须设置此项
            ctx.utils.setRoute(route);

            // viewer: 某些地方需要判断viewer
            ViewerContext viewer = new ViewerContext();

            viewer.obj = new User();
            ctx.utils.setViewerContext(viewer);

            // owner
            OwnerContext owner = new OwnerContext();

            owner.Id  = objOwner.Id;
            owner.obj = objOwner;
            ctx.utils.setOwnerContext(owner);

            // app
            IAppContext app = new AppContext();

            app.Id  = appId;
            app.obj = BlogApp.findById(appId);
            app.setAppType(typeof(BlogApp));     // 如果要使用alang语言包,必须设置此项
            ctx.utils.setAppContext(app);

            return(ctx);
        }
Esempio n. 7
0
        /// <summary>
        /// 模拟一个 MvcContext ,访问者是未登录的游客。被访问对象是app的页面
        /// </summary>
        /// <param name="objOwner"></param>
        /// <param name="appType"></param>
        /// <param name="appId"></param>
        /// <returns></returns>
        public static MvcContext GetOne(IMember objOwner, Type appType, int appId)
        {
            MvcContext ctx = getContextInit();

            // route
            Route route = new wojilu.Web.Mvc.Routes.Route();

            route.setAppId(appId);   // 为了让生成的link链接中有appId,必须设置此项
            ctx.utils.setRoute(route);

            // viewer: 某些地方需要判断viewer
            ViewerContext viewer = new ViewerContext();

            viewer.obj = new User();
            ctx.utils.setViewerContext(viewer);

            // owner
            OwnerContext owner = new OwnerContext();

            owner.Id  = objOwner.Id;
            owner.obj = objOwner;
            ctx.utils.setOwnerContext(owner);

            // app
            IAppContext app = new AppContext();

            app.Id  = appId;
            app.obj = ndb.findById(appType, appId);
            app.setAppType(appType);   // 如果要使用alang语言包,必须设置此项
            ctx.utils.setAppContext(app);

            return(ctx);
        }
Esempio n. 8
0
        /// <summary>
        /// 模拟一个 MvcContext ,访问者是未登录的游客。被访问对象不是app的页面
        /// </summary>
        /// <param name="objOwner"></param>
        /// <returns></returns>
        public static MvcContext GetOne(IMember objOwner)
        {
            MvcContext ctx = getContextInit();

            // route
            Route route = new wojilu.Web.Mvc.Routes.Route();

            ctx.utils.setRoute(route);

            // viewer: 某些地方需要判断viewer
            ViewerContext viewer = new ViewerContext();

            viewer.obj = new User();
            ctx.utils.setViewerContext(viewer);

            // owner
            OwnerContext owner = new OwnerContext();

            owner.Id  = objOwner.Id;
            owner.obj = objOwner;
            ctx.utils.setOwnerContext(owner);

            // app
            IAppContext app = new AppContext();

            app.obj = null;
            ctx.utils.setAppContext(app);

            return(ctx);
        }
Esempio n. 9
0
        private void refreshRouteAndOwner( MvcContext ctx, Route newRoute )
        {
            if (newRoute.owner != ctx.route.owner || newRoute.ownerType != ctx.route.ownerType) {
                ctx.utils.setRoute( newRoute );
                Init( ctx ); // 当前Owner已经变换,所以需要重新更新owner
            }
            else {
                ctx.utils.setRoute( newRoute );

            }
        }
Esempio n. 10
0
        private static Route parseRoute( String apath )
        {
            if (apath == null) return new Route();

            Route x = new Route();

            apath = processPageIndex( apath, x );

            PathAppId xPath = processAppId( apath.TrimStart( '/' ) );
            String path = xPath.Path;

            x.setAppId( xPath.AppId );

            Dictionary<String, String> map = getMap();

            foreach (KeyValuePair<String, String> kv in map) {

                if (isLinkToLow) {

                    if (strUtil.EqualsIgnoreCase( path, kv.Key )) {
                        // path=category
                        // map.Add( "category", "wojilu.Test.Web.Mvc.TestPostController.List" );
                        return getEqualMap( kv, x );
                    }

                    if (path.ToLower().StartsWith( kv.Key.ToLower() + separator )) {
                        return getParseResult( path, kv.Value, x );
                    }

                }
                else {

                    if (path.Equals( kv.Key )) {
                        // path=category
                        // map.Add( "category", "wojilu.Test.Web.Mvc.TestPostController.List" );
                        return getEqualMap( kv, x );
                    }

                    if (path.StartsWith( kv.Key + separator )) {
                        return getParseResult( path, kv.Value, x );
                    }

                }

            }

            return null;
        }
Esempio n. 11
0
        private static Route parseControllerAndAction( String[] arrPath, String mapController, Route x )
        {
            String action = arrPath[1];
            x.setController( mapController );
            x.setAction( action );

            return x;
        }
Esempio n. 12
0
        private static Route parseCAndAId( String[] arrPath, String mapController, Route x )
        {
            String[] arrValue = mapController.Split( '.' );
            String action = arrValue[arrValue.Length - 1];
            String controller = strUtil.TrimEnd( mapController, action ).TrimEnd( '.' );
            x.setController( controller );
            x.setAction( action );
            x.setId( cvt.ToInt( arrPath[1] ) );

            return x;
        }
Esempio n. 13
0
        private static Route parseActionId( String[] arrPath, String mapController, Route x )
        {
            String id = arrPath[2];
            if (cvt.IsInt( id ) == false) return null;

            String action = arrPath[1];
            x.setController( mapController );
            x.setAction( action );
            x.setId( cvt.ToInt( arrPath[2] ) );

            return x;
        }
Esempio n. 14
0
        private static Route getParseResult( String path, String mapController, Route x )
        {
            String[] arr = path.Split( separator[0] );
            if (arr.Length == 1) {
                return null;
            }
            else if (arr.Length == 2) {

                Boolean isMapController = mapController.EndsWith( "Controller" );
                if (isMapController) {
                    // path=post/Index
                    // map.Add( "post", "wojilu.Test.Web.Mvc.TestPostController" );
                    return parseControllerAndAction( arr, mapController, x );
                }
                else {
                    // path=product/99
                    // map.Add( "product", "wojilu.Test.Web.Mvc.TestPostController.Product" );
                    return parseCAndAId( arr, mapController, x );
                }

            }
            else if (arr.Length == 3) {
                // path=post/Show/88
                // map.Add( "post", "wojilu.Test.Web.Mvc.TestPostController" );
                return parseActionId( arr, mapController, x );
            }
            else {
                //throw new Exception( "path过长,请勿超过3项" );
                return null;
            }
        }
Esempio n. 15
0
 private static Route getEqualMap( KeyValuePair<String, String> kv, Route x )
 {
     String[] arr = kv.Value.Split( '.' );
     String action = arr[arr.Length - 1];
     String controller = strUtil.TrimEnd( kv.Value, action ).TrimEnd( '.' );
     x.setController( controller );
     x.setAction( action );
     return x;
 }
Esempio n. 16
0
        private static Route processController( Route route, String cleanUrl )
        {
            if (route == null || route.controller == null) return route;

            route.setCleanUrl( cleanUrl );

            if (route.owner == null) {

                route.setOwner( "site" );
                route.setOwnerType( "site" );
            }

            foreach (String aNamespace in MvcConfig.Instance.RootNamespace) {

                if (route.controller.StartsWith( aNamespace )) {

                    String cleanNs = strUtil.TrimStart( route.controller, aNamespace ).TrimStart( '.' );

                    String[] arrItem = cleanNs.Split( '.' );
                    String controller = arrItem[arrItem.Length - 1];
                    String ns = strUtil.TrimEnd( cleanNs, controller ).TrimEnd( '.' );

                    controller = strUtil.TrimEnd( controller, "Controller" );

                    route.setController( controller );
                    route.setNs( ns );
                    route.setRootNamespace( aNamespace );

                    return route;

                }

            }

            return route;
        }
Esempio n. 17
0
        private static void setDefaultAction( Route route ) {

            if (strUtil.HasText( route.action )) return;

            if (route.id > 0)
                route.setAction( "Show" );
            else
                route.setAction( "Index" );
        }
Esempio n. 18
0
        private static void setStrongTypeValue( Route result ) {

            if (result.getItem( "controller" ) != null) result.setController( result.getItem( "controller" ) );
            if (result.getItem( "action" ) != null) result.setAction( result.getItem( "action" ) );
            if (result.getItem( "query" ) != null) result.setQuery( result.getItem( "query" ) );
            if (result.getItem( "owner" ) != null) result.setOwner( result.getItem( "owner" ) );
            if (result.getItem( "ownertype" ) != null) result.setOwnerType( result.getItem( "ownertype" ) );
            if (result.getItem( "id" ) != null) result.setId( cvt.ToLong( result.getItem( "id" ) ) );
            if (result.getItem( "appid" ) != null) result.setAppId( cvt.ToLong( result.getItem( "appid" ) ) );

            int page = 1;
            if (result.getItem( "page" ) != null) {
                int routePage = Requirements.getPageNumber( result.getItem( "page" ) );
                if (routePage > 1) page = routePage;
            }

            result.setItem( "page", page );
            result.setPage( page );
            CurrentRequest.setCurrentPage( page );
        }
Esempio n. 19
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 );
        }
Esempio n. 20
0
        private static String processPageIndex( String apath, Route x )
        {
            String[] arrP = apath.Split( separator[0] );
            String lastItem = arrP[arrP.Length - 1];
            if (isPageNumber( lastItem )) {

                int pageIndex = cvt.ToInt( lastItem.TrimStart( 'p' ) );
                x.setPage( pageIndex );
                CurrentRequest.setCurrentPage( pageIndex );

                apath = strUtil.TrimEnd( apath, lastItem ).TrimEnd( separator[0] );

            }
            return apath;
        }
Esempio n. 21
0
 /// <summary>
 /// 设置当前路由 route
 /// </summary>
 /// <param name="route"></param>
 public void setRoute( Route route )
 {
     _route = route;
 }