Ejemplo n.º 1
0
        /// <summary>
        /// 获得图片的RSS
        /// </summary>
        /// <param name="ttl">Time To Live</param>
        /// <returns></returns>
        public static string GetPhotoRss(int ttl)
        {
            SAS.Cache.SASCache cache = SAS.Cache.SASCache.GetCacheService();

            SAS.Cache.ICacheStrategy ics = new RssCacheStrategy();
            ics.TimeOut = ttl;
            cache.LoadCacheStrategy(ics);

            string str = cache.RetrieveObject("/PHOTO/RSS/Index") as string;
            if (str != null)
                return str;

            string forumurl = "http://" + SASRequest.GetCurrentFullHost() + BaseConfigs.GetSitePath.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().Sitetitle));
            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().Sitetitle));
            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());
            cache.LoadDefaultCacheStrategy();

            return rssBuilder.ToString();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 获得在线用户总数量
        /// </summary>
        /// <returns>用户数量</returns>
        public static int GetOnlineAllUserCount()
        {
            int onlineUserCountCacheMinute = GeneralConfigs.GetConfig().OnlineUserCountCacheMinute;
            if (onlineUserCountCacheMinute == 0)
                return SAS.Data.DataProvider.OnlineUsers.GetOnlineAllUserCount();

            SAS.Cache.SASCache cache = SAS.Cache.SASCache.GetCacheService();
            int onlineAllUserCount = TypeConverter.ObjectToInt(cache.RetrieveObject("/SAS/OnlineUserCount"));
            if (onlineAllUserCount != 0)
                return onlineAllUserCount;

            onlineAllUserCount = SAS.Data.DataProvider.OnlineUsers.GetOnlineAllUserCount();
            SAS.Cache.ICacheStrategy ics = new RssCacheStrategy();
            ics.TimeOut = onlineUserCountCacheMinute;
            cache.LoadCacheStrategy(ics);
            cache.AddObject("/SAS/OnlineUserCount", onlineAllUserCount);
            cache.LoadDefaultCacheStrategy();
            return onlineAllUserCount;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 获取Rssxml
        /// </summary>
        /// <param name="ttl"></param>
        public static string GetRssXML(int ttl)
        {
            SAS.Cache.SASCache cache = SAS.Cache.SASCache.GetCacheService();
            string rssContent = cache.RetrieveObject("/SAS/RSSXML") as string;

            if (rssContent == null)
            {
                StringBuilder rssBuilder = new StringBuilder("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\r\n");
                rssBuilder.Append("<rss version=\"2.0\" xmlns:content=\"http://purl.org/rss/1.0/modules/content/\">\r\n");
                rssBuilder.Append("  <channel>\r\n");
                rssBuilder.Append("    <title>浙商黄页:浙江企业检索及网络自助推广平台</title>\r\n");
                rssBuilder.AppendFormat("    <link>{0}</link>", config.Weburl);
                rssBuilder.Append("    <language>en</language>\r\n");
                rssBuilder.Append("    <docs>http://blogs.law.harvard.edu/tech/rss</docs>\r\n");
                rssBuilder.Append("    <generator>www.cnzshy.com</generator>\r\n");
                rssBuilder.Append("    <description>\r\n");
                rssBuilder.Append("      <![CDATA[ 浙商黄页 -- 浙商 网络名片 天狼星 自助推广 ]]>\r\n");
                rssBuilder.Append("    </description>\r\n");
                rssBuilder.AppendFormat("    <ttl>{0}</ttl>\r\n", ttl.ToString());

                int actdr__id = 1;
                foreach (DataRow actdr in SAS.Data.DataProvider.Activities.GetEnableActivities().Select("", "createdate desc"))
                {
                    if (actdr__id > 10) break;
                    rssBuilder.Append("    <item>\r\n");
                    rssBuilder.AppendFormat("      <link>{0}</link>\r\n", config.Weburl.EndsWith("/") ? config.Weburl + "activity-" + actdr["id"] + ".html" : config.Weburl + "/" + "activity-" + actdr["id"] + ".html");
                    rssBuilder.AppendFormat("      <title><![CDATA[ {0} ]]></title>\r\n", actdr["atitle"]);
                    rssBuilder.Append("    <author>浙商黄页</author>\r\n");
                    rssBuilder.Append("    <category>www.cnzshy.com浙商黄页宣传活动</category>\r\n");
                    rssBuilder.AppendFormat("    <guid>{0}</guid>\r\n", config.Weburl.EndsWith("/") ? config.Weburl + "activity-" + actdr["id"] + ".html" : config.Weburl + "/" + "activity-" + actdr["id"] + ".html");
                    rssBuilder.AppendFormat("    <pubDate>{0}</pubDate>\r\n", Utils.HtmlEncode(Convert.ToDateTime(actdr["createdate"]).ToString("r").Trim()));
                    rssBuilder.Append("    <description>\r\n");
                    rssBuilder.AppendFormat("      <![CDATA[ <a title=\"{0}\" href=\"activity-{1}.html\"><img style=\"border:0\" alt=\"{0}\" src=\"{2}\"/></a> ]]>\r\n", actdr["atitle"], actdr["id"], actdr["rssimg"]);
                    rssBuilder.Append("    </description>\r\n");
                    rssBuilder.Append("    </item>\r\n");
                }

                foreach (Companys cominfo in SAS.Data.DataProvider.Companies.GetCompanyListByOrder(20, "en_update", true))
                {
                    rssBuilder.Append("    <item>\r\n");
                    rssBuilder.AppendFormat("      <link>{0}</link>\r\n", config.Weburl.EndsWith("/") ? config.Weburl + "company-" + cominfo.En_id + ".html" : config.Weburl + "/" + "company-" + cominfo.En_id + ".html");
                    rssBuilder.AppendFormat("      <title><![CDATA[ {0} ]]></title>\r\n", cominfo.En_name);
                    rssBuilder.Append("    <author>浙商黄页</author>\r\n");
                    rssBuilder.Append("    <category>www.cnzshy.com浙商黄页企业信息</category>\r\n");
                    rssBuilder.AppendFormat("    <guid>{0}</guid>\r\n", config.Weburl.EndsWith("/") ? config.Weburl + "company-" + cominfo.En_id + ".html" : config.Weburl + "/" + "company-" + cominfo.En_id + ".html");
                    rssBuilder.AppendFormat("    <pubDate>{0}</pubDate>\r\n", Utils.HtmlEncode(Convert.ToDateTime(cominfo.En_update).ToString("r").Trim()));
                    rssBuilder.Append("    <description>\r\n");
                    rssBuilder.AppendFormat("      <![CDATA[ <p><a title=\"{0}\" href=\"{1}\"><img style=\"border:0\" alt=\"{0}\" src=\"{2}\"/></a></p>\r\n{3} ]]>\r\n", cominfo.En_name, config.Weburl.EndsWith("/") ? config.Weburl + "company-" + cominfo.En_id + ".html" : config.Weburl + "/" + "company-" + cominfo.En_id + ".html", config.Weburl.EndsWith("/") ? config.Weburl + "showcardimg_" + cominfo.En_id + ".html" : config.Weburl + "/showcardimg_" + cominfo.En_id + ".html", Utils.HtmlEncode(Utils.ClearUBB(cominfo.En_desc)).Trim());
                    rssBuilder.Append("    </description>\r\n");
                    rssBuilder.Append("    </item>\r\n");
                }
                rssBuilder.Append("  </channel>\r\n");
                rssBuilder.Append("</rss>\r\n");
                rssContent = rssBuilder.ToString();
                SAS.Cache.ICacheStrategy ics = new RssCacheStrategy();
                ics.TimeOut = ttl;
                cache.LoadCacheStrategy(ics);
                cache.AddObject("/SAS/RSSXML", rssContent);
                cache.LoadDefaultCacheStrategy();
            }
            return rssContent;
        }