int BuildRssOutput( string strDataFile, string strNode, out string strError) { int nRet = 0; strError = ""; // 2018/1/27 if (strNode == null) { strError = "BuildRssOutput() 失败。strNode 参数值不应为 null"; return(-1); } string strDataFilePath = app.DataDir + "/browse/" + strDataFile; XmlDocument dom = new XmlDocument(); try { dom.Load(strDataFilePath); } catch (Exception ex) { strError = "装载文件 '" + strDataFilePath + "' 时出错: " + ex.Message; return(-1); } // 2014/12/2 // 兑现宏 nRet = CacheBuilder.MacroDom(dom, new List <string> { "name", "command" }, out strError); if (nRet == -1) { return(-1); } XmlNode node = null; try { node = CacheBuilder.GetDataNode(dom.DocumentElement, strNode); } catch (Exception ex) { throw new Exception("CacheBuilder.GetDataNode() 出现异常,strNode=[" + strNode + "]", ex); } if (node == null) { strError = "路径 '" + strNode + "' 在文件 '" + strDataFile + "' 中没有找到对应的节点"; return(-1); } bool bRss = false; long nMaxCount = -1; string strDirection = ""; // parameters: // nMaxCount -1表示无穷多 // strDirection head/tail CacheBuilder.GetRssParam(node, out bRss, out nMaxCount, out strDirection); if (bRss == false) { strError = "此节点不允许输出RSS"; return(-1); } string strCommand = DomUtil.GetAttr(node, "command"); string strPureCaption = DomUtil.GetAttr(node, "name"); string strDescription = DomUtil.GetAttr(node, "description"); if (strCommand == "~hidelist~") { strError = "此节点 ~hidelist~ 不允许输出RSS"; return(-1); } if (strCommand == "~none~") { strError = "此节点 ~none~ 不允许输出RSS"; return(-1); } // strDataFile 中为纯文件名 string strPrefix = strNode; string strCacheDir = app.DataDir + "/browse/cache/" + strDataFile; PathUtil.TryCreateDir(strCacheDir); string strResultsetFilename = strCacheDir + "/" + strPrefix; // 如果RSS文件已经存在,就不要从 dp2library 获取了 if (File.Exists(strResultsetFilename + ".rss") == true) { // return: // -1 出错 // 0 成功 // 1 暂时不能访问 nRet = DumpRssFile(strResultsetFilename + ".rss", out strError); if (nRet == -1) { return(-1); } return(0); } // 加入列表,要求创建RSS文件 /* * lock (app.PendingCacheFiles) * { * string strLine = strDataFile + ":" + strNode + ":rss"; // 仅仅要求创建RSS文件 * if (app.PendingCacheFiles.IndexOf(strLine) == -1) * app.PendingCacheFiles.Add(strLine); * } * app.ActivateCacheBuilder(); * */ CacheBuilder.AddToPendingList(app, strDataFile, strNode, "rss"); // "相关缓存正在被创建,请稍后重新访问"; strError = "RSS file is building, please retry soon later... 相关缓存正在被创建,请稍后重新访问"; this.Response.ContentType = "text/plain; charset=utf-8"; this.Response.StatusCode = 503; this.Response.StatusDescription = strError; this.Response.Write(strError); return(0); }
void DisplayNode(string strDataFileName, string strNodePath) { int nRet = 0; string strError = ""; this.BrowseSearchResultControl1.SelectAll(false); string strXmlFilePath = app.DataDir + "/browse/" + strDataFileName; XmlDocument dom = new XmlDocument(); dom.Load(strXmlFilePath); // 2014/12/2 // 兑现宏 nRet = CacheBuilder.MacroDom(dom, new List <string> { "name", "command" }, out strError); if (nRet == -1) { goto ERROR1; } XmlNode node = null; if (string.IsNullOrEmpty(strNodePath) == true) { // 找到第一个节点 node = GetFirstNode(dom.DocumentElement); if (node == null) { return; } strNodePath = CacheBuilder.MakeNodePath(node); } else { // TODO: 也可以用节点文字名字来选定 node = CacheBuilder.GetDataNode(dom.DocumentElement, strNodePath); if (node == null) { return; } } this.TreeView1.SelectedNodePath = ""; this.SelectingNodePath = strNodePath; string strPureCaption = DomUtil.GetAttr(node, "name"); string strDescription = DomUtil.GetAttr(node, "description"); if (String.IsNullOrEmpty(strDescription) == true) { this.Description1.Text = ""; } else { this.Description1.Text = "<div class='text'>" + strDescription + "</div>"; } string strCommand = DomUtil.GetAttr(node, "command"); bool bRss = false; long nMaxCount = -1; string strDirection = ""; // parameters: // nMaxCount -1表示无穷多 // strDirection head/tail CacheBuilder.GetRssParam(node, out bRss, out nMaxCount, out strDirection); // this.HyperLink_rss.Visible = bRss; if (strCommand == "~hidelist~") { // this.BrowseSearchResultControl1.ResultSetName = ""; this.BrowseSearchResultControl1.ResultsetFilename = ""; this.BrowseSearchResultControl1.ResultCount = 0; this.BrowseSearchResultControl1.StartIndex = 0; this.BrowseSearchResultControl1.Visible = false; return; } this.BrowseSearchResultControl1.Visible = true; if (strCommand == "~none~") { // this.BrowseSearchResultControl1.ResultSetName = ""; this.BrowseSearchResultControl1.ResultsetFilename = ""; this.BrowseSearchResultControl1.ResultCount = 0; this.BrowseSearchResultControl1.StartIndex = 0; return; } #if NO string strPureCaption = this.TreeView1.SelectedNode.Text; nRet = strPureCaption.IndexOf("("); if (nRet != -1) { strPureCaption = strPureCaption.Substring(0, nRet).Trim(); } #endif string strDataFile = strDataFileName; // PathUtil.PureName(strDataFile); string strPrefix = CacheBuilder.MakeNodePath(node); string strCacheDir = app.DataDir + "/browse/cache/" + strDataFile; PathUtil.TryCreateDir(strCacheDir); string strResultsetFilename = strCacheDir + "/" + strPrefix; string strRssString = "datafile=" + strDataFile + "&node=" + strPrefix; // this.HyperLink_rss.NavigateUrl = "browse.aspx?action=rss&" + strRssString; string strRssNavigateUrl = "browse.aspx?action=rss&" + strRssString; bool bRedo = false; REDO: // 如果文件已经存在,就不要从 dp2library 获取了 try { app.ResultsetLocks.LockForRead(strResultsetFilename, 500); try { if (this.Response.IsClientConnected == false) { return; } if (File.Exists(strResultsetFilename) == true) { // 2010/12/21 // 看看是否为每日强制更新的节点 // 获得Build相关参数 // parameters: // strBuildStyle 创建风格 perday / perhour CacheBuilder.GetBuildParam(node, out string strBuildStyle); if (String.IsNullOrEmpty(strBuildStyle) == false && strBuildStyle.ToLower() != "disable") { // 比较文件创建时间和当前时间,看看是否超过重建周期 if (CacheBuilder.HasExpired(strResultsetFilename, strBuildStyle) == true) { goto DO_REBUILD; } } long lHitCount = CacheBuilder.GetCount(app, strResultsetFilename, false); // 记忆下来 app.SetBrowseNodeCount(strDataFile, strNodePath, lHitCount.ToString()); this.BrowseSearchResultControl1.ResultsetFilename = strResultsetFilename; this.BrowseSearchResultControl1.ResultCount = (int)lHitCount; this.BrowseSearchResultControl1.StartIndex = 0; this.CreateRssLink(strPureCaption, strRssNavigateUrl); this.Page.Title = strPureCaption; // this.SelectedNodeCaption = strPureCaption + "(" + lHitCount.ToString() + ")"; this.TreeView1.SelectedNodePath = strNodePath; return; } } finally { app.ResultsetLocks.UnlockForRead(strResultsetFilename); } } catch (System.ApplicationException /*ex*/) { this.SetErrorInfo(strPureCaption + " 相关缓存文件暂时被占用,请稍后重新访问"); goto END1; } DO_REBUILD: if (bRedo == false) { /* * // 加入列表 * lock (app.PendingCacheFiles) * { * string strLine = strDataFile + ":" + strPrefix; * if (app.PendingCacheFiles.IndexOf(strLine) == -1) * app.PendingCacheFiles.Add(strLine); * } * app.ActivateCacheBuilder(); * */ CacheBuilder.AddToPendingList(app, strDataFile, strPrefix, ""); bRedo = true; if (Wait() == true) { return; } goto REDO; } else { this.SetErrorInfo(strPureCaption + " 相关缓存正在建立,请稍后重新访问"); // this.SelectedNodeCaption = strPureCaption; } END1: this.CreateRssLink(strPureCaption, strRssNavigateUrl); this.Page.Title = strPureCaption; this.BrowseSearchResultControl1.ResultSetName = ""; this.BrowseSearchResultControl1.ResultsetFilename = ""; this.BrowseSearchResultControl1.ResultCount = 0; this.BrowseSearchResultControl1.StartIndex = 0; this.TreeView1.SelectedNodePath = strNodePath; return; ERROR1: Response.Write(HttpUtility.HtmlEncode(strError)); Response.End(); }