// 处理一小批指纹数据的装入 // parameters: static void GetSomeFingerprintData( LibraryChannel channel, List <string> lines, CancellationToken token, out List <DigitalPlatform.LibraryClient.localhost.Record> records) { // strError = ""; records = new List <DigitalPlatform.LibraryClient.localhost.Record>(); for (; ;) { token.ThrowIfCancellationRequested(); DigitalPlatform.LibraryClient.localhost.Record[] searchresults = null; string[] paths = new string[lines.Count]; lines.CopyTo(paths); REDO_GETRECORDS: long lRet = channel.GetBrowseRecords( null, paths, "id,cols,format:cfgs/browse_fingerprint", out searchresults, out string strError); if (lRet == -1) { #if NO DialogResult temp_result = MessageBox.Show(this, strError + "\r\n\r\n是否重试?", "ReaderSearchForm", MessageBoxButtons.RetryCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); if (temp_result == DialogResult.Retry) { goto REDO_GETRECORDS; } return(-1); #endif if (Prompt != null) { MessagePromptEventArgs e = new MessagePromptEventArgs { // e.MessageText = "获得书目记录 '"+strCommand+"' ("+StringUtil.MakePathList(format_list)+") 时发生错误: " + strError; MessageText = strError + "\r\n\r\n是否重试?", Actions = "yes,no,cancel" }; Prompt(channel, e); if (e.ResultAction == "cancel") { throw new ChannelException(channel.ErrorCode, strError); } else if (e.ResultAction == "yes") { goto REDO_GETRECORDS; } else { // no 也是抛出异常。因为继续下一批代价太大 throw new ChannelException(channel.ErrorCode, strError); } } else { throw new ChannelException(channel.ErrorCode, strError); } } records.AddRange(searchresults); // 去掉已经做过的一部分 lines.RemoveRange(0, searchresults.Length); if (lines.Count == 0) { break; } } }
int GetBrowseCols(List <string> pathlist, List <ListViewItem> itemlist, out string strError) { strError = ""; EnableControls(false); LibraryChannel channel = this.GetChannel(); stop.OnStop += new StopEventHandler(this.DoStop); stop.Initial("正在填充浏览列 ..."); stop.BeginLoop(); this.Update(); Program.MainForm.Update(); try { int nStart = 0; int nCount = 0; for (; ;) { nCount = pathlist.Count - nStart; if (nCount > 100) { nCount = 100; } if (nCount <= 0) { break; } Application.DoEvents(); // 出让界面控制权 if (stop != null && stop.State != 0) { strError = "用户中断"; return(-1); } stop.SetMessage("正在装入浏览信息 " + (nStart + 1).ToString() + " - " + (nStart + nCount).ToString()); string[] paths = new string[nCount]; pathlist.CopyTo(nStart, paths, 0, nCount); Record[] searchresults = null; long lRet = channel.GetBrowseRecords( this.stop, paths, "id,cols", out searchresults, out strError); if (lRet == -1) { return(-1); } if (searchresults == null || searchresults.Length == 0) { strError = "searchresults == null || searchresults.Length == 0"; return(-1); } for (int i = 0; i < searchresults.Length; i++) { Record record = searchresults[i]; ListViewUtil.EnsureColumns(this.listView_browse, 2 + (record.Cols == null ? 0 : record.Cols.Length), 200); ListViewItem item = itemlist[nStart + i]; item.Text = record.Path; if (record.Cols != null) { for (int j = 0; j < record.Cols.Length; j++) { item.SubItems.Add(record.Cols[j]); } } } nStart += searchresults.Length; } } finally { stop.EndLoop(); stop.OnStop -= new StopEventHandler(this.DoStop); stop.Initial(""); this.ReturnChannel(channel); EnableControls(true); } return(0); }
public IEnumerator GetEnumerator() { // 首先按照服务器名的不同,划分为若干个区段 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[] paths = new string[batch.Count]; batch.CopyTo(paths); DigitalPlatform.LibraryClient.localhost.Record[] searchresults = null; string strError = ""; long lRet = channel.GetBrowseRecords( this.Stop, paths, "id,cols", out searchresults, out strError); if (lRet == -1) { throw new Exception(strError); } if (searchresults == null) { strError = "searchresults == null"; throw new Exception(strError); } for (int i = 0; i < searchresults.Length; i++) { DigitalPlatform.LibraryClient.localhost.Record record = searchresults[i]; Debug.Assert(batch[i] == record.Path, ""); // 包含服务器名 record.Path = record.Path + "@" + temp.ServerName; yield return(record); } CONTINUE: if (batch.Count > searchresults.Length) { // 有本次没有获取到的记录 batch.RemoveRange(0, searchresults.Length); /* * if (index == m_recpaths.Count - 1) * goto REDO; // 当前已经是最后一轮了,需要继续做完 * */ // 否则可以留给下一轮处理 } else { batch.Clear(); } } } // } finally { Program.MainForm.ReturnChannel(channel); } } }
/* Control FindControl(string strID) { foreach (Control control in this.Controls) { if (control.ID == strID) return control; } return null; } */ int FillBrowseCols(LibraryChannel channel, ref ArrayList aLine, out string strError) { strError = ""; string[] paths = new string[aLine.Count]; for (int i = 0; i < aLine.Count; i++) { paths[i] = ((string[])aLine[i])[0]; } // TODO: 一次调用的数目不一定能满足 Record[] search_results = null; long lRet = channel.GetBrowseRecords( null, paths, "id,cols", // strStyle, out search_results, out strError); if (lRet == -1) return -1; ArrayList results = new ArrayList(); for (int i = 0; i < search_results.Length; i++) { Record record = search_results[i]; string[] cols = new string[record.Cols.Length + 1]; cols[0] = record.Path; Array.Copy(record.Cols, 0, cols, 1, record.Cols.Length); results.Add(cols); } aLine = results; return 0; }
// 调用前,记录路径列已经有值 /// <summary> /// 刷新一个浏览行。调用前,记录路径列已经有值 /// </summary> /// <param name="channel">通讯通道</param> /// <param name="item">浏览行 ListViewItem 对象</param> /// <param name="strError">返回出错信息</param> /// <returns>-1: 出错; 0: 成功</returns> public int RefreshBrowseLine( LibraryChannel channel, ListViewItem item, out string strError) { strError = ""; string strRecPath = ListViewUtil.GetItemText(item, 0); string[] paths = new string[1]; paths[0] = strRecPath; DigitalPlatform.LibraryClient.localhost.Record[] searchresults = null; long lRet = channel.GetBrowseRecords( this.stop, paths, "id,cols", out searchresults, out strError); if (lRet == -1) return -1; if (searchresults == null || searchresults.Length == 0) { strError = "searchresults == null || searchresults.Length == 0"; return -1; } for (int i = 0; i < searchresults[0].Cols.Length; i++) { ListViewUtil.ChangeItemText(item, i + 1, searchresults[0].Cols[i]); } return 0; }