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 & dp2Circulation.GetBiblioInfoStyle.Timestamp) != 0) if (this.GetBiblioInfoStyle.HasFlag(GetBiblioInfoStyle.Timestamp) == true) // 新用法 { nTimestampIndex = format_list.Count; format_list.Add("timestamp"); } if ((this.GetBiblioInfoStyle & GetBiblioInfoStyle.Metadata) != 0) { nMetadataIndex = format_list.Count; format_list.Add("metadata"); } string[] formats = new string[format_list.Count]; format_list.CopyTo(formats); List <string> batch = new List <string>(); for (int index = 0; index < m_recpaths.Count; index++) { string s = m_recpaths[index]; batch.Add(s); // 每100个一批,或者最后一次 if (batch.Count >= 100 || (index == m_recpaths.Count - 1 && batch.Count > 0)) { REDO: string strCommand = "@path-list:" + StringUtil.MakePathList(batch); string[] results = null; byte[] timestamp = null; string strError = ""; // Channel.Timeout = new TimeSpan(0, 0, 5); 应该让调主设置这个值 long lRet = Channel.GetBiblioInfos( this.Stop, strCommand, "", formats, out results, out timestamp, out strError); if (lRet == -1) { if (this.Prompt != null) { MessagePromptEventArgs e = new MessagePromptEventArgs(); // e.MessageText = "获得书目记录 '"+strCommand+"' ("+StringUtil.MakePathList(format_list)+") 时发生错误: " + strError; e.MessageText = "获得书目记录时发生错误: " + strError + "\r\ncommand='" + strCommand + "' (" + StringUtil.MakePathList(format_list) + ")"; e.Actions = "yes,no,cancel"; this.Prompt(this, e); if (e.ResultAction == "cancel") { throw new ChannelException(Channel.ErrorCode, strError); } else if (e.ResultAction == "yes") { goto REDO; } else { // no 也是抛出异常。因为继续下一批代价太大 throw new ChannelException(Channel.ErrorCode, strError); } } else { throw new ChannelException(Channel.ErrorCode, strError); } } if (lRet == 0) { if (lRet == 0 && String.IsNullOrEmpty(strError) == true) { foreach (string path in batch) { BiblioItem item = new BiblioItem(); item.RecPath = path; item.ErrorCode = ErrorCode.NotFound; item.ErrorInfo = "书目记录 '" + path + "' 不存在"; yield return(item); } goto CONTINUE; } // 如果results.Length表现正常,其实还可以继续处理 if (results != null && results.Length > 0) { } else { // 2014/1/15 if (Channel.ErrorCode == ErrorCode.NotFound) { foreach (string path in batch) { BiblioItem item = new BiblioItem(); item.RecPath = path; item.ErrorCode = ErrorCode.NotFound; item.ErrorInfo = "书目记录 '" + path + "' 不存在"; yield return(item); } goto CONTINUE; } 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]; 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(); } } } }
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 & dp2Circulation.GetBiblioInfoStyle.Timestamp) != 0) if (this.GetBiblioInfoStyle.HasFlag(GetBiblioInfoStyle.Timestamp) == true) // 新用法 { nTimestampIndex = format_list.Count; format_list.Add("timestamp"); } if ((this.GetBiblioInfoStyle & GetBiblioInfoStyle.Metadata) != 0) { nMetadataIndex = format_list.Count; format_list.Add("metadata"); } string[] formats = new string[format_list.Count]; format_list.CopyTo(formats); List<string> batch = new List<string>(); for (int index = 0; index < m_recpaths.Count; index++) { string s = m_recpaths[index]; batch.Add(s); // 每100个一批,或者最后一次 if (batch.Count >= 100 || (index == m_recpaths.Count - 1 && batch.Count > 0)) { REDO: string strCommand = "@path-list:" + StringUtil.MakePathList(batch); string[] results = null; byte[] timestamp = null; string strError = ""; // Channel.Timeout = new TimeSpan(0, 0, 5); 应该让调主设置这个值 long lRet = Channel.GetBiblioInfos( this.Stop, strCommand, "", formats, out results, out timestamp, out strError); if (lRet == -1) { if (this.Prompt != null) { MessagePromptEventArgs e = new MessagePromptEventArgs(); e.MessageText = "获得书目记录 '"+strCommand+"' ("+StringUtil.MakePathList(format_list)+") 时发生错误: " + strError; e.Actions = "yes,no,cancel"; this.Prompt(this, e); if (e.ResultAction == "cancel") throw new ChannelException(Channel.ErrorCode, strError); else if (e.ResultAction == "yes") goto REDO; else { // no 也是抛出异常。因为继续下一批代价太大 throw new ChannelException(Channel.ErrorCode, strError); } } else throw new ChannelException(Channel.ErrorCode, strError); } if (lRet == 0) { if (lRet == 0 && String.IsNullOrEmpty(strError) == true) { foreach (string path in batch) { BiblioItem item = new BiblioItem(); item.RecPath = path; item.ErrorCode = ErrorCode.NotFound; item.ErrorInfo = "书目记录 '" + path + "' 不存在"; yield return item; } goto CONTINUE; } // 如果results.Length表现正常,其实还可以继续处理 if (results != null && results.Length > 0) { } else { // 2014/1/15 if (Channel.ErrorCode == ErrorCode.NotFound) { foreach (string path in batch) { BiblioItem item = new BiblioItem(); item.RecPath = path; item.ErrorCode = ErrorCode.NotFound; item.ErrorInfo = "书目记录 '" + path + "' 不存在"; yield return item; } goto CONTINUE; } 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]; 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(); } } }