Пример #1
0
        /// <summary>
        /// 开始采集
        /// </summary>
        /// <param name="folderid">目录名称</param>
        /// <param name="num">采集数量</param>
        public void Collecting(int folderid, int num, bool bnorepeat)
        {
            if (ShowProGressBar)
            {
                HProgressBar.Start("正在读取列表数据");
            }
            DataTable tb = GetSite(folderid);

            #region 检查数据是否完整
            if (tb == null || tb.Rows.Count < 1)
            {
                if (ShowProGressBar)
                {
                    HProgressBar.Roll("没有找到该站点的相关记录!", 0);
                }
                return;
            }
            DataRow r = tb.Rows[0];
            if (r.IsNull("LinkSetting") || r.IsNull("PageTitleSetting") || r.IsNull("PagebodySetting"))
            {
                if (ShowProGressBar)
                {
                    HProgressBar.Roll("相关的参数没有设置,无法取得新闻列表!", 0);
                }
                return;
            }
            if (bool.Parse(r["SaveRemotePic"].ToString()))
            {
                #region 远程图片
                string rtpath = NetCMS.Config.UIConfig.dirFile;
                if (rtpath == null || rtpath.Trim().Equals(""))
                {
                    if (ShowProGressBar)
                    {
                        HProgressBar.Roll("没有找到管理员附件目录!", 0);
                    }
                    return;
                }
                string dtpath = DateTime.Now.ToString("yyyyMMdd");
                PicSavePath = NetCMS.Common.ServerInfo.GetRootPath().TrimEnd('\\') + @"\" + rtpath + @"\RemoteFiles\" + dtpath;
                if (!Directory.Exists(PicSavePath))
                {
                    Directory.CreateDirectory(PicSavePath);
                }
                PicSaveUrl     = NetCMS.Publish.CommonData.getUrl() + "/" + rtpath + "/RemoteFiles/" + dtpath;
                bSaveRemotePic = true;
                #endregion
            }
            #endregion 检查数据是否完整
            if (ShowProGressBar)
            {
                HProgressBar.Roll("正在获取新闻列表页", 0);
            }

            string sListUrl = r["objURL"].ToString();
            string sEncode  = r["Encode"].ToString();
            bool   bReverse = bool.Parse(r["IsReverse"].ToString());
            string listset  = @"<body[^>]*>(?<list>[\s\S]+?)</body>";
            if (!r.IsNull("ListSetting"))
            {
                listset = r["ListSetting"].ToString();
            }
            PageList PL = new PageList(r["objURL"].ToString(), r["Encode"].ToString());
            PL.RuleOfList = listset;
            PL.RuleOfLink = r["LinkSetting"].ToString();
            string[] NewsUrl = GetNewsList(PL);
            if (NewsUrl == null)
            {
                if (ShowProGressBar)
                {
                    HProgressBar.Roll("没有找到相关新闻链接地址!", 0);
                }
                return;
            }
            int len = NewsUrl.Length;
            if (len < num)
            {
                int      pagetype = int.Parse(r["OtherType"].ToString());
                string[] otherurl = null;
                switch (pagetype)
                {
                case 0:
                    break;

                case 1:    //递归
                    otherurl = PL.Pagination(r["OtherPageSetting"].ToString(), num - len);
                    break;

                case 2:    //其他页
                    otherurl = PL.SinglePagination(r["OtherPageSetting"].ToString(), num - len);
                    break;

                case 3:    //索引页
                    otherurl = PL.IndexPagination(r["OtherPageSetting"].ToString(), int.Parse(r["StartPageNum"].ToString()), int.Parse(r["EndPageNum"].ToString()), num - len);
                    break;

                default:
                    break;
                }
                if (otherurl != null && otherurl.Length > 0)
                {
                    Array.Resize(ref NewsUrl, len + otherurl.Length);
                    otherurl.CopyTo(NewsUrl, len);
                }
            }
            if (NewsUrl.Length < 1)
            {
                if (ShowProGressBar)
                {
                    HProgressBar.Roll("从列表内容中没有找到任何新闻的相关链接!", 0);
                }
                return;
            }
            if (bReverse)
            {
                Array.Reverse(NewsUrl);
            }
            if (ShowProGressBar)
            {
                HProgressBar.Roll("开始采集新闻", 0);
            }
            int nSucceed = 0, nFailed = 0, nRepeat = 0;
            for (int i = 0; i < NewsUrl.Length; i++)
            {
                if (i >= num)
                {
                    break;
                }
                try
                {
                    int flag = CollectPage(NewsUrl[i], r, bnorepeat);
                    if (flag != 1)
                    {
                        nSucceed++;
                        if (flag == -1)
                        {
                            nRepeat++;
                        }
                    }
                    else
                    {
                        nFailed++;
                    }
                }
                catch
                {
                    nFailed++;
                }
                string prompt = "正在采集新闻,终止<a href=\"Collect_List.aspx\">返回</a>.成功:" + nSucceed * 100 / num + "% ";
                if (nRepeat > 0)
                {
                    prompt += "(其中重复:" + nRepeat * 100 / num + "%) ";
                }
                prompt += "失败:" + nFailed * 100 / num + "%";
                if (ShowProGressBar)
                {
                    HProgressBar.Roll(prompt, (i + 1) * 100 / num);
                }
            }
        }
        public void Execute()
        {
            if (Check())  //判断是否有发布条件
            {
                if (IsBar)
                {
                    HProgressBar.Start();  //进度条
                }
                #region 查询字段说明

                /*
                 *              a.NodeID, 栏目ID
                 *              a.NodeCode,栏目节点编码
                 *              a.ParentNode,栏目节点父编码
                 *              a.NodelDesc,栏目描述
                 *              a.CurrentImg,栏目图片
                 *              a.MouseOverImg,鼠标移到栏目显示的图片
                 *              a.NodeName,栏目名称
                 *              a.NodeType,是否父节点(1表示有子栏目,0 表示叶节点)
                 *              a.IsLeftDisplay,是否左边显示(后台)
                 *              a.NodelOrder,栏目排序
                 *                  a.NodelIcon,栏目图标
                 *                  a.WebSiteID,站点ID
                 *                  a.ColumnType,栏目类型(2=单页,1=模型)
                 *                  a.NodeDir,栏目目录
                 *                  a.ModuleID,模块ID,关联K_SysModule表
                 *                  CASE a.ColumnType WHEN 2 THEN 'K_SinglePage' ELSE b.TableName END AS TableName, 栏目对应的表,例如公司新闻的表是K_U_News
                 *                  a.linkUrl,自定义前台连接(静态路径)
                 *                  a.subdomain,前台程序连接例如:/cn/news/list.aspx
                 *                  a.IsTopMenuShow,前台头部是否显示
                 *                  a.IsLeftMenuShow,前台左边是否显示
                 *                  a.NodelEngDesc,栏目英文名称
                 *                  a.ContentTemplate,自定义内容页程序路径 例如 /cn/news/detail.aspx
                 *                  a.custommanagelink,栏目内容页保存路径
                 *                  a.IsCreateContentPage,内容页生成方式 1=ID文件命名,0=Title文件命名
                 */
                #endregion
                string menuSql = @"SELECT  a.NodeID,a.NodeCode,a.ParentNode,a.NodelDesc,a.CurrentImg,a.MouseOverImg,a.NodeName,a.NodeType,a.IsLeftDisplay,a.NodelOrder,
	                            a.NodelIcon,a.WebSiteID,a.ColumnType,
	                            a.NodeDir,a.ModuleID,
	                            CASE a.ColumnType WHEN 2 THEN 'K_SinglePage' ELSE b.TableName END AS TableName,
	                            a.linkUrl,a.subdomain,a.IsTopMenuShow,a.IsLeftMenuShow,a.NodelEngDesc,a.ContentTemplate,a.custommanagelink,a.IsCreateContentPage
	                            FROM K_SysModuleNode AS a Left JOIN K_SysModule AS b ON a.ModuleID=b.ModuleID 
                                Where a.IsValid=1 AND a.IsDel=0 And IsWeb =1 AND WebSiteID=" + siteID;
                if (!string.IsNullOrEmpty(nodeCodeList))
                {
                    menuSql += " AND a.NodeCode In(" + nodeCodeList + ")";
                }

                //获得栏目缓存数据
                DataTable dt = SQLHelper.GetDataSet(menuSql);

                CheckIsHtmlField(dt);

                if (IsBar)
                {
                    int countHtml = CreateHtmlCount(dt);
                    menuPercentage = 100 / (float)countHtml;
                }
                //生成首页
                if (IsIndex)
                {
                    if (IsBar)
                    {
                        finishedPercentage = finishedPercentage + menuPercentage;
                        //首页动态页面路径 /index.aspx或者/default.aspx;如果是其他语言版本,则为/en(站点目录)/index.aspx
                        HProgressBar.Roll("正在发布首页...", (int)finishedPercentage);
                    }
                    CreateHtmlByAspx("/" + siteDir + "/index.aspx", "/" + siteDir + "/index.html");
                }

                //生成栏目页
                if (IsMenuList)
                {
                    CreateMenuListHtml(dt);
                }

                //生成内容页
                if (IsContent)
                {
                    switch (PublishType)
                    {
                    case 1:
                        CreateContentByIDList(dt);
                        break;

                    case 2:
                        CreateContentByDate(dt);
                        break;

                    default:
                        CreateContent(dt);
                        break;
                    }
                }
            }
            if (IsBar)
            {
                if (finishedPercentage < 100)
                {
                    HProgressBar.Roll("", 100);
                }

                HProgressBar.Roll("发布完成。&nbsp;<a class=\"list_link\" href=\"javascript:location.href=\\'?NodeCode=" + NodeCode + "\\';\">返 回</a>", 100);
            }
        }