// 从结果集中提取指定范围的记录 // parameter: // strRanges 范围 // strStyle 样式,以逗号分隔,id:表示取id,cols表示取浏览格式,xml表示取xml记录体 // strLang 语言版本,用来获得记录路径 // richRecords 得到的记录数组,成员为类型为Record // result: // -1 出错 // >=0 结果集的总数 public long API_GetRichRecords( DpResultSet resultset, string strRanges, string strLang, string strStyle, out RichRecord[] richRecords, out string strError) { strError = ""; richRecords = null; int nCurCount = 0; List <RichRecord> aRichRecord = new List <RichRecord>(); string strFormat = StringUtil.GetStyleParam(strStyle, "format"); RangeList rangeList = new RangeList(strRanges); for (int i = 0; i < rangeList.Count; i++) { RangeItem rangeItem = (RangeItem)rangeList[i]; int nStart = (int)rangeItem.lStart; int nLength = (int)rangeItem.lLength; if (nLength == 0) { continue; } // long lPos = 0; // 应该用快速方式,不应用[]??? 2006/3/29 for (int j = 0; j < nLength; j++) { int nRet = 0; DpRecord dpRecord = resultset[j + nStart]; RichRecord richRecord = new RichRecord(); DbPath dbpath = new DbPath(dpRecord.ID); Database db = this.app.Dbs.GetDatabaseSafety(dbpath.Name); if (db == null) //也应放到本条的记录出错信息里 { strError = "没有找到数据库'" + dbpath.Name + "',换语言版本时出错"; richRecord.Result.Value = -1; richRecord.Result.ErrorCode = KernelApplication.Ret2ErrorCode(nRet); richRecord.Result.ErrorString = strError; } else { // 记录路径 if (StringUtil.IsInList("id", strStyle, true) == true || StringUtil.IsInList("path", strStyle, true) == true) { richRecord.Path = db.GetCaptionSafety(strLang) + "/" + dbpath.CompressedID; } // 浏览列 if (StringUtil.IsInList("cols", strStyle, true) == true) { string[] cols = null; nRet = db.GetCols( strFormat, dbpath.ID10, "", 0, out cols); // 2013/1/14 if (nRet == -1) { if (cols != null && cols.Length > 0) { strError = cols[0]; } else { strError = "GetCols() error"; } return(-1); } richRecord.Cols = cols; } bool bXml = false; bool bTimestamp = false; if (StringUtil.IsInList("xml", strStyle, true) == true) { bXml = true; } if (StringUtil.IsInList("timestamp", strStyle, true) == true) { bTimestamp = true; } if (bXml == true || bTimestamp == true) { string strGetStyle = ""; //"data,timestamp"; // ,outputpath, metadata if (bTimestamp == true) { StringUtil.SetInList(ref strGetStyle, "timestamp", true); } if (bXml == true) { StringUtil.SetInList(ref strGetStyle, "data", true); } int nStart0 = 0; int nLength0 = -1; int nMaxLength = 300 * 1024; // 每次最多获取300K int nTotalLength = 0; string strOutputID = ""; byte[] baTotal = null; byte[] baOutputTimestamp = null; int nAdditionError = 0; string strMetadata = ""; for (; ;) { byte[] baData = null; long lRet = db.GetXml(dbpath.ID, "", // strXPath, nStart0, nLength0, nMaxLength, strGetStyle, out baData, out strMetadata, out strOutputID, out baOutputTimestamp, true, out nAdditionError, out strError); if (lRet <= -1) { richRecord.Result.Value = -1; richRecord.Result.ErrorCode = KernelApplication.Ret2ErrorCode(nAdditionError); // nRet? richRecord.Result.ErrorString = strError; goto CONTINUE; } nTotalLength = (int)lRet; // 如果数据体太大 if (nTotalLength > QUOTA_SIZE) { richRecord.Result.Value = -1; richRecord.Result.ErrorCode = ErrorCodeValue.CommonError; richRecord.Result.ErrorString = "数据超过1M"; goto CONTINUE; } baTotal = ByteArray.Add(baTotal, baData); nStart0 += baData.Length; if (nStart0 >= nTotalLength) { break; } } // 记录体 // 转换成字符串 if (StringUtil.IsInList("xml", strStyle, true) == true) { richRecord.Xml = ByteArray.ToString(baTotal); } // 时间戳? if (StringUtil.IsInList("timestamp", strStyle, true) == true) { richRecord.baTimestamp = baOutputTimestamp; } // string strOutputPath = strDbName + "/" + strOutputID; } // 记录体 if (StringUtil.IsInList("xml", strStyle, true) == true) { /* * nRet = db.GetXmlDataSafety(dbpath.ID, * out richRecord.Xml, * out strError); * if (nRet <= -1) * { * richRecord.Result.Value = -1; * richRecord.Result.ErrorCode = RmswsApplication.Ret2ErrorCode(nRet); * richRecord.Result.ErrorString = strError; * } * */ } } CONTINUE: aRichRecord.Add(richRecord); Thread.Sleep(0); nCurCount++; // 如果超出最大范围,则停止 if (nCurCount >= SessionInfo.MaxRecordsCountPerApi) { break; } } } richRecords = new RichRecord[aRichRecord.Count]; for (int i = 0; i < richRecords.Length; i++) { richRecords[i] = aRichRecord[i]; } return(resultset.Count); }
// 从结果集中提取指定范围的记录 // parameter: // strRanges 范围 // strStyle 样式,以逗号分隔,id:表示取id,cols表示取浏览格式,xml表示取xml记录体 // strLang 语言版本,用来获得记录路径 // richRecords 得到的记录数组,成员为类型为Record // result: // -1 出错 // >=0 结果集的总数 public long API_GetRichRecords( DpResultSet resultset, string strRanges, string strLang, string strStyle, out RichRecord[] richRecords, out string strError) { strError = ""; richRecords = null; int nCurCount = 0; List<RichRecord> aRichRecord = new List<RichRecord>(); string strFormat = StringUtil.GetStyleParam(strStyle, "format"); RangeList rangeList = new RangeList(strRanges); for (int i = 0; i < rangeList.Count; i++) { RangeItem rangeItem = (RangeItem)rangeList[i]; int nStart = (int)rangeItem.lStart; int nLength = (int)rangeItem.lLength; if (nLength == 0) continue; // long lPos = 0; // 应该用快速方式,不应用[]??? 2006/3/29 for (int j = 0; j < nLength; j++) { int nRet = 0; DpRecord dpRecord = resultset[j + nStart]; RichRecord richRecord = new RichRecord(); DbPath dbpath = new DbPath(dpRecord.ID); Database db = this.app.Dbs.GetDatabaseSafety(dbpath.Name); if (db == null) //也应放到本条的记录出错信息里 { strError = "没有找到数据库'" + dbpath.Name + "',换语言版本时出错"; richRecord.Result.Value = -1; richRecord.Result.ErrorCode = KernelApplication.Ret2ErrorCode(nRet); richRecord.Result.ErrorString = strError; } else { // 记录路径 if (StringUtil.IsInList("id", strStyle, true) == true || StringUtil.IsInList("path", strStyle, true) == true) { richRecord.Path = db.GetCaptionSafety(strLang) + "/" + dbpath.CompressedID; } // 浏览列 if (StringUtil.IsInList("cols", strStyle, true) == true) { string[] cols = null; /*未完成 nRet = db.GetCols(dbpath.ID10, out cols, out strError); if (nRet <= -1) { richRecord.Result.Value = -1; richRecord.Result.ErrorCode = GlobalInfo.Ret2ErrorCode(nRet); richRecord.Result.ErrorString = strError; } */ nRet = db.GetCols( strFormat, dbpath.ID10, "", 0, out cols); // 2013/1/14 if (nRet == -1) { if (cols != null && cols.Length > 0) strError = cols[0]; else strError = "GetCols() error"; return -1; } richRecord.Cols = cols; } bool bXml = false; bool bTimestamp = false; if (StringUtil.IsInList("xml", strStyle, true) == true) bXml = true; if (StringUtil.IsInList("timestamp", strStyle, true) == true) bTimestamp = true; if (bXml == true || bTimestamp == true) { string strGetStyle = ""; //"data,timestamp"; // ,outputpath, metadata if (bTimestamp == true) StringUtil.SetInList(ref strGetStyle, "timestamp", true); if (bXml == true) StringUtil.SetInList(ref strGetStyle, "data", true); int nStart0 = 0; int nLength0 = -1; int nMaxLength = 300 * 1024; // 每次最多获取300K int nTotalLength = 0; string strOutputID = ""; byte[] baTotal = null; byte[] baOutputTimestamp = null; int nAdditionError = 0; string strMetadata = ""; for (; ; ) { byte[] baData = null; long lRet = db.GetXml(dbpath.ID, "", // strXPath, nStart0, nLength0, nMaxLength, strGetStyle, out baData, out strMetadata, out strOutputID, out baOutputTimestamp, true, out nAdditionError, out strError); if (lRet <= -1) { richRecord.Result.Value = -1; richRecord.Result.ErrorCode = KernelApplication.Ret2ErrorCode(nAdditionError); // nRet? richRecord.Result.ErrorString = strError; goto CONTINUE; } nTotalLength = (int)lRet; // 如果数据体太大 if (nTotalLength > QUOTA_SIZE) { richRecord.Result.Value = -1; richRecord.Result.ErrorCode = ErrorCodeValue.CommonError; richRecord.Result.ErrorString = "数据超过1M"; goto CONTINUE; } baTotal = ByteArray.Add(baTotal, baData); nStart0 += baData.Length; if (nStart0 >= nTotalLength) break; } // 记录体 // 转换成字符串 if (StringUtil.IsInList("xml", strStyle, true) == true) { richRecord.Xml = ByteArray.ToString(baTotal); } // 时间戳? if (StringUtil.IsInList("timestamp", strStyle, true) == true) { richRecord.baTimestamp = baOutputTimestamp; } // string strOutputPath = strDbName + "/" + strOutputID; } // 记录体 if (StringUtil.IsInList("xml", strStyle, true) == true) { /* nRet = db.GetXmlDataSafety(dbpath.ID, out richRecord.Xml, out strError); if (nRet <= -1) { richRecord.Result.Value = -1; richRecord.Result.ErrorCode = RmswsApplication.Ret2ErrorCode(nRet); richRecord.Result.ErrorString = strError; } * */ } } CONTINUE: aRichRecord.Add(richRecord); Thread.Sleep(0); nCurCount++; // 如果超出最大范围,则停止 if (nCurCount >= SessionInfo.MaxRecordsCountPerApi) break; } } richRecords = new RichRecord[aRichRecord.Count]; for (int i = 0; i < richRecords.Length; i++) { richRecords[i] = aRichRecord[i]; } return resultset.Count; }