static string GetXml(AccessLogItem item) { XmlDocument domOperLog = new XmlDocument(); domOperLog.LoadXml("<root />"); if (string.IsNullOrEmpty(item.LibraryCode) == false) { DomUtil.SetElementText(domOperLog.DocumentElement, "libraryCode", item.LibraryCode); } DomUtil.SetElementText(domOperLog.DocumentElement, "operation", "getRes"); DomUtil.SetElementText(domOperLog.DocumentElement, "path", item.Path); if (item.Size != 0) { DomUtil.SetElementText(domOperLog.DocumentElement, "size", item.Size.ToString()); } if (string.IsNullOrEmpty(item.MIME) == false) { DomUtil.SetElementText(domOperLog.DocumentElement, "mime", item.MIME); } if (string.IsNullOrEmpty(item.ClientAddress) == false) { OperLog.WriteClientAddress(domOperLog, item.ClientAddress); } if (item.HitCount != 1) { DomUtil.SetElementText(domOperLog.DocumentElement, "hitCount", item.HitCount.ToString()); } DomUtil.SetElementText(domOperLog.DocumentElement, "operator", item.Operator); DomUtil.SetElementText(domOperLog.DocumentElement, "operTime", DateTimeUtil.Rfc1123DateTimeStringEx(item.OperTime.ToLocalTime())); return(domOperLog.OuterXml); }
public bool Add(string operation, string path, long size, string mime, string clientAddress, long initial_hitcount, string operator_param, DateTime opertime, long maxItemCount) { AccessLogItem item = new AccessLogItem(); item.Operation = operation; item.Path = path; item.Size = size; item.MIME = mime; item.ClientAddress = clientAddress; item.HitCount = initial_hitcount; item.Operator = operator_param; item.OperTime = opertime; return(Add(item, maxItemCount)); }
// parameters: // maxItemCount 最大事项数。如果为 -1 表示不限制 public bool Add(AccessLogItem item, long maxItemCount) { MongoCollection <AccessLogItem> collection = this.LogCollection; if (collection == null) { return(false); } // 限制最大事项数 { string date = GetToday(); long newValue = _itemCount.GetValue(date, 1); if (maxItemCount != -1 && newValue > maxItemCount) { _itemCount.GetValue(date, -1); return(false); } } collection.Insert(item); return(true); }
static string GetXml(AccessLogItem item) { XmlDocument domOperLog = new XmlDocument(); domOperLog.LoadXml("<root />"); if (string.IsNullOrEmpty(item.LibraryCode) == false) { DomUtil.SetElementText(domOperLog.DocumentElement, "libraryCode", item.LibraryCode); } DomUtil.SetElementText(domOperLog.DocumentElement, "operation", "getRes"); DomUtil.SetElementText(domOperLog.DocumentElement, "path", item.Path); if (item.Size != 0) { DomUtil.SetElementText(domOperLog.DocumentElement, "size", item.Size.ToString()); } if (string.IsNullOrEmpty(item.MIME) == false) { DomUtil.SetElementText(domOperLog.DocumentElement, "mime", item.MIME); } if (string.IsNullOrEmpty(item.ClientAddress) == false) { OperLog.WriteClientAddress(domOperLog, item.ClientAddress); } if (item.HitCount != 1) { DomUtil.SetElementText(domOperLog.DocumentElement, "hitCount", item.HitCount.ToString()); } DomUtil.SetElementText(domOperLog.DocumentElement, "operator", item.Operator); DomUtil.SetElementText(domOperLog.DocumentElement, "operTime", DateTimeUtil.Rfc1123DateTimeStringEx(item.OperTime.ToLocalTime())); return domOperLog.OuterXml; }
// parameters: // maxItemCount 最大事项数。如果为 -1 表示不限制 public bool Add(AccessLogItem item, long maxItemCount) { MongoCollection<AccessLogItem> collection = this.LogCollection; if (collection == null) return false; // 限制最大事项数 { string date = GetToday(); long newValue = _itemCount.GetValue(date, 1); if (maxItemCount != -1 && newValue > maxItemCount) { _itemCount.GetValue(date, -1); return false; } } collection.Insert(item); return true; }
public bool Add(string operation, string path, long size, string mime, string clientAddress, long initial_hitcount, string operator_param, DateTime opertime, long maxItemCount) { AccessLogItem item = new AccessLogItem(); item.Operation = operation; item.Path = path; item.Size = size; item.MIME = mime; item.ClientAddress = clientAddress; item.HitCount = initial_hitcount; item.Operator = operator_param; item.OperTime = opertime; return Add(item, maxItemCount); }