Beispiel #1
0
        /// <summary>
        /// 获取自带头像列表
        /// </summary>
        /// <returns>自带头像列表</returns>
        public static DataTable GetAvatarList()
        {
            Discuz.Cache.DNTCache cache = Discuz.Cache.DNTCache.GetCacheService();
            DataTable             dt    = cache.RetrieveObject("/CommonAvatarList") as DataTable;

            if (dt != null)
            {
                return(dt);
            }

            dt = new DataTable();
            dt.Columns.Add("filename", Type.GetType("System.String"));

            DirectoryInfo dirinfo = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory + "avatars/common/");
            string        extname = "";

            foreach (FileSystemInfo file in dirinfo.GetFileSystemInfos())
            {
                if (file != null)
                {
                    extname = file.Extension.ToLower();
                    if (extname.Equals(".jpg") || extname.Equals(".gif") || extname.Equals(".png"))
                    {
                        DataRow dr = dt.NewRow();
                        dr["filename"] = @"avatars/common/" + file.Name;
                        dt.Rows.Add(dr);
                    }
                }
            }
            cache.AddObject("/CommonAvatarList", dt);
            return(dt);
        }
Beispiel #2
0
        public static Discuz.Common.Generic.SortedList <int, object> GetTopicTypeArray()
#endif
        {
            Discuz.Cache.DNTCache cache = Discuz.Cache.DNTCache.GetCacheService();
#if NET1
            System.Collections.SortedList topictypeList;
#else
            Discuz.Common.Generic.SortedList <int, object> topictypeList;
#endif
            topictypeList = cache.RetrieveObject("/TopicTypes") as Discuz.Common.Generic.SortedList <int, object>;

            if (topictypeList == null)
            {
#if NET1
                topictypeList = new System.Collections.SortedList();
#else
                topictypeList = new Discuz.Common.Generic.SortedList <int, object>();
#endif
                DataTable dt = DatabaseProvider.GetInstance().GetTopicTypeList();
                if (dt.Rows.Count > 0)
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        if ((dr["typeid"].ToString() != "") && (dr["name"].ToString() != ""))
                        {
                            topictypeList.Add(Int32.Parse(dr["typeid"].ToString()), dr["name"]);
                        }
                    }
                }

                cache.AddObject("/TopicTypes", topictypeList);
            }
            return(topictypeList);
        }
Beispiel #3
0
        /// <summary>
        /// 返回脏字过滤列表
        /// </summary>
        /// <returns>返回脏字过滤列表数组</returns>
        public static string[,] GetBanWordList()
        {
            Discuz.Cache.DNTCache cache = Discuz.Cache.DNTCache.GetCacheService();
            string[,] str = cache.RetrieveObject("/BanWordList") as string[, ];
            if (str != null)
            {
                return(str);
            }

            DataTable dt = DatabaseProvider.GetInstance().GetBanWordList();

            str = new string[dt.Rows.Count, 2];
            string temp = "";

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                temp = dt.Rows[i]["find"].ToString().Trim();
                foreach (Match m in r.Matches(temp))
                {
                    temp = temp.Replace(m.Groups[0].ToString(), m.Groups[0].ToString().Replace("{", ".{0,"));
                }
                str[i, 0] = temp.Replace("\\", "\\\\").Replace("\"", "\\\"").Replace("'", "\'").Replace("[", "\\[").Replace("]", "\\]");
                str[i, 1] = dt.Rows[i]["replacement"].ToString().Trim();
            }
            cache.AddObject("/BanWordList", str);
            dt.Dispose();
            return(str);
        }
Beispiel #4
0
        /// <summary>
        /// 获得在线用户列表图例
        /// </summary>
        /// <returns>在线用户列表图例</returns>
        public static string GetOnlineGroupIconList()
        {
            Discuz.Cache.DNTCache cache = Discuz.Cache.DNTCache.GetCacheService();
            string str = cache.RetrieveObject("/UI/OnlineIconList") as string;

            if (str != null && str != "")
            {
                return(str);
            }

            StringBuilder sb = new StringBuilder();
            IDataReader   dr = DatabaseProvider.GetInstance().GetOnlineGroupIconList();

            try
            {
                while (dr.Read())
                {
                    sb.Append("<img src=\"images/groupicons/");
                    sb.Append(dr["img"].ToString());
                    sb.Append("\" /> ");
                    sb.Append(dr["title"].ToString());
                    sb.Append(" &nbsp; &nbsp; &nbsp; ");
                }
                cache.AddObject("/UI/OnlineIconList", sb.ToString());
            }
            finally
            {
                dr.Close();
            }
            return(sb.ToString());
        }
Beispiel #5
0
        /// <summary>
        /// 获得版块下拉列表
        /// </summary>
        /// <returns>列表内容的html</returns>
        public static string GetForumListBoxOptionsCache()
        {
            Discuz.Cache.DNTCache cache = Discuz.Cache.DNTCache.GetCacheService();
            string str = cache.RetrieveObject("/UI/ForumListBoxOptions") as string;

            if (str != null)
            {
                return(str);
            }

            StringBuilder sb = new StringBuilder();
            IDataReader   dr = DatabaseProvider.GetInstance().GetVisibleForumList();

            try
            {
                while (dr.Read())
                {
                    sb.Append("<option value=\"");
                    sb.Append(dr["fid"].ToString());
                    sb.Append("\">");
                    sb.Append(Utils.GetSpacesString(Utils.StrToInt(dr["layer"].ToString(), 0)));
                    sb.Append(dr["name"].ToString().Trim());
                    sb.Append("</option>");
                }

                cache.AddObject("/UI/ForumListBoxOptions", sb.ToString());
                return(sb.ToString());
            }
            finally
            {
                dr.Close();
            }
        }
Beispiel #6
0
        /// <summary>
        /// 返回模板列表的下拉框html
        ///</summary>
        /// <returns>下拉框html</returns>
        public static string GetTemplateListBoxOptionsCache()
        {
            lock (lockHelper)
            {
                Discuz.Cache.DNTCache cache = Discuz.Cache.DNTCache.GetCacheService();
                string str = cache.RetrieveObject("/UI/TemplateListBoxOptions") as string;
                if (str != null)
                {
                    return(str);
                }

                StringBuilder sb = new StringBuilder();
                DataTable     dt = Templates.GetValidTemplateList();
                foreach (DataRow dr in dt.Rows)
                {
                    sb.Append("<li class=\"current\">");
                    sb.Append("<a href=\"###\" onclick=\"window.location.href='showtemplate.aspx?templateid=");
                    sb.Append(dr["templateid"].ToString());
                    sb.Append("'\">");
                    sb.Append(dr["name"].ToString().Trim());
                    sb.Append("</a>");
                    sb.Append("</li>");
                }
                cache.AddObject("/UI/TemplateListBoxOptions", sb.ToString());

                dt.Dispose();
                return(sb.ToString());
            }
        }
Beispiel #7
0
        /// <summary>
        /// 获得帖子列表
        /// </summary>
        /// <param name="count">数量</param>
        /// <param name="views">最小浏览量</param>
        /// <param name="fid">板块ID</param>
        /// <param name="timetype">期限类型,一天、一周、一月、不限制</param>
        /// <param name="ordertype">排序类型,时间倒序、浏览量倒序、最后回复倒序</param>
        /// <param name="isdigest">是否精华</param>
        /// <param name="cachetime">缓存的有效期(单位:分钟)</param>
        /// <returns></returns>
        public static DataTable GetTopicList(int count, int fid, TopicOrderType ordertype, bool digest, int cachetime, bool onlyimg, string fidlist, int tabid, TopicTimeType timetype)
        {
            //防止恶意行为
            cachetime = cachetime == 0 ? 1 : cachetime;
            count     = count > 50 ? 50 : (count < 1 ? 1 : count);

            Discuz.Cache.DNTCache cache = Discuz.Cache.DNTCache.GetCacheService();
            DataTable             dt    = cache.RetrieveObject("/Forum/ForumHostList-" + tabid) as DataTable;

            if (dt == null)
            {
                if (fidlist == "")
                {
                    fidlist = Forums.GetVisibleForum();
                }

                if (Focuses.GetFieldName(ordertype) == "digest")
                {
                    digest = true;
                }

                dt = Discuz.Data.Topics.GetTopicList(count, -1, fid, "", Focuses.GetStartDate(timetype), Focuses.GetFieldName(ordertype), fidlist, digest, onlyimg);

                cache.AddObject("/Forum/ForumHostList-" + tabid, dt, cachetime);
            }
            return(dt);
        }
Beispiel #8
0
        /// <summary>
        /// 获得勋章列表
        /// </summary>
        /// <returns>获得勋章列表</returns>
        public static DataTable GetMedalsList()
        {
            Discuz.Cache.DNTCache cache = Discuz.Cache.DNTCache.GetCacheService();
            DataTable             dt    = cache.RetrieveObject("/UI/MedalsList") as DataTable;

            if (dt != null)
            {
                return(dt);
            }

            dt = DatabaseProvider.GetInstance().GetMedalsList();
            string forumpath = BaseConfigs.GetBaseConfig().Forumpath;

            foreach (DataRow dr in dt.Rows)
            {
                if (dr["available"].ToString() == "1")
                {
                    if (dr["image"].ToString().Trim() != "")
                    {
                        dr["image"] = "<img border=\"0\" src=\"" + forumpath + "images/medals/" + dr["image"] + "\" alt=\"" + dr["name"] + "\" title=\"" + dr["name"] + "\" class=\"medals\" />";
                    }
                    else
                    {
                        dr["image"] = "";
                    }
                }
                else
                {
                    dr["image"] = "";
                }
            }

            cache.AddObject("/UI/MedalsList", dt);
            return(dt);
        }
Beispiel #9
0
        /// <summary>
        /// 获得友情链接列表
        /// </summary>
        /// <returns>友情链接列表</returns>
        public static DataTable GetForumLinkList()
        {
            Discuz.Cache.DNTCache cache = Discuz.Cache.DNTCache.GetCacheService();
            DataTable             dt    = cache.RetrieveObject("/ForumLinkList") as DataTable;

            if (dt != null)
            {
                return(dt);
            }

            dt = DatabaseProvider.GetInstance().GetForumLinkList();
            if (dt != null && dt.Rows.Count > 0)
            {
                StringBuilder sb = new StringBuilder();
                foreach (DataRow dr in dt.Rows)
                {
                    if (dr["note"].ToString().Equals(""))
                    {
                        if (dr["name"].ToString().Equals(""))
                        {
                            dr["name"] = "未知";
                        }
                        sb.Append("<a title=\"");
                        sb.Append(dr["name"].ToString());
                        sb.Append("\" href=\"");
                        sb.Append(dr["url"].ToString());
                        sb.Append("\" target=\"_blank\">");

                        if (dr["logo"].ToString().Equals(""))
                        {
                            sb.Append(dr["name"].ToString());
                        }
                        else
                        {
                            sb.Append("<img alt=\"");
                            sb.Append(dr["name"].ToString());
                            sb.Append("\" class=\"friendlinkimg\" src=\"");
                            sb.Append(dr["logo"].ToString());
                            sb.Append("\" />");
                        }
                        sb.Append("</a>\r\n");

                        dr.Delete();
                    }
                }
                if (sb.Length > 0)
                {
                    DataRow dr = dt.NewRow();
                    dr["name"] = "$$otherlink$$";
                    dr["url"]  = "";
                    dr["note"] = sb.ToString();
                    dr["logo"] = "";
                    dt.Rows.Add(dr);
                }
                dt.AcceptChanges();
            }
            cache.AddObject("/ForumLinkList", dt);
            return(dt);
        }
Beispiel #10
0
 private static void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
 {
     if (!applyMemCached)
     {
         //检查并移除相应的缓存项
         instance = CachesFileMonitor.CheckAndRemoveCache(instance);
     }
 }
Beispiel #11
0
        /// <summary>
        /// 获取一个帖子的缓存
        /// </summary>
        /// <param name="tid">帖子ID</param>
        /// <param name="cachetime">缓存的有效期</param>
        /// <returns></returns>
        public static DataTable GetFirstPostInfo(int tid, int cachetime)
        {
            Discuz.Cache.DNTCache cache = Discuz.Cache.DNTCache.GetCacheService();
            DataTable             dt    = cache.RetrieveObject("/Forum/HotForumFirst_" + tid) as DataTable;

            if (dt == null)
            {
                dt = Posts.GetPostList(tid.ToString());
                cache.AddObject("/Forum/HotForumFirst_" + tid, dt, cachetime);
            }
            return(dt);
        }
Beispiel #12
0
        /// <summary>
        /// 获得魔法表情列表
        /// </summary>
        /// <returns>魔法表情列表</returns>
        public static DataTable GetMagicList()
        {
            Discuz.Cache.DNTCache cache = Discuz.Cache.DNTCache.GetCacheService();
            DataTable             dt    = cache.RetrieveObject("/MagicList") as DataTable;

            if (dt == null || dt.Rows.Count == 0)
            {
                dt = DatabaseProvider.GetInstance().GetMagicList();
                cache.AddObject("/MagicList", dt);
            }
            return(dt);
        }
Beispiel #13
0
        /// <summary>
        /// 获取一个帖子的缓存
        /// </summary>
        /// <param name="tid">帖子ID</param>
        /// <param name="cachetime">缓存的有效期</param>
        /// <returns></returns>
        public static List <PostInfo> GetFirstPostInfo(int tid, int cachetime)
        {
            Discuz.Cache.DNTCache cache = Discuz.Cache.DNTCache.GetCacheService();
            List <PostInfo>       list  = cache.RetrieveObject("/Forum/HotForumFirst_" + tid) as List <PostInfo>;

            if (list == null || list.Count == 0)
            {
                list = Posts.GetPostList(tid.ToString());
                cache.AddObject("/Forum/HotForumFirst_" + tid, list, cachetime);
            }
            return(list);
        }
Beispiel #14
0
        /// <summary>
        /// 获得表情分类列表
        /// </summary>
        /// <returns>表情分类列表</returns>
        public static DataTable GetSmilieTypesCache()
        {
            Discuz.Cache.DNTCache cache       = Discuz.Cache.DNTCache.GetCacheService();
            DataTable             smilietypes = cache.RetrieveObject("/UI/SmiliesTypeList") as DataTable;

            if (smilietypes == null || smilietypes.Rows.Count == 0)
            {
                smilietypes = Smilies.GetSmilieTypes();
                cache.AddObject("/UI/SmiliesTypeList", smilietypes);
            }

            return(smilietypes);
        }
Beispiel #15
0
        /// <summary>
        /// 获取热门图片
        /// </summary>
        /// <param name="topNumber">获取的数量</param>
        /// <param name="orderBy">排序方式</param>
        /// <param name="cachetime">缓存时间</param>
        /// <returns></returns>
        private static DataTable HotImages(int count, int cachetime, string orderby, int tabid, string fidlist, int continuous)
        {
            Discuz.Cache.DNTCache cache = Discuz.Cache.DNTCache.GetCacheService();

            DataTable imagelist = cache.RetrieveObject("/Aggregation/HotImages_" + tabid + "List") as DataTable;

            if (imagelist == null)
            {
                imagelist = Discuz.Data.DatabaseProvider.GetInstance().GetWebSiteAggHotImages(count, orderby, fidlist, continuous);
                cache.AddObject("/Aggregation/HotImages_" + tabid + "List", imagelist, cachetime);
            }
            return(imagelist);
        }
Beispiel #16
0
 /// <summary>
 /// 单体模式返回当前类的实例
 /// </summary>
 /// <returns></returns>
 public static DNTCache GetCacheService()
 {
     if (instance == null)
     {
         lock (lockHelper)
         {
             if (instance == null)
             {
                 instance = new DNTCache();
             }
         }
     }
     return(instance);
 }
Beispiel #17
0
        /// <summary>
        /// 获取主题鉴定图片地址缓存数组
        /// </summary>
        /// <returns>主题鉴定图片地址缓存数组</returns>
        public static string GetTopicIdentifyFileNameJsArray()
        {
            Discuz.Cache.DNTCache cache = Discuz.Cache.DNTCache.GetCacheService();

            string jsArray = cache.RetrieveObject("/TopicIndentifysJsArray") as string;

            if (Utils.StrIsNullOrEmpty(jsArray))
            {
                GetTopicIdentifyCollection();
            }

            jsArray = cache.RetrieveObject("/TopicIndentifysJsArray") as string;

            return(jsArray);
        }
Beispiel #18
0
        /// <summary>
        /// 单体模式返回当前类的实例
        /// </summary>
        /// <returns></returns>
        public static DNTCache GetCacheService()
        {
            if (instance == null)
            {
                lock (lockHelper)
                {
                    if (instance == null)
                    {
                        instance = CachesFileMonitor.CheckAndRemoveCache(new DNTCache());
                    }
                }
            }

            return(instance);
        }
Beispiel #19
0
        /// <summary>
        /// 单体模式返回当前类的实例
        /// </summary>
        /// <returns></returns>
        public static DNTCache GetCacheService()
        {

            if (instance == null)
            {
                lock (lockHelper)
                {
                    if (instance == null)
                    {
                        instance = CachesFileMonitor.CheckAndRemoveCache(new DNTCache());
                    }
                }
            }

            return instance;
        }
Beispiel #20
0
        /// <summary>
        /// 检查和移除缓存
        /// </summary>
        /// <param name="instance"></param>
        /// <returns></returns>
        public static DNTCache CheckAndRemoveCache(DNTCache instance)//
        {
            //当程序运行中cache.config发生变化时则对缓存对象做删除的操作
            cachefilenewchange = System.IO.File.GetLastWriteTime(path);
            if (cachefileoldchange != cachefilenewchange)
            {
                lock (cachelockHelper)
                {
                    if (cachefileoldchange != cachefilenewchange)
                    {
                        //当有要清除的项时
                        DataSet dsSrc = new DataSet();
                        //dsSrc.ReadXml(path);

                        dsSrc = GetDataset();

                        foreach (DataRow dr in dsSrc.Tables[0].Rows)
                        {
                            if (dr["xpath"].ToString().Trim() != "")
                            {
                                DateTime removedatetime = DateTime.Now;
                                try
                                {
                                    removedatetime = Convert.ToDateTime(dr["removedatetime"].ToString().Trim());
                                }
                                catch
                                {
                                    ;
                                }

                                if (removedatetime > cachefilenewchange.AddSeconds(-2))
                                {
                                    string xpath = dr["xpath"].ToString().Trim();
                                    instance.RemoveObject(xpath, false);
                                }
                            }
                        }

                        cachefileoldchange = cachefilenewchange;

                        dsSrc.Dispose();
                    }
                }
            }
            return(instance);
        }
Beispiel #21
0
        /// <summary>
        /// 获得编辑器自定义按钮信息的javascript数组
        /// </summary>
        /// <returns>表情符的javascript数组</returns>
        public static string GetCustomEditButtonList()
        {
            Discuz.Cache.DNTCache cache = Discuz.Cache.DNTCache.GetCacheService();
            string str = cache.RetrieveObject("/UI/CustomEditButtonList") as string;

            if (str != null)
            {
                return(str);
            }

            StringBuilder sb = new StringBuilder();
            IDataReader   dr = Editors.GetCustomEditButtonList();

            try
            {
                while (dr.Read())
                {
                    //说明:[标签名,对应图标文件名,[参数1描述,参数2描述,...],[参数1默认值,参数2默认值,...]]
                    //实例["fly","swf.gif",["请输入flash网址","请输入flash宽度","请输入flash高度"],["http://","200","200"],3]
                    sb.AppendFormat(",'{0}':['", Utils.ReplaceStrToScript(dr["tag"].ToString()));
                    sb.Append(Utils.ReplaceStrToScript(dr["tag"].ToString()));
                    sb.Append("','");
                    sb.Append(Utils.ReplaceStrToScript(dr["icon"].ToString()));
                    sb.Append("','");
                    sb.Append(Utils.ReplaceStrToScript(dr["explanation"].ToString()));
                    sb.Append("',['");
                    sb.Append(Utils.ReplaceStrToScript(dr["paramsdescript"].ToString()).Replace(",", "','"));
                    sb.Append("'],['");
                    sb.Append(Utils.ReplaceStrToScript(dr["paramsdefvalue"].ToString()).Replace(",", "','"));
                    sb.Append("'],");
                    sb.Append(Utils.ReplaceStrToScript(dr["params"].ToString()));
                    sb.Append("]");
                }
                if (sb.Length > 0)
                {
                    sb.Remove(0, 1);
                }
                cache.AddObject("/UI/CustomEditButtonList", Utils.ClearBR(sb.ToString()));
                return(Utils.ClearBR(sb.ToString()));
            }
            finally
            {
                dr.Close();
            }
        }
Beispiel #22
0
        /// <summary>
        /// 获得表情符的json数据
        /// </summary>
        /// <returns>表情符的json数据</returns>
        public static string GetSmiliesCache()
        {
            Discuz.Cache.DNTCache cache = Discuz.Cache.DNTCache.GetCacheService();
            string str = cache.RetrieveObject("/UI/SmiliesList") as string;

            if (str != null)
            {
                return(str);
            }

            StringBuilder builder = new StringBuilder();
            DataTable     dt      = Smilies.GetSmiliesListDataTable();

            foreach (DataRow drCate in dt.Copy().Rows)
            {
                if (drCate["type"].ToString() == "0")
                {
                    builder.AppendFormat("'{0}': [\r\n", drCate["code"].ToString().Trim().Replace("'", "\\'"));
                    bool flag = false;
                    foreach (DataRow dr in dt.Rows)
                    {
                        if (dr["type"].ToString() == drCate["id"].ToString())
                        {
                            builder.Append("{'code' : '");
                            builder.Append(dr["code"].ToString().Trim().Replace("'", "\\'"));
                            builder.Append("', 'url' : '");
                            builder.Append(dr["url"].ToString().Trim().Replace("'", "\\'"));
                            builder.Append("'},\r\n");
                            flag = true;
                        }
                    }
                    if (builder.Length > 0 && flag)
                    {
                        builder.Remove(builder.Length - 3, 3);
                    }
                    builder.Append("\r\n],\r\n");
                }
            }
            builder.Remove(builder.Length - 3, 3);

            cache.AddObject("/UI/SmiliesList", builder.ToString());
            return(builder.ToString());
        }
Beispiel #23
0
        /// <summary>
        /// 获得干扰码字符串
        /// </summary>
        /// <returns>干扰码字符串</returns>
        public static string GetJammer()
        {
            ///干扰码组成(10 位随机字符 + 网站域名 + 10位随机字符)
            Discuz.Cache.DNTCache cache = Discuz.Cache.DNTCache.GetCacheService();
            string str = cache.RetrieveObject("/UI/Jammer") as string;

            if (str == null)
            {
                Random        rdm1 = new Random(unchecked ((int)DateTime.Now.Ticks));
                StringBuilder sb   = new StringBuilder();
                for (int i = 0; i < 10; i++)
                {
                    sb.Append(Convert.ToChar(rdm1.Next(1, 256)));
                }
                sb.Append(HttpContext.Current.Request.Url.Authority);
                for (int i = 0; i < 10; i++)
                {
                    sb.Append(Convert.ToChar(rdm1.Next(1, 256)));
                }
                str = sb.ToString();
                str = Utils.HtmlEncode(str);

                if (sb.Length > 0)
                {
                    sb.Remove(0, sb.Length);
                }

                sb.Append("<span style=\"display:none;font-size:0px\">");
                sb.Append(str);
                sb.Append("</span>");
                str = sb.ToString();
                Discuz.Cache.ICacheStrategy ics = new ForumCacheStrategy();
                ics.TimeOut = 720;
                cache.LoadCacheStrategy(ics);
                cache.AddObject("/UI/Jammer", str);
                cache.LoadDefaultCacheStrategy();

                //cache.AddObject("/UI/Jammer", str);
            }

            return(str);
        }
Beispiel #24
0
        /// <summary>
        /// 获取热门用户
        /// </summary>
        /// <param name="topNumber">获取的数量</param>
        /// <param name="orderBy">排序方式</param>
        /// <param name="cachetime">缓存时间</param>
        /// <returns></returns>
        public static ShortUserInfo[] GetUserList(int topNumber, string orderBy, int cachetime, int tabid)
        {
            Discuz.Cache.DNTCache cache = Discuz.Cache.DNTCache.GetCacheService();

            ShortUserInfo[] userList = cache.RetrieveObject("/Aggregation/Users_" + tabid + "List") as ShortUserInfo[];
            if (userList == null)
            {
                if (Utils.InArray(orderBy, "lastactivity,joindate"))
                {
                    List <ShortUserInfo> list = new List <ShortUserInfo>();
                    DataTable            dt   = Users.GetUserList(topNumber, 1, orderBy, "desc");
                    foreach (DataRow dr in dt.Rows)
                    {
                        ShortUserInfo info = new ShortUserInfo();
                        info.Uid          = TypeConverter.ObjectToInt(dr["uid"]);
                        info.Username     = dr["username"].ToString();
                        info.Lastactivity = dr["lastactivity"].ToString();
                        info.Joindate     = dr["joindate"].ToString();
                        list.Add(info);
                    }
                    userList = list.ToArray();
                }
                else
                {
                    userList = Stats.GetUserArray(orderBy);
                    if (userList.Length > topNumber)
                    {
                        List <ShortUserInfo> list = new List <ShortUserInfo>();
                        for (int i = 0; i < topNumber; i++)
                        {
                            list.Add(userList[i]);
                        }

                        userList = list.ToArray();
                    }
                }
                cache.AddObject("/Aggregation/Users_" + tabid + "List", userList, cachetime);
            }
            return(userList);
        }
Beispiel #25
0
        /// <summary>
        /// 获取热门板块
        /// </summary>
        /// <param name="topNumber">获取的数量</param>
        /// <param name="orderby">排序方式</param>
        /// <param name="fid">板块ID</param>
        /// <param name="cachetime">缓存时间</param>
        /// <returns></returns>
        public static List <ForumInfo> GetHotForumList(int topNumber, string orderby, int cachetime, int tabid)
        {
            Discuz.Cache.DNTCache cache     = Discuz.Cache.DNTCache.GetCacheService();
            List <ForumInfo>      forumList = cache.RetrieveObject("/Aggregation/HotForumList_" + tabid) as List <ForumInfo>;

            if (forumList == null)
            {
                forumList = Stats.GetForumArray(orderby);
                if (forumList.Count > topNumber)
                {
                    List <ForumInfo> list = new List <ForumInfo>();
                    for (int i = 0; i < topNumber; i++)
                    {
                        list.Add(forumList[i]);
                    }

                    forumList = list;
                }
                cache.AddObject("/Aggregation/HotForumList" + tabid, forumList, cachetime);
            }
            return(forumList);
        }
Beispiel #26
0
        public static Discuz.Common.Generic.List <TopicIdentify> GetTopicIdentifyCollection()
#endif
        {
            Discuz.Cache.DNTCache cache = Discuz.Cache.DNTCache.GetCacheService();

#if NET1
            TopicIdentifyCollection topicidentifyList = cache.RetrieveObject("/TopicIdentifys") as TopicIdentifyCollection;
#else
            Discuz.Common.Generic.List <TopicIdentify> topicidentifyList = cache.RetrieveObject("/TopicIdentifys") as Discuz.Common.Generic.List <TopicIdentify>;
#endif
            if (topicidentifyList == null)
            {
#if NET1
                topicidentifyList = new TopicIdentifyCollection();
#else
                topicidentifyList = new Discuz.Common.Generic.List <TopicIdentify>();
#endif
                IDataReader   reader  = DatabaseProvider.GetInstance().GetTopicsIdentifyItem();
                StringBuilder jsArray = new StringBuilder("<script type='text/javascript'>var topicidentify = { ");

                while (reader.Read())
                {
                    TopicIdentify topic = new TopicIdentify();
                    topic.Identifyid = Int32.Parse(reader["identifyid"].ToString());
                    topic.Name       = reader["name"].ToString();
                    topic.Filename   = reader["filename"].ToString();

                    topicidentifyList.Add(topic);
                    jsArray.AppendFormat("'{0}':'{1}',", reader["identifyid"].ToString(), reader["filename"].ToString());
                }
                reader.Close();
                jsArray.Remove(jsArray.Length - 1, 1);
                jsArray.Append("};</script>");
                cache.AddObject("/TopicIdentifys", topicidentifyList);
                cache.AddObject("/TopicIndentifysJsArray", jsArray.ToString());
            }

            return(topicidentifyList);
        }
Beispiel #27
0
        /// <summary>
        /// 获得图片的RSS
        /// </summary>
        /// <param name="ttl">Time To Live</param>
        /// <returns></returns>
        public static string GetPhotoRss(int ttl)
        {
            Discuz.Cache.DNTCache cache = Discuz.Cache.DNTCache.GetCacheService();

            //Discuz.Cache.ICacheStrategy ics = new RssCacheStrategy();
            //ics.TimeOut = ttl * 60;
            //cache.LoadCacheStrategy(ics);

            string str = cache.RetrieveObject("/PHOTO/RSS/Index") as string;

            if (str != null)
            {
                return(str);
            }

            string      forumurl = "http://" + DNTRequest.GetCurrentFullHost() + BaseConfigs.GetForumPath.ToLower();
            IDataReader reader   = DbProvider.GetInstance().GetFocusPhotoList(2, 20, 100);

            if (reader == null)
            {
                return("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<Rss>Specified photos not found</Rss>\r\n");
            }

            StringBuilder rssBuilder = new StringBuilder("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\r\n");

            rssBuilder.Append("<?xml-stylesheet type=\"text/xsl\" href=\"rss.xsl\" media=\"screen\"?>\r\n");
            rssBuilder.Append("<rss version=\"2.0\">\r\n");
            rssBuilder.Append("  <channel>\r\n");
            rssBuilder.Append("    <title>");
            rssBuilder.Append(Utils.HtmlEncode(GeneralConfigs.GetConfig().Forumtitle));
            rssBuilder.Append(" - ");
            rssBuilder.Append("最新照片");
            rssBuilder.Append("</title>\r\n");
            rssBuilder.Append("    <link>");
            rssBuilder.Append(forumurl);
            rssBuilder.Append("spaceindex.aspx");
            rssBuilder.Append("</link>\r\n");
            rssBuilder.AppendFormat("    <description>Latest 20 photos</description>\r\n");
            rssBuilder.Append("    <copyright>Copyright (c) ");
            rssBuilder.Append(Utils.HtmlEncode(GeneralConfigs.GetConfig().Forumtitle));
            rssBuilder.Append("</copyright>\r\n");
            rssBuilder.Append("    <generator>");
            rssBuilder.Append("Discuz!NT");
            rssBuilder.Append("</generator>\r\n");
            rssBuilder.Append("    <pubDate>");
            rssBuilder.Append(DateTime.Now.ToString("r"));
            rssBuilder.Append("</pubDate>\r\n");
            rssBuilder.AppendFormat("    <ttl>{0}</ttl>\r\n", ttl.ToString());
            while (reader.Read())
            {
                rssBuilder.Append("    <item>\r\n");
                rssBuilder.Append("      <title>");
                rssBuilder.Append(Utils.HtmlEncode(reader["title"].ToString().Trim()));
                rssBuilder.Append("</title>\r\n");
                rssBuilder.Append("      <description><![CDATA[<img src=\"");
                rssBuilder.Append(Utils.HtmlEncode(forumurl));
                rssBuilder.Append(reader["filename"].ToString().Trim());
                rssBuilder.Append("\"/>]]></description>\r\n");
                rssBuilder.Append("      <link>");
                rssBuilder.Append(Utils.HtmlEncode(forumurl));
                rssBuilder.Append("showphoto.aspx?photoid=");
                rssBuilder.Append(reader["photoid"].ToString());
                rssBuilder.Append("</link>\r\n");
                rssBuilder.Append("      <category>");
                rssBuilder.Append("</category>\r\n");
                rssBuilder.Append("      <author>");
                rssBuilder.Append(Utils.HtmlEncode(reader["username"].ToString().Trim()));
                rssBuilder.Append("</author>\r\n");
                rssBuilder.Append("      <pubDate>");
                rssBuilder.Append(Utils.HtmlEncode(Convert.ToDateTime(reader["postdate"]).ToString("r").Trim()));
                rssBuilder.Append("</pubDate>\r\n");
                rssBuilder.Append("    </item>\r\n");
            }
            reader.Close();
            rssBuilder.Append("  </channel>\r\n");
            rssBuilder.Append("</rss>");

            cache.AddObject("/PHOTO/RSS/Index", rssBuilder.ToString(), ttl * 60);
            //cache.LoadDefaultCacheStrategy();

            return(rssBuilder.ToString());
        }
Beispiel #28
0
        /// <summary>
        /// 检查和移除缓存
        /// </summary>
        /// <param name="instance"></param>
        /// <returns></returns>
        public static DNTCache CheckAndRemoveCache(DNTCache instance)//
        {
            //当程序运行中cache.config发生变化时则对缓存对象做删除的操作
            cachefilenewchange = System.IO.File.GetLastWriteTime(path);
            if (cachefileoldchange != cachefilenewchange)
            {
                lock (cachelockHelper)
                {
                    if (cachefileoldchange != cachefilenewchange)
                    {
                        //当有要清除的项时
                        DataSet dsSrc = new DataSet();
                        dsSrc.ReadXml(path);
                        foreach (DataRow dr in dsSrc.Tables[0].Rows)
                        {
                            if (dr["xpath"].ToString().Trim() != "")
                            {
                                DateTime removedatetime = DateTime.Now;
                                try
                                {
                                    removedatetime = Convert.ToDateTime(dr["removedatetime"].ToString().Trim());
                                }
                                catch
                                {
                                    ;
                                }

                                if (removedatetime > cachefilenewchange.AddSeconds(-2))
                                {
                                    string xpath = dr["xpath"].ToString().Trim();
                                    instance.RemoveObject(xpath, false);
                                }
                            }
                        }
                        cachefileoldchange = cachefilenewchange;
                        dsSrc.Dispose();
                    }
                }
            }
            return instance;
        }
Beispiel #29
0
 private static void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
 {
     //检查并移除相应的缓存项
     instance = CachesFileMonitor.CheckAndRemoveCache(instance);
 }
Beispiel #30
0
        /// <summary>
        /// 前台版块列表弹出菜单
        /// </summary>
        /// <param name="usergroupid">用户组id</param>
        /// <param name="userid">当前用户id</param>
        /// <param name="extname">扩展名称</param>
        /// <returns>版块列表弹出菜单</returns>
        public static string GetForumListMenuDivCache(int usergroupid, int userid, string extname)
        {
            Discuz.Cache.DNTCache cache = Discuz.Cache.DNTCache.GetCacheService();
            string str = cache.RetrieveObject("/ForumListMenuDiv") as string;

            if (str != null)
            {
                return(str);
            }

            StringBuilder sb = new StringBuilder();

            ForumInfo[] foruminfoarray = Forums.GetForumList();

            if (foruminfoarray.Length > 0)
            {
                sb.Append("<div class=\"popupmenu_popup\" id=\"forumlist_menu\" style=\"overflow-y: auto; display:none\">");

                foreach (ForumInfo info in foruminfoarray)
                {
                    if (info.Layer >= 0 && info.Layer <= 1 && info.Status == 1)
                    {
                        //判断是否为私密论坛
                        if (info.Viewperm != "" && !Utils.InArray(usergroupid.ToString(), info.Viewperm))
                        {
                            //
                        }
                        else
                        {
                            if (info.Layer == 0)
                            {
                                sb.Append("<dl>");
                                sb.Append("<dt>");
                                sb.Append("<a href=\"");
                                sb.Append(Urls.ShowForumAspxRewrite(info.Fid, 0));
                                sb.Append("\">");

                                sb.Append(info.Name);
                                sb.Append("</a></dt>");

                                sb.Append("<dd><ul>");
                                foreach (ForumInfo forum in foruminfoarray)
                                {
                                    if (int.Parse(forum.Parentidlist.Split(',')[0]) == info.Fid && forum.Layer == 1)
                                    {
                                        sb.Append("<li><a href=\"");
                                        sb.Append(Urls.ShowForumAspxRewrite(forum.Fid, 0));
                                        sb.Append("\">");
                                        sb.Append(forum.Name);
                                        sb.Append("</a></li>");
                                    }
                                }
                                sb.Append("</ul></dd>");
                                sb.Append("</dl>");
                            }
                        }
                    }
                }
            }
            sb.Append("</div>");
            str = sb.ToString().Replace("<dd><ul></ul></dd>", "");
            cache.AddObject("/ForumListMenuDiv", str);

            return(str);
        }
Beispiel #31
0
 /// <summary>
 /// 单体模式返回当前类的实例
 /// </summary>
 /// <returns></returns>
 public static DNTCache GetCacheService()
 {
     if (instance == null)
     {
         lock (lockHelper)
         {
             if (instance == null)
             {
                 instance = new DNTCache();
             }
         }
     }
     return instance;
 }