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
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. 3
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. 4
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. 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
        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. 7
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. 8
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. 9
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;
        }