// 获得一条MARC/XML记录 // return: // -1 error 包括not found // 0 found // 1 为诊断记录 public int GetOneRecord( string strStyle, int nTest, // 暂时使用 string strPathParam, // int index, 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 = Encoding.UTF8; // this.CurrentEncoding; baTimestamp = null; strSavePath = ""; strOutStyle = "marc"; logininfo = new LoginInfo(); lVersion = 0; int nRet = 0; if (strStyle != "marc" && strStyle != "xml") { strError = "dp2SearchForm只支持获取MARC格式记录和xml格式记录,不支持 '" + strStyle + "' 格式的记录"; return -1; } int index = -1; string strPath = ""; string strDirection = ""; nRet = Global.ParsePathParam(strPathParam, out index, out strPath, out strDirection, out strError); if (nRet == -1) return -1; ListViewItem curItem = null; if (index == -1) { // 找到 Item 行 curItem = ListViewUtil.FindItem(this.listView_browse, strPath, 0); if (curItem == null) { strError = "路径为 '" + strPath + "' 的事项在列表中没有找到"; return -1; } index = this.listView_browse.Items.IndexOf(curItem); // strDirection 方向。为 prev/next/current之一。current可以缺省。 if (strDirection == "prev") { if (index == 0) { strError = "到头"; return -1; } index--; } else if (strDirection == "next") { index++; } } { REDO: if (index >= this.listView_browse.Items.Count) { if (this.m_nCurrentPageNo >= this.m_nTotalPages - 1) { strError = "越过结果集尾部"; return -1; } nRet = DoGetNextBatch(out strError); if (nRet == -1) return -1; WaitSearchFinish(); goto REDO; } curItem = this.listView_browse.Items[index]; } bool bHilightBrowseLine = StringUtil.IsInList("hilight_browse_line", strParameters); bool bForceFullElementSet = StringUtil.IsInList("force_full", strParameters); 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(); } strPath = curItem.Text; ItemInfo info = (ItemInfo)curItem.Tag; if (bForceFullElementSet == true && info.EelementSet != "F") { // 需要重新装载这一条记录 List<ListViewItem> items = new List<ListViewItem>(); items.Add(curItem); #if NO // 观察和上次操作间隔的时间。保证大于一秒 TimeSpan delta = DateTime.Now - m_timeLastReload; if (delta < new TimeSpan(0,0,1)) Thread.Sleep(1000); #endif int nRedoCount = 0; REDO_RELOAD: m_bErrorBox = false; nRet = ReloadItems(items, 0, "F", out strError); m_timeLastReload = DateTime.Now; if (nRet == -1) { return -1; } bool bError = WaitSearchFinish(); if (bError == true && this.m_exception != null && this.m_exception is WebException) { WebException ex = this.m_exception as WebException; if (ex.Status == WebExceptionStatus.ProtocolError) { // 重做 if (nRedoCount < 2) { nRedoCount++; Thread.Sleep(1000); goto REDO_RELOAD; } // 询问是否重做 DialogResult result = MessageBox.Show(this, "重新装载时发生错误:\r\n\r\n" + strError + "\r\n\r\n是否重试?\r\n\r\n(Yes: 重试; No: 中断操作", "AmazonSearchForm", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); if (result == System.Windows.Forms.DialogResult.Yes) { Thread.Sleep(1000); goto REDO_RELOAD; } return -1; } } info = (ItemInfo)curItem.Tag; } record = new DigitalPlatform.Z3950.Record(); record.m_baRecord = Encoding.UTF8.GetBytes(info.Xml); record.m_strDBName = m_searchParameters != null ? m_searchParameters["SearchIndex"] : ""; record.m_strSyntaxOID = info.PreferSyntaxOID; // ??? record.m_strElementSetName = info.EelementSet; // B F strSavePath = this.CurrentProtocol + ":" + strPath; string strOutputPath = ""; { string strContent = info.Xml; if (strStyle == "marc") { // TODO: 转换为MARC nRet = ConvertXmlToMarc( record.m_strSyntaxOID, strContent, out strRecord, out strError); if (nRet == -1) return -1; strOutStyle = "marc"; if (string.IsNullOrEmpty(record.m_strSyntaxOID) == true) record.m_strSyntaxOID = "1.2.840.10003.5.1"; // UNIMARC return 0; } // 不是MARCXML格式 strRecord = strContent; strOutStyle = "xml"; return 0; } /* return GetOneRecord( true, strStyle, strPath, "", out strRecord, out strXmlFragment, out strOutputPath, out strOutStyle, out baTimestamp, out record, out currrentEncoding, out strError); * */ return 0; }
void LoadLinkedMarcRecord(string strMarc, byte [] baRecord) { int nRet = 0; string strError = ""; this.CurrentTimestamp = null; this.textBox_tempRecPath.Text = "marcfile:" + this.linkMarcFile.FileName + ":" + this.linkMarcFile.CurrentIndex.ToString(); this.SavePath = ""; this.CurrentEncoding = this.linkMarcFile.Encoding; string strMarcSyntax = this.linkMarcFile.MarcSyntax.ToLower(); // 2009/9/21 if (strMarcSyntax == "unimarc") this.AutoDetectedMarcSyntaxOID = "1.2.840.10003.5.1"; // UNIMARC else if (strMarcSyntax == "usmarc") { this.AutoDetectedMarcSyntaxOID = "1.2.840.10003.5.10"; // USMARC // this.MarcEditor.Lang = "en"; } // 装入MARC编辑器 this.MarcEditor.Marc = strMarc; this.CurrentRecord = null; DigitalPlatform.Z3950.Record record = new DigitalPlatform.Z3950.Record(); if (strMarcSyntax == "unimarc" || strMarcSyntax == "") record.m_strSyntaxOID = "1.2.840.10003.5.1"; else if (strMarcSyntax == "usmarc") record.m_strSyntaxOID = "1.2.840.10003.5.10"; else if (strMarcSyntax == "dt1000reader") record.m_strSyntaxOID = "1.2.840.10003.5.dt1000reader"; else { strError = "未知的MARC syntax '" + strMarcSyntax + "'"; goto ERROR1; } record.m_baRecord = baRecord; this.CurrentRecord = record; DisplayHtml(strMarc, record.m_strSyntaxOID); { if (this.CurrentEncoding.Equals(this.MainForm.Marc8Encoding) == true) { } else { if (baRecord == null) { baRecord = this.CurrentEncoding.GetBytes(strMarc); } } if (baRecord != null) { // 装入二进制编辑器 this.binaryEditor_originData.SetData( baRecord); } else { // TODO: 是否要清除原有内容? } this.label_originDataWarning.Text = ""; if (baRecord != null) { // 装入ISO2709文本 nRet = this.Set2709OriginText(baRecord, this.CurrentEncoding, out strError); if (nRet == -1) { this.textBox_originData.Text = strError; this.label_originDataWarning.Text = ""; } } } this.MarcEditor.MarcDefDom = null; // 强制刷新字段名提示 this.MarcEditor.RefreshNameCaption(); this.BiblioChanged = false; if (this.MarcEditor.FocusedFieldIndex == -1) this.MarcEditor.FocusedFieldIndex = 0; this.MarcEditor.Focus(); return; ERROR1: MessageBox.Show(this, strError); }
// 获得一条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记录 // 注:如果this.DtlpChannel被占用,启动启用新的通道 // TODO: 尚未处理启用新通道时启用新Stop的课题 // parameters: // strPath 记录路径。格式为"localhost/中文图书/ctlno/1" // strDirection 方向。为 prev/next/current之一。current可以缺省。 // strOutputPath [out]返回的实际路径。格式和strPath相同。 // return: // -1 error 包括not found // 0 found // 1 为诊断记录 int InternalGetOneRecord( string strStyle, string strPath, string strDirection, out string strMARC, out string strOutputPath, out string strOutStyle, out byte[] baTimestamp, out DigitalPlatform.Z3950.Record record, out Encoding currrentEncoding, out string strError) { strMARC = ""; record = null; strError = ""; currrentEncoding = this.CurrentEncoding; baTimestamp = null; strOutStyle = "marc"; strOutputPath = ""; // TODO: 需要参考dp1batch看获得outputpath的方法 if (strStyle != "marc") { strError = "DtlpSearchForm只支持获取MARC格式记录"; return -1; } int nRet = 0; int nStyle = DtlpChannel.XX_STYLE; // 获得详细记录 if (strDirection == "prev") nStyle |= DtlpChannel.PREV_RECORD; else if (strDirection == "next") nStyle |= DtlpChannel.NEXT_RECORD; /* // 将路径转换为内核可以接受的正规形态 string strPath = DigitalPlatform.DTLP.Global.ModifyDtlpRecPath(strPath, "ctlno"); * */ Stop temp_stop = this.stop; DtlpChannel channel = null; bool bNewChannel = false; if (this.m_nInSearching == 0) channel = this.DtlpChannel; else { channel = this.DtlpChannels.CreateChannel(0); bNewChannel = true; temp_stop = new Stop(); temp_stop.Tag = channel; temp_stop.Register(MainForm.stopManager, true); // 和容器关联 temp_stop.OnStop += new StopEventHandler(this.DoNewStop); temp_stop.Initial("正在初始化浏览器组件 ..."); temp_stop.BeginLoop(); } byte[] baPackage = null; Encoding encoding = null; try { nRet = channel.Search(strPath, nStyle, out baPackage); if (nRet == -1) { int errorcode = channel.GetLastErrno(); if (errorcode == DtlpChannel.GL_NOTEXIST && (strDirection == "prev" || strDirection == "next")) { if (strDirection == "prev") strError = "到头"; else if (strDirection == "next") strError = "到尾"; goto ERROR1; } strError = "检索出错:\r\n" + "检索式: " + strPath + "\r\n" + "错误码: " + errorcode + "\r\n" + "错误信息: " + channel.GetErrorString(errorcode) + "\r\n"; goto ERROR1; } encoding = channel.GetPathEncoding(strPath); } finally { if (bNewChannel == true) { temp_stop.EndLoop(); temp_stop.OnStop -= new StopEventHandler(this.DoNewStop); temp_stop.Initial(""); this.DtlpChannels.DestroyChannel(channel); channel = null; temp_stop.Unregister(); // 和容器关联 temp_stop = null; } } Package package = new Package(); package.LoadPackage(baPackage, encoding); nRet = package.Parse(PackageFormat.Binary); if (nRet == -1) { strError = "Package::Parse() error"; goto ERROR1; } strOutputPath = package.GetFirstPath(); byte[] content = null; nRet = package.GetFirstBin(out content); if (nRet == -1) { strError = "Package::GetFirstBin() error"; goto ERROR1; } if (content == null || content.Length < 9) { strError = "content length < 9"; goto ERROR1; } baTimestamp = new byte[9]; Array.Copy(content, baTimestamp, 9); byte[] marc = new byte[content.Length - 9]; Array.Copy(content, 9, marc, 0, content.Length - 9); // strMARC = this.CurrentEncoding.GetString(marc); strMARC = encoding.GetString(marc); // 去掉最后若干连续的29字符或者0字符 // 2008/3/11 int nDelta = 0; for (int i = strMARC.Length - 1; i > 24; i--) { char ch = strMARC[i]; if (ch == 0 || ch == 29) nDelta++; else break; } if (nDelta > 0) strMARC = strMARC.Substring(0, strMARC.Length - nDelta); // 自动识别MARC格式 string strOutMarcSyntax = ""; // 探测记录的MARC格式 unimarc / usmarc / reader // return: // 0 没有探测出来。strMarcSyntax为空 // 1 探测出来了 nRet = MarcUtil.DetectMarcSyntax(strMARC, out strOutMarcSyntax); if (strOutMarcSyntax == "") strOutMarcSyntax = "unimarc"; record = new DigitalPlatform.Z3950.Record(); if (strOutMarcSyntax == "unimarc" || strOutMarcSyntax == "") record.m_strSyntaxOID = "1.2.840.10003.5.1"; else if (strOutMarcSyntax == "usmarc") record.m_strSyntaxOID = "1.2.840.10003.5.10"; else if (strOutMarcSyntax == "dt1000reader") record.m_strSyntaxOID = "1.2.840.10003.5.dt1000reader"; else { /* strError = "未知的MARC syntax '" + strOutMarcSyntax + "'"; goto ERROR1; * */ // TODO: 可以出现菜单选择 } return 0; ERROR1: return -1; }
// 装载XML记录 public int LoadRecord(ISearchForm searchform, int index, bool bForceFullElementSet = false) { string strError = ""; string strMARC = ""; this.LinkedSearchForm = searchform; this.SavePath = ""; DigitalPlatform.Z3950.Record record = null; Encoding currentEncoding = null; this.CurrentRecord = null; byte[] baTimestamp = null; string strSavePath = ""; string strOutStyle = ""; LoginInfo logininfo = null; long lVersion = 0; string strXmlFragment = ""; string strParameters = "hilight_browse_line"; if (bForceFullElementSet == true) strParameters += ",force_full"; int nRet = searchform.GetOneRecord( "xml", index, // 即将废止 "index:" + index.ToString(), strParameters, // true, out strSavePath, out strMARC, out strXmlFragment, out strOutStyle, out baTimestamp, out lVersion, out record, out currentEncoding, out logininfo, out strError); if (nRet == -1) goto ERROR1; this.LoginInfo = logininfo; this.CurrentTimestamp = baTimestamp; this.SavePath = strSavePath; this.CurrentEncoding = currentEncoding; // 替换单个0x0a strMARC = strMARC.Replace("\r", ""); strMARC = strMARC.Replace("\n", "\r\n"); // 装入XML编辑器 // this.textBox_xml.Text = strMARC; this.PlainText = strMARC; // 能自动缩进 this.textBox_xml.Select(0, 0); // 装入XML只读Web控件 { string strTempFileName = MainForm.DataDir + "\\xml.xml"; // SUTRS if (record.m_strSyntaxOID == "1.2.840.10003.5.101") strTempFileName = MainForm.DataDir + "\\xml.txt"; using (Stream stream = File.Create(strTempFileName)) { // 写入xml内容 byte[] buffer = Encoding.UTF8.GetBytes(strMARC); stream.Write(buffer, 0, buffer.Length); } this.webBrowser_xml.Navigate(strTempFileName); } this.CurrentRecord = record; if (this.CurrentRecord != null && this.DisplayOriginPage == true) { // 装入二进制编辑器 this.binaryEditor_originData.SetData( this.CurrentRecord.m_baRecord); // 装入原始文本 nRet = this.SetOriginText(this.CurrentRecord.m_baRecord, this.CurrentEncoding, out strError); if (nRet == -1) { this.textBox_originData.Text = strError; } // 数据库名 this.textBox_originDatabaseName.Text = this.CurrentRecord.m_strDBName; // record syntax OID this.textBox_originMarcSyntaxOID.Text = this.CurrentRecord.m_strSyntaxOID; } // 构造路径 string strPath = searchform.CurrentProtocol + ":" + searchform.CurrentResultsetPath + "/" + (index + 1).ToString(); this.textBox_tempRecPath.Text = strPath; this.textBox_xml.Focus(); return 0; ERROR1: MessageBox.Show(this, strError); return -1; }
// 获得一条MARC/XML记录 // parameters: // strPath 记录路径。格式为"中文图书/1 @服务器名" // strDirection 方向。为 prev/next/current之一。current可以缺省。 // strOutputPath [out]返回的实际路径。格式和strPath相同。不包含协议名称部分。 // strXmlFragment 书目以外的XML其它片断。当strStyle不是"marc"的时候,不返回这个 // return: // -1 error 包括not found // 0 found // 1 为诊断记录 int InternalGetOneRecord( bool bUseLoop, string strStyle, string strPath, string strDirection, string strParameters, // "reload" 从数据库重新获取 out string strRecord, out string strXmlFragment, out string strOutputPath, out string strOutStyle, out byte[] baTimestamp, out DigitalPlatform.Z3950.Record record, out Encoding currrentEncoding, out string strError) { strXmlFragment = ""; strRecord = ""; strOutputPath = ""; record = null; strError = ""; currrentEncoding = this.CurrentEncoding; baTimestamp = null; strOutStyle = "marc"; if (strStyle != "marc" && strStyle != "xml") { strError = "dp2SearchForm只支持获取MARC格式记录和xml格式记录,不支持 '" + strStyle + "' 格式的记录"; return -1; } bool bReload = StringUtil.IsInList("reload", strParameters); string strXml = ""; // if (this.linkMarcFile != null) if (bReload == false) { BiblioInfo info = null; // 存储所获得书目记录 XML info = (BiblioInfo)this.m_biblioTable[strPath]; if (info != null) { if (string.IsNullOrEmpty(info.NewXml) == true) strXml = info.OldXml; else strXml = info.NewXml; Debug.Assert(string.IsNullOrEmpty(strXml) == false, ""); strOutputPath = info.RecPath; baTimestamp = info.Timestamp; goto SKIP0; } } // 解析记录路径 string strServerName = ""; string strPurePath = ""; ParseRecPath(strPath, out strServerName, out strPurePath); // 获得server url dp2Server server = this.dp2ResTree1.Servers.GetServerByName(strServerName); if (server == null) { strError = "名为 '" + strServerName + "' 的服务器在检索窗中尚未定义..."; return -1; } string strServerUrl = server.Url; Stop temp_stop = this.stop; LibraryChannel channel = null; bool bUseNewChannel = false; if (m_bInSearching == true) { channel = this.Channels.NewChannel(strServerUrl); bUseNewChannel = true; temp_stop = new Stop(); temp_stop.Register(MainForm.stopManager, true); // 和容器关联 } else { this.Channel = this.Channels.GetChannel(strServerUrl); channel = this.Channel; } if (bUseLoop == true) { temp_stop.OnStop += new StopEventHandler(this.DoStop); temp_stop.Initial("正在初始化浏览器组件 ..."); temp_stop.BeginLoop(); this.Update(); this.MainForm.Update(); } try { temp_stop.SetMessage("正在装入书目记录 " + strPath + " ..."); string[] formats = null; formats = new string[2]; formats[0] = "xml"; formats[1] = "outputpath"; // 获得实际路径 string[] results = null; // byte[] baTimestamp = null; Debug.Assert(string.IsNullOrEmpty(strPurePath) == false, ""); string strCmd = strPurePath; if (String.IsNullOrEmpty(strDirection) == false) strCmd += "$" + strDirection; long lRet = channel.GetBiblioInfos( temp_stop, strCmd, "", formats, out results, out baTimestamp, out strError); if (lRet == 0) { if (String.IsNullOrEmpty(strDirection) == true || strDirection == "current") strError = "路径为 '" + strPath + "' 的书目记录没有找到 ..."; else { string strText = strDirection; if (strDirection == "prev") strText = "前一条"; else if (strDirection == "next") strText = "后一条"; strError = "路径为 '" + strPath + "' 的" + strText + "书目记录没有找到 ..."; } 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; } strXml = results[0]; strOutputPath = results[1] + "@" + strServerName; Debug.Assert(string.IsNullOrEmpty(strXml) == false, ""); } finally { if (bUseLoop == true) { temp_stop.EndLoop(); temp_stop.OnStop -= new StopEventHandler(this.DoStop); temp_stop.Initial(""); } if (bUseNewChannel == true) { this.Channels.RemoveChannel(channel); channel = null; temp_stop.Unregister(); // 和容器关联 temp_stop = null; } } SKIP0: if (strStyle == "marc") { string strMarcSyntax = ""; string strOutMarcSyntax = ""; // 从数据记录中获得MARC格式 int nRet = MarcUtil.Xml2Marc(strXml, true, strMarcSyntax, out strOutMarcSyntax, out strRecord, out strError); if (nRet == -1) { strError = "XML转换到MARC记录时出错: " + strError; goto ERROR1; } Debug.Assert(string.IsNullOrEmpty(strRecord) == false, ""); record = new DigitalPlatform.Z3950.Record(); if (strOutMarcSyntax == "unimarc" || strOutMarcSyntax == "") record.m_strSyntaxOID = "1.2.840.10003.5.1"; else if (strOutMarcSyntax == "usmarc") record.m_strSyntaxOID = "1.2.840.10003.5.10"; else if (strOutMarcSyntax == "dc") record.m_strSyntaxOID = "?"; else { strError = "未知的MARC syntax '" + strOutMarcSyntax + "'"; goto ERROR1; } // 获得书目以外的其它XML片断 nRet = GetXmlFragment(strXml, out strXmlFragment, out strError); if (nRet == -1) goto ERROR1; } else { strRecord = strXml; strOutStyle = strStyle; record = new DigitalPlatform.Z3950.Record(); record.m_strSyntaxOID = "1.2.840.10003.5.109.10"; } 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 NO // 防止重入 if (m_bInSearching == true) { strError = "当前窗口正在被一个未结束的长操作使用,无法获得记录。请稍后再试。"; return -1; } #endif if (strStyle != "marc" && strStyle != "xml") { strError = "dp2SearchForm只支持获取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) { string strOutputPath = ""; nRet = InternalGetOneRecord( true, strStyle, strPath, strDirection, strParameters, // 2013/9/22 out strRecord, out strXmlFragment, out strOutputPath, out strOutStyle, out baTimestamp, out record, out currrentEncoding, out strError); if (string.IsNullOrEmpty(strOutputPath) == false) strSavePath = this.CurrentProtocol + ":" + strOutputPath; return nRet; } 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(); } #if NO if (this.linkMarcFile != null) { BiblioInfo info = null; int nRet = GetBiblioInfo( true, curItem, out info, out strError); if (info == null) { strError = "not found"; return -1; } if (strStyle == "marc") { string strMarcSyntax = ""; string strOutMarcSyntax = ""; // 从数据记录中获得MARC格式 nRet = MarcUtil.Xml2Marc(info.OldXml, true, strMarcSyntax, out strOutMarcSyntax, out strRecord, out strError); if (nRet == -1) { strError = "XML转换到MARC记录时出错: " + strError; return -1; } record = new DigitalPlatform.Z3950.Record(); if (strOutMarcSyntax == "unimarc" || strOutMarcSyntax == "") record.m_strSyntaxOID = "1.2.840.10003.5.1"; else if (strOutMarcSyntax == "usmarc") record.m_strSyntaxOID = "1.2.840.10003.5.10"; else if (strOutMarcSyntax == "dc") record.m_strSyntaxOID = "?"; else { strError = "未知的MARC syntax '" + strOutMarcSyntax + "'"; return -1; } // 获得书目以外的其它XML片断 nRet = GetXmlFragment(info.OldXml, out strXmlFragment, out strError); if (nRet == -1) return -1; } else { strRecord = info.OldXml; strOutStyle = strStyle; record = new DigitalPlatform.Z3950.Record(); record.m_strSyntaxOID = "1.2.840.10003.5.109.10"; } return 0; } #endif strPath = curItem.Text; strSavePath = this.CurrentProtocol + ":" + strPath; { string strOutputPath = ""; nRet = InternalGetOneRecord( true, strStyle, strPath, "", strParameters, // 2013/9/22 out strRecord, out strXmlFragment, out strOutputPath, out strOutStyle, out baTimestamp, out record, out currrentEncoding, out strError); if (string.IsNullOrEmpty(strOutputPath) == false) strSavePath = this.CurrentProtocol + ":" + strOutputPath; return nRet; } }
// 装载XML记录,根据记录路径 // parameters: // strPath 路径。例如 "图书总库/1@本地服务器" public int LoadDp2Record(dp2SearchForm dp2_searchform, string strPath, string strDirection, bool bLoadResObject) { string strError = ""; string strRecordXml = ""; if (dp2_searchform == null) { strError = "dp2_searchform参数不能为空"; goto ERROR1; } if (dp2_searchform.CurrentProtocol != "dp2library") { strError = "所提供的检索窗不是dp2library协议"; goto ERROR1; } DigitalPlatform.Z3950.Record record = null; Encoding currentEncoding = null; this.CurrentRecord = null; byte[] baTimestamp = null; string strOutStyle = ""; string strSavePath = ""; long lVersion = 0; LoginInfo logininfo = null; string strXmlFragment = ""; int nRet = dp2_searchform.GetOneRecord( // true, "xml", // strPath, // strDirection, 0, // test "path:" + strPath + ",direction:" + strDirection, "", out strSavePath, out strRecordXml, out strXmlFragment, out strOutStyle, out baTimestamp, out lVersion, out record, out currentEncoding, out logininfo, out strError); if (nRet == -1) goto ERROR1; this.CurrentTimestamp = baTimestamp; // this.SavePath = dp2_searchform.CurrentProtocol + ":" + strOutputPath; this.SavePath = strSavePath; this.CurrentEncoding = currentEncoding; string strServerName = ""; string strLocalPath = ""; strPath = strSavePath; // 解析记录路径。 // 记录路径为如下形态 "中文图书/1 @服务器" dp2SearchForm.ParseRecPath(strPath, out strServerName, out strLocalPath); string strBiblioDbName = dp2SearchForm.GetDbName(strLocalPath); // 获得cfgs\dcdef string strCfgFileName = "dcdef"; string strCfgPath = strBiblioDbName + "/cfgs/" + strCfgFileName + "@" + strServerName; // 和以前的不同,才有必要重新载入 if (this.DcCfgFilename != strCfgPath) { string strCode = ""; byte[] baCfgOutputTimestamp = null; // return: // -1 error // 0 not found // 1 found nRet = dp2_searchform.GetCfgFile(strCfgPath, out strCode, out baCfgOutputTimestamp, out strError); if (nRet == -1 || nRet == 0) goto ERROR1; nRet = this.DcEditor.LoadCfgCode(strCode, out strError); if (nRet == -1) goto ERROR1; this.DcCfgFilename = strCfgPath; } // 接着装入对象资源 if (bLoadResObject == true) { // this.binaryResControl1.Channel = dp2_searchform.GetChannel(dp2_searchform.GetServerUrl(strServerName)); nRet = this.binaryResControl1.LoadObject( dp2_searchform.GetChannel(dp2_searchform.GetServerUrl(strServerName)), strLocalPath, strRecordXml, "0", // TODO out strError); if (nRet == -1) { MessageBox.Show(this, strError); return -1; } } // TODO: 再次装入的时候有问题 // 装入DC编辑器 this.DcEditor.Xml = strRecordXml; this.CurrentRecord = record; this.BiblioChanged = false; this.DcEditor.Focus(); return 0; ERROR1: MessageBox.Show(this, strError); return -1; }
// 装载XML记录,根据结果集中位置 public int LoadRecord(ISearchForm searchform, int index) { string strError = ""; string strRecordXml = ""; this.LinkedSearchForm = searchform; this.SavePath = ""; DigitalPlatform.Z3950.Record record = null; Encoding currentEncoding = null; this.CurrentRecord = null; byte[] baTimestamp = null; string strSavePath = ""; string strOutStyle = ""; LoginInfo logininfo = null; long lVersion = 0; string strXmlFragment = ""; int nRet = searchform.GetOneRecord( "xml", index, // 即将废止 "index:" + index.ToString(), "hilight_browse_line", // true, out strSavePath, out strRecordXml, out strXmlFragment, out strOutStyle, out baTimestamp, out lVersion, out record, out currentEncoding, out logininfo, out strError); if (nRet == -1) goto ERROR1; this.LoginInfo = logininfo; this.CurrentTimestamp = baTimestamp; this.SavePath = strSavePath; this.CurrentEncoding = currentEncoding; // dp2library协议 if (searchform.CurrentProtocol == "dp2library") { dp2SearchForm dp2_searchform = this.GetDp2SearchForm(); if (dp2_searchform == null) { strError = "没有连接的或者打开的dp2检索窗,无法进行数据创建"; goto ERROR1; } string strProtocol = ""; string strPath = ""; nRet = Global.ParsePath(strSavePath, out strProtocol, out strPath, out strError); if (nRet == -1) goto ERROR1; string strServerName = ""; string strLocalPath = ""; // 解析记录路径。 // 记录路径为如下形态 "中文图书/1 @服务器" dp2SearchForm.ParseRecPath(strPath, out strServerName, out strLocalPath); string strBiblioDbName = dp2SearchForm.GetDbName(strLocalPath); // 获得cfgs\dcdef string strCfgFileName = "dcdef"; string strCfgPath = strBiblioDbName + "/cfgs/" + strCfgFileName + "@" + strServerName; // 和以前的不同,才有必要重新载入 if (this.DcCfgFilename != strCfgPath) { string strCode = ""; byte[] baCfgOutputTimestamp = null; // return: // -1 error // 0 not found // 1 found nRet = dp2_searchform.GetCfgFile(strCfgPath, out strCode, out baCfgOutputTimestamp, out strError); if (nRet == -1 || nRet == 0) goto ERROR1; nRet = this.DcEditor.LoadCfgCode(strCode, out strError); if (nRet == -1) goto ERROR1; this.DcCfgFilename = strCfgPath; } // 接着装入对象资源 { EnableStateCollection save = this.MainForm.DisableToolButtons(); try { // this.binaryResControl1.Channel = dp2_searchform.GetChannel(dp2_searchform.GetServerUrl(strServerName)); nRet = this.binaryResControl1.LoadObject( dp2_searchform.GetChannel(dp2_searchform.GetServerUrl(strServerName)), strLocalPath, strRecordXml, "0", // TODO out strError); if (nRet == -1) { MessageBox.Show(this, strError); return -1; } } finally { save.RestoreAll(); } } } /* // 替换单个0x0a strMARC = strMARC.Replace("\r", ""); strMARC = strMARC.Replace("\n", "\r\n"); * */ // TODO: 再次装入的时候有问题 // 装入DC编辑器 this.DcEditor.Xml = strRecordXml; /* // 装入XML只读Web控件 { string strTempFileName = MainForm.DataDir + "\\xml.xml"; // SUTRS if (record != null) { if (record.m_strSyntaxOID == "1.2.840.10003.5.101") strTempFileName = MainForm.DataDir + "\\xml.txt"; } Stream stream = File.Create(strTempFileName); // 写入xml内容 byte[] buffer = Encoding.UTF8.GetBytes(strRecordXml); stream.Write(buffer, 0, buffer.Length); stream.Close(); this.webBrowser_xml.Navigate(strTempFileName); } * */ this.CurrentRecord = record; /* if (this.CurrentRecord != null) { // 装入二进制编辑器 this.binaryEditor_originData.SetData( this.CurrentRecord.m_baRecord); // 装入原始文本 nRet = this.SetOriginText(this.CurrentRecord.m_baRecord, this.CurrentEncoding, out strError); if (nRet == -1) { this.textBox_originData.Text = strError; } // 数据库名 this.textBox_originDatabaseName.Text = this.CurrentRecord.m_strDBName; // record syntax OID this.textBox_originMarcSyntaxOID.Text = this.CurrentRecord.m_strSyntaxOID; }*/ // 构造结果集路径 string strFullPath = searchform.CurrentProtocol + ":" + searchform.CurrentResultsetPath + "/" + (index + 1).ToString(); this.textBox_tempRecPath.Text = strFullPath; this.BiblioChanged = false; this.DcEditor.Focus(); return 0; ERROR1: MessageBox.Show(this, strError); return -1; }
// 装载XML记录 public int LoadRecord(ISearchForm searchform, int index, bool bForceFullElementSet = false) { string strError = ""; string strMARC = ""; this.LinkedSearchForm = searchform; this.SavePath = ""; DigitalPlatform.Z3950.Record record = null; Encoding currentEncoding = null; this.CurrentRecord = null; byte[] baTimestamp = null; string strSavePath = ""; string strOutStyle = ""; LoginInfo logininfo = null; long lVersion = 0; string strXmlFragment = ""; string strParameters = "hilight_browse_line"; if (bForceFullElementSet == true) { strParameters += ",force_full"; } int nRet = searchform.GetOneRecord( "xml", index, // 即将废止 "index:" + index.ToString(), strParameters, // true, out strSavePath, out strMARC, out strXmlFragment, out strOutStyle, out baTimestamp, out lVersion, out record, out currentEncoding, out logininfo, out strError); if (nRet == -1) { goto ERROR1; } this.LoginInfo = logininfo; this.CurrentTimestamp = baTimestamp; this.SavePath = strSavePath; this.CurrentEncoding = currentEncoding; // 替换单个0x0a strMARC = strMARC.Replace("\r", ""); strMARC = strMARC.Replace("\n", "\r\n"); // 装入XML编辑器 // this.textBox_xml.Text = strMARC; this.PlainText = strMARC; // 能自动缩进 this.textBox_xml.Select(0, 0); // 装入XML只读Web控件 { string strTempFileName = MainForm.DataDir + "\\xml.xml"; // SUTRS if (record.m_strSyntaxOID == "1.2.840.10003.5.101") { strTempFileName = MainForm.DataDir + "\\xml.txt"; } using (Stream stream = File.Create(strTempFileName)) { // 写入xml内容 byte[] buffer = Encoding.UTF8.GetBytes(strMARC); stream.Write(buffer, 0, buffer.Length); } this.webBrowser_xml.Navigate(strTempFileName); } this.CurrentRecord = record; if (this.CurrentRecord != null && this.DisplayOriginPage == true) { // 装入二进制编辑器 this.binaryEditor_originData.SetData( this.CurrentRecord.m_baRecord); // 装入原始文本 nRet = this.SetOriginText(this.CurrentRecord.m_baRecord, this.CurrentEncoding, out strError); if (nRet == -1) { this.textBox_originData.Text = strError; } // 数据库名 this.textBox_originDatabaseName.Text = this.CurrentRecord.m_strDBName; // record syntax OID this.textBox_originMarcSyntaxOID.Text = this.CurrentRecord.m_strSyntaxOID; } // 构造路径 string strPath = searchform.CurrentProtocol + ":" + searchform.CurrentResultsetPath + "/" + (index + 1).ToString(); this.textBox_tempRecPath.Text = strPath; this.textBox_xml.Focus(); return(0); ERROR1: MessageBox.Show(this, strError); return(-1); }