protected void TreeView1_GetNodeData(object sender, GetNodeDataEventArgs e) { /* * if (e.Node == e.Node.OwnerDocument.DocumentElement) * return; * */ if (e.Node.Name[0] == '_') { return; } string strName = DomUtil.GetAttr(e.Node, "name"); if (string.IsNullOrEmpty(strName) == true) { return; } bool bCommand = true; string strCommand = DomUtil.GetAttr(e.Node, "command"); if (string.IsNullOrEmpty(strCommand) == false && strCommand[0] == '~') { bCommand = false; } /// string strSideBarFileName = Path.GetFileName(this.SideBarControl1.CfgFile).ToLower(); string strDataFile = Path.GetFileName(this.TreeView1.XmlFileName).ToLower(); string strNodePath = CacheBuilder.MakeNodePath(e.Node); string strCount = ""; if (bCommand == true) { strCount = app.GetBrowseNodeCount(strDataFile, strNodePath); if (string.IsNullOrEmpty(strCount) == true && app.CacheBuilder != null) { long lCount = app.CacheBuilder.GetCountByNodePath(strDataFile, strNodePath, false); if (lCount == -1) { strCount = "?"; } else { strCount = lCount.ToString(); } app.SetBrowseNodeCount(strDataFile, strNodePath, strCount); } } if (string.IsNullOrEmpty(strCount) == false) { // e.Name = strName + " (" + strCount + ")"; e.Name = strName; e.Count = strCount; } else { e.Name = strName; } if (strNodePath == this.SelectingNodePath) { e.Seletected = true; /* * // 如果有更适合的标题文字 * if (string.IsNullOrEmpty(this.SelectedNodeCaption) == false) * e.Name = this.SelectedNodeCaption; * */ } // TODO: 是否可以给每个节点都显示包含记录的数字? 为了提高速度,是否可以用一个hashtable来存储这个数字对照关系? string strSideBarParam = ""; if (string.IsNullOrEmpty(strSideBarFileName) == false) { strSideBarParam = "&sidebar=" + HttpUtility.UrlEncode(strSideBarFileName); } string strFormatParam = ""; if (string.IsNullOrEmpty(this.BrowseSearchResultControl1.CurrentFormat) == false) { strFormatParam = "&format=" + HttpUtility.UrlEncode(this.BrowseSearchResultControl1.CurrentFormat); } else if (string.IsNullOrEmpty(this.BrowseSearchResultControl1.FormatName) == false) { strFormatParam = "&format=" + HttpUtility.UrlEncode(this.BrowseSearchResultControl1.FormatName); } e.Url = "./browse.aspx?datafile=" + HttpUtility.UrlEncode(strDataFile) + strSideBarParam + "&node=" + strNodePath + strFormatParam; if (e.Node == e.Node.OwnerDocument.DocumentElement || IsParentPath(strNodePath, this.SelectingNodePath) == true) { e.Closed = false; } }
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 string strBuildStyle = ""; // 看看是否为每日强制更新的节点 // 获得Build相关参数 // parameters: // strBuildStyle 创建风格 perday / perhour CacheBuilder.GetBuildParam(node, out 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(); }
// 刷新一个缓存 protected void ButtonRefreshCache_Click(object sender, EventArgs e) { int nRet = 0; string strError = ""; string strNodePath = this.TreeView1.SelectedNodePath; if (string.IsNullOrEmpty(strNodePath) == true) { this.SetErrorInfo("尚未选定要刷新缓存的树节点"); return; } if (String.IsNullOrEmpty(sessioninfo.UserID) == true || StringUtil.IsInList("managecache", sessioninfo.RightsOrigin) == false) { this.SetErrorInfo("当前用户不具备 managecache 权限,不能刷新缓存"); return; } string strDataFileName = this.BrowseDataFileName.Value; string strXmlFilePath = app.DataDir + "/browse/" + strDataFileName; XmlDocument dom = new XmlDocument(); dom.Load(strXmlFilePath); // 2014/12/2 // 兑现宏 nRet = CacheBuilder.MacroDom(dom, new List <string> { "name", "date" }, out strError); if (nRet == -1) { goto ERROR1; } XmlNode node = CacheBuilder.GetDataNode(dom.DocumentElement, strNodePath); if (node == null) { return; } string strPrefix = CacheBuilder.MakeNodePath(node); // TODO: 需要把权限检查也放在AddToPendingList()等函数中 nRet = CacheBuilder.AddToPendingList(app, strDataFileName, strPrefix, ""); this.SetErrorInfo("刷新成功。共创建了" + nRet.ToString() + " 个新队列事项"); // this.SelectedNodeCaption = ""; // app.ClearBrowseNodeCount(strDataFileName, strNodePath); { this.BrowseSearchResultControl1.ResultSetName = ""; this.BrowseSearchResultControl1.ResultsetFilename = ""; this.BrowseSearchResultControl1.ResultCount = 0; this.BrowseSearchResultControl1.StartIndex = 0; } return; ERROR1: Response.Write(HttpUtility.HtmlEncode(strError)); Response.End(); }