// 获得名称对照表 // parameters: // keyname_table keyname --> 当前语言的名称 public static int GetKeyNameTable( OpacApplication app, string strFilterFileName, List <NodeInfo> nodeinfos, string strLang, out Hashtable keyname_table, out string strError) { strError = ""; int nRet = 0; keyname_table = new Hashtable(); FilterHost host = new FilterHost(); LoanFilterDocument filter = null; nRet = app.PrepareMarcFilter( host, strFilterFileName, out filter, out strError); if (nRet == -1) { goto ERROR1; } try { nRet = BuildKeyNameTable( filter, nodeinfos, strLang, out keyname_table, out strError); if (nRet == -1) { goto ERROR1; } } catch (Exception ex) { strError = "GetKeyNameTable() error: " + ExceptionUtil.GetDebugText(ex); return(-1); } finally { // 归还对象 app.Filters.SetFilter(strFilterFileName, filter); } return(0); ERROR1: return(-1); }
public int PrepareMarcFilter( FilterHost host, string strFilterFileName, out LoanFilterDocument filter, out string strError) { strError = ""; // 看看是否有现成可用的对象 filter = (LoanFilterDocument)this.Filters.GetFilter(strFilterFileName); if (filter != null) { filter.FilterHost = host; return(1); } // 新创建 filter = new LoanFilterDocument(); filter.FilterHost = host; filter.strOtherDef = "FilterHost Host = null;"; filter.strPreInitial = " LoanFilterDocument doc = (LoanFilterDocument)this.Document;\r\n"; filter.strPreInitial += " Host = (" + "FilterHost" + ")doc.FilterHost;\r\n"; try { filter.Load(strFilterFileName); } catch (Exception ex) { strError = ExceptionUtil.GetAutoText(ex); return(-1); } string strCode = ""; // c#代码 int nRet = filter.BuildScriptFile(out strCode, out strError); if (nRet == -1) { return(-1); } try { string[] saRef2 = filter.GetRefs(); filter.Assembly = this.AssemblyCache.GetObject(strFilterFileName, () => { string[] saAddRef1 = { this.BinDir + "\\digitalplatform.core.dll", this.BinDir + "\\digitalplatform.marcdom.dll", this.BinDir + "\\digitalplatform.marckernel.dll", this.BinDir + "\\digitalplatform.OPAC.Server.dll", this.BinDir + "\\digitalplatform.dll", this.BinDir + "\\digitalplatform.Text.dll", this.BinDir + "\\digitalplatform.IO.dll", this.BinDir + "\\digitalplatform.Xml.dll", this.BinDir + "\\digitalplatform.script.dll", this.BinDir + "\\digitalplatform.marcquery.dll", }; string strError1 = ""; string strWarning = ""; // string strLibPaths = ""; string[] saRef = StringUtil.Append(saRef2, saAddRef1); #if NO string[] saRef = new string[saRef2.Length + saAddRef1.Length]; Array.Copy(saRef2, saRef, saRef2.Length); Array.Copy(saAddRef1, 0, saRef, saRef2.Length, saAddRef1.Length); #endif Assembly assembly1 = null; // 创建Script的Assembly // 本函数内对saRef不再进行宏替换 nRet = ScriptManager.CreateAssembly_1(strCode, saRef, "", // strLibPaths, out assembly1, out strError1, out strWarning); if (nRet == -2) { throw new Exception(strError1); } if (nRet == -1) { if (string.IsNullOrEmpty(strWarning) == true) { throw new Exception(strError1); } } return(assembly1); }); } catch (Exception ex) { strError = ex.Message; return(-1); } return(0); }
// 将种记录数据从XML格式转换为HTML格式 public int ConvertBiblioXmlToHtml( string strFilterFileName, string strBiblioXml, string strRecPath, out string strBiblio, out KeyValueCollection result_params, out string strError) { strBiblio = ""; strError = ""; result_params = null; OpacApplication app = this; FilterHost host = new FilterHost(); host.RecPath = strRecPath; host.App = this; host.ResultParams = new KeyValueCollection(); // 如果必要,转换为MARC格式,调用filter string strOutMarcSyntax = ""; string strMarc = ""; // 将MARCXML格式的xml记录转换为marc机内格式字符串 // parameters: // bWarning ==true, 警告后继续转换,不严格对待错误; = false, 非常严格对待错误,遇到错误后不继续转换 // strMarcSyntax 指示marc语法,如果=="",则自动识别 // strOutMarcSyntax out参数,返回marc,如果strMarcSyntax == "",返回找到marc语法,否则返回与输入参数strMarcSyntax相同的值 int nRet = MarcUtil.Xml2Marc(strBiblioXml, true, "", // this.CurMarcSyntax, out strOutMarcSyntax, out strMarc, out strError); if (nRet == -1) { goto ERROR1; } LoanFilterDocument filter = null; nRet = app.PrepareMarcFilter( host, strFilterFileName, out filter, out strError); if (nRet == -1) { goto ERROR1; } try { nRet = filter.DoRecord(null, strMarc, 0, out strError); if (nRet == -1) { goto ERROR1; } strBiblio = host.ResultString; result_params = host.ResultParams; } catch (Exception ex) { strError = "filter.DoRecord error: " + ExceptionUtil.GetDebugText(ex); return(-1); } finally { // 归还对象 filter.FilterHost = null; // 2016/1/23 app.Filters.SetFilter(strFilterFileName, filter); } return(0); ERROR1: return(-1); }
// TODO: 如何中断长操作? // parameters: // strFacetDefXml 分面特性定义XML片断 // nMaxRecords 处理的最多记录数。如果 == -1,表示不限制 public static int DoFilter( OpacApplication app, LibraryChannel channel, string strResultsetName, string strFilterFileName, int nMaxRecords, SetProgress setprogress, ref Hashtable result_table, out long lOuputHitCount, // out string strFacetDefXml, out string strError) { strError = ""; lOuputHitCount = 0; long lRet = 0; int nRet = 0; // strFacetDefXml = ""; if (result_table == null) { result_table = new Hashtable(); } FilterHost host = new FilterHost(); LoanFilterDocument filter = null; nRet = app.PrepareMarcFilter( host, strFilterFileName, out filter, out strError); if (nRet == -1) { goto ERROR1; } try { /* * XmlNode node = filter.Dom.DocumentElement.SelectSingleNode("facetDef"); * if (node != null) * { * strFacetDefXml = node.OuterXml; * } * */ long lStart = 0; // int nCount = 0; for (; ;) { Record[] records = null; // return: // -1 出错 // >=0 结果集内记录的总数(注意,并不是本批返回的记录数) lRet = channel.GetSearchResult( null, "#" + strResultsetName, lStart, 100, "id,xml", "zh", out records, out strError); if (lRet == -1) { return(-1); } lOuputHitCount = lRet; long lCount = lRet; if (nMaxRecords != -1) { lCount = Math.Min(lCount, nMaxRecords); } if (setprogress != null) { setprogress(lCount, lStart); } foreach (Record record in records) { // 2014/12/21 if (string.IsNullOrEmpty(record.RecordBody.Xml) == true) { continue; } // 如果必要,转换为MARC格式,调用filter string strOutMarcSyntax = ""; string strMarc = ""; // 将MARCXML格式的xml记录转换为marc机内格式字符串 // parameters: // bWarning ==true, 警告后继续转换,不严格对待错误; = false, 非常严格对待错误,遇到错误后不继续转换 // strMarcSyntax 指示marc语法,如果=="",则自动识别 // strOutMarcSyntax out参数,返回marc,如果strMarcSyntax == "",返回找到marc语法,否则返回与输入参数strMarcSyntax相同的值 nRet = MarcUtil.Xml2Marc(record.RecordBody.Xml, true, "", // this.CurMarcSyntax, out strOutMarcSyntax, out strMarc, out strError); if (nRet == -1) { strError = "转换书目记录 " + record.Path + " 的 XML 格式到 MARC 时出错: " + strError; goto ERROR1; } host.RecPath = record.Path; host.App = app; host.ResultParams = new KeyValueCollection(); nRet = filter.DoRecord(null, strMarc, strOutMarcSyntax, 0, out strError); if (nRet == -1) { goto ERROR1; } nRet = AddItems(ref result_table, host.ResultParams, record.Path, out strError); if (nRet == -1) { return(-1); } } if (records.Length <= 0 // < 100 ) { break; } lStart += records.Length; // nCount += records.Length; if (lStart >= lCount) { if (setprogress != null) { setprogress(lCount, lCount); } break; } } } catch (Exception ex) { strError = "filter.DoRecord error: " + ExceptionUtil.GetDebugText(ex); return(-1); } finally { // 归还对象 filter.FilterHost = null; // 2016/1/23 app.Filters.SetFilter(strFilterFileName, filter); } return(0); ERROR1: return(-1); }