public DefaultThread(OpacApplication app, string strName) : base(app, strName) { this.Loop = true; this.PerTime = 5 * 60 * 1000; // 5分钟 }
// 获得名称对照表 // 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); }
// 初始化 SearchLog 对象 // parameters: // strEnable 启用哪些 log 功能? searchlog,hitcount public int Open(OpacApplication app, string strEnable, out string strError) { strError = ""; if (string.IsNullOrEmpty(app.MongoDbConnStr) == true) { strError = "opac.xml 中尚未配置 <mongoDB> 元素的 connectString 属性,无法初始化 SearchLog 对象"; return -1; } this.App = app; string strPrefix = app.MongoDbInstancePrefix; if (string.IsNullOrEmpty(strPrefix) == false) strPrefix = strPrefix + "_"; m_strSearchLogDatabaseName = strPrefix + "searchlog"; m_strHitCountDatabaseName = strPrefix + "hitcount"; try { this.m_mongoClient = new MongoClient(app.MongoDbConnStr); } catch (Exception ex) { strError = "初始化 SearchLog 时出错: " + ex.Message; return -1; } var server = m_mongoClient.GetServer(); if (StringUtil.IsInList("hitcount", strEnable) == true) { var db = server.GetDatabase(this.m_strHitCountDatabaseName); _hitCountCollection = db.GetCollection<HitCountItem>("hitcount"); if (_hitCountCollection.GetIndexes().Count == 0) _hitCountCollection.CreateIndex(new IndexKeysBuilder().Ascending("URL"), IndexOptions.SetUnique(true)); } if (StringUtil.IsInList("searchlog", strEnable) == true) { var db = server.GetDatabase(this.m_strSearchLogDatabaseName); this._searchLogCollection = db.GetCollection<SearchLogItem>("log"); #if NO if (_searchLogCollection.GetIndexes().Count == 0) _searchLogCollection.CreateIndex(new IndexKeysBuilder().Ascending("???"), IndexOptions.SetUnique(true)); #endif } return 0; }
public string ClientIP = ""; // 前端的 IP 地址 public SessionInfo(OpacApplication app) { Debug.Assert(app != null, ""); this.App = app; #if USE_SESSION_CHANNEL this.Channel.Url = app.WsUrl; this.Channel.BeforeLogin -= new BeforeLoginEventHandle(Channel_BeforeLogin); this.Channel.BeforeLogin += new BeforeLoginEventHandle(Channel_BeforeLogin); this.Channel.AfterLogin -= new AfterLoginEventHandle(Channel_AfterLogin); this.Channel.AfterLogin += new AfterLoginEventHandle(Channel_AfterLogin); #endif this.m_strTempDir = PathUtil.MergePath(app.SessionDir, this.GetHashCode().ToString()); }
public BatchTask(OpacApplication app, string strName) { if (String.IsNullOrEmpty(strName) == true) { this.Name = this.DefaultName; } else { this.Name = strName; } this.App = app; #if NO this.Channel.Url = app.WsUrl; this.Channel.BeforeLogin -= new BeforeLoginEventHandle(Channel_BeforeLogin); this.Channel.BeforeLogin += new BeforeLoginEventHandle(Channel_BeforeLogin); #endif this.ProgressFileName = Path.GetTempFileName(); try { // 如果文件存在,就打开,如果文件不存在,就创建一个新的 m_stream = File.Open( this.ProgressFileName, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite); this.ProgressFileVersion = DateTime.Now.Ticks; } catch (Exception ex) { string strError = "打开或创建文件 '" + this.ProgressFileName + "' 发生错误: " + ex.Message; throw new Exception(strError); } m_stream.Seek(0, SeekOrigin.End); }
// 根据特性的评注记录路径,获得一定范围的检索命中结果 // return: // -1 出错 // 0 没有找到 // 1 找到 public static int GetCommentsSearchResult( OpacApplication app, LibraryChannel channel, ItemLoadEventHandler itemLoadProc, SetStartEventHandler setStartProc, int nPerCount, string strCommentRecPath, bool bGetRecord, string strLang, // 2012/7/9 out int nStart, out string strError) { strError = ""; nStart = -1; long lHitCount = 0; bool bFound = false; List<string> aPath = null; for (int j = 0; ; j++) { nStart = j * nPerCount; // 只获得路径。确保所要的lStart lCount范围全部获得 long lRet = // this.Channel. channel.GetSearchResult( null, "default", nStart, // 0, nPerCount, // -1, strLang, out aPath, out strError); if (lRet == -1) goto ERROR1; lHitCount = lRet; if (lHitCount == 0) return 0; if (aPath.Count == 0) break; for (int i = 0; i < aPath.Count; i++) { if (aPath[i] == strCommentRecPath) { bFound = true; break; } } if (bFound == true) break; if (nStart >= lHitCount) break; } if (bFound == true) { if (// this.SetStart != null setStartProc != null) { SetStartEventArgs e = new SetStartEventArgs(); e.StartIndex = nStart; // this.SetStart(this, e); setStartProc(null, e); } for (int i = 0; i < aPath.Count; i++) { if (bGetRecord == true) { string strXml = ""; string strMetaData = ""; byte[] timestamp = null; string strOutputPath = ""; string strStyle = LibraryChannel.GETRES_ALL_STYLE; long lRet = // this.Channel. channel.GetRes( null, aPath[i], strStyle, out strXml, out strMetaData, out timestamp, out strOutputPath, out strError); if (lRet == -1) goto ERROR1; if (//this.ItemLoad != null itemLoadProc != null) { ItemLoadEventArgs e = new ItemLoadEventArgs(); e.Path = aPath[i]; e.Index = i; e.Count = aPath.Count; e.Xml = strXml; e.Timestamp = timestamp; e.TotalCount = (int)lHitCount; // this.ItemLoad(this, e); e.Channel = channel; itemLoadProc(null, e); } } else { if (//this.ItemLoad != null itemLoadProc != null) { ItemLoadEventArgs e = new ItemLoadEventArgs(); e.Path = aPath[i]; e.Index = i; e.Count = aPath.Count; e.Xml = ""; e.Timestamp = null; e.TotalCount = (int)lHitCount; // this.ItemLoad(this, e); e.Channel = channel; itemLoadProc(null, e); } } } return 1; // 找到 } nStart = -1; strError = "路径为 '" + strCommentRecPath + "' 的记录在结果集中没有找到"; return 0; // 没有找到 ERROR1: return -1; }
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); } }
// 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); }
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(); }
// 准备编辑区域 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, 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); } }
// 将一般库记录数据从XML格式转换为HTML格式 // parameters: // strRecPath 记录路径。用途是为了给宿主对象的RecPath成员赋值 // 2009/10/18 // return: // -2 基类为ReaderConverter public int ConvertRecordXmlToHtml( string strCsFileName, string strRefFileName, string strXml, string strRecPath, 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中RecordConverter派生类Type Type entryClassType = ScriptManager.GetDerivedClassType( assembly, "DigitalPlatform.OPAC.Server.RecordConverter"); if (entryClassType == null) { // 当没有找到RecordConverter的派生类时, // 继续从代码中找一下有没有ReaderConverter的派生类,如果有,则返回-2,这样函数返回后就为调主多提供了一点信息,便于后面继续处理 entryClassType = ScriptManager.GetDerivedClassType( assembly, "DigitalPlatform.OPAC.Server.ReaderConverter"); if (entryClassType == null) { strError = "从DigitalPlatform.OPAC.Server.RecordConverter派生的类 type entry not found"; goto ERROR1; } return(-2); } // new一个RecordConverter派生对象 RecordConverter obj = (RecordConverter)entryClassType.InvokeMember(null, BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.CreateInstance, null, null, null); // 为RecordConverter派生类设置参数 obj.App = app; obj.RecPath = strRecPath; // 调用关键函数Convert try { strResult = obj.Convert(strXml); } catch (Exception ex) { strError = "脚本执行时抛出异常: " + ExceptionUtil.GetDebugText(ex); goto ERROR1; } return(0); ERROR1: return(-1); }
public static string GetBiblioRecPath( OpacApplication app, string strCommentRecPath, string strParentID) { string strCommentDbName = StringUtil.GetDbName(strCommentRecPath); string strBiblioDbName = GetBiblioDbName(app, strCommentDbName); return strBiblioDbName + "/" + strParentID; }
protected void Application_Start(Object sender, EventArgs e) { RegisterRoutes(RouteTable.Routes); OpacApplication app = null; try { int nRet = 0; string strError = ""; #if NO string strErrorLogDir = this.Server.MapPath(".\\log"); PathUtil.CreateDirIfNeed(strErrorLogDir); string strErrorLogFileName = PathUtil.MergePath(strErrorLogDir, "error.txt"); #endif try { string strDataDir = ""; // reutrn: // -1 error // 0 not found start.xml // 1 found start.xml nRet = OpacApplication.GetDataDir(this.Server.MapPath("~/start.xml"), out strDataDir, out strError); if (nRet == -1) { strError = "搜寻配置文件start.xml时出错: " + strError; #if NO OpacApplication.WriteErrorLog(strErrorLogFileName, strError); #endif OpacApplication.WriteWindowsLog(strError); Application["errorinfo"] = strError; return; } if (nRet == 0) { #if NO // 实在没有start.xml文件, 默认虚拟目录就是数据目录 strDataDir = this.Server.MapPath("."); #endif // 2014/2/21 // 不再允许虚拟目录中 start.xml 没有的情况 OpacApplication.WriteWindowsLog("OpacApplication.GetDataDir() error : " + strError); Application["errorinfo"] = strError; return; } app = new OpacApplication(); Application["app"] = app; // string strHostDir = this.Server.MapPath("."); string strHostDir = Path.GetDirectoryName(this.Server.MapPath("~/start.xml")); // 2015/7/20 nRet = app.Load( false, strDataDir, strHostDir, out strError); if (nRet == -1) { #if NO OpacApplication.WriteErrorLog(strErrorLogFileName, strError); #endif // TODO: 预先试探一下写入数据目录中的错误日志文件是否成功。如果成功,则可以把错误信息写入那里 OpacApplication.WriteWindowsLog(strError); // Application["errorinfo"] = strError; app.GlobalErrorInfo = strError; } else { nRet = app.Verify(out strError); if (nRet == -1) { #if NO OpacApplication.WriteErrorLog(strErrorLogFileName, strError); #endif OpacApplication.WriteWindowsLog(strError); // Application["errorinfo"] = strError; app.GlobalErrorInfo = strError; } } OpacApplication.WriteWindowsLog("dp2OPAC Application 启动成功", EventLogEntryType.Information); } catch (Exception ex) { strError = "装载配置文件 opac.xml 出错: " + ExceptionUtil.GetDebugText(ex); #if NO OpacApplication.WriteErrorLog(strErrorLogFileName, strError); #endif OpacApplication.WriteWindowsLog(strError); if (app != null) app.GlobalErrorInfo = strError; else Application["errorinfo"] = strError; } } catch (Exception ex) { string strErrorText = "Application_Start阶段出现异常: " + ExceptionUtil.GetDebugText(ex); OpacApplication.WriteWindowsLog(strErrorText); if (app != null) app.GlobalErrorInfo = strErrorText; else Application["errorinfo"] = strErrorText; } }
// TODO: 结果集是和 channel 在一起的。如果 channel 不确定,就需要用全局结果集 // 获得一定范围的检索命中结果 // return: public int GetCommentsSearchResult( OpacApplication app, int nStart, int nMaxCount, bool bGetRecord, string strLang, // 2012/7/9 out string strError) { strError = ""; List <string> aPath = null; long lRet = this.Channel.GetSearchResult( null, "default", nStart, // 0, nMaxCount, // -1, strLang, out aPath, out strError); if (lRet == -1) { goto ERROR1; } long lHitCount = lRet; if (aPath.Count == 0) { strError = "GetSearchResult aPath error"; goto ERROR1; } for (int i = 0; i < aPath.Count; i++) { if (bGetRecord == true) { string strXml = ""; string strMetaData = ""; byte[] timestamp = null; string strOutputPath = ""; string strStyle = LibraryChannel.GETRES_ALL_STYLE; lRet = this.Channel.GetRes( null, aPath[i], strStyle, out strXml, out strMetaData, out timestamp, out strOutputPath, out strError); if (lRet == -1) { goto ERROR1; } if (this.ItemLoad != null) { ItemLoadEventArgs e = new ItemLoadEventArgs(); e.Path = aPath[i]; e.Index = i; e.Count = aPath.Count; e.Xml = strXml; e.Timestamp = timestamp; e.TotalCount = (int)lHitCount; this.ItemLoad(this, e); } } else { if (this.ItemLoad != null) { ItemLoadEventArgs e = new ItemLoadEventArgs(); e.Path = aPath[i]; e.Index = i; e.Count = aPath.Count; e.Xml = ""; e.Timestamp = null; e.TotalCount = (int)lHitCount; this.ItemLoad(this, e); } } } return(0); ERROR1: return(-1); }
// return: // null xml文件不存在,或者<borrowInfoControl>元素不存在 static string GetColumnStyle(OpacApplication app) { if (app == null || app.WebUiDom == null) return null; XmlNode node = app.WebUiDom.DocumentElement.SelectSingleNode("borrowInfoControl"); if (node == null) return null; return DomUtil.GetAttr(node, "columnStyle"); }
// 将种记录数据从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); }
// 将读者记录数据从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); } } }
// 映射内核脚本配置文件到本地 // parameters: // sessioninfo_param 如果为null,函数内部会自动创建一个SessionInfo对象,是管理员权限 // return: // -1 error // 0 成功,为.cs文件 // 1 成功,为.fltx文件 public int MapKernelScriptFile( string strBiblioDbName, string strScriptFileName, out string strLocalPath, out string strError) { strError = ""; strLocalPath = ""; int nRet = 0; LibraryChannel channel = this.GetChannel(); 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 { this.ReturnChannel(channel); } }
// 初始化 SearchLog 对象 // parameters: // strEnable 启用哪些 log 功能? searchlog,hitcount public int Open(OpacApplication app, string strEnable, out string strError) { strError = ""; if (string.IsNullOrEmpty(app.MongoDbConnStr) == true) { strError = "opac.xml 中尚未配置 <mongoDB> 元素的 connectString 属性,无法初始化 SearchLog 对象"; return(-1); } this.App = app; string strPrefix = app.MongoDbInstancePrefix; if (string.IsNullOrEmpty(strPrefix) == false) { strPrefix = strPrefix + "_"; } m_strSearchLogDatabaseName = strPrefix + "searchlog"; m_strHitCountDatabaseName = strPrefix + "hitcount"; try { this.m_mongoClient = new MongoClient(app.MongoDbConnStr); } catch (Exception ex) { strError = "初始化 SearchLog 时出错: " + ex.Message; return(-1); } var server = m_mongoClient.GetServer(); if (StringUtil.IsInList("hitcount", strEnable) == true) { var db = server.GetDatabase(this.m_strHitCountDatabaseName); _hitCountCollection = db.GetCollection <HitCountItem>("hitcount"); if (_hitCountCollection.GetIndexes().Count == 0) { _hitCountCollection.CreateIndex(new IndexKeysBuilder().Ascending("URL"), IndexOptions.SetUnique(true)); } } if (StringUtil.IsInList("searchlog", strEnable) == true) { var db = server.GetDatabase(this.m_strSearchLogDatabaseName); this._searchLogCollection = db.GetCollection <SearchLogItem>("log"); #if NO if (_searchLogCollection.GetIndexes().Count == 0) { _searchLogCollection.CreateIndex(new IndexKeysBuilder().Ascending("???"), IndexOptions.SetUnique(true)); } #endif } return(0); }
/* * ASP.NET 4.0.30319.0 Error 2016/10/14 17:06:02 * 发生了未经处理的异常,已终止进程。 * * Application ID: /LM/W3SVC/1/ROOT/dp2OPAC * * Process ID: 15760 * * Exception: System.ObjectDisposedException * * Message: 已关闭 Safe handle * * StackTrace: 在 System.Runtime.InteropServices.SafeHandle.DangerousAddRef(Boolean& success) * 在 Microsoft.Win32.Win32Native.SetEvent(SafeWaitHandle handle) * 在 System.Threading.EventWaitHandle.Set() * 在 DigitalPlatform.OPAC.Server.BatchTask.ThreadMain() * 在 System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) * 在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) * 在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) * 在 System.Threading.ThreadHelper.ThreadStart() * */ // 工作线程 public virtual void ThreadMain() { try { WaitHandle[] events = new WaitHandle[2]; events[0] = eventClose; events[1] = eventActive; while (true) { int index = 0; try { index = WaitHandle.WaitAny(events, PerTime, false); } catch (System.Threading.ThreadAbortException /*ex*/) { /* * // 调试用 * OpacApplication.WriteWindowsLog("BatchTask俘获了ThreadAbortException异常", EventLogEntryType.Information); * */ this.App.Save(null, false); // 触发保存 this.App.WriteErrorLog("刚才是ThreadAbortException触发了配置文件保存"); break; } if (index == WaitHandle.WaitTimeout) { // 超时 eventActive.Reset(); Worker(); } else if (index == 0) { break; } else { // 得到激活信号 eventActive.Reset(); Worker(); } // 是否循环? if (this.Loop == false) { break; } } this.ManualStart = false; // 这个变量只在一轮处理中管用 } catch (Exception ex) { string strErrorText = "BatchTask工作线程出现异常: " + ExceptionUtil.GetDebugText(ex); try { this.App.WriteErrorLog(strErrorText); } catch { OpacApplication.WriteWindowsLog(strErrorText); } this.AppendResultText(strErrorText + "\r\n"); } finally { // 2009/7/16 移动到这里 try { eventFinished.Set(); } catch (ObjectDisposedException) // 2016/10/15 { } // 2009/7/16 新增 this.m_bClosed = true; } }
// parameters: // bOnlyAppend ==true表示仅仅追究没有的问题,已经有的不再重复。==false,表示全部都刷新 public static int RefreshAll(OpacApplication app, string strDataFile, bool bOnlyAppend, out string strError) { strError = ""; string strDataFilePath = app.DataDir + "/browse/" + strDataFile; XmlDocument dom = new XmlDocument(); try { dom.Load(strDataFilePath); } catch (Exception ex) { strError = "装载文件 '" + strDataFilePath + "' 时出错: " + ex.Message; return -1; } // 2014/12/2 // 兑现宏 int nRet = CacheBuilder.MacroDom(dom, out strError); if (nRet == -1) return -1; XmlNodeList nodes = dom.DocumentElement.SelectNodes("//*"); List<string> lines = new List<string>(); for (int i = 0; i < nodes.Count; i++) { XmlNode node = nodes[i]; if (node.NodeType != XmlNodeType.Element) continue; if (node.Name == "_title") continue; if (node.Name == "caption") continue; bool bRss = false; long nMaxCount = -1; string strDirection = ""; // parameters: // nMaxCount -1表示无穷多 // strDirection head/tail GetRssParam(node, out bRss, out nMaxCount, out strDirection); string strCommand = DomUtil.GetAttr(node, "command"); if (strCommand == "~hidelist~") { // strError = "此节点 ~hidelist~ 不必创建缓存"; continue; } if (strCommand == "~none~") { // strError = "此节点 ~none~ 不必创建缓存"; continue; } /* string strPureCaption = DomUtil.GetAttr(node, "name"); string strDescription = DomUtil.GetAttr(node, "description"); */ string strPrefix = MakeNodePath(node); if (bOnlyAppend == true) { // strDataFile 中为纯文件名 string strCacheDir = app.DataDir + "/browse/cache/" + strDataFile; PathUtil.CreateDirIfNeed(strCacheDir); string strResultsetFilename = strCacheDir + "/" + strPrefix; string strRssString = "datafile=" + strDataFile + "&node=" + strPrefix; if (File.Exists(strResultsetFilename) == true) { if (File.Exists(strResultsetFilename + ".index") == false) goto DO_ADD; if (File.Exists(strResultsetFilename + ".rss") == true) continue; } string strLine = strDataFile + ":" + strPrefix + ":rss"; lines.Add(strLine.ToLower()); continue; } DO_ADD: { string strLine = strDataFile + ":" + strPrefix; lines.Add(strLine.ToLower()); } } int nCount = 0; if (lines.Count > 0) { lock (app.PendingCacheFiles) { foreach (string strLine in lines) { if (app.PendingCacheFiles.IndexOf(strLine) == -1) { nCount++; app.PendingCacheFiles.Add(strLine); } } } /* if (nCount > 0) app.ActivateCacheBuilder(); * */ } // 无论如何都激活 app.ActivateCacheBuilder(); return nCount; }
// 根据特性的评注记录路径,获得一定范围的检索命中结果 // return: // -1 出错 // 0 没有找到 // 1 找到 public int GetCommentsSearchResult( OpacApplication app, int nPerCount, string strCommentRecPath, bool bGetRecord, string strLang, // 2012/7/9 out int nStart, out string strError) { strError = ""; nStart = -1; long lHitCount = 0; bool bFound = false; List <string> aPath = null; for (int j = 0; ; j++) { nStart = j * nPerCount; // 只获得路径。确保所要的lStart lCount范围全部获得 long lRet = this.Channel.GetSearchResult( null, "default", nStart, // 0, nPerCount, // -1, strLang, out aPath, out strError); if (lRet == -1) { goto ERROR1; } lHitCount = lRet; if (lHitCount == 0) { return(0); } if (aPath.Count == 0) { break; } for (int i = 0; i < aPath.Count; i++) { if (aPath[i] == strCommentRecPath) { bFound = true; break; } } if (bFound == true) { break; } if (nStart >= lHitCount) { break; } } if (bFound == true) { if (this.SetStart != null) { SetStartEventArgs e = new SetStartEventArgs(); e.StartIndex = nStart; this.SetStart(this, e); } for (int i = 0; i < aPath.Count; i++) { if (bGetRecord == true) { string strXml = ""; string strMetaData = ""; byte[] timestamp = null; string strOutputPath = ""; string strStyle = LibraryChannel.GETRES_ALL_STYLE; long lRet = this.Channel.GetRes( null, aPath[i], strStyle, out strXml, out strMetaData, out timestamp, out strOutputPath, out strError); if (lRet == -1) { goto ERROR1; } if (this.ItemLoad != null) { ItemLoadEventArgs e = new ItemLoadEventArgs(); e.Path = aPath[i]; e.Index = i; e.Count = aPath.Count; e.Xml = strXml; e.Timestamp = timestamp; e.TotalCount = (int)lHitCount; this.ItemLoad(this, e); } } else { if (this.ItemLoad != null) { ItemLoadEventArgs e = new ItemLoadEventArgs(); e.Path = aPath[i]; e.Index = i; e.Count = aPath.Count; e.Xml = ""; e.Timestamp = null; e.TotalCount = (int)lHitCount; this.ItemLoad(this, e); } } } return(1); // 找到 } nStart = -1; strError = "路径为 '" + strCommentRecPath + "' 的记录在结果集中没有找到"; return(0); // 没有找到 ERROR1: return(-1); }
// return: // 0 没有创建新的队列事项 // 1 创建了新的队列事项 public static int AddToPendingList(OpacApplication app, string strDataFile, string strNodePath, string strPart) { // 加入列表 lock (app.PendingCacheFiles) { string strLine = strDataFile + ":" + strNodePath; if (String.IsNullOrEmpty(strPart) == false) strLine += ":" + strPart; strLine = strLine.ToLower(); if (app.PendingCacheFiles.IndexOf(strLine) == -1) { app.PendingCacheFiles.Add(strLine); app.ActivateCacheBuilder(); return 1; } } app.ActivateCacheBuilder(); return 0; }
// 保存修改后的读者记录DOM // return: // -2 时间戳冲突 // -1 error // 0 没有必要保存(changed标志为false) // 1 成功保存 public int SaveLoginReaderDom( out string strError) { strError = ""; if (this.ReaderInfo == null) { strError = "尚未装载过ReaderInfo"; return(0); } if (string.IsNullOrEmpty(this.UserID) == true) { strError = "尚未登录"; return(0); } if (this.IsReader == false) { strError = "当前登录的用户不是读者类型"; return(-2); } if (this.ReaderInfo.ReaderDomChanged == false) { return(0); } XmlDocument readerdom = this.ReaderInfo.ReaderDom; byte[] output_timestamp = null; string strOutputPath = ""; string strOutputXml = ""; long lRet = 0; string strExistingXml = ""; ErrorCodeValue kernel_errorcode = ErrorCodeValue.NoError; // 注:保存读者记录本来是为上传透着个性头像,修改 preference 等用途提供的。如果用代理帐户做这个操作,就要求代理帐户具有修改读者记录的权限,同时修改哪些字段就得不到限制了。可以考虑在 dp2library,增加一种功能,在代理帐户修改读者记录的时候,模仿读者权限来进行限制? LibraryChannel channel = this.GetChannel(true); // this.GetChannel(true, this.m_strParameters); try { lRet = // this.Channel. channel.SetReaderInfo( null, "change", this.ReaderInfo.ReaderDomPath, readerdom.OuterXml, "", // sessioninfo.Account.ReaderDomOldXml, // strOldXml this.ReaderInfo.ReaderDomTimestamp, out strExistingXml, out strOutputXml, out strOutputPath, out output_timestamp, out kernel_errorcode, out strError); if (lRet == -1) { if (// this.Channel. channel.ErrorCode == ErrorCode.TimestampMismatch || kernel_errorcode == ErrorCodeValue.TimestampMismatch) { return(-2); } return(-1); } } finally { //ReleaseTempChannel(temp); this.ReturnChannel(channel); } int nRet = OpacApplication.LoadToDom(strOutputXml, out readerdom, out strError); if (nRet == -1) { strError = "装载读者记录进入XML DOM时发生错误: " + strError; return(-1); } this.ReaderInfo.ReaderDom = readerdom; RefreshReaderAccount(ref this.ReaderInfo, readerdom); this.ReaderInfo.ReaderDomChanged = false; this.ReaderInfo.ReaderDomTimestamp = output_timestamp; return(1); }
// 返回结果集文件中包含的记录数 // return: // -1 出错 // >=0 记录数 public static long GetCount(OpacApplication app, string strResultsetFilename, bool bLock) { try { if (bLock == true) app.ResultsetLocks.LockForRead(strResultsetFilename, 500); try { return DpResultSet.GetCount(strResultsetFilename + ".index"); } finally { if (bLock == true) app.ResultsetLocks.UnlockForRead(strResultsetFilename); } } catch (System.ApplicationException) { return -1; } }
static string GetBiblioDbName(OpacApplication app, string strCommentDbName) { string strBiblioDbName = ""; string strError = ""; // return: // -1 出错 // 0 没有找到 // 1 找到 int nRet = app.GetBiblioDbNameByCommentDbName(strCommentDbName, out strBiblioDbName, out strError); if (nRet != 1) return null; return strBiblioDbName; }
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"); }
// 创建文章内容 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; }
public CacheBuilder(OpacApplication app, string strName) : base(app, strName) { this.Loop = true; }
// 设置或者刷新一个操作记载 public static int SetOperation( OpacApplication app, ref XmlDocument dom, string strOperName, string strOperator, string strComment, bool bAppend, out string strError) { strError = ""; if (dom.DocumentElement == null) { strError = "dom.DocumentElement == null"; return -1; } XmlNode nodeOperations = dom.DocumentElement.SelectSingleNode("operations"); if (nodeOperations == null) { nodeOperations = dom.CreateElement("operations"); dom.DocumentElement.AppendChild(nodeOperations); } XmlNodeList nodes = nodeOperations.SelectNodes("operation[@name='" + strOperName + "']"); if (bAppend == true) { // 删除多余9个的 if (nodes.Count > 9) { for (int i = 0; i < nodes.Count - 9; i++) { XmlNode node = nodes[i]; node.ParentNode.RemoveChild(node); } } } else { if (nodes.Count > 1) { for (int i = 0; i < nodes.Count - 1; i++) { XmlNode node = nodes[i]; node.ParentNode.RemoveChild(node); } } } { XmlNode node = null; if (bAppend == true) { } else { node = nodeOperations.SelectSingleNode("operation[@name='" + strOperName + "']"); } if (node == null) { node = dom.CreateElement("operation"); nodeOperations.AppendChild(node); DomUtil.SetAttr(node, "name", strOperName); } string strTime = DateTimeUtil.Rfc1123DateTimeString(DateTime.UtcNow);// app.Clock.GetClock(); DomUtil.SetAttr(node, "time", strTime); DomUtil.SetAttr(node, "operator", strOperator); if (String.IsNullOrEmpty(strComment) == false) DomUtil.SetAttr(node, "comment", strComment); } return 0; }
/* * <itemsControl> <columns type="series" hideColumns="price,accessNo"/> <columns type="book" hideColumns="price"/> </itemsControl> * * */ // 2012/6/2 // 获得需要隐藏的栏目列表 static List<string> GetHideColumns(OpacApplication app, string strBiblioDbName) { List<string> results = new List<string>(); XmlNodeList nodes = app.WebUiDom.DocumentElement.SelectNodes( "itemsControl/columns"); if (nodes.Count == 0) return results; string strHideColumns = ""; foreach (XmlNode node in nodes) { string strCurrentType = DomUtil.GetAttr(node, "type"); string strCurrentHideColumns = DomUtil.GetAttr(node, "hideColumns"); string strCurrentDbType = ""; ItemDbCfg cfg = app.GetBiblioDbCfg(strBiblioDbName); if (String.IsNullOrEmpty(cfg.IssueDbName) == true) strCurrentDbType = "book"; else strCurrentDbType = "series"; // 如果数据库类型能够匹配 if (StringUtil.IsInList(strCurrentDbType, strCurrentType) == true) { strHideColumns = strCurrentHideColumns; break; } // 如果书目库名能够匹配 if (StringUtil.IsInList(strBiblioDbName, strCurrentType) == true) { strHideColumns = strCurrentHideColumns; break; } } if (string.IsNullOrEmpty(strHideColumns) == true) return results; // 没有匹配的 return StringUtil.SplitList(strHideColumns); }
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; }
static string GetInvisibleCaptionList(OpacApplication app, string strDbType, string strLang) { XmlNode nodeControl = app.WebUiDom.DocumentElement.SelectSingleNode(strDbType + "Search"); if (nodeControl == null) return ""; XmlNode nodeUse = DomUtil.GetLangedNode( strLang, nodeControl, "use", false); if (nodeUse == null) nodeUse = nodeControl.SelectSingleNode("use"); if (nodeUse == null) return ""; return DomUtil.GetAttr(nodeUse, "invisible"); }
// 检索出评注数据 // return: // 命中的全部结果数量。 public static long SearchComments( OpacApplication app, LibraryChannel channel, string strBiblioRecPath, out string strError) { strError = ""; // string strXml = ""; Debug.Assert(String.IsNullOrEmpty(strBiblioRecPath) == false, ""); //string strBiblioDbName = ResPath.GetDbName(strBiblioRecPath); string strBiblioDbName = StringUtil.GetDbName(strBiblioRecPath); if (String.IsNullOrEmpty(strBiblioDbName) == true) { strError = "从书目记录路径 '" + strBiblioRecPath + "' 中无法获得库名部分"; return -1; } string strCommentDbName = ""; // 根据书目库名, 找到对应的评注库名 // return: // -1 出错 // 0 没有找到 // 1 找到 int nRet = app.GetCommentDbName(strBiblioDbName, out strCommentDbName, out strError); if (nRet == -1) return -1; //string strBiblioRecId = ResPath.GetRecordId(strBiblioRecPath); string strBiblioRecId = StringUtil.GetRecordId(strBiblioRecPath); string strQueryXml = "<target list='" + StringUtil.GetXmlStringSimple(strCommentDbName + ":" + "父记录") // 2007/9/14 + "'><item><order>DESC</order><word>" + strBiblioRecId + "</word><match>exact</match><relation>=</relation><dataType>string</dataType><maxCount>-1</maxCount></item><lang>zh</lang></target>"; // LibraryChannel channel = this.GetChannel(true, this.m_strParameters); try { long lRet = //this.Channel. channel.Search( null, strQueryXml, "default", "", // strOuputStyle out strError); if (lRet == -1) return -1; if (lRet == 0) { strError = "没有找到"; return 0; } return lRet; } finally { // this.ReturnChannel(channel); } }
static string BuildTargetText( OpacApplication app, string strDbType, string strDbName, string strFrom) { string strTargetList = ""; if (String.IsNullOrEmpty(strDbName) == true || strDbName.ToLower() == "<all>" || strDbName == "<全部>") { List<string> dbnames = new List<string>(); for (int j = 0; j < app.ItemDbs.Count; j++) { ItemDbCfg cfg = app.ItemDbs[j]; string strName = ""; if (strDbType == "item") strName = cfg.DbName; else if (strDbType == "comment") strName = cfg.CommentDbName; else if (strDbType == "order") strName = cfg.OrderDbName; else if (strDbType == "issue") strName = cfg.IssueDbName; if (String.IsNullOrEmpty(strName) == true) continue; dbnames.Add(strName); } for (int j = 0; j < dbnames.Count; j++) { strTargetList += StringUtil.GetXmlStringSimple(dbnames[j] + ":" + strFrom) + ";"; } } else if (strDbName.IndexOf(",") != -1) { string[] parts = strDbName.Split(new char[] { ',' }); for (int j = 0; j < parts.Length; j++) { strTargetList += StringUtil.GetXmlStringSimple(parts[j] + ":" + strFrom) + ";"; } } else { strTargetList = StringUtil.GetXmlStringSimple(strDbName + ":" + strFrom); } return strTargetList; }
// TODO: 结果集是和 channel 在一起的。如果 channel 不确定,就需要用全局结果集 // 获得一定范围的检索命中结果 // return: public static int GetCommentsSearchResult( OpacApplication app, LibraryChannel channel, ItemLoadEventHandler itemLoadProc, int nStart, int nMaxCount, bool bGetRecord, string strLang, // 2012/7/9 out string strError) { strError = ""; List<string> aPath = null; long lRet = // this.Channel. channel.GetSearchResult( null, "default", nStart, // 0, nMaxCount, // -1, strLang, out aPath, out strError); if (lRet == -1) goto ERROR1; long lHitCount = lRet; if (aPath.Count == 0) { strError = "GetSearchResult aPath error"; goto ERROR1; } for (int i = 0; i < aPath.Count; i++) { if (bGetRecord == true) { string strXml = ""; string strMetaData = ""; byte[] timestamp = null; string strOutputPath = ""; string strStyle = LibraryChannel.GETRES_ALL_STYLE; lRet = // this.Channel. channel.GetRes( null, aPath[i], strStyle, out strXml, out strMetaData, out timestamp, out strOutputPath, out strError); if (lRet == -1) goto ERROR1; if (// this.ItemLoad != null itemLoadProc != null ) { ItemLoadEventArgs e = new ItemLoadEventArgs(); e.Path = aPath[i]; e.Index = i; e.Count = aPath.Count; e.Xml = strXml; e.Timestamp = timestamp; e.TotalCount = (int)lHitCount; // this.ItemLoad(this, e); e.Channel = channel; itemLoadProc(null, e); } } else { if (// this.ItemLoad != null itemLoadProc != null) { ItemLoadEventArgs e = new ItemLoadEventArgs(); e.Path = aPath[i]; e.Index = i; e.Count = aPath.Count; e.Xml = ""; e.Timestamp = null; e.TotalCount = (int)lHitCount; // this.ItemLoad(this, e); e.Channel = channel; itemLoadProc(null, e); } } } return 0; ERROR1: return -1; }
// 创建评注记录XML检索式 // 用作者和作者显示名共同限定检索 public static int BuildCommentQueryXml( OpacApplication app, string strDisplayName, string strCreator, string strDbName, int nMaxCount, bool bDesc, out string strXml, out string strError) { strError = ""; strXml = ""; string strOneDbQuery = ""; string strFrom = "作者显示名"; string strTargetList = BuildTargetText( app, "comment", strDbName, strFrom); if (String.IsNullOrEmpty(strTargetList) == true) { strError = "不具备检索目标"; return -1; } // strFrom为"<全部>",表示利用全部途径检索,内核是支持这样使用的 strOneDbQuery = "<target list='" + strTargetList + "'><item><word>" + StringUtil.GetXmlStringSimple(strDisplayName) + "</word><match>" + StringUtil.GetXmlStringSimple("exact") + "</match><relation>=</relation><dataType>string</dataType>" + "<maxCount>" + nMaxCount.ToString() + "</maxCount>" + (bDesc == true ? "<order>DESC</order>" : "") + "</item><lang>zh</lang></target>"; strXml += strOneDbQuery; strXml += "<operator value='AND'/>"; ///// strFrom = "作者"; strTargetList = BuildTargetText( app, "comment", strDbName, strFrom); if (String.IsNullOrEmpty(strTargetList) == true) { strError = "不具备检索目标"; return -1; } strOneDbQuery = "<target list='" + strTargetList + "'><item><word>" + StringUtil.GetXmlStringSimple(strCreator) + "</word><match>" + StringUtil.GetXmlStringSimple("exact") + "</match><relation>=</relation><dataType>string</dataType>" + "<maxCount>" + nMaxCount.ToString() + "</maxCount>" + (bDesc == true ? "<order>DESC</order>" : "") + "</item><lang>zh</lang></target>"; strXml += strOneDbQuery; strXml = "<group>" + strXml + "</group>"; return 0; }
// 获得一系列册的摘要字符串 // // paramters: // strStyle 风格。逗号间隔的列表。如果包含html text表示格式。forcelogin // strOtherParams <a>命令中其余的参数。例如" target='_blank' "可以用来打开新窗口 public static string GetBarcodesSummary( OpacApplication app, // SessionInfo sessioninfo, LibraryChannel channel, string strBarcodes, string strArrivedItemBarcode, string strStyle, string strOtherParams) { string strSummary = ""; if (strOtherParams == null) strOtherParams = ""; string strDisableClass = ""; if (string.IsNullOrEmpty(strArrivedItemBarcode) == false) strDisableClass = "deleted"; bool bForceLogin = false; if (StringUtil.IsInList("forcelogin", strStyle) == true) bForceLogin = true; string strPrevBiblioRecPath = ""; string[] barcodes = strBarcodes.Split(new char[] { ',' }); for (int j = 0; j < barcodes.Length; j++) { string strBarcode = barcodes[j]; if (String.IsNullOrEmpty(strBarcode) == true) continue; // 获得摘要 string strOneSummary = ""; string strBiblioRecPath = ""; string strError = ""; long lRet = channel.GetBiblioSummary( null, strBarcode, null, strPrevBiblioRecPath, // 前一个path out strBiblioRecPath, out strOneSummary, out strError); if (lRet == -1 || lRet == 0) strOneSummary = strError; /* LibraryServerResult result = this.GetBiblioSummary(sessioninfo, strBarcode, null, strPrevBiblioRecPath, // 前一个path out strBiblioRecPath, out strOneSummary); if (result.Value == -1 || result.Value == 0) strOneSummary = result.ErrorInfo; * */ if (strOneSummary == "" && strPrevBiblioRecPath == strBiblioRecPath) strOneSummary = "(同上)"; if (StringUtil.IsInList("html", strStyle) == true) { string strBarcodeLink = "<a " + (string.IsNullOrEmpty(strDisableClass) == false && strBarcode != strArrivedItemBarcode ? "class='" + strDisableClass + "'" : "") + " href='book.aspx?barcode=" + strBarcode + (bForceLogin == true ? "&forcelogin=userid" : "") + "' " + strOtherParams + " >" + strBarcode + "</a>"; strSummary += strBarcodeLink + " : " + strOneSummary + "<br/>"; } else { strSummary += strBarcode + " : " + strOneSummary + "<br/>"; } strPrevBiblioRecPath = strBiblioRecPath; } return strSummary; }
// 创建XML检索式 public static int BuildQueryXml( OpacApplication app, string strDbType, string strWord, string strDbName, string strFrom, string strMatchStyle, int nMaxCount, bool bDesc, out string strXml, out string strError) { strError = ""; strXml = ""; // int nUsed = 0; { string strOneDbQuery = ""; { string strTargetList = ""; if (String.IsNullOrEmpty(strDbName) == true || strDbName.ToLower() == "<all>" || strDbName == "<全部>") { List<string> dbnames = new List<string>(); for (int j = 0; j < app.ItemDbs.Count; j++) { ItemDbCfg cfg = app.ItemDbs[j]; string strName = ""; if (strDbType == "item") strName = cfg.DbName; else if (strDbType == "comment") strName = cfg.CommentDbName; else if (strDbType == "order") strName = cfg.OrderDbName; else if (strDbType == "issue") strName = cfg.IssueDbName; if (String.IsNullOrEmpty(strName) == true) continue; dbnames.Add(strName); } for (int j = 0; j < dbnames.Count; j++) { strTargetList += StringUtil.GetXmlStringSimple(dbnames[j] + ":" + strFrom) + ";"; } /* if (dbnames.Count == 0) { strError = "没有发现任何实体库"; return -1; } * */ } else if (strDbName.IndexOf(",") != -1) { string[] parts = strDbName.Split(new char[] { ',' }); for (int j = 0; j < parts.Length; j++) { strTargetList += StringUtil.GetXmlStringSimple(parts[j] + ":" + strFrom) + ";"; } } else { strTargetList = StringUtil.GetXmlStringSimple(strDbName + ":" + strFrom); // 2007/9/14 } if (String.IsNullOrEmpty(strTargetList) == true) { strError = "不具备检索目标"; return -1; } // strFrom为"<全部>",表示利用全部途径检索,内核是支持这样使用的 // 2007/4/5 改造 加上了 GetXmlStringSimple() strOneDbQuery = "<target list='" + strTargetList + "'><item><word>" + StringUtil.GetXmlStringSimple(strWord) + "</word><match>" + StringUtil.GetXmlStringSimple(strMatchStyle) // 2007/9/14 + "</match><relation>=</relation><dataType>string</dataType>" + "<maxCount>" + nMaxCount.ToString() + "</maxCount>" + (bDesc == true ? "<order>DESC</order>" : "") + "</item><lang>zh</lang></target>"; } strXml = strOneDbQuery; /* if (i > 0) strXml += "<operator value='" + strLogic + "'/>"; strXml += strOneDbQuery; nUsed++; * */ } /* if (nUsed > 1) { strXml = "<group>" + strXml + "</group>"; } * */ return 0; }
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); } }
public BatchTask(OpacApplication app, string strName) { if (String.IsNullOrEmpty(strName) == true) this.Name = this.DefaultName; else this.Name = strName; this.App = app; #if NO this.Channel.Url = app.WsUrl; this.Channel.BeforeLogin -= new BeforeLoginEventHandle(Channel_BeforeLogin); this.Channel.BeforeLogin += new BeforeLoginEventHandle(Channel_BeforeLogin); #endif this.ProgressFileName = Path.GetTempFileName(); try { // 如果文件存在,就打开,如果文件不存在,就创建一个新的 m_stream = File.Open( this.ProgressFileName, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite); this.ProgressFileVersion = DateTime.Now.Ticks; } catch (Exception ex) { string strError = "打开或创建文件 '" + this.ProgressFileName + "' 发生错误: " + ex.Message; throw new Exception(strError); } m_stream.Seek(0, SeekOrigin.End); }