// 合并检索点 // parameters: // strNewXml 新记录的XML。可以为""或者null // strOldXml 旧记录的XML。可以为""或者null // bOutputDom 是否利用newDom/oldDom顺便输出DOM? // return: // -1 出错 // 0 成功 public int MergeKeys(string strID, string strNewXml, string strOldXml, bool bOutputDom, out KeyCollection newKeys, out KeyCollection oldKeys, out XmlDocument newDom, out XmlDocument oldDom, out string strError) { newKeys = null; oldKeys = null; newDom = null; oldDom = null; strError = ""; int nRet; KeysCfg keysCfg = null; nRet = this.GetKeysCfg(out keysCfg, out strError); if (nRet == -1) return -1; // 根据新xml创建检索点 newKeys = new KeyCollection(); if (String.IsNullOrEmpty(strNewXml) == false) { newDom = new XmlDocument(); newDom.PreserveWhitespace = true; //设PreserveWhitespace为true try { newDom.LoadXml(strNewXml); } catch (Exception ex) { strError = "加载新数据到dom时出错。" + ex.Message; return -1; } if (keysCfg != null) { nRet = keysCfg.BuildKeys(newDom, strID, "zh",//strLang, // "",//strStyle, this.KeySize, out newKeys, out strError); if (nRet == -1) return -1; newKeys.Sort(); newKeys.RemoveDup(); } } oldKeys = new KeyCollection(); if (String.IsNullOrEmpty(strOldXml) == false && strOldXml.Length > 1) // 2012/1/31 { oldDom = new XmlDocument(); oldDom.PreserveWhitespace = true; //设PreserveWhitespace为true try { oldDom.LoadXml(strOldXml); } catch (Exception ex) { strError = "加载旧数据到dom时出错。" + ex.Message; return -1; } if (keysCfg != null) { nRet = keysCfg.BuildKeys(oldDom, strID, "zh",//strLang, // "",//strStyle, this.KeySize, out oldKeys, out strError); if (nRet == -1) return -1; oldKeys.Sort(); oldKeys.RemoveDup(); } } // 新旧检索点碰 KeyCollection dupKeys = new KeyCollection(); dupKeys = KeyCollection.Merge(newKeys, oldKeys); if (bOutputDom == false) { newDom = null; oldDom = null; } return 0; }
// 假写xml数据,得到检索点集合 // parameter: // strXml xml数据 // strID 记录ID,构造检索点用 // strLang 语言版本 // strStyle 风格,控制返回值 // keyColl out参数,返回检索点集合的 // strError out参数,返回出错信息 // return: // -1 出错 // 0 成功 // 线: 安全的 public int API_PretendWrite(string strXml, string strRecordID, string strLang, // string strStyle, out KeyCollection keys, out string strError) { keys = null; strError = ""; //**********对数据库加读锁************** this.m_db_lock.AcquireReaderLock(m_nTimeOut); #if DEBUG_LOCK this.container.WriteDebugInfo("PretendWrite(),对'" + this.GetCaption("zh-CN") + "'数据库加读锁。"); #endif try { //加载数据到DOM XmlDocument domData = new XmlDocument(); domData.PreserveWhitespace = true; //设PreserveWhitespace为true try { domData.LoadXml(strXml); } catch (Exception ex) { strError = "PretendWrite()里,加载参数中的xml数据出错。原因:" + ex.Message; return -1; } KeysCfg keysCfg = null; int nRet = this.GetKeysCfg(out keysCfg, out strError); if (nRet == -1) return -1; if (keysCfg != null) { //创建检索点 keys = new KeyCollection(); nRet = keysCfg.BuildKeys(domData, strRecordID, strLang, // strStyle, this.KeySize, out keys, out strError); if (nRet == -1) return -1; //排序去重 keys.Sort(); keys.RemoveDup(); } return 0; } finally { //****************对数据库解读锁************** this.m_db_lock.ReleaseReaderLock(); #if DEBUG_LOCK this.container.WriteDebugInfo("PretendWrite(),对'" + this.GetCaption("zh-CN") + "'数据库解读锁。"); #endif } }