void SearchLine(RegisterLine line) { string strError = ""; int nRet = 0; if (this.ServersDom == null) { strError = "ServersDom 为空"; goto ERROR1; } string strTotalError = ""; this.Progress.OnStop += new StopEventHandler(this.DoStop); // this.Progress.Initial("进行一轮任务处理..."); this.Progress.BeginLoop(); try { int nHitCount = 0; line.SetBiblioSearchState("searching"); line.BiblioSummary = "正在检索 " + line.BiblioBarcode + " ..."; XmlNodeList servers = this.ServersDom.DocumentElement.SelectNodes("server"); foreach (XmlElement server in servers) { AccountInfo account = EntityRegisterBase.GetAccountInfo(server); Debug.Assert(account != null, ""); _base.CurrentAccount = account; #if NO string strName = server.GetAttribute("name"); string strType = server.GetAttribute("type"); string strUrl = server.GetAttribute("url"); string strUserName = server.GetAttribute("userName"); string strPassword = server.GetAttribute("password"); // e.Password = this.MainForm.DecryptPasssword(e.Password); string strIsReader = server.GetAttribute("isReader"); #endif if (account.ServerType == "dp2library") { nRet = SearchLineDp2library(line, account, out strError); if (nRet == -1) strTotalError += strError + "\r\n"; else nHitCount += nRet; } else if (account.ServerType == "amazon") { nRet = SearchLineAmazon(line, account, out strError); if (nRet == -1) strTotalError += strError + "\r\n"; else nHitCount += nRet; } } line.SetBiblioSearchState(nHitCount.ToString()); // if (nHitCount == 1) { // TODO: 如果有报错的行,是否就不要自动模拟双击了? 假如这种情况是因为红泥巴服务器持续无法访问引起的,需要有配置办法可以临时禁用这个数据源 // 模拟双击 int index = line._biblioRegister.GetFirstRecordIndex(); if (index == -1) { strError = "获得第一个浏览记录 index 时出错"; goto ERROR1; } nRet = line._biblioRegister.SelectBiblio(index, out strError); if (nRet == -1) goto ERROR1; } else { if (nHitCount > 1) line.SetDisplayMode("select"); else { // 进入详细状态,可以新创建一条记录 line.AddBiblioBrowseLine(BiblioRegisterControl.TYPE_INFO, "没有命中书目记录。双击本行新创建书目记录", "", BuildBlankBiblioInfo(line.BiblioBarcode)); line.SetDisplayMode("select"); } } } finally { this.Progress.EndLoop(); this.Progress.OnStop -= new StopEventHandler(this.DoStop); // this.Progress.Initial(""); } if (string.IsNullOrEmpty(strTotalError) == false) { // DisplayFloatErrorText(strTotalError); line._biblioRegister.BarColor = "R"; // 红色,需引起注意 this.SetColorList(); } else { line._biblioRegister.BarColor = "Y"; // 黄色表示等待选择? this.SetColorList(); } return; ERROR1: line.SetDisplayMode("summary"); line.SetBiblioSearchState("error"); line.BiblioSummary = strError; DisplayFloatErrorText(strError); line._biblioRegister.BarColor = "R"; // 红色,需引起注意 this.SetColorList(); }
// 针对 dp2library 服务器进行检索 // parameters: // // return: // -1 出错 // >=0 命中的记录数 int SearchLineDp2library(RegisterLine line, AccountInfo account, out string strError) { strError = ""; int nRet = 0; // ??? _currentAccount = account; _channel = _base.GetChannel(account.ServerUrl, account.UserName); _channel.Timeout = new TimeSpan(0, 0, 5); // 超时值为 5 秒 try { string strQueryWord = line.BiblioBarcode; string strFromStyle = ""; try { strFromStyle = this.MainForm.GetBiblioFromStyle("ISBN"); } catch (Exception ex) { strError = ex.Message; goto ERROR1; } if (String.IsNullOrEmpty(strFromStyle) == true) { strError = "GetFromStyle()没有找到 '" + "ISBN" + "' 对应的style字符串"; goto ERROR1; } string strMatchStyle = "left"; // BiblioSearchForm.GetCurrentMatchStyle(this.comboBox_matchStyle.Text); if (string.IsNullOrEmpty(strQueryWord) == true) { if (strMatchStyle == "null") { strQueryWord = ""; // 专门检索空值 strMatchStyle = "exact"; } else { // 为了在检索词为空的时候,检索出全部的记录 strMatchStyle = "left"; } } else { if (strMatchStyle == "null") { strError = "检索空值的时候,请保持检索词为空"; goto ERROR1; } } ServerInfo server_info = null; if (line != null) line.BiblioSummary = "正在获取服务器 " + account.ServerName + " 的配置信息 ..."; // 准备服务器信息 nRet = _base.GetServerInfo( // line, _channel, account, out server_info, out strError); if (nRet == -1) goto ERROR1; // 可以不报错 ? line.BiblioSummary = "正在针对 "+account.ServerName+ " \r\n检索 " + line.BiblioBarcode + " ..."; string strQueryXml = ""; long lRet = _channel.SearchBiblio(Progress, server_info == null ? "<全部>" : server_info.GetBiblioDbNames(), // "<全部>", strQueryWord, // this.textBox_queryWord.Text, 1000, strFromStyle, strMatchStyle, _base.Lang, null, // strResultSetName "", // strSearchStyle "", // strOutputStyle out strQueryXml, out strError); if (lRet == -1) { strError = "针对服务器 '"+account.ServerName+"' 检索出错: " + strError; goto ERROR1; } // 装入浏览格式 long lHitCount = lRet; long lStart = 0; long lCount = lHitCount; DigitalPlatform.CirculationClient.localhost.Record[] searchresults = null; string strStyle = "id"; List<string> biblio_recpaths = new List<string>(); // 装入浏览格式 for (; ; ) { if (this.Progress != null && this.Progress.State != 0) { break; } // DoTasks(); lRet = _channel.GetSearchResult( this.Progress, null, // strResultSetName lStart, lCount, strStyle, // bOutputKeyCount == true ? "keycount" : "id,cols", _base.Lang, out searchresults, out strError); if (lRet == -1) { strError = "检索共命中 " + lHitCount.ToString() + " 条,已装入 " + lStart.ToString() + " 条," + strError; goto ERROR1; } if (lRet == 0) break; // 处理浏览结果 foreach (DigitalPlatform.CirculationClient.localhost.Record searchresult in searchresults) { biblio_recpaths.Add(searchresult.Path); } { // 获得书目摘要 BiblioLoader loader = new BiblioLoader(); loader.Channel = _channel; loader.Stop = this.Progress; loader.Format = "xml"; loader.GetBiblioInfoStyle = GetBiblioInfoStyle.Timestamp; loader.RecPaths = biblio_recpaths; try { int i = 0; foreach (BiblioItem item in loader) { string strXml = item.Content; string strMARC = ""; string strMarcSyntax = ""; // 将XML格式转换为MARC格式 // 自动从数据记录中获得MARC语法 nRet = MarcUtil.Xml2Marc(strXml, // info.OldXml, true, null, out strMarcSyntax, out strMARC, out strError); if (nRet == -1) { strError = "XML转换到MARC记录时出错: " + strError; goto ERROR1; } string strBrowseText = ""; nRet = BuildMarcBrowseText( strMarcSyntax, strMARC, out strBrowseText, out strError); if (nRet == -1) { strError = "MARC记录转换到浏览格式时出错: " + strError; goto ERROR1; } RegisterBiblioInfo info = new RegisterBiblioInfo(); info.OldXml = strMARC; info.Timestamp = item.Timestamp; info.RecPath = item.RecPath + "@" + account.ServerName; info.MarcSyntax = strMarcSyntax; line.AddBiblioBrowseLine( -1, info.RecPath, strBrowseText, info); i++; } } catch (Exception ex) { strError = ex.Message; goto ERROR1; } // lIndex += biblio_recpaths.Count; biblio_recpaths.Clear(); } lStart += searchresults.Length; lCount -= searchresults.Length; if (lStart >= lHitCount || lCount <= 0) break; } return (int)lHitCount; } finally { _base.ReturnChannel(_channel); _channel = null; } ERROR1: #if NO line.SetDisplayMode("summary"); line.SetBiblioSearchState("error"); line.BiblioSummary = strError; #endif line.AddBiblioBrowseLine(strError, BiblioRegisterControl.TYPE_ERROR); return -1; }
// 保存书目记录和下属的册记录 void SaveLine(RegisterLine line) { string strError = ""; int nRet = 0; this.Progress.OnStop += new StopEventHandler(this.DoStop); // this.Progress.Initial("进行一轮任务处理..."); this.Progress.BeginLoop(); try { string strCancelSaveBiblio = ""; AccountInfo _currentAccount = _base.GetAccountInfo(line._biblioRegister.ServerName); if (_currentAccount == null) { strError = "服务器名 '" + line._biblioRegister.ServerName + "' 没有配置"; goto ERROR1; } // line.SetBiblioSearchState("searching"); if (line._biblioRegister.BiblioChanged == true || Global.IsAppendRecPath(line._biblioRegister.BiblioRecPath) == true || _currentAccount.IsLocalServer == false) { // TODO: 确定目标 dp2library 服务器 目标书目库 string strServerName = ""; string strBiblioRecPath = ""; // 根据书目记录的路径,匹配适当的目标 // return: // -1 出错 // 0 没有找到 // 1 找到 nRet = GetTargetInfo(line, _currentAccount.IsLocalServer == false? true : false, out strServerName, out strBiblioRecPath); #if NO if (nRet != 1) { strError = "line (servername='" + line._biblioRegister.ServerName + "' bibliorecpath='" + line._biblioRegister.BiblioRecPath + "') 没有找到匹配的保存目标"; goto ERROR1; } #endif if (nRet == -1) goto ERROR1; if (nRet == 0) { strError = "来自服务器 '" + line._biblioRegister.ServerName + "' 的书目记录 '" + line._biblioRegister.BiblioRecPath + "' 没有找到匹配的保存目标"; bool bAppend = Global.IsAppendRecPath(line._biblioRegister.BiblioRecPath); if (bAppend == true || _currentAccount.IsLocalServer == false) goto ERROR1; // 虽然书目记录无法保存,但继续寻求保存册记录 strCancelSaveBiblio = strError; goto SAVE_ENTITIES; } // if nRet == 0 并且 书目记录路径不是追加型的 // 虽然无法兑现修改后保存,但是否可以依然保存实体记录? string strXml = ""; nRet = GetBiblioXml( line, out strXml, out strError); if (nRet == -1) goto ERROR1; string strWarning = ""; string strOutputPath = ""; byte[] baNewTimestamp = null; nRet = SaveXmlBiblioRecordToDatabase( strServerName, strBiblioRecPath, strXml, line._biblioRegister.Timestamp, out strOutputPath, out baNewTimestamp, out strWarning, out strError); if (nRet == -1) goto ERROR1; line._biblioRegister.ServerName = strServerName; line._biblioRegister.BiblioRecPath = strOutputPath; line._biblioRegister.Timestamp = baNewTimestamp; line._biblioRegister.BiblioChanged = false; } // line.SetDisplayMode("summary"); SAVE_ENTITIES: // 保存下属的册记录 { EntityInfo[] entities = null; // 构造用于保存的实体信息数组 nRet = line._biblioRegister.BuildSaveEntities( "change", null, out entities, out strError); if (nRet == -1) goto ERROR1; if (entities.Length > 0) { // 分批进行保存 // return: // -2 部分成功,部分失败 // -1 出错 // 0 保存成功,没有错误和警告 nRet = SaveEntities( line, entities, out strError); if (nRet == -1 || nRet == -2) goto ERROR1; line._biblioRegister.EntitiesChanged = false; } else { line._biblioRegister.EntitiesChanged = false; line._biblioRegister.BarColor = "G"; // 绿色 return; } } line.SetDisplayMode("summary"); if (string.IsNullOrEmpty(strCancelSaveBiblio) == false) { line.BiblioSummary = "书目记录无法保存,但册记录保存成功\r\n(" + strCancelSaveBiblio + ")"; line._biblioRegister.BarColor = "R"; // 表示操作未完全完成 } else { line.BiblioSummary = "保存成功"; line._biblioRegister.BarColor = "G"; // 绿色 } this.SetColorList(); return; } finally { this.Progress.EndLoop(); this.Progress.OnStop -= new StopEventHandler(this.DoStop); // this.Progress.Initial(""); } ERROR1: line.SetDisplayMode("summary"); line.SetBiblioSearchState("error"); line.BiblioSummary = strError; line._biblioRegister.BarColor = "R"; // 红色 this.SetColorList(); }