// 映射内核脚本配置文件到本地 // parameters: // sessioninfo_param 如果为null,函数内部会自动创建一个SessionInfo对象,是管理员权限 // return: // -1 error // 0 成功,为.cs文件 // 1 成功,为.fltx文件 public int MapKernelScriptFile( SessionInfo sessioninfo_param, string strBiblioDbName, string strScriptFileName, out string strLocalPath, out string strError) { strError = ""; strLocalPath = ""; int nRet = 0; SessionInfo sessioninfo = null; // 应该用管理员的权限来做这个事情 // 临时的SessionInfo对象 if (sessioninfo_param == null) { sessioninfo = new SessionInfo(this); sessioninfo.UserID = this.ManagerUserName; sessioninfo.Password = this.ManagerPassword; sessioninfo.IsReader = false; } else sessioninfo = sessioninfo_param; try { // 将种记录数据从XML格式转换为HTML格式 // 需要从内核映射过来文件 // string strScriptFileName = "./cfgs/loan_biblio.fltx"; // 将脚本文件名正规化 // 因为在定义脚本文件的时候, 有一个当前库名环境, // 如果定义为 ./cfgs/filename 表示在当前库下的cfgs目录下, // 而如果定义为 /cfgs/filename 则表示在同服务器的根下 string strRemotePath = OpacApplication.CanonicalizeScriptFileName( strBiblioDbName, strScriptFileName); // TODO: 还可以考虑支持http://这样的配置文件。 nRet = this.CfgsMap.MapFileToLocal( sessioninfo.Channel, strRemotePath, out strLocalPath, out strError); if (nRet == -1) goto ERROR1; if (nRet == 0) { strError = "内核配置文件 " + strRemotePath + "没有找到,因此无法获得书目html格式数据"; goto ERROR1; } bool bFltx = false; // 如果是一般.cs文件, 还需要获得.cs.ref配置文件 if (OpacApplication.IsCsFileName( strScriptFileName) == true) { string strTempPath = ""; nRet = this.CfgsMap.MapFileToLocal( sessioninfo_param.Channel, strRemotePath + ".ref", out strTempPath, out strError); if (nRet == -1) { strError = "内核配置文件 " + strRemotePath + ".ref" + "没有找到,因此无法获得书目html格式数据"; goto ERROR1; } bFltx = false; } else { bFltx = true; } if (bFltx == true) return 1; // 为.fltx文件 return 0; ERROR1: return -1; } finally { if (sessioninfo_param == null) { sessioninfo.CloseSession(); } } }
void CloseManagerSession() { if (m_managerSession != null) { m_managerSession.CloseSession(); m_managerSession = null; } }
void RenderReservation(OpacApplication app, SessionInfo sessioninfo, XmlDocument dom) { // 预约请求 PlaceHolder reservation = (PlaceHolder)this.FindControl("reservation"); this.ReservationBarcodes = new List<string>(); XmlNodeList nodes = dom.DocumentElement.SelectNodes("reservations/request"); this.ReservationLineCount = nodes.Count; for (int i = 0; i < nodes.Count; i++) { PlaceHolder line = (PlaceHolder)reservation.FindControl("reservation_line" + Convert.ToString(i)); if (line == null) { Control insertpos = reservation.FindControl("reservation_insertpos"); line = NewReservationLine(insertpos.Parent, i, insertpos); //this.ReservationLineCount++; } line.Visible = true; LiteralControl left = (LiteralControl)line.FindControl("reservation_line" + Convert.ToString(i) + "left"); CheckBox checkbox = (CheckBox)line.FindControl("reservation_line" + Convert.ToString(i) + "checkbox"); LiteralControl right = (LiteralControl)line.FindControl("reservation_line" + Convert.ToString(i) + "right"); XmlNode node = nodes[i]; string strBarcodes = DomUtil.GetAttr(node, "items"); this.ReservationBarcodes.Add(strBarcodes); string strRequestDate = DateTimeUtil.LocalTime(DomUtil.GetAttr(node, "requestDate")); string strResult = ""; string strTrClass = " class='dark' "; if ((i % 2) == 1) strTrClass = " class='light' "; strResult += "<tr " + strTrClass + "><td nowrap>"; // 左 left.Text = strResult; // 右开始 strResult = " "; // 2007/1/18 string strArrivedItemBarcode = DomUtil.GetAttr(node, "arrivedItemBarcode"); //strResult += "" + strBarcodes + "</td>"; int nBarcodesCount = GetBarcodesCount(strBarcodes); strResult += "" + MakeBarcodeListHyperLink(strBarcodes, strArrivedItemBarcode, ",") + (nBarcodesCount > 1 ? " 之一" : "") // 2007/7/5 + "</td>"; // 操作者 string strOperator = DomUtil.GetAttr(node, "operator"); // 状态 string strArrivedDate = DomUtil.GetAttr(node, "arrivedDate"); string strState = DomUtil.GetAttr(node, "state"); if (strState == "arrived") { strArrivedDate = DateTimeUtil.LocalTime(strArrivedDate); // text-level: 用户提示 strState = string.Format(this.GetString("册s已于s到书"), // "册 {0} 已于 {1} 到书" strArrivedItemBarcode, strArrivedDate); // "册 " + strArrivedItemBarcode + " 已于 " + strArrivedDate + " 到书"; if (nBarcodesCount > 1) { strState += string.Format(this.GetString("同一预约请求中的其余s册旋即失效"), // ";同一预约请求中的其余 {0} 册旋即失效" (nBarcodesCount - 1).ToString()); // ";同一预约请求中的其余 " + (nBarcodesCount - 1).ToString() + " 册旋即失效"; // 2007/7/5 } } strResult += "<td>" + strState + "</td>"; /* string strSummary = GetBarcodesSummary( app, sessioninfo, strBarcodes, "html", ""); * */ strResult += "<td width='50%' class='pending'>formated:" + BuildBarcodeList(strBarcodes, strArrivedItemBarcode) + "</td>"; strResult += "<td nowrap>" + strRequestDate + "</td>"; strResult += "<td nowrap>" + strOperator + "</td>"; strResult += "</tr>"; right.Text = strResult; } // 把多余的行隐藏起来 for (int i = nodes.Count; ; i++) { PlaceHolder line = (PlaceHolder)reservation.FindControl("reservation_line" + Convert.ToString(i)); if (line == null) break; line.Visible = false; } if (nodes.Count == 0) { Control insertpos = reservation.FindControl("reservation_insertpos"); int pos = insertpos.Parent.Controls.IndexOf(insertpos); if (pos == -1) { // text-level: 内部错误 throw new Exception("插入参照对象没有找到"); } LiteralControl literal = new LiteralControl(); literal.Text = "<tr class='dark'><td colspan='5'>" + this.GetString("无预约信息") // "(无预约信息)" + "<td></tr>"; insertpos.Parent.Controls.AddAt(pos, literal); } }
// 创建文章内容 int BuildContent( OpacApplication app, SessionInfo sessioninfo, string strRecPath, out string strParentID, out string strResultParam, out byte[] timestamp, out string strError) { strError = ""; strResultParam = ""; strParentID = ""; timestamp = null; bool bManager = false; if (string.IsNullOrEmpty(sessioninfo.UserID) == true || StringUtil.IsInList("managecomment", sessioninfo.RightsOrigin) == false) bManager = false; else bManager = true; string strErrorComment = ""; string strXml; if (String.IsNullOrEmpty(this.m_strXml) == true) { // return: // -1 出错 // 0 没有找到 // 1 找到 int nRet = GetRecord( app, sessioninfo, null, strRecPath, out strXml, out timestamp, out strError); if (nRet == -1) return -1; if (nRet == 0) strErrorComment = strError; } else { strXml = this.m_strXml; timestamp = this.m_timestamp; } XmlDocument dom = new XmlDocument(); try { if (string.IsNullOrEmpty(strXml) == false) dom.LoadXml(strXml); else dom.LoadXml("<root />"); } catch (Exception ex) { strError = ExceptionUtil.GetAutoText(ex); return -1; } strParentID = DomUtil.GetElementText(dom.DocumentElement, "parent"); // 帖子状态:精华、...。 string strState = DomUtil.GetElementText(dom.DocumentElement, "state"); // 帖子标题 string strTitle = DomUtil.GetElementText(dom.DocumentElement, "title"); if (string.IsNullOrEmpty(strXml) == true) strTitle = strErrorComment; // 作者 string strOriginCreator = DomUtil.GetElementText(dom.DocumentElement, "creator"); string strOriginContent = DomUtil.GetElementText(dom.DocumentElement, "content"); string strOperInfo = ""; { string strFirstOperator = ""; string strTime = ""; XmlNode node = dom.DocumentElement.SelectSingleNode("operations/operation[@name='create']"); if (node != null) { strFirstOperator = DomUtil.GetAttr(node, "operator"); strTime = DomUtil.GetAttr(node, "time"); strOperInfo += " " + this.GetString("创建") + ": " + GetUTimeString(strTime); } node = dom.DocumentElement.SelectSingleNode("operations/operation[@name='lastContentModified']"); if (node != null) { string strLastOperator = DomUtil.GetAttr(node, "operator"); strTime = DomUtil.GetAttr(node, "time"); strOperInfo += "<br/>" + this.GetString("最后修改") + ": " + GetUTimeString(strTime); if (strLastOperator != strFirstOperator) strOperInfo += " (" + strLastOperator + ")"; } XmlNodeList nodes = dom.DocumentElement.SelectNodes("operations/operation[@name='stateModified']"); if (nodes.Count > 0) { XmlNode tail = nodes[nodes.Count - 1]; string strLastOperator = DomUtil.GetAttr(tail, "operator"); strTime = DomUtil.GetAttr(tail, "time"); strOperInfo += "<br/>" + this.GetString("状态最后修改") + ": " + GetUTimeString(strTime); if (strLastOperator != strFirstOperator) strOperInfo += " (" + strLastOperator + ")"; } } /* strResult += "<div class='operinfo' title='" + this.GetString("记录路径") + ": " + strRecPath + "'>" + strOperInfo + "</div>";*/ bool bDisplayOriginContent = false; string strDisplayState = ""; string strStateImage = ""; { if (StringUtil.IsInList("审查", strState) == true) { strStateImage = "<img src='" + MyWebPage.GetStylePath(app, "censor.gif") + "'/>"; strDisplayState = this.GetString("审查"); } if (StringUtil.IsInList("屏蔽", strState) == true) { strStateImage = "<img src='" + MyWebPage.GetStylePath(app, "disable.gif") + "'/>"; if (String.IsNullOrEmpty(strDisplayState) == false) strDisplayState += ","; strDisplayState += this.GetString("屏蔽"); } if (StringUtil.IsInList("审查", strState) == false && StringUtil.IsInList("屏蔽", strState) == false) bDisplayOriginContent = true; // 管理员和作者本人都能看到被屏蔽的内容 if (bManager == true || strOriginCreator == sessioninfo.UserID) bDisplayOriginContent = true; } if (string.IsNullOrEmpty(strXml) == true) strDisplayState = strErrorComment; StringBuilder strResult = new StringBuilder(4096); // headbar { string strUserInfoUrl = ""; string strImageUrl = ""; string strDisplayNameComment = ""; // 关于显示名的注释 string strCreator = GetCreatorDisplayName(dom); if (bDisplayOriginContent == false || string.IsNullOrEmpty(strXml) == true) { strTitle = new string('*', strTitle.Length); strCreator = new string('*', strCreator.Length); strUserInfoUrl = ""; strImageUrl = MyWebPage.GetStylePath(app, "nonephoto.png"); // TODO: 将来可以更换为表示屏蔽状态的头像 } else { strUserInfoUrl = "./userinfo.aspx?" + GetCreatorUrlParam(dom); strImageUrl = "./getphoto.aspx?" + GetCreatorUrlParam(dom); } if (strCreator.IndexOf("[") != -1 && bManager == true) { // 如果是显示名,并且当前为管理员状态 strDisplayNameComment = "管理员注: 该用户的证条码号(或帐户名)为 " + DomUtil.GetElementText(dom.DocumentElement, "creator") + "\r\n(此信息为机密信息,普通用户看不到)"; strDisplayNameComment = HttpUtility.HtmlEncode(strDisplayNameComment); } strResult.Append("<div class='headbar'>"); strResult.Append("<div class='creator_pic' title='" + this.GetString("作者头像") + "'>" + "<a href='" + strUserInfoUrl + "' target='_blank'><img border='0' width='64' height='64' src='" + strImageUrl + "' /></a>" + "</div>"); // strResult.Append("<div class='title_and_creator'>"); if (String.IsNullOrEmpty(strTitle) == false) { strResult.Append("<div class='title' title='" + this.GetString("文章标题") + "'>" + HttpUtility.HtmlEncode(strTitle) + "</div>"); } if (String.IsNullOrEmpty(strCreator) == false) { strResult.Append("<div class='creator' title='" + (String.IsNullOrEmpty(strDisplayNameComment) == false ? strDisplayNameComment : this.GetString("作者")) + "'>" + "<a href='" + strUserInfoUrl + "' target='_blank'>" + HttpUtility.HtmlEncode( strCreator // String.IsNullOrEmpty(strDisplayName) == false ? strDisplayName : strCreator ) + "</a>" + "</div>"); } strResult.Append("<div class='operinfo' title='" + this.GetString("记录路径") + ": " + strRecPath + "'>" + strOperInfo + "</div>"); strResult.Append("</div>"); // of title_and_creator strResult.Append("<div class='path' title='" + this.GetString("记录路径") + "'>" + "<a href='./book.aspx?CommentRecPath=" + HttpUtility.UrlEncode(strRecPath) + "#active' target='_blank'>" + strRecPath + "</a>" + "</div>"); strResult.Append("<div class='clear'> </div>"); strResult.Append("</div>"); // of headbar } // 屏蔽原因 if (String.IsNullOrEmpty(strDisplayState) == false) { strResult.Append("<div class='forbidden' title='" + this.GetString("屏蔽原因") + "'>" + strStateImage + (string.IsNullOrEmpty(strXml) == false ? string.Format(this.GetString("本评注目前为X状态"), strDisplayState) : strDisplayState) + (strOriginCreator == sessioninfo.UserID ? "," + this.GetString("其他人(非管理员)看不到下列内容") : "") + "</div>"); } // 精品和锁定状态 { string strImage = ""; if (StringUtil.IsInList("精品", strState) == true) { strImage = "<img src='" + MyWebPage.GetStylePath(app, "valuable.gif") + "'/>"; strResult.Append("<div class='valuable' title='精品'>" + strImage + this.GetString("精品") + "</div>"); } if (StringUtil.IsInList("锁定", strState) == true) { strImage = "<img src='" + MyWebPage.GetStylePath(app, "locked.gif") + "'/>"; strResult.Append("<div class='locked' title='锁定'>" + strImage + this.GetString("锁定") + "</div>"); } } if (bDisplayOriginContent == true) { string strType = DomUtil.GetElementText(dom.DocumentElement, "type"); string strOrderSuggestion = DomUtil.GetElementText(dom.DocumentElement, "orderSuggestion"); if (strType == "订购征询") { string strOrderSuggestionText = this.GetString("建议不要订购本书"); string strYesOrNo = "no"; if (strOrderSuggestion == "yes") { strOrderSuggestionText = this.GetString("建议订购本书"); strYesOrNo = "yes"; } strResult.Append("<div class='order_suggestion " + strYesOrNo + "' title='" + this.GetString("订购建议") + "'>" + HttpUtility.HtmlEncode(strOrderSuggestionText) + "</div>"); } if (String.IsNullOrEmpty(strOriginContent) == false) { string strContent = strOriginContent.Replace("\\r", "\r\n"); strContent = ParseHttpString( this.Page, strContent); strContent = GetHtmlContentFromPureText(null, /*this.Page,*/ strContent, Text2HtmlStyle.P); strResult.Append("<div class='content' title='" + this.GetString("文章正文") + "'>" + strContent + "</div>"); } XmlNamespaceManager nsmgr = new XmlNamespaceManager(new NameTable()); nsmgr.AddNamespace("dprms", DpNs.dprms); // 全部<dprms:file>元素 XmlNodeList nodes = dom.DocumentElement.SelectNodes( "//dprms:file", nsmgr); foreach (XmlNode node in nodes) { string strMime = DomUtil.GetAttr(node, "__mime"); if (StringUtil.HasHead(strMime, "image/") == false) continue; // 只关注图像文件 string strID = DomUtil.GetAttr(node, "id"); string strUrl = "./getobject.aspx?uri=" + HttpUtility.UrlEncode(strRecPath) + "/object/" + strID; strResult.Append("<div class='image' title='" + this.GetString("图像文件") + "'>" + "<img src='" + strUrl + "' />" + "</div>"); } } if (bManager == true) { string strText = GetStateModifiedHistory(dom); if (String.IsNullOrEmpty(strText) == false) strResult.Append("<div class='historytitle'>" + this.GetString("状态修改史") + ":</div>" + strText); } // 设置命令行 按钮状态 PlaceHolder cmdline = (PlaceHolder)this.FindControl("cmdline"); string strEditAction = this.EditAction; if (String.IsNullOrEmpty(strEditAction) == false) cmdline.Visible = false; else { Button change = (Button)this.FindControl("changebutton"); Button delete = (Button)this.FindControl("deletebutton"); Button state = (Button)this.FindControl("statebutton"); // 非编辑状态 bool bChangable = false; if (((string.IsNullOrEmpty(sessioninfo.UserID) == false && strOriginCreator == sessioninfo.UserID) // 创建者本人 || bManager == true) // 管理者 /*&& this.Active == true*/) bChangable = true; else bChangable = false; // 进一步根据状态进行限定 if (bChangable == true) { // 非管理者,在“锁定”状态下不能修改和删除 if (bManager == false && StringUtil.IsInList("锁定", strState) == true) bChangable = false; } if (bChangable == true) { change.Visible = true; delete.Visible = true; } else { change.Visible = false; delete.Visible = false; } if (bManager == true) state.Visible = true; else state.Visible = false; // 如果每个按钮都是不可见,则隐藏命令条 if (change.Visible == false && delete.Visible == false && state.Visible == false) cmdline.Visible = false; } strResultParam = strResult.ToString(); return 0; }
void submit_button_Click(object sender, EventArgs e) { string strError = ""; OpacApplication app = (OpacApplication)this.Page.Application["app"]; SessionInfo sessioninfo = (SessionInfo)this.Page.Session["sessioninfo"]; string strCreator = sessioninfo.UserID; // 先创建一条书目记录 TextBox biblio_title = (TextBox)this.FindControl("edit_biblio_title"); TextBox biblio_author = (TextBox)this.FindControl("edit_biblio_author"); TextBox biblio_publisher = (TextBox)this.FindControl("edit_biblio_publisher"); TextBox biblio_isbn = (TextBox)this.FindControl("edit_biblio_isbn"); TextBox biblio_price = (TextBox)this.FindControl("edit_biblio_price"); TextBox biblio_summary = (TextBox)this.FindControl("edit_biblio_summary"); // 检查必备字段 if (String.IsNullOrEmpty(biblio_title.Text) == true) { strError = "尚未输入书名/刊名"; goto ERROR1; } DropDownList store_dbname = (DropDownList)this.FindControl("store_dbname"); string strBiblioDbName = store_dbname.SelectedValue; if (String.IsNullOrEmpty(strBiblioDbName) == true) { strError = "尚未选定目标库"; goto ERROR1; } string strBiblioRecPath = ""; string strMarcSyntax = ""; string strMARC = ""; // 得到目标书目库的MARC格式 ItemDbCfg cfg = app.GetBiblioDbCfg(strBiblioDbName); if (cfg == null) { strError = "目标库 '" + strBiblioDbName + "' 不是系统定义的的书目库"; goto ERROR1; } strMarcSyntax = cfg.BiblioDbSyntax; int nRet = BuildBiblioRecord( strMarcSyntax, biblio_title.Text, biblio_author.Text, biblio_publisher.Text, biblio_isbn.Text, biblio_price.Text, biblio_summary.Text, strCreator, out strMARC, out strError); if (nRet == -1) goto ERROR1; // 保存 // 将MARC格式转换为XML格式 string strXml = ""; nRet = MarcUtil.Marc2Xml( strMARC, strMarcSyntax, out strXml, out strError); if (nRet == -1) goto ERROR1; /* // 临时的SessionInfo对象 SessionInfo temp_sessioninfo = new SessionInfo(app); // 模拟一个账户 Account account = new Account(); account.LoginName = "neworderbiblio"; account.Password = ""; account.Rights = "setbiblioinfo"; account.Type = ""; account.Barcode = ""; account.Name = "neworderbiblio"; account.UserID = "neworderbiblio"; account.RmsUserName = app.ManagerUserName; account.RmsPassword = app.ManagerPassword; temp_sessioninfo.Account = account; * */ SessionInfo temp_sessioninfo = new SessionInfo(app); temp_sessioninfo.UserID = app.ManagerUserName; temp_sessioninfo.Password = app.ManagerPassword; temp_sessioninfo.IsReader = false; string strOutputBiblioRecPath = ""; try { strBiblioRecPath = strBiblioDbName + "/?"; byte[] baOutputTimestamp = null; long lRet = temp_sessioninfo.Channel.SetBiblioInfo( null, "new", strBiblioRecPath, "xml", strXml, null, "", out strOutputBiblioRecPath, out baOutputTimestamp, out strError); if (lRet == -1) { strError = "创建书目记录发生错误: " + strError; goto ERROR1; } /* LibraryServerResult result = app.SetBiblioInfo( temp_sessioninfo, "new", strBiblioRecPath, "xml", strXml, null, out strOutputBiblioRecPath, out baOutputTimestamp); if (result.Value == -1) { strError = result.ErrorInfo; goto ERROR1; } * */ } finally { temp_sessioninfo.CloseSession(); temp_sessioninfo = null; } // 清除每个输入域的内容 biblio_title.Text = ""; biblio_author.Text = ""; biblio_publisher.Text = ""; biblio_isbn.Text = ""; biblio_summary.Text = ""; biblio_price.Text = ""; strBiblioRecPath = strOutputBiblioRecPath; CommentControl commentcontrol = (CommentControl)this.FindControl("commentcontrol"); // 创建评注记录 if (String.IsNullOrEmpty(commentcontrol.EditTitle) == false || String.IsNullOrEmpty(commentcontrol.EditContent) == false) { string strWarning = ""; commentcontrol.BiblioRecPath = strBiblioRecPath; nRet = commentcontrol.DoSubmit( out strWarning, out strError); if (nRet == -1) goto ERROR1; if (String.IsNullOrEmpty(strWarning) == false) this.SetDebugInfo("warninginfo", strWarning); } string strUrl = "./book.aspx?bibliorecpath=" + HttpUtility.UrlEncode(strBiblioRecPath); string strText = "新的荐购书目记录创建成功。点击此处可查看:<a href='" + strUrl + "' target='_blank'>" + strUrl + "</a>"; SetInfo(strText); this.SetDebugInfo("succeedinfo", strText); return; ERROR1: SetDebugInfo("errorinfo", strError); }
// TODO: 以后白名单里面可以配置更大的数量 protected void Session_Start(Object sender, EventArgs e) { OpacApplication app = null; try { app = (OpacApplication)Application["app"]; if (app == null) { throw new Exception("app == null while Session_Start(). global error info : " + (string)Application["errorinfo"]); } string strClientIP = HttpContext.Current.Request.UserHostAddress; // 增量计数 if (app != null) { long v = app.IpTable.IncIpCount(strClientIP, 1); if (v >= app.IpTable.MAX_SESSIONS_PER_IP) { app.IpTable.IncIpCount(strClientIP, -1); Session.Abandon(); return; } } SessionInfo sessioninfo = new SessionInfo(app); sessioninfo.ClientIP = strClientIP; Session["sessioninfo"] = sessioninfo; // throw new Exception("test exception"); app.IncSesstionCounter(Request.UserHostAddress); } catch (Exception ex) { string strErrorText = "Session_Start阶段出现异常: " + ExceptionUtil.GetDebugText(ex); OpacApplication.WriteWindowsLog(strErrorText); if (app != null) app.GlobalErrorInfo = strErrorText; else Application["errorinfo"] = strErrorText; } }
// 检索顶层文章 // return: // -1 error // 其他 命中数 private int SearchTopLevelArticles( SessionInfo sessioninfo, System.Web.UI.Page page, out string strError) { strError = ""; if (page != null && page.Response.IsClientConnected == false) // 灵敏中断 { strError = "中断"; return -1; } // 检索全部评注文章 一定时间范围内的? List<string> dbnames = new List<string>(); for (int i = 0; i < this.ItemDbs.Count; i++) { ItemDbCfg cfg = this.ItemDbs[i]; string strDbName = cfg.CommentDbName; if (String.IsNullOrEmpty(strDbName) == true) continue; dbnames.Add(strDbName); } DateTime now = DateTime.Now; DateTime oneyearbefore = now - new TimeSpan(365, 0, 0, 0); string strTime = DateTimeUtil.Rfc1123DateTimeString(oneyearbefore.ToUniversalTime()); string strQueryXml = ""; for (int i = 0; i < dbnames.Count; i++) { string strDbName = dbnames[i]; string strOneQueryXml = "<target list='" + strDbName + ":" + "最后修改时间'><item><word>" // <order>DESC</order> + strTime + "</word><match>exact</match><relation>" + StringUtil.GetXmlStringSimple(">=") + "</relation><dataType>number</dataType><maxCount>" + "-1"// Convert.ToString(m_nMaxLineCount) + "</maxCount></item><lang>zh</lang></target>"; if (i > 0) strQueryXml += "<operator value='OR' />"; strQueryXml += strOneQueryXml; } if (dbnames.Count > 0) strQueryXml = "<group>" + strQueryXml + "</group>"; if (page != null) { page.Response.Write("--- begin search ...<br/>"); page.Response.Flush(); } LibraryChannel channel = this.GetChannel(); try { DateTime time = DateTime.Now; long nRet = // sessioninfo.Channel. channel.Search( null, strQueryXml, "default", "", // outputstyle out strError); if (nRet == -1) { strError = "检索时出错: " + strError; return -1; } TimeSpan delta = DateTime.Now - time; if (page != null) { page.Response.Write("search end. hitcount=" + nRet.ToString() + ", time=" + delta.ToString() + "<br/>"); page.Response.Flush(); } if (nRet == 0) return 0; // not found if (page != null && page.Response.IsClientConnected == false) // 灵敏中断 { strError = "中断"; return -1; } if (page != null) { page.Response.Write("--- begin get search result ...<br/>"); page.Response.Flush(); } time = DateTime.Now; List<string> aPath = null; nRet = // sessioninfo.Channel. channel.GetSearchResult( null, "default", 0, -1, "zh", out aPath, out strError); if (nRet == -1) { strError = "获得检索结果时出错: " + strError; return -1; } if (page != null) { delta = DateTime.Now - time; page.Response.Write("get search result end. lines=" + aPath.Count.ToString() + ", time=" + delta.ToString() + "<br/>"); page.Response.Flush(); } if (aPath.Count == 0) { strError = "获取的检索结果为空"; return -1; } if (page != null && page.Response.IsClientConnected == false) // 灵敏中断 { strError = "中断"; return -1; } if (page != null) { page.Response.Write("--- begin build storage ...<br/>"); page.Response.Flush(); } time = DateTime.Now; this.CommentColumn.Clear(); // 清空集合 // 加入新行对象。新行对象中,只初始化了m_strRecPath参数 for (int i = 0; i < Math.Min(aPath.Count, 1000000); i++) // <Math.Min(aPath.Count, 10) { Line line = new Line(); // line.Container = this; line.m_strRecPath = aPath[i]; nRet = line.InitialInfo( page, channel, // sessioninfo.Channel, out strError); if (nRet == -1) return -1; if (nRet == 1) return -1; // 灵敏中断 TopArticleItem item = new TopArticleItem(); item.Line = line; this.CommentColumn.Add(item); if (page != null && (i % 100) == 0) { page.Response.Write("process " + Convert.ToString(i) + "<br/>"); page.Response.Flush(); } } if (page != null) { delta = DateTime.Now - time; page.Response.Write("build storage end. time=" + delta.ToString() + "<br/>"); page.Response.Flush(); } return 1; } finally { this.ReturnChannel(channel); } }
public int GetPatronTempId( SessionInfo sessioninfo, string strReaderBarcode, out string strCode, out string strError) { strError = ""; strCode = ""; // 临时的SessionInfo对象 SessionInfo session = sessioninfo; if (sessioninfo == null) { session = new SessionInfo(this); session.UserID = this.ManagerUserName; session.Password = this.ManagerPassword; session.IsReader = false; } try { // 读入读者记录 long lRet = session.Channel.VerifyReaderPassword(null, "!getpatrontempid:" + strReaderBarcode, null, out strError); if (lRet == -1 || lRet == 0) { // text-level: 内部错误 strError = "获得读者证号二维码时发生错误: " + strError; return -1; } strCode = strError; return 0; } finally { if (sessioninfo == null) session.CloseSession(); } }
public int GetReaderPhotoPath( // SessionInfo sessioninfo, string strReaderBarcode, string strEncyptBarcode, string strDisplayName, out string strPhotoPath, out string strError) { strError = ""; strPhotoPath = ""; if (String.IsNullOrEmpty(strEncyptBarcode) == false) { string strTemp = OpacApplication.DecryptPassword(strEncyptBarcode); if (strTemp == null) { strError = "strEncyptBarcode中包含的文字格式不正确"; return -1; } strReaderBarcode = strTemp; } // 临时的SessionInfo对象 SessionInfo session = new SessionInfo(this); session.UserID = this.ManagerUserName; session.Password = this.ManagerPassword; session.IsReader = false; try { // 读入读者记录 string strReaderXml = ""; byte[] reader_timestamp = null; string strOutputReaderRecPath = ""; string strResultTypeList = "xml"; string[] results = null; long lRet = session.Channel.GetReaderInfo(null, this.dp2LibraryVersion >= 2.22 ? "@barcode:" + strReaderBarcode // dp2Library V2.22 及以后可以使用这个方法 : strReaderBarcode, strResultTypeList, out results, out strOutputReaderRecPath, out reader_timestamp, out strError); if (lRet == 0) { strError = "读者证条码号 '" + strReaderBarcode + "' 不存在"; return 0; } if (lRet == -1) { // text-level: 内部错误 strError = "读入读者记录时发生错误: " + strError; return -1; } if (lRet > 1) { // text-level: 内部错误 strError = "读入读者记录时,发现读者证条码号 '" + strReaderBarcode + "' 命中 " + lRet.ToString() + " 条,这是一个严重错误,请系统管理员尽快处理。"; return -1; } if (results.Length != 1) { strError = "results.Length error"; return -1; } strReaderXml = results[0]; /* int nRet = this.GetReaderRecXml( sessioninfo.Channels, strReaderBarcode, out strReaderXml, out strOutputReaderRecPath, out reader_timestamp, out strError); if (nRet == 0) { strError = "读者证条码号 '" + strReaderBarcode + "' 不存在"; return 0; } if (nRet == -1) { // text-level: 内部错误 strError = "读入读者记录时发生错误: " + strError; return -1; } if (nRet > 1) { // text-level: 内部错误 strError = "读入读者记录时,发现读者证条码号 '" + strReaderBarcode + "' 命中 " + nRet.ToString() + " 条,这是一个严重错误,请系统管理员尽快处理。"; return -1; } * */ XmlDocument readerdom = null; int nRet = OpacApplication.LoadToDom(strReaderXml, out readerdom, out strError); if (nRet == -1) { // text-level: 内部错误 strError = "装载读者记录进入XML DOM时发生错误: " + strError; return -1; } // 验证显示名 if (String.IsNullOrEmpty(strDisplayName) == false) { string strDisplayNameValue = DomUtil.GetElementText(readerdom.DocumentElement, "displayName"); if (strDisplayName.Trim() != strDisplayNameValue.Trim()) { strError = "虽然读者记录找到了,但是显示名已经不匹配"; return 0; } } // 看看是不是已经有图像对象 XmlNamespaceManager nsmgr = new XmlNamespaceManager(new NameTable()); nsmgr.AddNamespace("dprms", DpNs.dprms); // 全部<dprms:file>元素 XmlNodeList nodes = readerdom.DocumentElement.SelectNodes("//dprms:file[@usage='photo']", nsmgr); if (nodes.Count == 0) { strError = "读者记录中没有头像对象"; return 0; } strPhotoPath = strOutputReaderRecPath + "/object/" + DomUtil.GetAttr(nodes[0], "id"); return 1; } finally { session.CloseSession(); } }
public int GetBiblioRecPathByCommentRecPath( SessionInfo sessioninfo, string strCommentRecPath, out string strBiblioRecPath, out string strError) { strError = ""; strBiblioRecPath = ""; // int nRet = 0; string strOutputItemPath = ""; string strItemXml = ""; byte[] item_timestamp = null; { string strCommentDbName0 = ResPath.GetDbName(strCommentRecPath); // 需要检查一下数据库名是否在允许的实体库名之列 if (this.IsCommentDbName(strCommentDbName0) == false) { strError = "评注记录路径 '" + strCommentRecPath + "' 中的数据库名 '" + strCommentDbName0 + "' 不在配置的评注库名之列,因此拒绝操作。"; return -1; } } // string strMetaData = ""; // string strTempOutputPath = ""; // string strOutputPath = ""; string strBiblio = ""; long lRet = sessioninfo.Channel.GetCommentInfo( null, "@path:" + strCommentRecPath, // null, "xml", // strResultType out strItemXml, out strOutputItemPath, out item_timestamp, "recpath", // strBiblioType out strBiblio, out strBiblioRecPath, out strError); if (lRet == -1) { strError = "获取评注记录 '" + strCommentRecPath + "' 时出错: " + strError; return -1; } /* long lRet = channel.GetRes(strCommentRecPath, out strItemXml, out strMetaData, out item_timestamp, out strOutputItemPath, out strError); if (lRet == -1) { strError = "获取评注记录 " + strCommentRecPath + " 时发生错误: " + strError; return -1; } * */ return 1; }
public int GetBiblioRecPathByItemRecPath( SessionInfo sessioninfo, string strItemRecPath, out string strBiblioRecPath, out string strError) { strError = ""; strBiblioRecPath = ""; string strOutputItemPath = ""; string strItemXml = ""; byte[] item_timestamp = null; { string strItemDbName0 = ResPath.GetDbName(strItemRecPath); // 需要检查一下数据库名是否在允许的实体库名之列 if (this.IsItemDbName(strItemDbName0) == false) { strError = "册记录路径 '" + strItemRecPath + "' 中的数据库名 '" + strItemDbName0 + "' 不在配置的实体库名之列,因此拒绝操作。"; return -1; } } string strBiblio = ""; long lRet = sessioninfo.Channel.GetItemInfo( null, "@path:" + strItemRecPath, "xml", // strResultType out strItemXml, out strOutputItemPath, out item_timestamp, "recpath", // strBiblioType out strBiblio, out strBiblioRecPath, out strError); if (lRet == -1) { strError = "获取册记录 '" + strItemRecPath + "' 时出错: " + strError; return -1; } return 1; }
public int GetBiblioRecPath( SessionInfo sessioninfo, string strItemBarcode, // string strReaderBarcode, out string strBiblioRecPath, //out string strWarning, out string strError) { strError = ""; // strWarning = ""; strBiblioRecPath = ""; // int nRet = 0; string strOutputItemPath = ""; string strItemXml = ""; byte[] item_timestamp = null; string strBiblio = ""; int nResultCount = 0; long lRet = sessioninfo.Channel.GetItemInfo( null, strItemBarcode, "", // strResultType out strItemXml, out strOutputItemPath, out item_timestamp, "recpath", // strBiblioType out strBiblio, out strBiblioRecPath, out strError); if (lRet == 0) { strError = "册条码号为 '" + strItemBarcode + "' 的册记录没有找到"; return 0; } if (lRet == -1) return -1; nResultCount = (int)lRet; return nResultCount; }
public int GetXmlDefs( bool bOuputDebugInfo, out string strDebugInfo, out string strError) { strError = ""; strDebugInfo = ""; long lRet = 0; this.m_lock.AcquireWriterLock(m_nLockTimeout); try { // 临时的SessionInfo对象 SessionInfo session = new SessionInfo(this); session.UserID = this.ManagerUserName; session.Password = this.ManagerPassword; session.IsReader = false; try { // 检查版本号 { string strVersion = ""; string strUID = ""; lRet = session.Channel.GetVersion( null, out strVersion, out strUID, out strError); if (lRet == -1) { strError = "针对 dp2Library 服务器 " + session.Channel.Url + " 获得版本号的过程发生错误:" + strError; goto ERROR1; } double value = 0; if (string.IsNullOrEmpty(strVersion) == true) { strVersion = "2.0以下"; value = 2.0; } else { // 检查最低版本号 if (double.TryParse(strVersion, out value) == false) { strError = "dp2Library 版本号 '" + strVersion + "' 格式不正确"; goto ERROR1; } } this.dp2LibraryVersion = value; this.dp2LibraryUID = strUID; double base_version = 2.40; // 2.18 if (value < base_version) { strError = "当前 dp2OPAC 版本需要和 dp2Library " + base_version + " 或以上版本配套使用 (而当前 dp2Library 版本号为 '" + strVersion + "' )。请立即升级 dp2Library 到最新版本。"; return -2; } } // 获取虚拟库定义 string strXml = ""; lRet = session.Channel.GetSystemParameter( null, "virtual", "def", out strXml, out strError); if (lRet == -1) { strError = "(" + session.UserID + ")获取虚拟库定义时发生错误: " + strError; // this.WriteErrorLog(strError); goto ERROR1; } if (bOuputDebugInfo == true) strDebugInfo += "*** virtual/def:\r\n" + strXml + "\r\n"; XmlNode node_virtual = this.OpacCfgDom.DocumentElement.SelectSingleNode("virtualDatabases"); if (node_virtual == null) { node_virtual = this.OpacCfgDom.CreateElement("virtualDatabases"); this.OpacCfgDom.DocumentElement.AppendChild(node_virtual); } node_virtual = DomUtil.SetElementOuterXml(node_virtual, strXml); Debug.Assert(node_virtual != null, ""); // 获取<arrived>定义 lRet = session.Channel.GetSystemParameter( null, "system", "arrived", out strXml, out strError); if (lRet == -1) { strError = "(" + session.UserID + ")获取<arrived>定义时发生错误: " + strError; // this.WriteErrorLog(strError); goto ERROR1; } if (bOuputDebugInfo == true) strDebugInfo += "*** system/arrived:\r\n" + strXml + "\r\n"; XmlNode node_arrived = this.OpacCfgDom.DocumentElement.SelectSingleNode("arrived"); if (node_arrived == null) { node_arrived = this.OpacCfgDom.CreateElement("arrived"); this.OpacCfgDom.DocumentElement.AppendChild(node_arrived); } node_arrived = DomUtil.SetElementOuterXml(node_arrived, strXml); Debug.Assert(node_arrived != null, ""); // 获取<browseformats>定义 lRet = session.Channel.GetSystemParameter( null, "opac", "browseformats", out strXml, out strError); if (lRet == -1) { strError = "(" + session.UserID + ")获取<browseformats>定义时发生错误: " + strError; // this.WriteErrorLog(strError); goto ERROR1; } if (bOuputDebugInfo == true) strDebugInfo += "*** opac/browseformats:\r\n" + strXml + "\r\n"; XmlNode node_browseformats = this.OpacCfgDom.DocumentElement.SelectSingleNode("browseformats"); if (node_browseformats == null) { node_browseformats = this.OpacCfgDom.CreateElement("browseformats"); this.OpacCfgDom.DocumentElement.AppendChild(node_browseformats); } node_browseformats.InnerXml = strXml; // 获取<biblioDbGroup>定义 lRet = session.Channel.GetSystemParameter( null, "system", "biblioDbGroup", out strXml, out strError); if (lRet == -1) { strError = "(" + session.UserID + ")获取<biblioDbGroup>定义时发生错误: " + strError; // this.WriteErrorLog(strError); goto ERROR1; } if (bOuputDebugInfo == true) strDebugInfo += "*** system/biblioDbGroup:\r\n" + strXml + "\r\n"; XmlNode node_biblioDbGroup = this.OpacCfgDom.DocumentElement.SelectSingleNode("biblioDbGroup"); if (node_biblioDbGroup == null) { node_biblioDbGroup = this.OpacCfgDom.CreateElement("biblioDbGroup"); this.OpacCfgDom.DocumentElement.AppendChild(node_biblioDbGroup); } node_biblioDbGroup.InnerXml = strXml; ClearInvisibleDatabaseDef(ref node_biblioDbGroup, node_virtual); // 2012/10/23 // 获取<readerDbGroup>定义 { lRet = session.Channel.GetSystemParameter( null, "system", "readerDbGroup", out strXml, out strError); if (lRet == -1) { strError = "(" + session.UserID + ")获取<readerDbGroup>定义时发生错误: " + strError; // this.WriteErrorLog(strError); goto ERROR1; } if (bOuputDebugInfo == true) strDebugInfo += "*** system/readerDbGroup:\r\n" + strXml + "\r\n"; XmlNode node_readerDbGroup = this.OpacCfgDom.DocumentElement.SelectSingleNode("readerDbGroup"); if (node_readerDbGroup == null) { node_readerDbGroup = this.OpacCfgDom.CreateElement("readerDbGroup"); this.OpacCfgDom.DocumentElement.AppendChild(node_readerDbGroup); } node_readerDbGroup.InnerXml = strXml; } this.Changed = true; this.ActivateManagerThread(); // 检查 simulatereader 和 simulateworder 权限 if (StringUtil.IsInList("simulatereader", session.Channel.Rights) == false || StringUtil.IsInList("simulateworker", session.Channel.Rights) == false) { strError = "OPAC 代理账户 '" + this.ManagerUserName + "' 缺乏 simulatereader 和 simulateworker 权限。请在 dp2library 中为它增配这两个权限"; return -1; } this.XmlLoaded = true; // 预约到书 // 元素<arrived> // 属性dbname/reserveTimeSpan/outofReservationThreshold/canReserveOnshelf XmlNode node = this.OpacCfgDom.DocumentElement.SelectSingleNode("//arrived"); if (node != null) { this.ArrivedDbName = DomUtil.GetAttr(node, "dbname"); this.ArrivedReserveTimeSpan = DomUtil.GetAttr(node, "reserveTimeSpan"); int nValue = 0; int nRet = DomUtil.GetIntegerParam(node, "outofReservationThreshold", 10, out nValue, out strError); if (nRet == -1) { strError = "元素<arrived>属性outofReservationThreshold读入时发生错误: " + strError; goto ERROR1; } this.OutofReservationThreshold = nValue; bool bValue = false; nRet = DomUtil.GetBooleanParam(node, "canReserveOnshelf", true, out bValue, out strError); if (nRet == -1) { strError = "元素<arrived>属性canReserveOnshelf读入时发生错误: " + strError; goto ERROR1; } this.CanReserveOnshelf = bValue; } return 0; } finally { session.CloseSession(); } } finally { this.m_lock.ReleaseWriterLock(); } ERROR1: return -1; }
public int GetDbFroms( string strDbType, string strLang, out BiblioDbFromInfo[] infos, out string strError) { strError = ""; infos = null; string strKey = strDbType + "|" + strLang; infos = (BiblioDbFromInfo[])this.m_fromTable[strKey]; if (infos != null) return 1; this.m_lock.AcquireWriterLock(m_nLockTimeout); try { // 临时的SessionInfo对象 SessionInfo session = new SessionInfo(this); session.UserID = this.ManagerUserName; session.Password = this.ManagerPassword; session.IsReader = false; try { // 获取虚拟库定义 long lRet = session.Channel.ListDbFroms(null, strDbType, strLang, out infos, out strError); if (lRet == -1) { strError = "(" + session.UserID + ")获得from定义时发生错误: " + strError; // this.WriteErrorLog(strError); goto ERROR1; } } finally { session.CloseSession(); } } finally { this.m_lock.ReleaseWriterLock(); } this.m_fromTable[strKey] = infos; return 0; ERROR1: return -1; }
// 将读者记录数据从XML格式转换为HTML格式 // parameters: // strRecPath 读者记录路径 2009/10/18 public int ConvertReaderXmlToHtml( SessionInfo sessioninfo, string strCsFileName, string strRefFileName, string strXml, string strRecPath, OperType opertype, string[] saBorrowedItemBarcode, string strCurrentItemBarcode, out string strResult, out string strError) { strResult = ""; strError = ""; OpacApplication app = this; // 转换为html格式 Assembly assembly = null; int nRet = app.GetXml2HtmlAssembly( strCsFileName, strRefFileName, app.BinDir, out assembly, out strError); if (nRet == -1) { goto ERROR1; } // 得到Assembly中Converter派生类Type Type entryClassType = ScriptManager.GetDerivedClassType( assembly, "DigitalPlatform.OPAC.Server.ReaderConverter"); if (entryClassType == null) { strError = "从DigitalPlatform.OPAC.Server.ReaderConverter派生的类 type entry not found"; goto ERROR1; } // new一个Converter派生对象 ReaderConverter obj = (ReaderConverter)entryClassType.InvokeMember(null, BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.CreateInstance, null, null, null); // 为Converter派生类设置参数 // obj.MainForm = this; obj.BorrowedItemBarcodes = saBorrowedItemBarcode; obj.CurrentItemBarcode = strCurrentItemBarcode; obj.OperType = opertype; obj.App = app; obj.SessionInfo = sessioninfo; obj.RecPath = strRecPath; // 调用关键函数Convert try { strResult = obj.Convert(strXml); } catch (Exception ex) { strError = "脚本执行时抛出异常: " + ExceptionUtil.GetDebugText(ex); goto ERROR1; } return(0); ERROR1: return(-1); }
public int SaveUploadFile( System.Web.UI.Page page, string strXmlRecPath, string strFileID, string strResTimeStamp, HttpPostedFile postedFile, int nLogoLimitW, int nLogoLimitH, out string strError) { strError = ""; // 临时的SessionInfo对象 SessionInfo session = new SessionInfo(this); session.UserID = this.ManagerUserName; session.Password = this.ManagerPassword; session.IsReader = false; try { return SaveUploadFile(page, session.Channel, strXmlRecPath, strFileID, strResTimeStamp, postedFile, nLogoLimitW, nLogoLimitH, out strError); } finally { session.CloseSession(); } }
public static string GetMyBookshelfFilename( OpacApplication app, SessionInfo sessioninfo) { if (String.IsNullOrEmpty(sessioninfo.UserID) == true) return null; string strUserID = sessioninfo.UserID; if (String.IsNullOrEmpty(strUserID) == true) return null; string strType = "reader"; if (sessioninfo.IsReader == false) strType = "worker"; string strDir = PathUtil.MergePath(app.DataDir + "/personaldata/" + strType, strUserID); PathUtil.CreateDirIfNeed(strDir); return PathUtil.MergePath(strDir, "mybookshelf.resultset"); }
public int DownloadObject(System.Web.UI.Page Page, LibraryChannel channel, string strPath, bool bSaveAs, string strStyle, out string strError) { strError = ""; if (channel == null) { // 临时的SessionInfo对象 // 用管理员身份 SessionInfo session = new SessionInfo(this); session.UserID = this.ManagerUserName; session.Password = this.ManagerPassword; session.IsReader = false; try { return DownloadObject0(Page, session.Channel, strPath, bSaveAs, strStyle, out strError); } finally { session.CloseSession(); } } else { return DownloadObject0(Page, channel, strPath, bSaveAs, strStyle, out strError); } }
// [外部调用] // 创建内存和物理存储对象 public int CreateCommentColumn( SessionInfo sessioninfo, System.Web.UI.Page page, out string strError) { this.m_lockCommentColumn.AcquireWriterLock(m_nCommentColumnLockTimeout); try { strError = ""; int nRet = 0; // TODO: 如何获得应用服务器帐户的权限字符串? if (String.IsNullOrEmpty(sessioninfo.UserID) == true || StringUtil.IsInList("managecache", sessioninfo.RightsOrigin) == false) { strError = "当前帐户不具备 managecache 权限,不能创建栏目缓存"; return -1; } this.CloseCommentColumn(); if (page != null && page.Response.IsClientConnected == false) // 灵敏中断 { strError = "中断"; return -1; } if (this.CommentColumn == null) this.CommentColumn = new ColumnStorage(); this.CommentColumn.ReadOnly = false; this.CommentColumn.m_strBigFileName = this.StorageFileName; this.CommentColumn.m_strSmallFileName = this.StorageFileName + ".index"; this.CommentColumn.Open(true); this.CommentColumn.Clear(); // 检索 nRet = SearchTopLevelArticles( sessioninfo, page, out strError); if (nRet == -1) return -1; // 排序 if (page != null) { page.Response.Write("--- begin sort ...<br/>"); page.Response.Flush(); } DateTime time = DateTime.Now; this.CommentColumn.Sort(); if (page != null) { TimeSpan delta = DateTime.Now - time; page.Response.Write("sort end. time=" + delta.ToString() + "<br/>"); page.Response.Flush(); } // 保存物理文件 string strTemp1; string strTemp2; this.CommentColumn.Detach(out strTemp1, out strTemp2); this.CommentColumn.ReadOnly = true; this.CloseCommentColumn(); // 重新装载 nRet = LoadCommentColumn( this.StorageFileName, out strError); if (nRet == -1) return -1; return 0; } finally { this.m_lockCommentColumn.ReleaseWriterLock(); } }
public void ThreadPoolCallBack(object context) { FilterTaskInput input = (FilterTaskInput)context; string strError = ""; #if NO // 临时的SessionInfo对象 SessionInfo session = new SessionInfo(input.App); session.UserID = input.App.ManagerUserName; session.Password = input.App.ManagerPassword; session.IsReader = false; #endif LibraryChannel channel = input.App.GetChannel(); try { Hashtable result_table = null; long lHitCount = 0; int nRet = ResultsetFilter.DoFilter( input.App, channel, // session.Channel, input.ResultSetName, input.FilterFileName, input.MaxCount, _SetProgress, ref result_table, out lHitCount, out strError); if (nRet == -1) { this.ErrorInfo = strError; this.TaskState = TaskState.Done; return; } this.HitCount = lHitCount; // 继续加工 List<NodeInfo> output_items = null; nRet = ResultsetFilter.BuildResultsetFile(result_table, input.DefDom, // input.aggregation_names, input.TempDir, // input.SessionInfo.GetTempDir(), out output_items, out strError); if (nRet == -1) { this.ErrorInfo = strError; this.TaskState = TaskState.Done; return; } { this.ResultItems = output_items; this.TaskState = TaskState.Done; } if (input.ShareResultSet == true) { // 删除全局结果集对象 // 管理结果集 // parameters: // strAction share/remove 分别表示共享为全局结果集对象/删除全局结果集对象 long lRet = // session.Channel. channel.ManageSearchResult( null, "remove", "", input.ResultSetName, out strError); if (lRet == -1) this.ErrorInfo = strError; input.ShareResultSet = false; input.ResultSetName = ""; } } finally { #if NO session.CloseSession(); #endif input.App.ReturnChannel(channel); } #if NO if (input.SessionInfo != null && string.IsNullOrEmpty(input.TaskName) == false) input.SessionInfo.SetFilterTask(input.TaskName, this); #endif input.App.SetFilterTask(input.TaskName, this); }
// 准备编辑区域 int PrepareEdit( OpacApplication app, SessionInfo sessioninfo, string strEditAction, string strRecPath, out string strError) { strError = ""; Button minimize_button = (Button)this.FindControl("minimize_button"); if (this.Minimized != "true") minimize_button.Visible = false; if (this.Active == false) { Button button = (Button)this.FindControl("changebutton"); button.Enabled = false; button = (Button)this.FindControl("deletebutton"); button.Enabled = false; button = (Button)this.FindControl("statebutton"); button.Enabled = false; button = (Button)this.FindControl("submit_button"); button.Enabled = false; button = (Button)this.FindControl("cancel_button"); button.Enabled = false; minimize_button.Enabled = false; } PlaceHolder inputline = (PlaceHolder)this.FindControl("inputline"); PlaceHolder cmdline = (PlaceHolder)this.FindControl("cmdline"); if (String.IsNullOrEmpty(strEditAction) == true) { inputline.Visible = false; // cmdline.Visible = false; return 0; } /* bool bManager = false; if (sessioninfo.Account == null || StringUtil.IsInList("managecomment", sessioninfo.RightsOrigin) == false) bManager = false; else bManager = true; * */ HiddenField edit_type = (HiddenField)this.FindControl("edit_type"); TextBox edit_title = (TextBox)this.FindControl("edit_title"); TextBox edit_content = (TextBox)this.FindControl("edit_content"); HiddenField biblio_recpath = (HiddenField)this.FindControl("biblio_recpath"); RadioButton edit_yes = (RadioButton)this.FindControl("edit_yes"); RadioButton edit_no = (RadioButton)this.FindControl("edit_no"); LiteralControl recordinfo = (LiteralControl)this.FindControl("recordinfo"); HiddenField comment_recpath = (HiddenField)this.FindControl("comment_recpath"); if (this.Active == false) { edit_title.Enabled = false; edit_content.Enabled = false; edit_yes.Enabled = false; edit_no.Enabled = false; } string strOrderSuggestion = ""; if (String.IsNullOrEmpty(strRecPath) == true) { strOrderSuggestion = "yes"; recordinfo.Text = this.GetString("创建者") + ": " + GetCurrentAccountDisplayName(); } else { string strXml; byte[] timestamp = null; if (String.IsNullOrEmpty(this.m_strXml) == true) { // return: // -1 出错 // 0 没有找到 // 1 找到 int nRet = this.GetRecord( app, sessioninfo, null, strRecPath, out strXml, out timestamp, out strError); if (nRet == -1) return -1; } else { strXml = this.m_strXml; timestamp = this.m_timestamp; } XmlDocument dom = new XmlDocument(); try { if (string.IsNullOrEmpty(strXml) == false) dom.LoadXml(strXml); else dom.LoadXml("<root />"); } catch (Exception ex) { strError = ExceptionUtil.GetAutoText(ex); return -1; } string strParentID = DomUtil.GetElementText(dom.DocumentElement, "parent"); // 帖子状态:精华、...。 string strState = DomUtil.GetElementText(dom.DocumentElement, "state"); // 帖子标题 string strTitle = DomUtil.GetElementText(dom.DocumentElement, "title"); // 作者 string strOriginCreator = DomUtil.GetElementText(dom.DocumentElement, "creator"); string strOriginContent = DomUtil.GetElementText(dom.DocumentElement, "content"); string strType = DomUtil.GetElementText(dom.DocumentElement, "type"); strOrderSuggestion = DomUtil.GetElementText(dom.DocumentElement, "orderSuggestion"); edit_title.Text = strTitle; string strContent = strOriginContent.Replace("\\r", "\r\n"); edit_content.Text = strContent; edit_type.Value = strType; if (strEditAction == "changestate") { this.SetStateValueToControls(strState); } // recpath_holder.Visible = true; recordinfo.Text = this.GetString("修改者") + ": " + GetCurrentAccountDisplayName() + "; " + this.GetString("记录路径") + ": " + strRecPath; comment_recpath.Value = strRecPath; // 修改他人的评注 if (string.IsNullOrEmpty(sessioninfo.UserID) == false && strOriginCreator != sessioninfo.UserID) { // "您正在编辑他人的评注。原始创建者为 "+strOriginCreator+"。" this.SetCommentInfo("comment", string.Format(this.GetString("您正在编辑他人的评注。原始创建者为X。"), strOriginCreator) ); } } if (string.IsNullOrEmpty(sessioninfo.UserID) == false) { if (IsReaderHasnotDisplayName() == true) { recordinfo.Text += "<div class='comment'>" + this.GetString("若想以个性化的作者名字发表评注") + ",<a href='./personalinfo.aspx' target='_blank'>" + this.GetString("点这里立即添加我的显示名") + "</a></div>"; } /* // 准备relogin string strSHA1 = Cryptography.GetSHA1(sessioninfo.UserID + "|" + sessioninfo.Account.Password); this.ReLogin = "******" + sessioninfo.UserID + ",token=" + strSHA1 + ",type=" + sessioninfo.Account.Type; * */ } bool bOrderComment = false; if (edit_type.Value == "订购征询") { if (strOrderSuggestion == "yes") edit_yes.Checked = true; else edit_no.Checked = true; bOrderComment = true; } PlaceHolder ordercomment_description_holder = (PlaceHolder)this.FindControl("ordercomment_description_holder"); LiteralControl description = (LiteralControl)this.FindControl("edit_description"); if (bOrderComment == true) { // ordercomment_description_holder.Visible = true; if (strEditAction == "new") description.Text = this.GetString("本书正在征求订购意见") + ":"; else description.Text = this.GetString("订购建议") + ":"; //type.Value = "订购征询"; if (this.Minimized == "true") minimize_button.Text = this.GetString("本书正在征求订购意见"); } else { ordercomment_description_holder.Visible = false; if (strEditAction == "new") description.Text = this.GetString("在此贡献您的书评") + ":"; else description.Text = this.GetString("评注") + ":"; //type.Value = "书评"; if (this.Minimized == "true") minimize_button.Text = this.GetString("在此贡献您的书评"); } // PlaceHolder cmdline = (PlaceHolder)this.FindControl("cmdline"); cmdline.Visible = false; PlaceHolder state_holder = (PlaceHolder)this.FindControl("state_holder"); if (this.EditAction == "changestate") { // 仅仅修改状态。上面的编辑字段都不要出现,只出现状态编辑 state_holder.Visible = true; PlaceHolder edit_up_holder = (PlaceHolder)this.FindControl("edit_up_holder"); edit_up_holder.Visible = false; } else { // 修改内容。上面的编辑字段都出现,状态编辑部分不出现 state_holder.Visible = false; } return 0; }
// return: // -1 出错 // 0 没有找到 // 1 找到 public int GetRecord( OpacApplication app, SessionInfo sessioninfo, string strRecPath, out string strXml, out byte[] timestamp, out string strError) { strError = ""; timestamp = null; strXml = ""; /* string strStyle = "content,data,timestamp"; string strMetaData; string strOutputPath; long nRet = sessioninfo.Channel.GetRes( null, strRecPath, strStyle, out strXml, out strMetaData, out timestamp, out strOutputPath, out strError); if (nRet == -1) { strError = "获取记录 '" + strRecPath + "' 时出错: " + strError; return -1; } * */ string strOutputPath = ""; string strBiblio = ""; string strBiblioRecPath = ""; // return: // -1 出错 // 0 没有找到 // 1 找到 // >1 命中多于1条 long lRet = sessioninfo.Channel.GetCommentInfo( null, "@path:" + strRecPath, // null, "xml", // strResultType out strXml, out strOutputPath, out timestamp, "recpath", // strBiblioType out strBiblio, out strBiblioRecPath, out strError); if (lRet == -1) { strError = "获取评注记录 '" + strRecPath + "' 时出错: " + strError; return -1; } if (lRet == 0) { strError = "评注记录 '" + strRecPath + "' 没有找到"; return 0; } m_strXml = strXml; m_timestamp = timestamp; return 1; }
// return: // -1 出错 // 0 没有找到 // 1 找到 public int GetRecord( OpacApplication app, SessionInfo sessioninfo, LibraryChannel channel_param, string strRecPath, out string strXml, out byte[] timestamp, out string strError) { strError = ""; timestamp = null; strXml = ""; LibraryChannel channel = null; if (channel_param != null) channel = channel_param; else channel = sessioninfo.GetChannel(true); try { string strOutputPath = ""; string strBiblio = ""; string strBiblioRecPath = ""; // return: // -1 出错 // 0 没有找到 // 1 找到 // >1 命中多于1条 long lRet = // sessioninfo.Channel. channel.GetCommentInfo( null, "@path:" + strRecPath, // null, "xml", // strResultType out strXml, out strOutputPath, out timestamp, "recpath", // strBiblioType out strBiblio, out strBiblioRecPath, out strError); if (lRet == -1) { strError = "获取评注记录 '" + strRecPath + "' 时出错: " + strError; return -1; } if (lRet == 0) { strError = "评注记录 '" + strRecPath + "' 没有找到"; return 0; } m_strXml = strXml; m_timestamp = timestamp; return 1; } finally { if (channel_param == null) sessioninfo.ReturnChannel(channel); } }
// 获得当前渲染内容的 HTML 片断代码 public static int GetContentText( OpacApplication app, SessionInfo sessioninfo, string strResultSetName, int nStart, int nCount, string strLang, out string strResult, out string strError) { strError = ""; strResult = ""; long lRet = 0; StringBuilder text = new StringBuilder(4096); Record[] searchresults = null; long lStart = nStart; long lCount = nCount; long lTotalCount = 0; for (; ; ) { lRet = sessioninfo.Channel.GetSearchResult( null, strResultSetName, lStart, lCount, "id", // cols strLang, out searchresults, out strError); if (lRet == -1 && searchresults == null) return -1; if (lRet != -1) lTotalCount = lRet; int i = 0; foreach (Record record in searchresults) { // data-index 书目记录位于结果集中的偏移量 // data_recpath 书目记录路径 text.Append("<div class='bibliorecord' data-index='"+(lStart+i).ToString()+"' data-recpath='"+HttpUtility.HtmlAttributeEncode(record.Path)+"'></div>\r\n"); i++; } lStart += searchresults.Length; lCount -= searchresults.Length; if (lStart >= lTotalCount) break; if (lStart + lCount > lTotalCount) lCount = lTotalCount - lStart; if (lCount <= 0) break; } strResult = text.ToString(); return 0; }
SessionInfo GetManagerSession(OpacApplication app) { // 临时的SessionInfo对象 if (m_managerSession == null) { // SessionInfo session m_managerSession = new SessionInfo(app); m_managerSession.UserID = app.ManagerUserName; m_managerSession.Password = app.ManagerPassword; m_managerSession.IsReader = false; } return m_managerSession; }
public void ThreadPoolCallBack(object context) { FilterTaskInput input = (FilterTaskInput)context; Hashtable result_table = null; string strError = ""; // 临时的SessionInfo对象 SessionInfo session = new SessionInfo(input.App); session.UserID = input.App.ManagerUserName; session.Password = input.App.ManagerPassword; session.IsReader = false; try { long lHitCount = 0; int nRet = ResultsetFilter.DoFilter( input.App, session.Channel, input.ResultSetName, input.FilterFileName, input.MaxCount, _SetProgress, ref result_table, out lHitCount, out strError); if (nRet == -1) { this.ErrorInfo = strError; this.TaskState = TaskState.Done; return; } this.HitCount = lHitCount; /* if (string.IsNullOrEmpty(strFacetDefXml) == false) { this.DefDom = new XmlDocument(); try { this.DefDom.LoadXml(strFacetDefXml); } catch (Exception ex) { this.ErrorInfo = "strDefXml装入XMLDOM出错: " + ex.Message; this.TaskState = TaskState.Done; return; } } * */ // 继续加工 List<NodeInfo> output_items = null; nRet = ResultsetFilter.BuildResultsetFile(result_table, input.DefDom, // input.aggregation_names, input.SessionInfo.GetTempDir(), out output_items, out strError); if (nRet == -1) { this.ErrorInfo = strError; this.TaskState = TaskState.Done; return; } { this.ResultItems = output_items; this.TaskState = TaskState.Done; } if (input.ShareResultSet == true) { // 删除全局结果集对象 // 管理结果集 // parameters: // strAction share/remove 分别表示共享为全局结果集对象/删除全局结果集对象 long lRet = session.Channel.ManageSearchResult( null, "remove", "", input.ResultSetName, out strError); if (lRet == -1) this.ErrorInfo = strError; input.ShareResultSet = false; input.ResultSetName = ""; } } finally { session.CloseSession(); } if (input.SessionInfo != null && string.IsNullOrEmpty(input.TaskName) == false) input.SessionInfo.SetFilterTask(input.TaskName, this); }
string BuildBrowseContent( OpacApplication app, SessionInfo sessioninfo, string strDbName, string[] cols) { string strError = ""; List<string> captions = null; // 先从catch中找 captions = (List<string>)this.m_usedColumnCaptionTable[strDbName]; if (captions == null) { // 获得一个库的浏览列标题 // return: // -1 出错 // 0 没有找到 // 1 找到 int nRet = app.GetBrowseColumnCaptions( sessioninfo, strDbName, this.Lang, out captions, out strError); if (nRet == -1) return StringUtil.MakePathList(cols).Replace(",", "<br/>") + "<br/>" + strError; if (nRet == 0 || captions == null || captions.Count == 0) return StringUtil.MakePathList(cols).Replace(",", "<br/>"); this.m_usedColumnCaptionTable[strDbName] = captions; } StringBuilder result = new StringBuilder(4096); result.Append("<table class='brief_content'>"); for (int i = 1; i < cols.Length; i++) { result.Append("<tr><td class='name'>"); string strName = ""; if (i - 1 < captions.Count) strName = captions[i - 1]; result.Append(strName + "</td><td class='value'>" + cols[i]); result.Append("</td></tr>"); } result.Append("</table>"); return result.ToString(); }
TempChannel GetTempChannel(string strPassword) { TempChannel temp = new TempChannel(); if (StringUtil.HasHead(this.Password, "token:") == true) { // 临时的SessionInfo对象 SessionInfo session = new SessionInfo(this.App); session.UserID = this.App.ManagerUserName; session.Password = this.App.ManagerPassword; session.IsReader = false; temp.Session = session; temp.Channel = session.Channel; } else { temp.Channel = this.Channel; } return temp; }
void RenderBorrow( OpacApplication app, SessionInfo sessioninfo, XmlDocument dom) { string strReaderType = DomUtil.GetElementText(dom.DocumentElement, "readerType"); // 获得日历 string strError = ""; /* Calendar calendar = null; int nRet = app.GetReaderCalendar(strReaderType, out calendar, out strError); if (nRet == -1) { this.SetDebugInfo("warninginfo", strError); calendar = null; } * */ // return: // null xml文件不存在,或者<borrowInfoControl>元素不存在 string strColumnStyle = GetColumnStyle(app); if (strColumnStyle == null) strColumnStyle = ""; // 2009/11/23 防止ToLower()抛出异常 // 借阅的册 PlaceHolder borrowinfo = (PlaceHolder)this.FindControl("borrowinfo"); // 清空集合 this.BorrowBarcodes = new List<string>(); string strReaderBarcode = DomUtil.GetElementText(dom.DocumentElement, "barcode"); XmlNodeList nodes = dom.DocumentElement.SelectNodes("borrows/borrow"); this.BorrowLineCount = nodes.Count; for (int i = 0; i < nodes.Count; i++) { PlaceHolder line = (PlaceHolder)borrowinfo.FindControl("borrowinfo_line" + Convert.ToString(i)); if (line == null) { Control insertpos = borrowinfo.FindControl("borrowinfo_insertpos"); line = NewBorrowLine(insertpos.Parent, i, insertpos); // this.BorrowLineCount++; } line.Visible = true; LiteralControl left = (LiteralControl)line.FindControl("borrowinfo_line" + Convert.ToString(i) + "left"); CheckBox checkbox = (CheckBox)line.FindControl("borrowinfo_line" + Convert.ToString(i) + "checkbox"); LiteralControl right = (LiteralControl)line.FindControl("borrowinfo_line" + Convert.ToString(i) + "right"); XmlNode node = nodes[i]; string strBarcode = DomUtil.GetAttr(node, "barcode"); // 添加到集合 this.BorrowBarcodes.Add(strBarcode); string strNo = DomUtil.GetAttr(node, "no"); string strBorrowDate = DomUtil.GetAttr(node, "borrowDate"); string strPeriod = DomUtil.GetAttr(node, "borrowPeriod"); string strOperator = DomUtil.GetAttr(node, "operator"); string strRenewComment = DomUtil.GetAttr(node, "renewComment"); string strOverDue = ""; bool bOverdue = false; // 是否超期 DateTime timeReturning = DateTime.MinValue; string strTips = ""; #if NO if (strColumnStyle.ToLower() == "style1") { DateTime timeNextWorkingDay; long lOver = 0; string strPeriodUnit = ""; // 获得还书日期 // return: // -1 数据格式错误 // 0 没有发现超期 // 1 发现超期 strError中有提示信息 // 2 已经在宽限期内,很容易超期 nRet = app.GetReturningTime( calendar, strBorrowDate, strPeriod, out timeReturning, out timeNextWorkingDay, out lOver, out strPeriodUnit, out strError); if (nRet == -1) strOverDue = strError; else { strTips = strError; if (nRet == 1) { bOverdue = true; strOverDue = " (" + string.Format(this.GetString("已超期s"), // 已超期 {0} app.GetDisplayTimePeriodStringEx(lOver.ToString() + " " + strPeriodUnit)) + ")"; /* strOverDue = " (已超期 " + lOver.ToString() + " " + app.GetDisplayTimeUnitLang(strPeriodUnit) + ")"; * */ } } } else { // string strError = ""; // 检查超期情况。 // return: // -1 数据格式错误 // 0 没有发现超期 // 1 发现超期 strError中有提示信息 nRet = app.CheckPeriod( calendar, strBorrowDate, strPeriod, out strError); if (nRet == -1) strOverDue = strError; else { if (nRet == 1) bOverdue = true; strOverDue = strError; // 其他无论什么情况都显示出来 } } #endif string strResult = ""; string strTrClass = " class='dark' "; if ((i % 2) == 1) strTrClass = " class='light' "; strResult += "<tr " + strTrClass + " nowrap><td class='barcode' nowrap>"; // 左 left.Text = strResult; // checkbox // checkbox.Text = Convert.ToString(i + 1); // 右开始 strResult = " "; strResult += "<a href='book.aspx?barcode=" + strBarcode + "&borrower=" + strReaderBarcode + "'>" + strBarcode + "</a></td>"; #if NO // 获得摘要 string strSummary = ""; string strBiblioRecPath = ""; long lRet = sessioninfo.Channel.GetBiblioSummary( null, strBarcode, null, null, out strBiblioRecPath, out strSummary, out strError); if (lRet == -1 || lRet == 0) strSummary = strError; /* LibraryServerResult result = app.GetBiblioSummary( sessioninfo, strBarcode, null, null, out strBiblioRecPath, out strSummary); if (result.Value == -1 || result.Value == 0) strSummary = result.ErrorInfo; * */ #endif strResult += "<td class='summary pending' width='50%'>" + strBarcode + "</td>"; strResult += "<td class='no' nowrap align='right'>" + strNo + "</td>"; // 续借次 strResult += "<td class='borrowdate' nowrap>" + OpacApplication.LocalDateOrTime(strBorrowDate, strPeriod) + "</td>"; strResult += "<td class='borrowperiod' nowrap>" + app.GetDisplayTimePeriodStringEx(strPeriod) + "</td>"; strOverDue = DomUtil.GetAttr(node, "overdueInfo"); string strOverdue1 = DomUtil.GetAttr(node, "overdueInfo1"); string strIsOverdue = DomUtil.GetAttr(node, "isOverdue"); if (strIsOverdue == "yes") bOverdue = true; string strTimeReturning = DomUtil.GetAttr(node, "timeReturning"); if (String.IsNullOrEmpty(strTimeReturning) == false) timeReturning = DateTimeUtil.FromRfc1123DateTimeString(strTimeReturning).ToLocalTime(); if (strColumnStyle.ToLower() == "style1") { strTips = strOverDue; strOverDue = strOverdue1; if (bOverdue == true) strResult += "<td class='returningdate overdue'>" + "<a title=\"" + strTips.Replace("\"", "'") + "\">" + OpacApplication.LocalDateOrTime(timeReturning, strPeriod) // + timeReturning.ToString("d") + strOverDue + "</a>" + "</td>"; else strResult += "<td class='returningdate'>" + "<a title=\"" + strTips.Replace("\"", "'") + "\">" + OpacApplication.LocalDateOrTime(timeReturning, strPeriod) // + timeReturning.ToString("d") + strOverDue + "</a>" + "</td>"; } else { if (bOverdue == true) strResult += "<td class='overdue'>" + strOverDue + "</td>"; else strResult += "<td class='notoverdue'>" + strOverDue + "</td>"; } strResult += "<td class='renewcomment'>" + strRenewComment.Replace(";", "<br/>") + "</td>"; strResult += "<td class='operator' nowrap>" + strOperator + "</td>"; strResult += "</tr>"; right.Text = strResult; } // 把多余的行隐藏起来 for (int i = nodes.Count; ; i++) { PlaceHolder line = (PlaceHolder)borrowinfo.FindControl("borrowinfo_line" + Convert.ToString(i)); if (line == null) break; line.Visible = false; } if (nodes.Count == 0) { Control insertpos = borrowinfo.FindControl("borrowinfo_insertpos"); int pos = insertpos.Parent.Controls.IndexOf(insertpos); if (pos == -1) { // text-level: 内部错误 throw new Exception("插入参照对象没有找到"); } LiteralControl literal = new LiteralControl(); literal.Text = "<tr class='dark'><td colspan='8'>" + this.GetString("(无借阅信息)") + "<td></tr>"; insertpos.Parent.Controls.AddAt(pos, literal); } }
// 获得一个库的浏览列标题 // return: // -1 出错 // 0 没有找到 // 1 找到 public int GetBrowseColumnCaptions( SessionInfo sessioninfo, string strDbName, string strLang, out List<string> captions, out string strError) { strError = ""; captions = null; REDO: List<BrowseColumnCaption> results = (List<BrowseColumnCaption>)this.BrowsColumnTable[strDbName]; if (results != null && results.Count > 0) { if (results.Count == 1) { captions = results[0].ColumnCaptions; return 1; } string strLangLeft = ""; string strLangRight = ""; DomUtil.SplitLang(strLang, out strLangLeft, out strLangRight); for (int i = 0; i < results.Count; i++) { BrowseColumnCaption cur_captions = results[i]; string strThisLang = cur_captions.Lang; string strThisLangLeft = ""; string strThisLangRight = ""; DomUtil.SplitLang(strThisLang, out strThisLangLeft, out strThisLangRight); // 是不是左右都匹配则更好?如果不行才是第一个左边匹配的 if (strThisLangLeft == strLangLeft) { captions = cur_captions.ColumnCaptions; return 1; } } captions = results[0].ColumnCaptions; return 1; } string strRemotePath = strDbName + "/cfgs/browse"; string strLocalPath = ""; #if NO // 临时的SessionInfo对象 SessionInfo session = new SessionInfo(this); session.UserID = this.ManagerUserName; session.Password = this.ManagerPassword; session.IsReader = false; session.Parameters = ""; // 2014/12/23 #endif LibraryChannel channel = this.GetChannel(); try { int nRet = this.CfgsMap.MapFileToLocal( channel, //session.Channel, strRemotePath, out strLocalPath, out strError); if (nRet == -1) { strError = "获得配置文件 '" + strRemotePath + "' 时发生错误:" + strError; return -1; } if (nRet == 0) return 0; } finally { #if NO session.CloseSession(); #endif this.ReturnChannel(channel); } XmlDocument dom = new XmlDocument(); try { dom.Load(strLocalPath); } catch (Exception ex) { strError = "数据库 " + strDbName + " 的browse配置文件 '" + strLocalPath + "' 装入XMLDOM时出错: " + ex.Message; return -1; } List<BrowseColumnCaption> defs = new List<BrowseColumnCaption>(); XmlNodeList lang_nodes = dom.DocumentElement.SelectNodes("//col/title/caption/@lang"); if (lang_nodes.Count > 0) { List<string> langs = new List<string>(); foreach (XmlNode node in lang_nodes) { string strValue = node.Value; if (langs.IndexOf(strValue) == -1) langs.Add(strValue); } XmlNodeList col_nodes = dom.DocumentElement.SelectNodes("//col"); foreach (string lang in langs) { BrowseColumnCaption one = new BrowseColumnCaption(); one.Lang = lang; one.ColumnCaptions = new List<string>(); defs.Add(one); foreach (XmlNode node in col_nodes) { XmlNode nodeTitle = node.SelectSingleNode("title"); if (nodeTitle != null) { string strCaption = DomUtil.GetLangedNodeText( lang, nodeTitle, "caption", true); one.ColumnCaptions.Add(strCaption); } else { // 被迫使用<col>元素的title属性 one.ColumnCaptions.Add(DomUtil.GetAttr(node, "title")); } } } this.BrowsColumnTable[strDbName] = defs; goto REDO; } { BrowseColumnCaption one = new BrowseColumnCaption(); one.Lang = "zh"; // 缺省为zh one.ColumnCaptions = new List<string>(); defs.Add(one); XmlNodeList nodes = dom.DocumentElement.SelectNodes("//col"); for (int j = 0; j < nodes.Count; j++) { string strColumnTitle = DomUtil.GetAttr(nodes[j], "title"); one.ColumnCaptions.Add(strColumnTitle); } this.BrowsColumnTable[strDbName] = defs; goto REDO; } }
// 将读者记录数据从XML格式转换为HTML格式 // parameters: // strRecPath 读者记录路径 2009/10/18 public int ConvertReaderXmlToHtml( SessionInfo sessioninfo, string strCsFileName, string strRefFileName, string strXml, string strRecPath, OperType opertype, string[] saBorrowedItemBarcode, string strCurrentItemBarcode, out string strResult, out string strError) { strResult = ""; strError = ""; OpacApplication app = this; // 转换为html格式 Assembly assembly = null; int nRet = app.GetXml2HtmlAssembly( strCsFileName, strRefFileName, app.BinDir, out assembly, out strError); if (nRet == -1) { goto ERROR1; } // 得到Assembly中Converter派生类Type Type entryClassType = ScriptManager.GetDerivedClassType( assembly, "DigitalPlatform.OPAC.Server.ReaderConverter"); if (entryClassType == null) { strError = "从DigitalPlatform.OPAC.Server.ReaderConverter派生的类 type entry not found"; goto ERROR1; } // new一个Converter派生对象 ReaderConverter obj = (ReaderConverter)entryClassType.InvokeMember(null, BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.CreateInstance, null, null, null); // 为Converter派生类设置参数 // obj.MainForm = this; obj.BorrowedItemBarcodes = saBorrowedItemBarcode; obj.CurrentItemBarcode = strCurrentItemBarcode; obj.OperType = opertype; obj.App = app; obj.SessionInfo = sessioninfo; obj.RecPath = strRecPath; // 调用关键函数Convert try { strResult = obj.Convert(strXml); } catch (Exception ex) { strError = "脚本执行时抛出异常: " + ExceptionUtil.GetDebugText(ex); goto ERROR1; } return 0; ERROR1: return -1; }
// 映射内核脚本配置文件到本地 // parameters: // sessioninfo_param 如果为null,函数内部会自动创建一个SessionInfo对象,是管理员权限 // return: // -1 error // 0 成功,为.cs文件 // 1 成功,为.fltx文件 public int MapKernelScriptFile( SessionInfo sessioninfo_param, string strBiblioDbName, string strScriptFileName, out string strLocalPath, out string strError) { strError = ""; strLocalPath = ""; int nRet = 0; LibraryChannel channel = null; #if NO SessionInfo sessioninfo = null; #endif // 应该用管理员的权限来做这个事情 // 临时的SessionInfo对象 if (sessioninfo_param == null) { #if NO sessioninfo = new SessionInfo(this); sessioninfo.UserID = this.ManagerUserName; sessioninfo.Password = this.ManagerPassword; sessioninfo.IsReader = false; #endif channel = this.GetChannel(); } else { #if NO sessioninfo = sessioninfo_param; #endif channel = sessioninfo_param.Channel; } try { // 将种记录数据从XML格式转换为HTML格式 // 需要从内核映射过来文件 // string strScriptFileName = "./cfgs/loan_biblio.fltx"; // 将脚本文件名正规化 // 因为在定义脚本文件的时候, 有一个当前库名环境, // 如果定义为 ./cfgs/filename 表示在当前库下的cfgs目录下, // 而如果定义为 /cfgs/filename 则表示在同服务器的根下 string strRemotePath = OpacApplication.CanonicalizeScriptFileName( strBiblioDbName, strScriptFileName); // TODO: 还可以考虑支持http://这样的配置文件。 nRet = this.CfgsMap.MapFileToLocal( channel, // sessioninfo.Channel, strRemotePath, out strLocalPath, out strError); if (nRet == -1) { goto ERROR1; } if (nRet == 0) { strError = "内核配置文件 " + strRemotePath + "没有找到,因此无法获得书目html格式数据"; goto ERROR1; } bool bFltx = false; // 如果是一般.cs文件, 还需要获得.cs.ref配置文件 if (OpacApplication.IsCsFileName( strScriptFileName) == true) { string strTempPath = ""; nRet = this.CfgsMap.MapFileToLocal( channel, // sessioninfo_param.Channel, strRemotePath + ".ref", out strTempPath, out strError); if (nRet == -1) { strError = "内核配置文件 " + strRemotePath + ".ref" + "没有找到,因此无法获得书目html格式数据"; goto ERROR1; } bFltx = false; } else { bFltx = true; } if (bFltx == true) { return(1); // 为.fltx文件 } return(0); ERROR1: return(-1); } finally { if (sessioninfo_param == null) { #if NO sessioninfo.CloseSession(); #endif this.ReturnChannel(channel); } } }