Exemple #1
0
        public virtual void Init(MvcContext ctx)
        {
            if (ctx.utils.isEnd())
            {
                return;
            }

            CurrentRequest.setItem("_user_factory", new UserFactory());

            User user = this.getViewer(ctx);

            if (user.Id == UserFactory.Guest.Id && ctx.web.UserIsLogin)
            {
                signOut(ctx);
                return;
            }
            else if (user.Status == MemberStatus.Deleted || user.Status == MemberStatus.Approving)
            {
                signOut(ctx);
                return;
            }

            if (ctx.web.UserIsLogin)
            {
                loginService.UpdateLastLogin(user, ctx.Ip);
            }

            ViewerContext context = new ViewerContext(ctx);

            context.Id      = user.Id;
            context.obj     = user;
            context.IsLogin = ctx.web.UserIsLogin;
            ctx.utils.setViewerContext(context);
        }
Exemple #2
0
        public void SideBar()
        {
            Page        data         = ctx.GetItem("_currentPage") as Page;
            List <Page> relativeList = ctx.GetItem("_relativeList") as List <Page>;

            // 1) 所属分类
            set("category.Name", data.Category.Name);

            // 2) 添加命令
            String cmd = hasPermission(data.Category) ? string.Format("<a href=\"{0}\" class=\"btn\"><i class=\"icon-plus\"></i> 添加页面</a>", to(Add, data.Category.Id)) : "";

            set("addCmd", cmd);

            // 3) 树形列表
            Tree <Page> tree = new Tree <Page>(relativeList);

            CurrentRequest.setItem("__currentPageParentId", data.ParentId);
            treeBinder binder = new treeBinder(data.Id);

            binder.link = this.ctx.link;
            List <zNode> nodes = tree.GetZNodeList(binder);

            set("jsonData", Json.ToString(nodes));

            // 4) 传统链接
            set("tree", tree.RenderList("mytree", true, binder, data.Id));

            // 5) 当前菜单的url
            Page homePage = relativeList.Count == 0 ? data : tree.GetAllOrdered()[0];

            ctx.SetItem("_moduleUrl", to(Show, homePage.Id));
        }
Exemple #3
0
        //--------------------------------------------------------------------------------------------------------------

        /// <summary>
        /// 将实际映射到的目标path存入 httpContext,方便 PageHelper 生成翻页链接
        /// </summary>
        /// <param name="path"></param>
        public static void setRoutePath(String path)
        {
            if (path.StartsWith("http") == false && path.StartsWith("/") == false)
            {
                path = "/" + path;
            }
            CurrentRequest.setItem("trueHttpPath", path);
        }
Exemple #4
0
        /// <summary>
        /// 将所有日志即可写入磁盘
        /// </summary>
        internal static void Flush()
        {
            StringBuilder sb = CurrentRequest.getItem(_contextLogItem) as StringBuilder;

            if (sb != null)
            {
                writeContentToFile(sb.ToString());
                CurrentRequest.setItem(_contextLogItem, null);
            }
        }
Exemple #5
0
 /// <summary>
 /// 在 web 系统中,记录 sql 执行的次数
 /// </summary>
 public static void LogSqlCount()
 {
     if (CurrentRequest.getItem("sqlcount") == null)
     {
         CurrentRequest.setItem("sqlcount", 1);
     }
     else
     {
         CurrentRequest.setItem("sqlcount", ((int)CurrentRequest.getItem("sqlcount")) + 1);
     }
 }
Exemple #6
0
        private static void clearTransactionAll()
        {
            Dictionary <String, IDbTransaction> dic = CurrentRequest.getItem(_transactionKey) as Dictionary <String, IDbTransaction>;

            if (dic == null)
            {
                return;
            }
            dic.Clear();
            CurrentRequest.setItem(_transactionKey, dic);
        }
Exemple #7
0
        internal static IDictionary getContextCache()
        {
            Object dic = CurrentRequest.getItem(_contextCacheKey);

            if (dic == null)
            {
                dic = new Hashtable();
                CurrentRequest.setItem(_contextCacheKey, dic);
            }
            return(dic as IDictionary);
        }
Exemple #8
0
 /// <summary>
 /// 在 web 系统中,记录 sql 执行的次数
 /// </summary>
 public static void LogSqlCount()
 {
     if (CurrentRequest.getItem(getSqlCountLabel()) == null)
     {
         CurrentRequest.setItem(getSqlCountLabel(), 1);
     }
     else
     {
         CurrentRequest.setItem(getSqlCountLabel(), ((int)CurrentRequest.getItem(getSqlCountLabel())) + 1);
     }
 }
Exemple #9
0
        //------------------------------------------------------------------------------

        /// <summary>
        /// 获取所有的数据库连接
        /// </summary>
        /// <returns></returns>
        public static Dictionary <String, IDbConnection> getConnectionAll()
        {
            Dictionary <String, IDbConnection> dic;

            dic = CurrentRequest.getItem(_connectionKey) as Dictionary <String, IDbConnection>;
            if (dic == null)
            {
                dic = new Dictionary <String, IDbConnection>();
                CurrentRequest.setItem(_connectionKey, dic);
            }
            return(dic);
        }
Exemple #10
0
        private static Dictionary <String, IDbTransaction> getTransactionAll()
        {
            Dictionary <String, IDbTransaction> dic;

            dic = CurrentRequest.getItem(_transactionKey) as Dictionary <String, IDbTransaction>;
            if (dic == null)
            {
                dic = new Dictionary <String, IDbTransaction>();
                CurrentRequest.setItem(_transactionKey, dic);
            }
            return(dic);
        }
Exemple #11
0
        // 避免同一页面的多个验证码冲突
        private int getCount()
        {
            String CaptchaCountKey = "CaptchaCount";
            object objCount        = CurrentRequest.getItem(CaptchaCountKey);

            if (objCount == null)
            {
                objCount = 1;
                CurrentRequest.setItem(CaptchaCountKey, objCount);
                return(1);
            }

            return((int)objCount + 1);
        }
Exemple #12
0
        //--------------------------------------------------------------------

        /// <summary>
        /// 获取当前语言字符(比如 zh-cn,或 en-us)
        /// </summary>
        /// <returns></returns>
        public static String getLangString()
        {
            Object ret = CurrentRequest.getItem("__lang_name");

            if (ret == null)
            {
                String langCookie = CurrentRequest.getLangCookie();
                logger.Info("lang cookie: " + ret);
                ret = getLangNamePrivate(langCookie);
                CurrentRequest.setItem("__lang_name", ret);
            }

            return(ret.ToString());
        }
Exemple #13
0
        /// <summary>
        /// 将日志写入磁盘
        /// </summary>
        /// <param name="msg"></param>
        public static void WriteFile(ILogMsg msg)
        {
            if (!SystemInfo.IsWeb || LogConfig.Instance.InRealTime)
            {
                writeFilePrivate(msg);
                return;
            }
            StringBuilder sb = CurrentRequest.getItem("currentLogList") as StringBuilder;

            if (sb == null)
            {
                sb = new StringBuilder();
                CurrentRequest.setItem("currentLogList", sb);
            }
            sb.AppendFormat("{0} {1} {2} - {3} \r\n", msg.LogTime, msg.LogLevel, msg.TypeName, msg.Message);
        }
Exemple #14
0
        /// <summary>
        /// 将日志写入磁盘
        /// </summary>
        /// <param name="msg"></param>
        public static void WriteFile(ILogMsg msg)
        {
            if (SystemInfo.IsWeb == false)
            {
                writeFilePrivate(msg);
                return;
            }

            StringBuilder sb = CurrentRequest.getItem(_contextLogItem) as StringBuilder;

            if (sb == null)
            {
                sb = new StringBuilder();
                CurrentRequest.setItem(_contextLogItem, sb);
            }

            sb.AppendFormat("{0} {1} {2} - {3} \r\n", msg.LogTime, msg.LogLevel, msg.TypeName, msg.Message);
        }
Exemple #15
0
        private static void setConnection(String key, IDbConnection cn)
        {
            Dictionary <String, IDbConnection> dic;

            dic = CurrentRequest.getItem(_connectionKey) as Dictionary <String, IDbConnection>;
            if (dic == null)
            {
                dic = new Dictionary <String, IDbConnection>();
            }
            if (dic.ContainsKey(key))
            {
                dic[key] = cn;
            }
            else
            {
                dic.Add(key, cn);
            }
            CurrentRequest.setItem(_connectionKey, dic);
        }
Exemple #16
0
        private static void setTransaction(String key, IDbTransaction trans)
        {
            Dictionary <String, IDbTransaction> dic;

            dic = CurrentRequest.getItem(_transactionKey) as Dictionary <String, IDbTransaction>;
            if (dic == null)
            {
                dic = new Dictionary <String, IDbTransaction>();
            }
            if (dic.ContainsKey(key))
            {
                dic[key] = trans;
            }
            else
            {
                dic.Add(key, trans);
            }
            CurrentRequest.setItem(_transactionKey, dic);
        }
Exemple #17
0
        //-------------------------------- viewer ----------------------------------

        public void InitViewer(MvcContext ctx)
        {
            ctx.setCacheCondition(new CacheCondition());


            CurrentRequest.setItem("_user_factory", new UserFactory());

            User user = this.getViewer(ctx);

            if (user.Id == UserFactory.Guest.Id && ctx.web.UserIsLogin)
            {
                signOut(ctx);
                return;
            }
            else if (user.Status == MemberStatus.Deleted || user.Status == MemberStatus.Approving)
            {
                signOut(ctx);
                return;
            }

            if (ctx.web.UserIsLogin)
            {
                loginService.UpdateLastLogin(user, ctx.Ip);
            }

            ViewerContext context = new ViewerContext();

            context.Id      = user.Id;
            context.obj     = user;
            context.IsLogin = ctx.web.UserIsLogin;
            ctx.utils.setViewerContext(context);

            // 编辑器
            if (context.IsLogin)
            {
                Link lnk = new Link(ctx);
                ctx.SetItem("editorUploadUrl", lnk.To(user, "Users/Admin/UserUpload", "UploadForm", -1, -1));
                ctx.SetItem("editorMyPicsUrl", lnk.To(user, "Users/Admin/UserUpload", "MyPics", -1, -1));
            }
        }
Exemple #18
0
 public void SetItem(String key, object obj)
 {
     CurrentRequest.setItem(key, obj);
 }
Exemple #19
0
        //------------------------------------------------------------------------------

        public static void beginAndMarkTransactionAll()
        {
            CurrentRequest.setItem(_beginTransactionAll, true);   // 如果当前没有打开的数据库连接,则打上标记,等真正打开的时候启用事务
            beginTransactionAll();
        }