// 处理一条记录 int DoOneRecord( long lPeriodValue, string strPeriodUnit, string strPath, string strRecXml, byte[] baTimeStamp, out string strError) { strError = ""; long lRet = 0; int nRet = 0; XmlDocument dom = new XmlDocument(); try { dom.LoadXml(strRecXml); } catch (Exception ex) { strError = "装载XML到DOM出错: " + ex.Message; return(-1); } string strDate = DomUtil.GetElementText(dom.DocumentElement, "date"); bool bDelete = false; // DateTime date; try { date = DateTimeUtil.FromRfc1123DateTimeString(strDate); } catch { strError = "记录 " + strPath + " 消息日期值 '" + strDate + "' 格式错误"; this.App.WriteErrorLog(strError); // 注意仍然要删除 bDelete = true; goto DO_DELETE; } // 正规化时间date nRet = LibraryApplication.RoundTime(strPeriodUnit, ref date, out strError); if (nRet == -1) { strError = "正规化date时间 " + date.ToString() + " (时间单位: " + strPeriodUnit + ") 时出错: " + strError; return(-1); } DateTime now = this.App.Clock.UtcNow; // DateTime.UtcNow; // 正规化时间now nRet = LibraryApplication.RoundTime(strPeriodUnit, ref now, out strError); if (nRet == -1) { strError = "正规化now时间 " + now.ToString() + " (时间单位: " + strPeriodUnit + ") 时出错: " + strError; return(-1); } TimeSpan delta = now - date; long lDelta = 0; nRet = LibraryApplication.ParseTimeSpan( delta, strPeriodUnit, out lDelta, out strError); if (nRet == -1) { return(-1); } if (lDelta >= lPeriodValue) { bDelete = true; } DO_DELETE: if (bDelete == true) { RmsChannel channel = this.RmsChannels.GetChannel(this.App.WsUrl); byte[] output_timestamp = null; lRet = channel.DoDeleteRes( strPath, baTimeStamp, out output_timestamp, out strError); if (lRet == -1) { // 可以这次不删除,以后还有机会 strError = "删除记录 " + strPath + "时出错: " + strError; return(-1); } // 这个指标没有按分馆来计算 if (this.App.Statis != null) { this.App.Statis.IncreaseEntryValue( "", "消息监控", "删除过期消息条数", 1); } } return(0); }
// 判断是否超过保留期限 // return: // -1 error // 0 没有超过 // 1 已经超过 int CheckeOutOfReservation( Calendar calendar, XmlDocument queue_rec_dom, out string strError) { strError = ""; string strState = DomUtil.GetElementText(queue_rec_dom.DocumentElement, "state"); // 对通知完成后的记录, 循环中不必处理 if (StringUtil.IsInList("outof", strState) == true) return 0; string strNotifyDate = DomUtil.GetElementText(queue_rec_dom.DocumentElement, "notifyDate"); /* string strItemBarcode = DomUtil.GetElementText(queue_rec_dom.DocumentElement, "itemBarcode"); string strReaderBarcode = DomUtil.GetElementText(queue_rec_dom.DocumentElement, "readerBarcode"); * */ // 解析期限值 string strPeriodUnit = ""; long lPeriodValue = 0; int nRet = LibraryApplication.ParsePeriodUnit( this.App.ArrivedReserveTimeSpan, out lPeriodValue, out strPeriodUnit, out strError); if (nRet == -1) { strError = "预约保留期限 值 '" + this.App.ArrivedReserveTimeSpan + "' 格式错误: " + strError; return -1; } // DateTime notifydate; try { notifydate = DateTimeUtil.FromRfc1123DateTimeString(strNotifyDate); } catch { strError = "通知日期值 '" + strNotifyDate + "' 格式错误"; return -1; } DateTime timeEnd = DateTime.MinValue; nRet = LibraryApplication.GetOverTime( calendar, notifydate, lPeriodValue, strPeriodUnit, out timeEnd, out strError); if (nRet == -1) { strError = "计算保留期过程发生错误: " + strError; return -1; } DateTime now = this.App.Clock.UtcNow; // DateTime.UtcNow; // 正规化时间 nRet = DateTimeUtil.RoundTime(strPeriodUnit, ref now, out strError); if (nRet == -1) return -1; TimeSpan delta = now - timeEnd; long lDelta = 0; nRet = LibraryApplication.ParseTimeSpan( delta, strPeriodUnit, out lDelta, out strError); if (nRet == -1) return -1; if (lDelta > 0) return 1; return 0; }