private string[] GetNewsList(PageList pagelist) { if (!pagelist.Fetch()) { HProgressBar.Roll(pagelist.LastError, 0); } pagelist.FigureList(); pagelist.FigureNewsUrls(); return(pagelist.NewsUrl); }
private bool CreateMenuListHtml(DataTable MenuDt) { for (int i = 0; i < ListMenu.Count; i++) { string nodeCode = ListMenu[i].ToString(); DataRow[] dr = MenuDt.Select("NodeCode='" + nodeCode + "'"); if (dr.Length > 0) { string tableName = dr[0]["TableName"].ToString(); //模块对应的数据表 string linkUrl = dr[0]["LinkUrl"].ToString(); //静态页面地址 string aspxUrl = dr[0]["subdomain"].ToString(); //动态页面地址 if (string.IsNullOrEmpty(linkUrl) || string.IsNullOrEmpty(aspxUrl)) { continue; } if (IsBar) { finishedPercentage = finishedPercentage + menuPercentage; //首页动态页面路径 /index.aspx或者/default.aspx;如果是其他语言版本,则为/en(站点目录)/index.aspx HProgressBar.Roll("正在发布栏目" + dr[0]["NodeName"].ToString().Replace("'", "") + "...", (int)finishedPercentage); } if (aspxUrl.IndexOf("?") == -1) { aspxUrl += "?nc=" + nodeCode; } else if (aspxUrl.IndexOf("nc=") == -1) { aspxUrl += "&nc=" + nodeCode; } //单页 if (tableName == "K_SinglePage") { CreateHtmlByAspx(aspxUrl, linkUrl); } else //列表 { string pageUrl = ("/" + linkUrl + "?").Split('?')[0]; string[] arrPageUrl = pageUrl.Split('/'); CreateHtmlByAspxList(aspxUrl, linkUrl, arrPageUrl[arrPageUrl.Length - 1]); } } } return(true); }
/// <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); } } }
private void CreateContent(DataTable MenuDt) { string sWhere = " 1=1"; if (UnPublished) { sWhere += " AND IsHtml<>1"; } for (int i = 0; i < ListMenu.Count; i++) { string nodeCode = ListMenu[i].ToString(); DataRow[] dr = MenuDt.Select("NodeCode='" + nodeCode + "' AND TableName<>'K_SinglePage'"); if (dr.Length > 0) { string tableName = dr[0]["TableName"].ToString(); //模块对应的数据表 string linkUrl = dr[0]["LinkUrl"].ToString(); //静态页面地址 string aspxUrl = dr[0]["subdomain"].ToString(); //动态页面地址 string contentUrl = dr[0]["ContentTemplate"].ToString(); //动态页面地址 string htmlDir = dr[0]["custommanagelink"].ToString(); string ContentFileType = dr[0]["IsCreateContentPage"].ToString(); if (string.IsNullOrEmpty(tableName) || string.IsNullOrEmpty(aspxUrl) || string.IsNullOrEmpty(htmlDir)) { continue; } //根据ID读取内容信息 string infoSql = "select Title,ID,AddDate from " + tableName + " where " + sWhere + " AND NODECODE='" + nodeCode + "'"; SqlDataReader infodr = SQLHelper.ExecuteReader(SQLHelper.ConnectionStringLocalTransaction, CommandType.Text, infoSql); if (!infodr.HasRows) { return; } //内容程序路径 if (string.IsNullOrEmpty(contentUrl)) { string url = (aspxUrl + "?").Split('?')[0]; if (url.IndexOf("/") != -1) { string[] urlArr = url.Split('/'); contentUrl = url.Replace(urlArr[urlArr.Length - 1], "") + "content.aspx"; } else { contentUrl = "content.aspx"; } } //判断内容程序路径是否已经有参数 if (contentUrl.IndexOf("?") == -1) { contentUrl += "?id="; } else { contentUrl += "&id="; } //内容页生成方式:True=ID,False=标题 bool iscreate = false; //内容页生成方式:True=ID,False=标题 if (ContentFileType == "True") { while (infodr.Read()) { if (IsBar) { finishedPercentage = finishedPercentage + menuPercentage; //首页动态页面路径 /index.aspx或者/default.aspx;如果是其他语言版本,则为/en(站点目录)/index.aspx HProgressBar.Roll("正在发布内容" + infodr["ID"].ToString() + ".html" + "...", (int)finishedPercentage); } string htmlUrl = htmlDir.Replace("{date}", DateTime.Parse(infodr["AddDate"].ToString()).ToString("yyyyMM")) + infodr["ID"].ToString() + ".html"; iscreate = CreateHtmlByAspx(contentUrl + infodr["ID"].ToString(), htmlUrl); if (iscreate) { SQLHelper.ExecuteNonQuery(SQLHelper.ConnectionStringLocalTransaction, CommandType.Text, "update " + tableName + " set IsHtml=1 where id='" + infodr["ID"].ToString() + "'"); } } } else { while (infodr.Read()) { if (IsBar) { finishedPercentage = finishedPercentage + menuPercentage; //首页动态页面路径 /index.aspx或者/default.aspx;如果是其他语言版本,则为/en(站点目录)/index.aspx HProgressBar.Roll("正在发布内容" + infodr["Title"].ToString().Replace("'", "") + ".html" + "...", (int)finishedPercentage); } string htmlUrl = htmlDir.Replace("{date}", DateTime.Parse(infodr["AddDate"].ToString()).ToString("yyyyMM")) + infodr["Title"].ToString() + ".html"; iscreate = CreateHtmlByAspx(contentUrl + infodr["ID"].ToString(), htmlUrl); if (iscreate) { SQLHelper.ExecuteNonQuery(SQLHelper.ConnectionStringLocalTransaction, CommandType.Text, "update " + tableName + " set IsHtml=1 where id='" + infodr["ID"].ToString() + "'"); } } } infodr.Close(); infodr.Dispose(); } } }
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("发布完成。 <a class=\"list_link\" href=\"javascript:location.href=\\'?NodeCode=" + NodeCode + "\\';\">返 回</a>", 100); } }