// return: // 0 没有创建新的队列事项 // 1 创建了新的队列事项 public static int AddToPendingList(OpacApplication app, string strDataFile, string strNodePath, string strPart) { // 加入列表 lock (app.PendingCacheFiles) { string strLine = strDataFile + ":" + strNodePath; if (String.IsNullOrEmpty(strPart) == false) strLine += ":" + strPart; strLine = strLine.ToLower(); if (app.PendingCacheFiles.IndexOf(strLine) == -1) { app.PendingCacheFiles.Add(strLine); app.ActivateCacheBuilder(); return 1; } } app.ActivateCacheBuilder(); return 0; }
// parameters: // bOnlyAppend ==true表示仅仅追究没有的问题,已经有的不再重复。==false,表示全部都刷新 public static int RefreshAll(OpacApplication app, string strDataFile, bool bOnlyAppend, out string strError) { strError = ""; 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 // 兑现宏 int nRet = CacheBuilder.MacroDom(dom, out strError); if (nRet == -1) return -1; XmlNodeList nodes = dom.DocumentElement.SelectNodes("//*"); List<string> lines = new List<string>(); for (int i = 0; i < nodes.Count; i++) { XmlNode node = nodes[i]; if (node.NodeType != XmlNodeType.Element) continue; if (node.Name == "_title") continue; if (node.Name == "caption") continue; bool bRss = false; long nMaxCount = -1; string strDirection = ""; // parameters: // nMaxCount -1表示无穷多 // strDirection head/tail GetRssParam(node, out bRss, out nMaxCount, out strDirection); string strCommand = DomUtil.GetAttr(node, "command"); if (strCommand == "~hidelist~") { // strError = "此节点 ~hidelist~ 不必创建缓存"; continue; } if (strCommand == "~none~") { // strError = "此节点 ~none~ 不必创建缓存"; continue; } /* string strPureCaption = DomUtil.GetAttr(node, "name"); string strDescription = DomUtil.GetAttr(node, "description"); */ string strPrefix = MakeNodePath(node); if (bOnlyAppend == true) { // strDataFile 中为纯文件名 string strCacheDir = app.DataDir + "/browse/cache/" + strDataFile; PathUtil.CreateDirIfNeed(strCacheDir); string strResultsetFilename = strCacheDir + "/" + strPrefix; string strRssString = "datafile=" + strDataFile + "&node=" + strPrefix; if (File.Exists(strResultsetFilename) == true) { if (File.Exists(strResultsetFilename + ".index") == false) goto DO_ADD; if (File.Exists(strResultsetFilename + ".rss") == true) continue; } string strLine = strDataFile + ":" + strPrefix + ":rss"; lines.Add(strLine.ToLower()); continue; } DO_ADD: { string strLine = strDataFile + ":" + strPrefix; lines.Add(strLine.ToLower()); } } int nCount = 0; if (lines.Count > 0) { lock (app.PendingCacheFiles) { foreach (string strLine in lines) { if (app.PendingCacheFiles.IndexOf(strLine) == -1) { nCount++; app.PendingCacheFiles.Add(strLine); } } } /* if (nCount > 0) app.ActivateCacheBuilder(); * */ } // 无论如何都激活 app.ActivateCacheBuilder(); return nCount; }