// parameters: // biblioRecPathList 按照出现先后的顺序存储书目记录路径 // groupTable 书目记录路径 --> List<string> (册记录路径列表) // return: // -1 出错 // 0 中断处理 // 1 正常结束处理 public static int Dump( LibraryChannel channel, Stop stop, string strDbType, List <string> biblioRecPathList, Hashtable groupTable, Delegate_biblioPrepared biblioPrepared, Delegate_itemPrepared itemPrepared, Delegate_biblioDone biblioDone, Delegate_idle idle, out string strError) { strError = ""; int nRet = 0; foreach (string strBiblioRecPath in biblioRecPathList) { // Application.DoEvents(); if (idle != null) { if (idle() == false) { strError = "中断处理"; return(0); } } if (stop != null && stop.State != 0) { strError = "用户中断"; return(0); } string[] results = null; byte[] baTimestamp = null; stop.SetMessage("正在获取书目记录 " + strBiblioRecPath); long lRet = channel.GetBiblioInfos( stop, strBiblioRecPath, "", new string[] { "xml" }, // formats out results, out baTimestamp, out strError); if (lRet == 0) { return(-1); } if (lRet == -1) { return(-1); } if (results == null || results.Length == 0) { strError = "GetBiblioInfos() results error"; return(-1); } string strXml = results[0]; BiblioInfo biblio_info = new BiblioInfo(); biblio_info.RecPath = strBiblioRecPath; biblio_info.OldXml = strXml; biblio_info.Timestamp = baTimestamp; if (biblioPrepared != null) { if (biblioPrepared(biblio_info) == false) { strError = "中断处理"; return(0); } } List <string> item_recpaths = (List <string>)groupTable[strBiblioRecPath]; foreach (string item_recpath in item_recpaths) { // 获得一条记录 //return: // -1 出错 // 0 没有找到 // 1 找到 nRet = GetRecord( channel, stop, strDbType, item_recpath, out string strItemXml, out byte[] baItemTimestamp, out strError); if (nRet == -1) { return(-1); } #if NO XmlDocument item_dom = new XmlDocument(); item_dom.LoadXml(strItemXml); #endif BiblioInfo item_info = new BiblioInfo(); item_info.RecPath = item_recpath; item_info.Timestamp = baItemTimestamp; item_info.OldXml = strItemXml; // DomUtil.RemoveEmptyElements(item_dom.DocumentElement); if (itemPrepared != null) { if (itemPrepared(biblio_info, item_info) == false) { strError = "中断处理"; return(0); } } } if (biblioDone != null) { if (biblioDone(biblio_info) == false) { strError = "中断处理"; return(0); } } } return(1); }
// 装入书目记录 // 本函数在后期修改this.BiblioRecPath。如果中间出错,则不修改 // parameters: // strDirectionStyle prev/next/空 // bWarningNotSaved 是否警告装入前书目信息修改后尚未保存? // return: // -1 error // 0 not found // 1 found int LoadBiblioRecord( LibraryChannel channel, string strBiblioRecPath, string strDirectionStyle, bool bWarningNotSaved, bool bLoadSubrecords, out string strOutputBiblioRecPath, out string strXml, out string strSubRecords, out string strError) { strXml = ""; strSubRecords = ""; strOutputBiblioRecPath = ""; // 2008/6/24 if (String.IsNullOrEmpty(strDirectionStyle) == false) { if (strDirectionStyle != "prev" && strDirectionStyle != "next") { strError = "未知的strDirectionStyle参数值 '" + strDirectionStyle + "'"; return -1; } } if (bWarningNotSaved == true && this.Cataloging == true && this.BiblioChanged == true) { // 警告尚未保存 DialogResult result = MessageBox.Show(this, "当前有编目信息被修改后尚未保存。若此时装载新内容,现有未保存信息将丢失。\r\n\r\n确实要装入新内容? ", "EntityForm", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); if (result != DialogResult.Yes) { strError = "放弃装载书目记录"; return -1; } } #if NO LibraryChannel channel = this.GetChannel(); Progress.OnStop += new StopEventHandler(this.DoStop); Progress.Initial("正在装入书目记录 ..."); Progress.BeginLoop(); #endif Progress.Initial("正在装入书目记录 ..."); try { if (String.IsNullOrEmpty(strDirectionStyle) == false) { strBiblioRecPath += "$" + strDirectionStyle; } #if NO Global.SetHtmlString(this.webBrowser_biblioRecord, "(空白)"); #endif this.m_webExternalHost_biblio.SetHtmlString("(空白)", "entityform_error"); Progress.SetMessage("正在装入书目记录 " + strBiblioRecPath + " ..."); bool bCataloging = this.Cataloging; /* long lRet = Channel.GetBiblioInfo( stop, strBiblioRecPath, "html", out strHtml, out strError); * */ List<string> format_list = new List<string>(); format_list.Add("outputpath"); format_list.Add("html"); if (bCataloging == true) { format_list.Add("xml"); } if (bLoadSubrecords) { format_list.Add("subrecords:all" + (this.DisplayOtherLibraryItem == true ? "|getotherlibraryitem" : "")); } string[] results = null; byte[] baTimestamp = null; long lRet = channel.GetBiblioInfos( Progress, strBiblioRecPath, "", format_list.ToArray(), out results, out baTimestamp, out strError); if (lRet == 0) { // Global.SetHtmlString(this.webBrowser_biblioRecord, "路径为 '" + strBiblioRecPath + "' 的书目记录没有找到 ..."); this.m_webExternalHost_biblio.SetHtmlString("路径为 '" + strBiblioRecPath + "' 的书目记录没有找到 ...", "entityform_error"); return 0; // not found } string strHtml = ""; bool bError = false; string strErrorText = ""; if (results != null && results.Length >= 1) strOutputBiblioRecPath = results[0]; if (results != null && results.Length >= 2) strHtml = results[1]; if (lRet == -1) { // 暂时不报错 bError = true; strErrorText = strError; // 有报错的情况下不刷新时间戳 2008/11/28 changed } else { // 2014/11/5 if (string.IsNullOrEmpty(strError) == false) { bError = true; strErrorText = strError; } // 没有报错时,要对results进行严格检查 if (results == null) { strError = "results == null"; goto ERROR1; } if (results.Length != format_list.Count) { strError = "result.Length != formats.Length"; goto ERROR1; } // 没有报错的情况下才刷新时间戳 2008/11/28 changed this.BiblioTimestamp = baTimestamp; } #if NO Global.SetHtmlString(this.webBrowser_biblioRecord, strHtml, this.MainForm.DataDir, "entityform_biblio"); #endif this.m_webExternalHost_biblio.SetHtmlString(strHtml, "entityform_biblio"); // 如果没有修改BiblioRecPath,就不能把MARC编辑器中的书目记录修改,否则因BiblioChanged已经为true,可能会导致后面在原有书目记录上作错误的自动保存的副作用 this.BiblioRecPath = strOutputBiblioRecPath; // 2008/6/24 { // subrecords 后面可能带有冒号。需要前方一致匹配 int index = IndexOfFormat(format_list, "subrecords"); if (index != -1) { if (results != null && results.Length > index) strSubRecords = results[index]; } } if (bCataloging == true) { int index = format_list.IndexOf("xml"); Debug.Assert(index != -1, ""); if (results != null && results.Length > index) strXml = results[index]; if (bError == false) // 2008/6/24 { // return: // -1 error // 0 空的记录 // 1 成功 int nRet = SetBiblioRecordToMarcEditor(strXml, out strError); if (nRet == -1) goto ERROR1; // 2008/11/13 if (nRet == 0) MessageBox.Show(this, "警告:当前书目记录 '" + strOutputBiblioRecPath + "' 是一条空记录"); this.BiblioChanged = false; // 2009/10/24 // 根据998$t 兑现ReadOnly状态 string strTargetBiblioRecPath = this.m_marcEditor.Record.Fields.GetFirstSubfield("998", "t"); if (String.IsNullOrEmpty(strTargetBiblioRecPath) == false) { if (this.LinkedRecordReadonly == true) { // TODO: 装载目标记录,替代当前全部内容(除了998) this.m_marcEditor.ReadOnly = true; } } else { // 如果必要,恢复可编辑状态 if (this.m_marcEditor.ReadOnly != false) this.m_marcEditor.ReadOnly = false; } // 注:非采购工作库,也可以设定目标记录路径 // TODO: 未来可以增加“终点库”角色,这样的库才是不能设定目标记录路径的 /* // 根据当前库是不是采购工作库,决定“设置目标记录”按钮是否为Enabled if (this.MainForm.IsOrderWorkDb(this.BiblioDbName) == true) this.toolStripButton_setTargetRecord.Enabled = true; else this.toolStripButton_setTargetRecord.Enabled = false; * */ } } if (bError == true) { strError = strErrorText; goto ERROR1; } } finally { #if NO Progress.EndLoop(); Progress.OnStop -= new StopEventHandler(this.DoStop); Progress.Initial(""); this.ReturnChannel(channel); #endif Progress.Initial(""); } return 1; ERROR1: return -1; }
protected void Page_Load(object sender, EventArgs e) { if (WebUtil.PrepareEnvironment(this, ref app, ref sessioninfo) == false) { return; } // 是否登录? if (string.IsNullOrEmpty(sessioninfo.UserID) == true) { sessioninfo.UserID = "public"; sessioninfo.IsReader = false; } string strError = ""; int nRet = 0; string strBarcode = this.Request["barcode"]; if (string.IsNullOrEmpty(strBarcode) == true) { strError = "需要指定barcode参数"; goto ERROR1; } string strLang = this.Request["lang"]; if (string.IsNullOrEmpty(strLang) == false) { //this.UICulture = strLang; //this.Culture = strLang; try { Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(strLang); Thread.CurrentThread.CurrentUICulture = new CultureInfo(strLang); } catch { } //this.Session["lang"] = Thread.CurrentThread.CurrentUICulture.Name; } #if NO // test this.Response.Write("test"); this.Response.End(); return; #endif if (StringUtil.HasHead(strBarcode, "biblio_html:") == true) { string strBiblioRecPath = strBarcode.Substring("biblio_html:".Length); // 获得书目记录XML string[] formats = new string[1]; formats[0] = "xml"; byte[] timestamp = null; string[] results = null; // 2016/1/24 if (string.IsNullOrEmpty(sessioninfo.UserID) == true) { strError = "sessioninfo.UserID 为空 (sessioninfo.Parameters='" + sessioninfo.Parameters + "') {F548F93A-3ED7-4F7A-8729-CD65E375D360}"; goto ERROR1; } LibraryChannel channel = null; #if CHANNEL_POOL channel = sessioninfo.GetChannel(true /*, sessioninfo.Parameters*/); #else channel = sessioninfo.GetChannel(false); #endif long lRet = channel.GetBiblioInfos( null, strBiblioRecPath, "", formats, out results, out timestamp, out strError); #if CHANNEL_POOL sessioninfo.ReturnChannel(channel); #endif if (lRet == -1) { strError = "获得书目记录 '" + strBiblioRecPath + "' 时出错: " + strError; goto ERROR1; } if (lRet == 0) { strError = "书目记录 '" + strBiblioRecPath + "' 不存在"; goto ERROR1; } if (results == null || results.Length < 1) { strError = "results error {87C72690-662D-48E3-920D-B0E0C5D53726}"; goto ERROR1; } string strBiblioXml = results[0]; // 创建HTML string strBiblioDbName = StringUtil.GetDbName(strBiblioRecPath); // 需要从内核映射过来文件 string strLocalPath = ""; nRet = app.MapKernelScriptFile( // null, // sessioninfo, strBiblioDbName, "./cfgs/opac_biblio.fltx", // OPAC查询固定认这个角色的配置文件,作为公共查询书目格式创建的脚本。而流通前端,创建书目格式的时候,找的是loan_biblio.fltx配置文件 out strLocalPath, out strError); if (nRet == -1) { goto ERROR1; } // 将种记录数据从XML格式转换为HTML格式 string strResult = ""; KeyValueCollection result_params = null; string strFilterFileName = strLocalPath; // app.CfgDir + "\\biblio.fltx"; nRet = app.ConvertBiblioXmlToHtml( strFilterFileName, strBiblioXml, strBiblioRecPath, out strResult, out result_params, out strError); if (nRet == -1) { goto ERROR1; } this.Response.Write(strResult); this.Response.End(); return; } else if (StringUtil.HasHead(strBarcode, "formated:") == true) { strBarcode = strBarcode.Substring("formated:".Length); string strArrivedItemBarcode = ""; string[] barcodes = strBarcode.Split(new char[] { ',' }); string strTemp = ""; foreach (string barcode in barcodes) { if (string.IsNullOrEmpty(barcode) == true) { continue; } if (string.IsNullOrEmpty(strTemp) == false) { strTemp += ","; } if (barcode[0] == '!') { strArrivedItemBarcode = barcode.Substring(1); strTemp += strArrivedItemBarcode; } else { strTemp += barcode; } } strBarcode = strTemp; string strStyle = "html"; // this.Request["style"]; string strOtherParams = ""; // this.Request["otherparams"]; LibraryChannel channel = null; #if CHANNEL_POOL channel = sessioninfo.GetChannel(true /*, sessioninfo.Parameters*/); // 2016/1/25 增加第二参数 #else channel = sessioninfo.GetChannel(false); #endif // 获得一系列册的摘要字符串 // // paramters: // strStyle 风格。逗号间隔的列表。如果包含html text表示格式。forcelogin // strOtherParams <a>命令中其余的参数。例如" target='_blank' "可以用来打开新窗口 string strResult = ReservationInfoControl.GetBarcodesSummary( app, channel, strBarcode, strArrivedItemBarcode, strStyle, strOtherParams); #if CHANNEL_POOL sessioninfo.ReturnChannel(channel); #endif this.Response.Write(strResult); this.Response.End(); return; } else { // 2016/1/25 if (string.IsNullOrEmpty(sessioninfo.UserID) == true) { strError = "sessioninfo.UserID 为空 (sessioninfo.Parameters='" + sessioninfo.Parameters + "') {9A54CD5B-B1CF-43D2-8AE3-1969B5873055}"; goto ERROR1; } // 获得摘要 string strSummary = ""; string strBiblioRecPath = ""; LibraryChannel channel = null; #if CHANNEL_POOL channel = sessioninfo.GetChannel(true /*, sessioninfo.Parameters*/); // 2016/1/25 增加第二参数 #else channel = sessioninfo.GetChannel(false); #endif long lRet = channel.GetBiblioSummary( null, strBarcode, null, null, out strBiblioRecPath, out strSummary, out strError); #if CHANNEL_POOL sessioninfo.ReturnChannel(channel); #endif if (lRet == -1 || lRet == 0) { strSummary = strError; } this.Response.Write(strSummary); this.Response.End(); } return; ERROR1: this.Response.Write(strError); this.Response.End(); }
// 获得一条MARC/XML记录 // return: // -1 error 包括not found // 0 found // 1 为诊断记录 public int GetOneRecord( string strStyle, int nTest, string strPathParam, string strParameters, // bool bHilightBrowseLine, out string strSavePath, out string strRecord, out string strXmlFragment, out string strOutStyle, out byte[] baTimestamp, out long lVersion, out DigitalPlatform.Z3950.Record record, out Encoding currrentEncoding, out LoginInfo logininfo, out string strError) { strXmlFragment = ""; strRecord = ""; record = null; strError = ""; currrentEncoding = this.CurrentEncoding; baTimestamp = null; strSavePath = ""; strOutStyle = "marc"; logininfo = new LoginInfo(); lVersion = 0; // 防止重入 if (m_bInSearch == true) { strError = "当前窗口正在被一个未结束的长操作使用,无法获得记录。请稍后再试。"; return(-1); } if (strStyle != "marc" && strStyle != "xml") { strError = "DupForm只支持获取MARC格式记录和xml格式记录,不支持 '" + strStyle + "' 格式的记录"; return(-1); } int nRet = 0; int index = -1; string strPath = ""; string strDirection = ""; nRet = Global.ParsePathParam(strPathParam, out index, out strPath, out strDirection, out strError); if (nRet == -1) { return(-1); } if (index == -1) { strError = "暂时不支持没有 index 的用法"; return(-1); } bool bHilightBrowseLine = StringUtil.IsInList("hilight_browse_line", strParameters); if (index >= this.listView_browse.Items.Count) { strError = "越过结果集尾部"; return(-1); } ListViewItem curItem = this.listView_browse.Items[index]; if (bHilightBrowseLine == true) { // 修改listview中事项的选定状态 for (int i = 0; i < this.listView_browse.SelectedItems.Count; i++) { this.listView_browse.SelectedItems[i].Selected = false; } curItem.Selected = true; curItem.EnsureVisible(); } string strPurePath = curItem.Text; string strServerName = this.LibraryServerName; strPath = strPurePath + "@" + this.LibraryServerName; strSavePath = this.CurrentProtocol + ":" + strPath; // 拉上一个dp2检索窗,好办事 dp2SearchForm dp2_searchform = this.GetDp2SearchForm(); if (dp2_searchform == null) { strError = "没有打开的dp2检索窗,无法GetOneRecordSyntax()"; return(-1); } // 获得server url string strServerUrl = dp2_searchform.GetServerUrl(strServerName); if (strServerUrl == null) { strError = "没有找到服务器名 '" + strServerName + "' 对应的URL"; return(-1); } this.Channel = this.Channels.GetChannel(strServerUrl); stop.OnStop += new StopEventHandler(this.DoStop); stop.Initial("正在初始化浏览器组件 ..."); stop.BeginLoop(); this.Update(); this.MainForm.Update(); try { stop.SetMessage("正在装入书目记录 " + strPath + " ..."); string[] formats = null; formats = new string[1]; formats[0] = "xml"; string[] results = null; long lRet = Channel.GetBiblioInfos( stop, strPurePath, "", formats, out results, out baTimestamp, out strError); if (lRet == 0) { strError = "路径为 '" + strPath + "' 的书目记录没有找到 ..."; goto ERROR1; // not found } if (lRet == -1) { goto ERROR1; } // this.BiblioTimestamp = baTimestamp; if (results == null) { strError = "results == null"; goto ERROR1; } if (results.Length != formats.Length) { strError = "result.Length != formats.Length"; goto ERROR1; } string strXml = results[0]; if (strStyle == "marc") { string strMarcSyntax = ""; string strOutMarcSyntax = ""; // 从数据记录中获得MARC格式 nRet = MarcUtil.Xml2Marc(strXml, true, strMarcSyntax, out strOutMarcSyntax, out strRecord, out strError); if (nRet == -1) { strError = "XML转换到MARC记录时出错: " + strError; goto ERROR1; } // 获得书目以外的其它XML片断 nRet = dp2SearchForm.GetXmlFragment(strXml, out strXmlFragment, out strError); if (nRet == -1) { goto ERROR1; } } else { strRecord = strXml; strOutStyle = strStyle; } } finally { stop.EndLoop(); stop.OnStop -= new StopEventHandler(this.DoStop); stop.Initial(""); } return(0); ERROR1: return(-1); }
// 获得一条MARC/XML记录 // return: // -1 error 包括not found // 0 found // 1 为诊断记录 public int GetOneRecord( string strStyle, int nTest, string strPathParam, string strParameters, // bool bHilightBrowseLine, out string strSavePath, out string strRecord, out string strXmlFragment, out string strOutStyle, out byte[] baTimestamp, out long lVersion, out DigitalPlatform.Z3950.Record record, out Encoding currrentEncoding, out LoginInfo logininfo, out string strError) { strXmlFragment = ""; strRecord = ""; record = null; strError = ""; currrentEncoding = this.CurrentEncoding; baTimestamp = null; strSavePath = ""; strOutStyle = "marc"; logininfo = new LoginInfo(); lVersion = 0; // 防止重入 if (m_bInSearch == true) { strError = "当前窗口正在被一个未结束的长操作使用,无法获得记录。请稍后再试。"; return -1; } if (strStyle != "marc" && strStyle != "xml") { strError = "DupForm只支持获取MARC格式记录和xml格式记录,不支持 '" + strStyle + "' 格式的记录"; return -1; } int nRet = 0; int index = -1; string strPath = ""; string strDirection = ""; nRet = Global.ParsePathParam(strPathParam, out index, out strPath, out strDirection, out strError); if (nRet == -1) return -1; if (index == -1) { strError = "暂时不支持没有 index 的用法"; return -1; } bool bHilightBrowseLine = StringUtil.IsInList("hilight_browse_line", strParameters); if (index >= this.listView_browse.Items.Count) { strError = "越过结果集尾部"; return -1; } ListViewItem curItem = this.listView_browse.Items[index]; if (bHilightBrowseLine == true) { // 修改listview中事项的选定状态 for (int i = 0; i < this.listView_browse.SelectedItems.Count; i++) { this.listView_browse.SelectedItems[i].Selected = false; } curItem.Selected = true; curItem.EnsureVisible(); } string strPurePath = curItem.Text; string strServerName = this.LibraryServerName; strPath = strPurePath + "@" + this.LibraryServerName; strSavePath = this.CurrentProtocol + ":" + strPath; // 拉上一个dp2检索窗,好办事 dp2SearchForm dp2_searchform = this.GetDp2SearchForm(); if (dp2_searchform == null) { strError = "没有打开的dp2检索窗,无法GetOneRecordSyntax()"; return -1; } // 获得server url string strServerUrl = dp2_searchform.GetServerUrl(strServerName); if (strServerUrl == null) { strError = "没有找到服务器名 '" + strServerName + "' 对应的URL"; return -1; } this.Channel = this.Channels.GetChannel(strServerUrl); stop.OnStop += new StopEventHandler(this.DoStop); stop.Initial("正在初始化浏览器组件 ..."); stop.BeginLoop(); this.Update(); this.MainForm.Update(); try { stop.SetMessage("正在装入书目记录 " + strPath + " ..."); string[] formats = null; formats = new string[1]; formats[0] = "xml"; string[] results = null; long lRet = Channel.GetBiblioInfos( stop, strPurePath, "", formats, out results, out baTimestamp, out strError); if (lRet == 0) { strError = "路径为 '" + strPath + "' 的书目记录没有找到 ..."; goto ERROR1; // not found } if (lRet == -1) goto ERROR1; // this.BiblioTimestamp = baTimestamp; if (results == null) { strError = "results == null"; goto ERROR1; } if (results.Length != formats.Length) { strError = "result.Length != formats.Length"; goto ERROR1; } string strXml = results[0]; if (strStyle == "marc") { string strMarcSyntax = ""; string strOutMarcSyntax = ""; // 从数据记录中获得MARC格式 nRet = MarcUtil.Xml2Marc(strXml, true, strMarcSyntax, out strOutMarcSyntax, out strRecord, out strError); if (nRet == -1) { strError = "XML转换到MARC记录时出错: " + strError; goto ERROR1; } // 获得书目以外的其它XML片断 nRet = dp2SearchForm.GetXmlFragment(strXml, out strXmlFragment, out strError); if (nRet == -1) goto ERROR1; } else { strRecord = strXml; strOutStyle = strStyle; } } finally { stop.EndLoop(); stop.OnStop -= new StopEventHandler(this.DoStop); stop.Initial(""); } return 0; ERROR1: return -1; }
// 装载数据 public override bool LoadData() { string strError = ""; int nRet = 0; BiblioInfo info = this.BiblioInfo; string strRecPath = this.BiblioInfo.RecPath; if (string.IsNullOrEmpty(info.OldXml) == true) { lock (syncRoot) { channel = this.Container.MainForm.GetChannel(); } try { // 显示 正在处理 this.HTML = GetWaitingHtml("正在获取书目记录 " + strRecPath); ShowData(); string[] results = null; byte[] baTimestamp = null; // 获得书目记录 channel.Timeout = new TimeSpan(0, 0, 5); long lRet = channel.GetBiblioInfos( Stop, strRecPath, "", new string[] { "xml" }, // formats out results, out baTimestamp, out strError); if (lRet == 0) { nRet = -1; strError = "获取书目记录 " + strRecPath + " 时出错: " + strError; } else if (lRet == -1) { nRet = -1; strError = "获取书目记录 " + strRecPath + " 时出错: " + strError; } else { if (results == null || results.Length == 0) { strError = "results error"; throw new Exception(strError); } // TODO: 对 BiblioInfo 的成员进行操作的时候,是否要 lock 一下对象? string strXml = results[0]; info.OldXml = strXml; info.Timestamp = baTimestamp; info.RecPath = strRecPath; } } finally { LibraryChannel temp_channel = channel; lock (syncRoot) { channel = null; } this.Container.MainForm.ReturnChannel(temp_channel); } } string strXml1 = ""; string strHtml2 = ""; string strXml2 = ""; if (nRet == -1) { strHtml2 = HttpUtility.HtmlEncode(strError); } else { nRet = BiblioSearchForm.GetXmlHtml(info, out strXml1, out strXml2, out strHtml2, out strError); if (nRet == -1) { throw new Exception(strError); } } this.HTML = "<html>" + this.Container.MainForm.GetMarcHtmlHeadString(true) + "<body>" + strHtml2 + EntityForm.GetTimestampHtml(info.Timestamp) + "</body></html>"; this.XML = BiblioSearchForm.MergeXml(strXml1, strXml2); return(true); }
int BuildRssFile( LibraryChannel channel, string strResultsetFilename, long nMaxCount, string strDirection, string strChannelTitle, string strChannelLink, string strSelfLink, string strChannelDescription, string strOutputFilename, out int nOutputCount, out string strError) { strError = ""; nOutputCount = 0; int nRet = 0; long lRet = 0; if (String.IsNullOrEmpty(strOutputFilename) == true) strOutputFilename = strResultsetFilename + ".rss"; bool bDone = false; /* if (File.Exists(strOutputFilename) == true) return 0; * */ XmlTextWriter writer = new XmlTextWriter(strOutputFilename, Encoding.UTF8); writer.Formatting = Formatting.Indented; writer.Indentation = 4; DpResultSet resultset = null; this.App.ResultsetLocks.LockForRead(strResultsetFilename + ".rss", 500); try { resultset = new DpResultSet(false, false); try { resultset.Attach(strResultsetFilename, strResultsetFilename + ".index"); } catch (Exception ex) { strError = "打开结果集文件时出错: " + ex.Message; return -1; } try { writer.WriteStartDocument(); writer.WriteStartElement("rss"); writer.WriteAttributeString("version", "2.0"); writer.WriteAttributeString("xmlns", "dc", null, "http://purl.org/dc/elements/1.1/"); writer.WriteAttributeString("xmlns", "atom", null, "http://www.w3.org/2005/Atom"); writer.WriteAttributeString("xmlns", "content", null, "http://purl.org/rss/1.0/modules/content/"); writer.WriteStartElement("channel"); writer.WriteStartElement("title"); writer.WriteString(strChannelTitle); writer.WriteEndElement(); writer.WriteStartElement("link"); writer.WriteString(strChannelLink); writer.WriteEndElement(); writer.WriteStartElement("atom", "link", "http://www.w3.org/2005/Atom"); writer.WriteAttributeString("href", strSelfLink); writer.WriteAttributeString("rel", "self"); writer.WriteAttributeString("type", "application/rss+xml"); writer.WriteEndElement(); if (string.IsNullOrEmpty(strChannelDescription) == false) strChannelDescription = strChannelLink; writer.WriteStartElement("description"); writer.WriteString(strChannelDescription); writer.WriteEndElement(); // 2011/7/4 DateTime now = DateTime.Now.ToUniversalTime(); writer.WriteStartElement("pubDate"); writer.WriteString(DateTimeUtil.Rfc1123DateTimeString(now)); writer.WriteEndElement(); writer.WriteStartElement("lastBuildDate"); writer.WriteString(DateTimeUtil.Rfc1123DateTimeString(now)); writer.WriteEndElement(); long nCount = resultset.Count; long nStart = 0; if (strDirection == "head" && nMaxCount != -1) nCount = Math.Min(nMaxCount, nCount); else if (strDirection == "tail" && nMaxCount != -1) { nStart = nCount - nMaxCount; if (nStart < 0) nStart = 0; } for (long i = nStart; i < nCount; i++) { if (this.m_bClosed == true || this.Stopped == true) { strError = "中断"; return -1; } DpRecord record = resultset[i]; string strPath = record.ID; // TODO: 对于实体库记录或者评注库记录,可以检索其从属的书目记录来取得书名等? // 或者评注库记录本身就有文章名 // 实体库记录可以link到 book.aspx?itemrecpath=??? string strBiblioDbName = ""; // string strDbName = ResPath.GetDbName(strPath); string strDbName = StringUtil.GetDbName(strPath); string strDbType = this.App.GetDbType(strDbName, out strBiblioDbName); if (strDbType == null) { strError = "数据库 '" + strDbName + "' 的类型无法识别"; return -1; } string strItemMetadata = ""; XmlDocument itemdom = null; string strBiblioRecPath = ""; if (strDbType == "item" || strDbType == "comment") { string strStyle = LibraryChannel.GETRES_ALL_STYLE; string strItemXml = ""; byte[] item_timestamp = null; string strItemOutputPath = ""; // TODO: 优化为成批获取 lRet = channel.GetRes(null, strPath, strStyle, out strItemXml, out strItemMetadata, out item_timestamp, out strItemOutputPath, out strError); if (lRet == -1) { strError = "获取记录 '" + strPath + "' 时发生错误: " + strError; return -1; } nRet = OpacApplication.LoadToDom(strItemXml, out itemdom, out strError); if (nRet == -1) { strError = "装载记录 '" + strPath + "' 进入XML DOM时发生错误: " + strError; return -1; } string strParentID = DomUtil.GetElementText(itemdom.DocumentElement, "parent"); strBiblioRecPath = strBiblioDbName + "/" + strParentID; } else if (strDbType == "biblio") { strBiblioRecPath = strPath; } // 从数据库中获取 string strBiblioXml = ""; byte[] timestamp = null; string[] formats = new string[3]; formats[0] = "xml"; formats[1] = "summary"; formats[2] = "metadata"; string[] results = null; lRet = channel.GetBiblioInfos( null, strBiblioRecPath, "", formats, out results, out timestamp, out strError); if (lRet == -1) return -1; if (lRet == 0) continue; // TODO: 产生一条占位记录? /* LibraryServerResult result = this.App.GetBiblioInfos( sessioninfo, strBiblioRecPath, formats, out results, out timestamp); if (result.Value == -1) { strError = result.ErrorInfo; return -1; } if (result.Value == 0) continue; // TODO: 产生一条占位记录? */ if (results == null || results.Length != 3) { strError = "results error {5E0FC5A1-819D-4655-AB3B-5CE6AAAB1BFE}"; return -1; } strBiblioXml = results[0]; string strSummary = results[1]; string strBiblioMetaData = results[2]; string strMetaData = ""; if (strDbType == "biblio") strMetaData = strBiblioMetaData; else strMetaData = strItemMetadata; // 取metadata Hashtable values = StringUtil.ParseMetaDataXml(strMetaData, out strError); if (values == null) { strError = "parse metadata error: " + strError; return -1; } string strPubDate = ""; string strLastModified = (string)values["lastmodified"]; if (String.IsNullOrEmpty(strLastModified) == false) { DateTime time = DateTime.Parse(strLastModified); strPubDate = DateTimeUtil.Rfc1123DateTimeString(time.ToUniversalTime()); } string strTitle = ""; string strLink = ""; List<string> authors = null; if (strDbType == "biblio") strLink = this.App.OpacServerUrl + "/book.aspx?BiblioRecPath=" + HttpUtility.UrlEncode(strBiblioRecPath); else if (strDbType == "item") strLink = this.App.OpacServerUrl + "/book.aspx?ItemRecPath=" + HttpUtility.UrlEncode(strPath) + "#active"; else if (strDbType == "comment") strLink = this.App.OpacServerUrl + "/book.aspx?CommentRecPath=" + HttpUtility.UrlEncode(strPath) + "#active"; if (strDbType == "biblio" || strDbType == "item") { nRet = GetBiblioInfos( strBiblioXml, out strTitle, out authors, out strError); } else if (strDbType == "comment") { nRet = GetCommentInfos( itemdom, out strTitle, out authors, out strError); } string strItemSummary = ""; string strItemSummaryHtml = ""; if (strDbType == "item" || strDbType == "comment") { // 获得实体记录或者评注记录的摘要 nRet = GetSummary(strDbType, itemdom, "text", out strItemSummary, out strError); if (nRet == -1) { strError = "创建记录 '" + strPath + "' 的摘要信息时发生错误: " + strError; return -1; } // 获得实体记录或者评注记录的摘要 nRet = GetSummary(strDbType, itemdom, "html", out strItemSummaryHtml, out strError); if (nRet == -1) { strError = "创建记录 '" + strPath + "' 的摘要信息时发生错误: " + strError; return -1; } } writer.WriteStartElement("item"); writer.WriteAttributeString("id", (i + 1).ToString()); writer.WriteStartElement("title"); writer.WriteString(strTitle); writer.WriteEndElement(); foreach (string strAuthor in authors) { // writer.WriteStartElement("author"); writer.WriteStartElement("dc", "creator", "http://purl.org/dc/elements/1.1/"); writer.WriteString(strAuthor); writer.WriteEndElement(); } if (String.IsNullOrEmpty(strSummary) == false || String.IsNullOrEmpty(strItemSummary) == false) { writer.WriteStartElement("description"); if (String.IsNullOrEmpty(strItemSummary) == false) { if (strDbType == "comment") writer.WriteString(strItemSummary + "\r\n\r\n从属于: " + strSummary); else writer.WriteString(strItemSummary + "\r\n\r\n" + strSummary); } else writer.WriteString(strSummary); writer.WriteEndElement(); } // <content:encoded> if (String.IsNullOrEmpty(strItemSummaryHtml) == false) { writer.WriteStartElement("content", "encoded", "http://purl.org/rss/1.0/modules/content/"); if (strDbType == "comment") writer.WriteCData(strItemSummaryHtml + "<br/><br/>从属于: " + strSummary); else writer.WriteCData(strItemSummaryHtml + "<br/><br/>" + strSummary); writer.WriteEndElement(); } writer.WriteStartElement("link"); writer.WriteString(strLink); writer.WriteEndElement(); // 2011/7/4 writer.WriteStartElement("guid"); writer.WriteAttributeString("isPermaLink", "true"); writer.WriteString(strLink); writer.WriteEndElement(); writer.WriteStartElement("pubDate"); writer.WriteString(strPubDate); writer.WriteEndElement(); writer.WriteEndElement(); // </item> nOutputCount++; } } finally { string strTemp1 = ""; string strTemp2 = ""; resultset.Detach(out strTemp1, out strTemp2); } writer.WriteEndElement(); // </channel> writer.WriteEndElement(); // </rss> writer.WriteEndDocument(); bDone = true; } finally { // this.App.EndLoop(strOutputFilename, true); this.App.ResultsetLocks.UnlockForRead(strResultsetFilename + ".rss"); writer.Close(); if (bDone == false) File.Delete(strOutputFilename); // 不完整的文件要删除掉才行 } return 0; }
public IEnumerator GetEnumerator() { List <string> format_list = new List <string>(); int nContentIndex = format_list.Count; int nTimestampIndex = -1; int nMetadataIndex = -1; format_list.Add(this.Format); if ((this.GetBiblioInfoStyle & dp2Catalog.GetBiblioInfoStyle.Timestamp) != 0) { nTimestampIndex = format_list.Count; format_list.Add("timestamp"); } if ((this.GetBiblioInfoStyle & dp2Catalog.GetBiblioInfoStyle.Metadata) != 0) { nMetadataIndex = format_list.Count; format_list.Add("metadata"); } string[] formats = new string[format_list.Count]; format_list.CopyTo(formats); // 首先按照服务器名的不同,划分为若干个区段 List <OneBatch> batchs = new List <OneBatch>(); { OneBatch batch = new OneBatch(); for (int index = 0; index < m_recpaths.Count; index++) { string s = m_recpaths[index]; // 解析记录路径 string strServerName = ""; string strPurePath = ""; dp2SearchForm.ParseRecPath(s, out strServerName, out strPurePath); // 服务器名发生变化了 if (batch.Count > 0 && strServerName != batch.ServerName) { batchs.Add(batch); batch = new OneBatch(); batch.ServerName = strServerName; batch.Add(strPurePath); continue; } if (string.IsNullOrEmpty(batch.ServerName) == true) { batch.ServerName = strServerName; } batch.Add(strPurePath); } if (batch.Count > 0) { batchs.Add(batch); } } // 进行循环获取 foreach (OneBatch temp in batchs) { // 获得server url dp2Server server = this.Servers.GetServerByName(temp.ServerName); if (server == null) { string strError = "名为 '" + temp.ServerName + "' 的服务器在检索窗中尚未定义..."; throw new Exception(strError); } string strServerUrl = server.Url; LibraryChannel channel = this.ChannelManager.GetChannel(strServerUrl); try { List <string> batch = new List <string>(); for (; batch.Count > 0 || temp.Count > 0;) { if (batch.Count == 0) { for (int i = 0; i < Math.Min(temp.Count, 100); i++) { batch.Add(temp[i]); } temp.RemoveRange(0, batch.Count); } // 每100个一批 if (batch.Count > 0) { REDO: string strCommand = "@path-list:" + StringUtil.MakePathList(batch); string[] results = null; byte[] timestamp = null; string strError = ""; long lRet = channel.GetBiblioInfos( this.Stop, strCommand, "", formats, out results, out timestamp, out strError); if (lRet == -1) { throw new Exception(strError); } if (lRet == 0) { if (lRet == 0 && String.IsNullOrEmpty(strError) == true) { foreach (string path in batch) { BiblioItem item = new BiblioItem(); item.RecPath = path + "@" + temp.ServerName; item.ErrorCode = ErrorCode.NotFound; item.ErrorInfo = "书目记录 '" + path + "' 不存在"; yield return(item); } goto CONTINUE; } // 如果results.Length表现正常,其实还可以继续处理 if (results != null && results.Length > 0) { } else { strError = "获得书目记录 '" + StringUtil.MakePathList(batch) + "' 时发生错误: " + strError; throw new Exception(strError); } } if (results == null) { strError = "results == null"; throw new Exception(strError); } for (int i = 0; i < results.Length / formats.Length; i++) { BiblioItem item = new BiblioItem(); item.RecPath = batch[i] + "@" + temp.ServerName; if (nContentIndex != -1) { item.Content = results[i * formats.Length + nContentIndex]; } if (nTimestampIndex != -1) { item.Timestamp = ByteArray.GetTimeStampByteArray(results[i * formats.Length + nTimestampIndex]); } if (nMetadataIndex != -1) { item.Metadata = results[i * formats.Length + nMetadataIndex]; } if (string.IsNullOrEmpty(item.Content) == true) { item.ErrorCode = ErrorCode.NotFound; item.ErrorInfo = "书目记录 '" + item.RecPath + "' 不存在"; } yield return(item); } CONTINUE: if (batch.Count > results.Length / formats.Length) { // 有本次没有获取到的记录 batch.RemoveRange(0, results.Length / formats.Length); /* * if (index == m_recpaths.Count - 1) * goto REDO; // 当前已经是最后一轮了,需要继续做完 * */ // 否则可以留给下一轮处理 } else { batch.Clear(); } } } // } finally { Program.MainForm.ReturnChannel(channel); } } }
// 删除所选择的书目记录 public void DeleteSelectedRecords() { string strError = ""; if (this._linkMarcFile != null) { strError = "暂不支持从 MARC 文件中直接删除记录"; goto ERROR1; } if (this.listView_browse.SelectedItems.Count == 0) { strError = "尚未选择要删除的书目记录"; goto ERROR1; } DialogResult result = MessageBox.Show(this, "确实要从数据库中删除所选定的 " + this.listView_browse.SelectedItems.Count.ToString() + " 个书目记录?\r\n\r\n(警告:书目记录被删除后,无法恢复。如果删除书目记录,则其下属的册、期、订购、评注记录和对象资源会一并删除)\r\n\r\n(OK 删除;Cancel 取消)", "dp2SearchForm", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); if (result == System.Windows.Forms.DialogResult.Cancel) return; List<ListViewItem> items = new List<ListViewItem>(); foreach (ListViewItem item in this.listView_browse.SelectedItems) { items.Add(item); } stop.Style = StopStyle.EnableHalfStop; stop.OnStop += new StopEventHandler(this.DoStop); stop.Initial("正在删除书目记录 ..."); stop.BeginLoop(); this.EnableControlsInSearching(false); // 暂时禁止因为 listview 选择发生改变而频繁刷新状态行 this.listView_browse.SelectedIndexChanged -= new System.EventHandler(this.listView_browse_SelectedIndexChanged); this._processing++; try { stop.SetProgressRange(0, items.Count); for (int i = 0; i < items.Count; i++) { if (stop != null && stop.State != 0) { strError = "已中断"; goto ERROR1; } ListViewItem item = items[i]; string strRecPath = ListViewUtil.GetItemText(item, 0); // 解析记录路径 string strServerName = ""; string strPurePath = ""; ParseRecPath(strRecPath, out strServerName, out strPurePath); // 获得server url dp2Server server = this.dp2ResTree1.Servers.GetServerByName(strServerName); if (server == null) { strError = "名为 '" + strServerName + "' 的服务器在检索窗中尚未定义..."; goto ERROR1; } string strServerUrl = server.Url; this.Channel = this.Channels.GetChannel(strServerUrl); string[] results = null; byte[] baTimestamp = null; string strOutputPath = ""; stop.SetMessage("正在删除书目记录 " + strPurePath); long lRet = Channel.GetBiblioInfos( stop, strPurePath, "", null, // formats out results, out baTimestamp, out strError); if (lRet == -1) { result = MessageBox.Show(this, "在获得记录 '" + strRecPath + "' 的时间戳的过程中出现错误: " + strError + "。\r\n\r\n是否继续强行删除此记录? (Yes 强行删除;No 不删除;Cancel 放弃当前未完成的全部删除操作)", "dp2SearchForm", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); if (result == System.Windows.Forms.DialogResult.Cancel) goto ERROR1; if (result == System.Windows.Forms.DialogResult.No) continue; } if (lRet == -1 || lRet == 0) goto ERROR1; byte[] baNewTimestamp = null; lRet = Channel.SetBiblioInfo( stop, "delete", strPurePath, "xml", "", // strXml, baTimestamp, "", out strOutputPath, out baNewTimestamp, out strError); if (lRet == -1) goto ERROR1; stop.SetProgressValue(i); this.listView_browse.Items.Remove(item); } } finally { this._processing--; stop.EndLoop(); stop.OnStop -= new StopEventHandler(this.DoStop); stop.Initial(""); stop.HideProgress(); stop.Style = StopStyle.None; this.EnableControlsInSearching(true); this.listView_browse.SelectedIndexChanged += new System.EventHandler(this.listView_browse_SelectedIndexChanged); } MessageBox.Show(this, "成功删除书目记录 " + items.Count + " 条"); return; ERROR1: MessageBox.Show(this, strError); }
int GetBiblioInfo( bool bCheckSearching, ListViewItem item, out BiblioInfo info, out string strError) { strError = ""; info = null; if (this.m_biblioTable == null) return 0; string strRecPath = item.Text; if (string.IsNullOrEmpty(strRecPath) == true) return 0; // 存储所获得书目记录 XML info = (BiblioInfo)this.m_biblioTable[strRecPath]; if (info == null || string.IsNullOrEmpty(info.OldXml) == true) { if (bCheckSearching == true && this._linkMarcFile == null) { if (this.InSearching == true) return 0; } // 解析记录路径 string strServerName = ""; string strPurePath = ""; ParseRecPath(strRecPath, out strServerName, out strPurePath); // 获得server url dp2Server server = this.dp2ResTree1.Servers.GetServerByName(strServerName); if (server == null) { strError = "名为 '" + strServerName + "' 的服务器在检索窗中尚未定义..."; return -1; } string strServerUrl = server.Url; this.Channel = this.Channels.GetChannel(strServerUrl); string[] results = null; byte[] baTimestamp = null; // 获得书目记录 long lRet = Channel.GetBiblioInfos( stop, strPurePath, "", new string[] { "xml" }, // formats out results, out baTimestamp, out strError); if (lRet == 0) return -1; // 是否设定为特殊状态? if (lRet == -1) return -1; if (results == null || results.Length == 0) { strError = "results error"; return -1; } string strXml = results[0]; // 滞后创建新对象,避免在 hashtable 中存在一个尚未初始化的对象,而被其他线程抢先使用了 if (info == null) { info = new BiblioInfo(); info.RecPath = strRecPath; this.m_biblioTable[strRecPath] = info; } info.OldXml = strXml; info.Timestamp = baTimestamp; info.RecPath = strRecPath; } return 1; }
int SaveChangedRecords(List<ListViewItem> items, out string strError) { strError = ""; int nReloadCount = 0; int nSavedCount = 0; stop.Style = StopStyle.EnableHalfStop; stop.OnStop += new StopEventHandler(this.DoStop); stop.Initial("正在保存书目记录 ..."); stop.BeginLoop(); this.EnableControlsInSearching(false); this.listView_browse.Enabled = false; try { stop.SetProgressRange(0, items.Count); for (int i = 0; i < items.Count; i++) { if (stop != null && stop.State != 0) { strError = "已中断"; return -1; } ListViewItem item = items[i]; string strRecPath = item.Text; if (string.IsNullOrEmpty(strRecPath) == true) { stop.SetProgressValue(i); goto CONTINUE; } BiblioInfo info = (BiblioInfo)this.m_biblioTable[strRecPath]; if (info == null) goto CONTINUE; if (string.IsNullOrEmpty(info.NewXml) == true) goto CONTINUE; stop.SetMessage("正在保存书目记录 " + strRecPath); // 解析记录路径 string strServerName = ""; string strPurePath = ""; ParseRecPath(strRecPath, out strServerName, out strPurePath); // 获得server url dp2Server server = this.dp2ResTree1.Servers.GetServerByName(strServerName); if (server == null) { strError = "名为 '" + strServerName + "' 的服务器在检索窗中尚未定义..."; return -1; } string strServerUrl = server.Url; this.Channel = this.Channels.GetChannel(strServerUrl); string strOutputPath = ""; byte[] baNewTimestamp = null; long lRet = Channel.SetBiblioInfo( stop, "change", strPurePath, "xml", info.NewXml, info.Timestamp, "", out strOutputPath, out baNewTimestamp, out strError); if (lRet == -1) { if (Channel.ErrorCode == ErrorCode.TimestampMismatch) { DialogResult result = MessageBox.Show(this, "保存书目记录 " + strRecPath + " 时遭遇时间戳不匹配: " + strError + "。\r\n\r\n此记录已无法被保存。\r\n\r\n请问现在是否要顺便重新装载此记录? \r\n\r\n(Yes 重新装载;\r\nNo 不重新装载、但继续处理后面的记录保存; \r\nCancel 中断整批保存操作)", "BiblioSearchForm", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); if (result == System.Windows.Forms.DialogResult.Cancel) break; if (result == System.Windows.Forms.DialogResult.No) goto CONTINUE; // 重新装载书目记录到 OldXml string[] results = null; // byte[] baTimestamp = null; lRet = Channel.GetBiblioInfos( stop, strPurePath, "", new string[] { "xml" }, // formats out results, out baNewTimestamp, out strError); if (lRet == 0) { // TODO: 警告后,把 item 行移除? return -1; } if (lRet == -1) return -1; if (results == null || results.Length == 0) { strError = "results error"; return -1; } info.OldXml = results[0]; info.Timestamp = baNewTimestamp; nReloadCount++; goto CONTINUE; } return -1; } // 检查是否有部分字段被拒绝 if (Channel.ErrorCode == ErrorCode.PartialDenied) { DialogResult result = MessageBox.Show(this, "保存书目记录 " + strRecPath + " 时部分字段被拒绝。\r\n\r\n此记录已部分保存成功。\r\n\r\n请问现在是否要顺便重新装载此记录以便观察? \r\n\r\n(Yes 重新装载(到旧记录部分);\r\nNo 不重新装载、但继续处理后面的记录保存; \r\nCancel 中断整批保存操作)", "BiblioSearchForm", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); if (result == System.Windows.Forms.DialogResult.Cancel) break; if (result == System.Windows.Forms.DialogResult.No) goto CONTINUE; // 重新装载书目记录到 OldXml string[] results = null; // byte[] baTimestamp = null; lRet = Channel.GetBiblioInfos( stop, strPurePath, "", new string[] { "xml" }, // formats out results, out baNewTimestamp, out strError); if (lRet == 0) { // TODO: 警告后,把 item 行移除? return -1; } if (lRet == -1) return -1; if (results == null || results.Length == 0) { strError = "results error"; return -1; } info.OldXml = results[0]; info.Timestamp = baNewTimestamp; nReloadCount++; goto CONTINUE; } info.Timestamp = baNewTimestamp; info.OldXml = info.NewXml; info.NewXml = ""; item.BackColor = SystemColors.Window; item.ForeColor = SystemColors.WindowText; nSavedCount++; this.m_nChangedCount--; Debug.Assert(this.m_nChangedCount >= 0, ""); CONTINUE: stop.SetProgressValue(i); } } finally { stop.EndLoop(); stop.OnStop -= new StopEventHandler(this.DoStop); stop.Initial(""); stop.HideProgress(); stop.Style = StopStyle.None; this.EnableControlsInSearching(true); this.listView_browse.Enabled = true; } //2013/10/22 int nRet = RefreshListViewLines(items, out strError); if (nRet == -1) return -1; DoViewComment(false); strError = ""; if (nSavedCount > 0) strError += "共保存书目记录 " + nSavedCount + " 条"; if (nReloadCount > 0) { if (string.IsNullOrEmpty(strError) == false) strError += " ; "; strError += "有 " + nReloadCount + " 条书目记录因为时间戳不匹配或部分字段被拒绝而重新装载旧记录部分(请观察后重新保存)"; } return 0; }
// return: // -1 出错 // 0 未发生改变 // 1 发生了改变 int ChangeOneRecord(string strBiblioRecPath, DateTime now, out string strError) { strError = ""; int nRet = 0; stop.SetMessage("正在处理 " + strBiblioRecPath + " ..."); string[] formats = new string[1]; formats[0] = "xml"; string[] results = null; byte[] timestamp = null; long lRet = Channel.GetBiblioInfos( stop, strBiblioRecPath, "", formats, out results, out timestamp, out strError); if (lRet == 0) { return(0); // not found } if (lRet == -1) { return(-1); } if (results.Length == 0) { strError = "results length error"; return(-1); } string strXml = results[0]; XmlDocument domOrigin = new XmlDocument(); try { domOrigin.LoadXml(strXml); } catch (Exception ex) { strError = "装载XML到DOM时发生错误: " + ex.Message; return(-1); } string strMARC = ""; string strMarcSyntax = ""; string strOutMarcSyntax = ""; // 将XML格式转换为MARC格式 // 自动从数据记录中获得MARC语法 nRet = MarcUtil.Xml2Marc(strXml, true, strMarcSyntax, out strOutMarcSyntax, out strMARC, out strError); if (nRet == -1) { strError = "XML转换到MARC记录时出错: " + strError; return(-1); } // 修改 // return: // -1 出错 // 0 未发生改变 // 1 发生了改变 nRet = ModifyField998(ref strMARC, now, out strError); if (nRet == -1) { return(-1); } if (nRet == 0) { return(0); } // 转换回xml格式 XmlDocument domMarc = null; nRet = MarcUtil.Marc2Xml(strMARC, strOutMarcSyntax, out domMarc, out strError); if (nRet == -1) { return(-1); } // 合并<dprms:file>元素 XmlNamespaceManager nsmgr = new XmlNamespaceManager(new NameTable()); nsmgr.AddNamespace("dprms", DpNs.dprms); XmlNodeList nodes = domOrigin.DocumentElement.SelectNodes("//dprms:file", nsmgr); for (int i = 0; i < nodes.Count; i++) { XmlNode new_node = domMarc.CreateElement("dprms", "file", DpNs.dprms); domMarc.DocumentElement.AppendChild(new_node); DomUtil.SetElementOuterXml(new_node, nodes[i].OuterXml); } // 保存 byte[] baNewTimestamp = null; string strOutputPath = ""; lRet = Channel.SetBiblioInfo( stop, "change", strBiblioRecPath, "xml", domMarc.DocumentElement.OuterXml, timestamp, "", out strOutputPath, out baNewTimestamp, out strError); if (lRet == -1) { strError = "保存书目记录 '" + strBiblioRecPath + "' 时出错: " + strError; return(-1); } return(1); }
int PrepareBiblioRecord( out string strError) { strError = ""; int nRet = 0; long lRet = 0; // string strOutputPath = ""; if (string.IsNullOrEmpty(this.RecPath) == true) { return(0); // 此时无法进行初始化 } OpacApplication app = (OpacApplication)this.Page.Application["app"]; SessionInfo sessioninfo = (SessionInfo)this.Page.Session["sessioninfo"]; string strBiblioXml = ""; LibraryChannel channel = sessioninfo.GetChannel(true); try { // string strBiblioState = ""; byte[] timestamp = null; string[] formats = new string[1]; formats[0] = "xml"; string[] results = null; lRet = // sessioninfo.Channel. channel.GetBiblioInfos( null, this.RecPath, "", formats, out results, out timestamp, out strError); if (lRet == -1) { strError = "获得书目记录 '" + this.RecPath + "' 时出错: " + strError; goto ERROR1; } if (lRet == 0) { strError = "书目记录 '" + this.RecPath + "' 不存在"; goto ERROR1; } if (results == null || results.Length < 1) { strError = "results error {A9217775-645E-42F1-8307-22B26C0E1D69}"; goto ERROR1; } strBiblioXml = results[0]; this.m_strXml = strBiblioXml; this.Timestamp = ByteArray.GetHexTimeStampString(timestamp); this.BiblioRecPath = this.RecPath; } finally { sessioninfo.ReturnChannel(channel); } if (app.SearchLog != null) { SearchLogItem log = new SearchLogItem(); log.IP = this.Page.Request.UserHostAddress.ToString(); log.Query = ""; log.Time = DateTime.UtcNow; log.HitCount = 1; log.Format = "biblio"; log.RecPath = this.RecPath; app.SearchLog.AddLogItem(log); } string strMarc = ""; // 转换为MARC { string strOutMarcSyntax = ""; // 将MARCXML格式的xml记录转换为marc机内格式字符串 // parameters: // bWarning ==true, 警告后继续转换,不严格对待错误; = false, 非常严格对待错误,遇到错误后不继续转换 // strMarcSyntax 指示marc语法,如果=="",则自动识别 // strOutMarcSyntax out参数,返回marc,如果strMarcSyntax == "",返回找到marc语法,否则返回与输入参数strMarcSyntax相同的值 nRet = MarcUtil.Xml2Marc(strBiblioXml, true, "", // this.CurMarcSyntax, out strOutMarcSyntax, out strMarc, out strError); if (nRet == -1) { goto ERROR1; } this.m_strMARC = strMarc; } bool bAjax = true; if (this.DisableAjax == true) { bAjax = false; } else { if (app != null && app.WebUiDom != null && app.WebUiDom.DocumentElement != null) { XmlNode nodeBiblioControl = app.WebUiDom.DocumentElement.SelectSingleNode( "biblioControl"); if (nodeBiblioControl != null) { DomUtil.GetBooleanParam(nodeBiblioControl, "ajax", true, out bAjax, out strError); } } } if (bAjax == false) { string strBiblio = ""; string strBiblioDbName = StringUtil.GetDbName(this.RecPath); // 需要从内核映射过来文件 string strLocalPath = ""; nRet = app.MapKernelScriptFile( // null, // sessioninfo, strBiblioDbName, "./cfgs/opac_biblio.fltx", // OPAC查询固定认这个角色的配置文件,作为公共查询书目格式创建的脚本。而流通前端,创建书目格式的时候,找的是loan_biblio.fltx配置文件 out strLocalPath, out strError); if (nRet == -1) { goto ERROR1; } // 将种记录数据从XML格式转换为HTML格式 KeyValueCollection result_params = null; // 2006/11/28 changed string strFilterFileName = strLocalPath; // app.CfgDir + "\\biblio.fltx"; nRet = app.ConvertBiblioXmlToHtml( strFilterFileName, strBiblioXml, this.RecPath, out strBiblio, out result_params, out strError); if (nRet == -1) { goto ERROR1; } // TODO: Render的时候设置,已经晚了半拍 // 要想办法在全部Render前得到题名和进行设置 if (this.AutoSetPageTitle == true && result_params != null && result_params.Count > 0) { string strTitle = result_params["title"].Value; if (string.IsNullOrEmpty(strTitle) == false) { this.Page.Title = strTitle; } bool bHasDC = false; // 探测一下,是否有至少一个DC.开头的 key ? foreach (KeyValue item in result_params) { if (StringUtil.HasHead(item.Key, "DC.") == true) { bHasDC = true; break; } } if (bHasDC == true) { // <header profile="http://dublincore.org/documents/2008/08/04/dc-html/"> this.Page.Header.Attributes.Add("profile", "http://dublincore.org/documents/2008/08/04/dc-html/"); // DC rel // HtmlLink link = new HtmlLink(); link.Href = "http://purl.org/dc/elements/1.1/"; link.Attributes.Add("rel", "schema.DC"); this.Page.Header.Controls.Add(link); // <link rel="schema.DCTERMS" href="http://purl.org/dc/terms/" > link = new HtmlLink(); link.Href = "http://purl.org/dc/terms/"; link.Attributes.Add("rel", "schema.DCTERMS"); this.Page.Header.Controls.Add(link); foreach (KeyValue item in result_params) { if (StringUtil.HasHead(item.Key, "DC.") == false && StringUtil.HasHead(item.Key, "DCTERMS.") == false) { continue; } HtmlMeta meta = new HtmlMeta(); meta.Name = item.Key; meta.Content = item.Value; if (StringUtil.HasHead(item.Value, "urn:") == true || StringUtil.IsHttpUrl(item.Value) == true || StringUtil.HasHead(item.Value, "info:") == true ) { meta.Attributes.Add("scheme", "DCTERMS.URI"); } this.Page.Header.Controls.Add(meta); } } } this.m_strOpacBiblio = strBiblio; } return(0); ERROR1: return(-1); }
void submit_button_Click(object sender, EventArgs e) { int nRet = 0; long lRet = 0; string strError = ""; // string strOutputPath = ""; OpacApplication app = (OpacApplication)this.Page.Application["app"]; SessionInfo sessioninfo = (SessionInfo)this.Page.Session["sessioninfo"]; bool bManager = false; if (string.IsNullOrEmpty(sessioninfo.UserID) == true || StringUtil.IsInList("managecomment", sessioninfo.RightsOrigin) == false) { bManager = false; } else { bManager = true; } if (bManager == false) { strError = "当前帐户不具备 managecomment 权限, 不能进行修改书目状态的操作"; goto ERROR1; } LibraryChannel channel = sessioninfo.GetChannel(true); try { string strBiblioRecPath = this.BiblioRecPath; byte[] timestamp = null; string strBiblioXml = ""; string[] formats = new string[1]; formats[0] = "xml"; string[] results = null; lRet = // sessioninfo.Channel. channel.GetBiblioInfos( null, strBiblioRecPath, "", formats, out results, out timestamp, out strError); if (lRet == -1) { strError = "获得书目记录 '" + strBiblioRecPath + "' 时出错: " + strError; goto ERROR1; } if (lRet == 0) { strError = "书目记录 '" + strBiblioRecPath + "' 不存在"; goto ERROR1; } if (results == null || results.Length < 1) { strError = "results error {11AD709F-2DBC-41DE-8129-184FFAD59815}"; goto ERROR1; } strBiblioXml = results[0]; byte[] old_timestamp = ByteArray.GetTimeStampByteArray(this.Timestamp); if (ByteArray.Compare(timestamp, old_timestamp) != 0) { strError = "修改被拒绝。因为记录 '" + strBiblioRecPath + "' 在保存前已经被其他人修改过。请重新装载"; goto ERROR1; } string strOutMarcSyntax = ""; string strMarc = ""; // 将MARCXML格式的xml记录转换为marc机内格式字符串 // parameters: // bWarning ==true, 警告后继续转换,不严格对待错误; = false, 非常严格对待错误,遇到错误后不继续转换 // strMarcSyntax 指示marc语法,如果=="",则自动识别 // strOutMarcSyntax out参数,返回marc,如果strMarcSyntax == "",返回找到marc语法,否则返回与输入参数strMarcSyntax相同的值 nRet = MarcUtil.Xml2Marc(strBiblioXml, true, "", // this.CurMarcSyntax, out strOutMarcSyntax, out strMarc, out strError); if (nRet == -1) { goto ERROR1; } string strBiblioState = MarcDocument.GetFirstSubfield(strMarc, "998", "s"); // 状态 // 修改998字段 string strOldBiblioState = strBiblioState; this.GetStateValueFromControls(ref strBiblioState); if (strOldBiblioState == strBiblioState) { // 也退出编辑态 cancel_button_Click(this, new EventArgs()); strError = "状态没有发生变化,放弃保存书目记录"; goto ERROR1; } MarcUtil.SetFirstSubfield(ref strMarc, "998", "s", strBiblioState); // 保存 // 将MARC格式转换为XML格式 // 2015/10/12 从 Marc2Xml() 修改为 Marc2XmlEx() string strXml = strBiblioXml; nRet = MarcUtil.Marc2XmlEx( strMarc, strOutMarcSyntax, ref strXml, out strError); if (nRet == -1) { goto ERROR1; } string strOutputBiblioRecPath = ""; byte[] baOutputTimestamp = null; lRet = // sessioninfo.Channel. channel.SetBiblioInfo( null, "change", strBiblioRecPath, "xml", strXml, timestamp, "", out strOutputBiblioRecPath, out baOutputTimestamp, out strError); if (lRet == -1) { goto ERROR1; } this.Timestamp = ByteArray.GetHexTimeStampString(baOutputTimestamp); return; } finally { sessioninfo.ReturnChannel(channel); } ERROR1: this.SetDebugInfo("errorinfo", strError); }
// 装载数据 public override bool LoadData() { string strError = ""; int nRet = 0; BiblioInfo info = this.BiblioInfo; string strRecPath = this.BiblioInfo.RecPath; if (string.IsNullOrEmpty(info.OldXml) == true) { lock (syncRoot) { channel = this.Container.MainForm.GetChannel(); } try { // 显示 正在处理 this.HTML = GetWaitingHtml("正在获取书目记录 " + strRecPath); ShowData(); string[] results = null; byte[] baTimestamp = null; // 获得书目记录 channel.Timeout = new TimeSpan(0, 0, 5); long lRet = channel.GetBiblioInfos( Stop, strRecPath, "", new string[] { "xml" }, // formats out results, out baTimestamp, out strError); if (lRet == 0) { nRet = -1; strError = "获取书目记录 "+strRecPath+" 时出错: " + strError; } else if (lRet == -1) { nRet = -1; strError = "获取书目记录 " + strRecPath + " 时出错: " + strError; } else { if (results == null || results.Length == 0) { strError = "results error"; throw new Exception(strError); } // TODO: 对 BiblioInfo 的成员进行操作的时候,是否要 lock 一下对象? string strXml = results[0]; info.OldXml = strXml; info.Timestamp = baTimestamp; info.RecPath = strRecPath; } } finally { LibraryChannel temp_channel = channel; lock (syncRoot) { channel = null; } this.Container.MainForm.ReturnChannel(temp_channel); } } string strXml1 = ""; string strHtml2 = ""; string strXml2 = ""; if (nRet == -1) { strHtml2 = HttpUtility.HtmlEncode(strError); } else { nRet = BiblioSearchForm.GetXmlHtml(info, out strXml1, out strXml2, out strHtml2, out strError); if (nRet == -1) throw new Exception(strError); } this.HTML = "<html>" + this.Container.MainForm.GetMarcHtmlHeadString(true) + "<body>" + strHtml2 + EntityForm.GetTimestampHtml(info.Timestamp) + "</body></html>"; this.XML = BiblioSearchForm.MergeXml(strXml1, strXml2); return true; }