// 将册记录数据从XML格式转换为HTML格式 // 兼容旧函数,一次性调用(只触发Item()函数),无批概念 // parameters: // strRecPath 册记录路径。用途是为了给宿主对象的RecPath成员赋值 // 2009/10/18 public int ConvertItemXmlToHtml( string strCsFileName, string strRefFileName, string strXml, string strRecPath, out string strResult, out string strError) { strResult = ""; strError = ""; ItemConverter obj = this.NewItemConverter( strCsFileName, strRefFileName, out strError); if (obj == null) { return(-1); } obj.App = this; // 调用关键函数Item try { ItemConverterEventArgs e = new ItemConverterEventArgs(); e.Index = 0; e.Count = 1; e.ActiveBarcode = ""; e.Xml = strXml; e.RecPath = strRecPath; // 2009/10/18 obj.Item(this, e); strResult = e.ResultString; } catch (Exception ex) { strError = "脚本执行时抛出异常: " + ExceptionUtil.GetDebugText(ex); goto ERROR1; } return(0); ERROR1: return(-1); }
// 从cs文件创建Assembly并new好ItemConverter派生对象 public ItemConverter NewItemConverter( string strCsFileName, string strRefFileName, out string strError) { strError = ""; ItemConverter obj = null; Assembly assembly = null; int nRet = this.GetXml2HtmlAssembly( strCsFileName, strRefFileName, this.BinDir, out assembly, out strError); if (nRet == -1) { goto ERROR1; } // 得到Assembly中Converter派生类Type Type entryClassType = ScriptManager.GetDerivedClassType( assembly, "DigitalPlatform.LibraryServer.ItemConverter"); if (entryClassType == null) { strError = "从DigitalPlatform.LibraryServer.ItemConverter派生的类 type entry not found"; goto ERROR1; } // new一个Converter派生对象 obj = (ItemConverter)entryClassType.InvokeMember(null, BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.CreateInstance, null, null, null); return(obj); ERROR1: return(null); }
// 将册记录数据从XML格式转换为HTML格式 public static int RunItemConverter( string strFunction, ItemConverter obj, object sender, ItemConverterEventArgs e, out string strError) { strError = ""; // 调用关键函数Item try { if (strFunction == "item") { obj.Item(sender, e); } else if (strFunction == "begin") { obj.Begin(sender, e); } else if (strFunction == "end") { obj.End(sender, e); } } catch (Exception ex) { strError = "脚本执行时抛出异常: " + ExceptionUtil.GetDebugText(ex); goto ERROR1; } return(0); ERROR1: return(-1); }
// 将册记录数据从XML格式转换为HTML格式 public static int RunItemConverter( string strFunction, ItemConverter obj, object sender, ItemConverterEventArgs e, out string strError) { strError = ""; // 调用关键函数Item try { if (strFunction == "item") obj.Item(sender, e); else if (strFunction == "begin") obj.Begin(sender, e); else if (strFunction == "end") obj.End(sender, e); } catch (Exception ex) { strError = "脚本执行时抛出异常: " + ExceptionUtil.GetDebugText(ex); goto ERROR1; } return 0; ERROR1: return -1; }
protected override void Render(HtmlTextWriter output) { int nRet = 0; long lRet = 0; string strError = ""; string strOutputPath = ""; string strItemXml = ""; LibraryApplication app = (LibraryApplication)this.Page.Application["app"]; SessionInfo sessioninfo = (SessionInfo)this.Page.Session["sessioninfo"]; string strItemRecPath = ""; RmsChannel channel = sessioninfo.Channels.GetChannel(app.WsUrl); if (channel == null) { strError = "channel == null"; goto ERROR1; } if (String.IsNullOrEmpty(this.Barcode) == false) { // 获得册记录 // return: // -1 error // 0 not found // 1 命中1条 // >1 命中多于1条 nRet = app.GetItemRecXml( channel, this.Barcode, out strItemXml, out strOutputPath, out strError); if (nRet == 0) { strError = "册条码号为 '" + this.Barcode + "' 的册记录没有找到"; goto ERROR1; } if (nRet == -1) { goto ERROR1; } strItemRecPath = strOutputPath; } string strItemDbName = ""; string strBiblioRecID = ""; string strBiblioDbName = ""; // 若需要同时取得种记录 if ((this.DispStyle & DispStyle.Biblio) == DispStyle.Biblio) { string strBiblioRecPath = ""; if (String.IsNullOrEmpty(this.BiblioRecPath) == true) { /* * // 准备工作: 映射数据库名 * nRet = app.GetGlobalCfg(sessioninfo.Channels, * out strError); * if (nRet == -1) * goto ERROR1; * */ strItemDbName = ResPath.GetDbName(strOutputPath); // string strBiblioDbName = ""; // 根据实体库名, 找到对应的书目库名 // return: // -1 出错 // 0 没有找到 // 1 找到 nRet = app.GetBiblioDbNameByItemDbName(strItemDbName, out strBiblioDbName, out strError); if (nRet == -1) { goto ERROR1; } if (nRet == 0) { strError = "实体库名 '" + strItemDbName + "' 没有找到对应的书目库名"; goto ERROR1; } XmlDocument dom = new XmlDocument(); try { dom.LoadXml(strItemXml); } catch (Exception ex) { strError = "册记录XML装载到DOM出错:" + ex.Message; goto ERROR1; } strBiblioRecID = DomUtil.GetElementText(dom.DocumentElement, "parent"); // if (String.IsNullOrEmpty(strBiblioRecID) == true) { strError = "册记录XML中<parent>元素缺乏或者值为空, 因此无法定位种记录"; goto ERROR1; } strBiblioRecPath = strBiblioDbName + "/" + strBiblioRecID; } else { strBiblioRecPath = this.BiblioRecPath; strBiblioDbName = ResPath.GetDbName(this.BiblioRecPath); if (String.IsNullOrEmpty(strItemDbName) == true) { // 根据书目库名, 找到对应的实体库名 // return: // -1 出错 // 0 没有找到 // 1 找到 nRet = app.GetItemDbName(strBiblioDbName, out strItemDbName, out strError); if (nRet == -1) { goto ERROR1; } } strBiblioRecID = ResPath.GetRecordId(this.BiblioRecPath); } string strBiblioXml = ""; string strMetaData = ""; byte[] timestamp = null; lRet = channel.GetRes(strBiblioRecPath, out strBiblioXml, out strMetaData, out timestamp, out strOutputPath, out strError); if (lRet == -1) { strError = "获得种记录 '" + strBiblioRecPath + "' 时出错: " + strError; goto ERROR1; } // 需要从内核映射过来文件 string strLocalPath = ""; nRet = app.MapKernelScriptFile( sessioninfo, strBiblioDbName, "./cfgs/loan_biblio.fltx", out strLocalPath, out strError); if (nRet == -1) { goto ERROR1; } // 将种记录数据从XML格式转换为HTML格式 string strBiblio = ""; // 2006/11/28 changed string strFilterFileName = strLocalPath; // app.CfgDir + "\\biblio.fltx"; if (string.IsNullOrEmpty(strBiblioXml) == false) { nRet = app.ConvertBiblioXmlToHtml( strFilterFileName, strBiblioXml, strBiblioRecPath, out strBiblio, out strError); if (nRet == -1) { goto ERROR1; } } else { strBiblio = ""; } // output.Write(strBiblio); LiteralControl literal = (LiteralControl)FindControl("biblio"); literal.Text = strBiblio; } if ((this.DispStyle & DispStyle.Items) == DispStyle.Items) { this.ItemConverter = app.NewItemConverter( app.CfgDir + "\\itemopac.cs", app.CfgDir + "\\itemopac.cs.ref", out strError); if (this.ItemConverter == null) { goto ERROR1; } this.ItemConverter.App = app; // 检索出该种的所有册 sessioninfo.ItemLoad += new ItemLoadEventHandler(SessionInfo_ItemLoad); tempOutput = ""; // tempOutput = output; try { nRet = sessioninfo.SearchItems( app, strItemDbName, strBiblioRecID, out strError); if (nRet == -1) { goto ERROR1; } } finally { sessioninfo.ItemLoad -= new ItemLoadEventHandler(SessionInfo_ItemLoad); //tempOutput = null; this.ItemConverter = null; } LiteralControl literal = (LiteralControl)FindControl("items"); literal.Text = tempOutput; tempOutput = ""; } else if ((this.DispStyle & DispStyle.Item) == DispStyle.Item) { string strResult = ""; // 取得册信息 // 将册记录数据从XML格式转换为HTML格式 nRet = app.ConvertItemXmlToHtml( app.CfgDir + "\\itemxml2html.cs", app.CfgDir + "\\itemxml2html.cs.ref", strItemXml, strItemRecPath, // 2009/10/18 out strResult, out strError); if (nRet == -1) { goto ERROR1; } // output.Write(strResult); LiteralControl literal = (LiteralControl)FindControl("items"); literal.Text = strResult; } base.Render(output); return; ERROR1: output.Write(strError); }
protected override void Render(HtmlTextWriter output) { int nRet = 0; long lRet = 0; string strError = ""; string strOutputPath = ""; string strItemXml = ""; LibraryApplication app = (LibraryApplication)this.Page.Application["app"]; SessionInfo sessioninfo = (SessionInfo)this.Page.Session["sessioninfo"]; string strItemRecPath = ""; RmsChannel channel = sessioninfo.Channels.GetChannel(app.WsUrl); if (channel == null) { strError = "channel == null"; goto ERROR1; } if (String.IsNullOrEmpty(this.Barcode) == false) { // 获得册记录 // return: // -1 error // 0 not found // 1 命中1条 // >1 命中多于1条 nRet = app.GetItemRecXml( channel, this.Barcode, out strItemXml, out strOutputPath, out strError); if (nRet == 0) { strError = "册条码号为 '" + this.Barcode + "' 的册记录没有找到"; goto ERROR1; } if (nRet == -1) goto ERROR1; strItemRecPath = strOutputPath; } string strItemDbName = ""; string strBiblioRecID = ""; string strBiblioDbName = ""; // 若需要同时取得种记录 if ( (this.DispStyle & DispStyle.Biblio ) == DispStyle.Biblio) { string strBiblioRecPath = ""; if (String.IsNullOrEmpty(this.BiblioRecPath) == true) { /* // 准备工作: 映射数据库名 nRet = app.GetGlobalCfg(sessioninfo.Channels, out strError); if (nRet == -1) goto ERROR1; * */ strItemDbName = ResPath.GetDbName(strOutputPath); // string strBiblioDbName = ""; // 根据实体库名, 找到对应的书目库名 // return: // -1 出错 // 0 没有找到 // 1 找到 nRet = app.GetBiblioDbNameByItemDbName(strItemDbName, out strBiblioDbName, out strError); if (nRet == -1) goto ERROR1; if (nRet == 0) { strError = "实体库名 '" + strItemDbName + "' 没有找到对应的书目库名"; goto ERROR1; } XmlDocument dom = new XmlDocument(); try { dom.LoadXml(strItemXml); } catch (Exception ex) { strError = "册记录XML装载到DOM出错:" + ex.Message; goto ERROR1; } strBiblioRecID = DomUtil.GetElementText(dom.DocumentElement, "parent"); // if (String.IsNullOrEmpty(strBiblioRecID) == true) { strError = "册记录XML中<parent>元素缺乏或者值为空, 因此无法定位种记录"; goto ERROR1; } strBiblioRecPath = strBiblioDbName + "/" + strBiblioRecID; } else { strBiblioRecPath = this.BiblioRecPath; strBiblioDbName = ResPath.GetDbName(this.BiblioRecPath); if (String.IsNullOrEmpty(strItemDbName) == true) { // 根据书目库名, 找到对应的实体库名 // return: // -1 出错 // 0 没有找到 // 1 找到 nRet = app.GetItemDbName(strBiblioDbName, out strItemDbName, out strError); if (nRet == -1) goto ERROR1; } strBiblioRecID = ResPath.GetRecordId(this.BiblioRecPath); } string strBiblioXml = ""; string strMetaData = ""; byte[] timestamp = null; lRet = channel.GetRes(strBiblioRecPath, out strBiblioXml, out strMetaData, out timestamp, out strOutputPath, out strError); if (lRet == -1) { strError = "获得种记录 '" + strBiblioRecPath + "' 时出错: " + strError; goto ERROR1; } // 需要从内核映射过来文件 string strLocalPath = ""; nRet = app.MapKernelScriptFile( sessioninfo, strBiblioDbName, "./cfgs/loan_biblio.fltx", out strLocalPath, out strError); if (nRet == -1) goto ERROR1; // 将种记录数据从XML格式转换为HTML格式 string strBiblio = ""; // 2006/11/28 changed string strFilterFileName = strLocalPath; // app.CfgDir + "\\biblio.fltx"; if (string.IsNullOrEmpty(strBiblioXml) == false) { nRet = app.ConvertBiblioXmlToHtml( strFilterFileName, strBiblioXml, strBiblioRecPath, out strBiblio, out strError); if (nRet == -1) goto ERROR1; } else strBiblio = ""; // output.Write(strBiblio); LiteralControl literal = (LiteralControl)FindControl("biblio"); literal.Text = strBiblio; } if ((this.DispStyle & DispStyle.Items) == DispStyle.Items) { this.ItemConverter = app.NewItemConverter( app.CfgDir + "\\itemopac.cs", app.CfgDir + "\\itemopac.cs.ref", out strError); if (this.ItemConverter == null) goto ERROR1; this.ItemConverter.App = app; // 检索出该种的所有册 sessioninfo.ItemLoad += new ItemLoadEventHandler(SessionInfo_ItemLoad); tempOutput = ""; // tempOutput = output; try { nRet = sessioninfo.SearchItems( app, strItemDbName, strBiblioRecID, out strError); if (nRet == -1) goto ERROR1; } finally { sessioninfo.ItemLoad -= new ItemLoadEventHandler(SessionInfo_ItemLoad); //tempOutput = null; this.ItemConverter = null; } LiteralControl literal = (LiteralControl)FindControl("items"); literal.Text = tempOutput; tempOutput = ""; } else if ((this.DispStyle & DispStyle.Item) == DispStyle.Item) { string strResult = ""; // 取得册信息 // 将册记录数据从XML格式转换为HTML格式 nRet = app.ConvertItemXmlToHtml( app.CfgDir + "\\itemxml2html.cs", app.CfgDir + "\\itemxml2html.cs.ref", strItemXml, strItemRecPath, // 2009/10/18 out strResult, out strError); if (nRet == -1) goto ERROR1; // output.Write(strResult); LiteralControl literal = (LiteralControl)FindControl("items"); literal.Text = strResult; } base.Render(output); return; ERROR1: output.Write(strError); }