// 对每个日志文件,每个日志记录进行循环 // return: // 0 普通返回 // 1 要全部中断 int DoLoop( OperLogForm.Delegate_doRecord procDoRecord, out string strError) { strError = ""; int nRet = 0; // long lRet = 0; List <string> LogFileNames = null; // TODO: 是否需要检查起止日期是否为空值?空值是警告还是就当作今天? string strStartDate = DateTimeUtil.DateTimeToString8(this.dateControl_start.Value); string strEndDate = DateTimeUtil.DateTimeToString8(this.dateControl_end.Value); string strWarning = ""; // 根据日期范围,发生日志文件名 // parameters: // strStartDate 起始日期。8字符 // strEndDate 结束日期。8字符 // return: // -1 错误 // 0 成功 nRet = OperLogLoader.MakeLogFileNames(strStartDate, strEndDate, true, out LogFileNames, out strWarning, out strError); if (nRet == -1) { return(-1); } if (String.IsNullOrEmpty(strWarning) == false) { MessageBox.Show(this, strWarning); } string strStyle = ""; if (Program.MainForm.AutoCacheOperlogFile == true) { strStyle = "autocache"; } ProgressEstimate estimate = new ProgressEstimate(); nRet = OperLogForm.ProcessFiles(this, stop, estimate, Channel, LogFileNames, Program.MainForm.OperLogLevel, strStyle, "", // strFilter Program.MainForm.OperLogCacheDir, null, // param, procDoRecord, // DoRecord, out strError); if (nRet == -1) { return(-1); } return(nRet); }
// 对每个日志文件,每个日志记录进行循环 // return: // -1 出错 // 0 普通返回 // 1 要全部中断 int DoLoop( OperLogForm.Delegate_doRecord procDoRecord, out string strError) { strError = ""; int nRet = 0; // long lRet = 0; List <string> LogFileNames = null; // TODO: 是否需要检查起止日期是否为空值?空值是警告还是就当作今天? string strStartDate = DateTimeUtil.DateTimeToString8(this.dateControl_start.Value); string strEndDate = DateTimeUtil.DateTimeToString8(this.dateControl_end.Value); // 根据日期范围,发生日志文件名 // parameters: // strStartDate 起始日期。8字符 // strEndDate 结束日期。8字符 // return: // -1 错误 // 0 成功 nRet = OperLogLoader.MakeLogFileNames(strStartDate, strEndDate, true, out LogFileNames, out string strWarning, out strError); if (nRet == -1) { return(-1); } if (String.IsNullOrEmpty(strWarning) == false) { MessageBox.Show(this, strWarning); } string strStyle = ""; if (Program.MainForm.AutoCacheOperlogFile == true) { strStyle = "autocache"; } ProgressEstimate estimate = new ProgressEstimate(); LibraryChannel channel = this.GetChannel(); TimeSpan old_timeout = channel.Timeout; channel.Timeout = TimeSpan.FromSeconds(10); try { #if NO nRet = OperLogForm.ProcessFiles(this, stop, estimate, channel, LogFileNames, Program.MainForm.OperLogLevel, strStyle, "", // strFilter Program.MainForm.OperLogCacheDir, null, // param, procDoRecord, // DoRecord, out strError); if (nRet == -1) { return(-1); } return(nRet); #endif bool bAccessLog = StringUtil.IsInList("accessLog", strStyle); OperLogLoader loader = new OperLogLoader(); loader.Channel = channel; loader.Stop = this.Progress; loader.Estimate = estimate; loader.Dates = LogFileNames; loader.Level = Program.MainForm.OperLogLevel; loader.AutoCache = StringUtil.IsInList("autocache", strStyle); // false; loader.CacheDir = Program.MainForm.OperLogCacheDir; loader.LogType = bAccessLog ? LogType.AccessLog : LogType.OperLog; // loader.Filter = "borrow,return"; loader.Prompt -= new MessagePromptEventHandler(loader_Prompt); loader.Prompt += new MessagePromptEventHandler(loader_Prompt); foreach (OperLogItem item in loader) { if (stop != null && stop.State != 0) { strError = "用户中断"; return(1); } if (stop != null) { stop.SetMessage("正在获取 " + item.Date + " " + item.Index.ToString() + " " + estimate.Text + "..."); } if (string.IsNullOrEmpty(item.Xml) == true) { continue; } nRet = procDoRecord(item.Date + ".log", item.Xml, false, // bInCacheFile, 0, item.Index, item.AttachmentLength, null, out strError); if (nRet == -1) { return(-1); } } return(0); } catch (InterruptException ex) { strError = ex.Message; return(1); } finally { channel.Timeout = old_timeout; this.ReturnChannel(channel); } }