/// <summary> /// Returns a page of errors from the folder in descending order of logged time as defined by the sortable filenames. /// </summary> public override int GetErrors(int pageIndex, int pageSize, IList errorEntryList) { if (pageIndex < 0) { pageIndex = 0; } if (pageSize < 0) { pageSize = 25; } string[] fileList = Directory.GetFiles(LogPath, "*.xml"); if (fileList.Length < 1) { return(0); } Array.Sort(fileList); Array.Reverse(fileList); int currentItem = pageIndex * pageSize; int lastItem = (currentItem + pageSize < fileList.Length) ? currentItem + pageSize : fileList.Length; for (int i = currentItem; i < lastItem; i++) { FileInfo f = new FileInfo(fileList[i]); FileStream s = f.OpenRead(); XmlTextReader r = new XmlTextReader(s); try { while (r.IsStartElement("error")) { SimpleErrorHandler.Error error = new SimpleErrorHandler.Error(); error.FromXml(r); error.IsProtected = f.IsReadOnly; // have we "protected" this file from deletion? errorEntryList.Add(new ErrorLogEntry(this, error.Id, error)); } } finally { r.Close(); } } return(fileList.Length); }
/// <summary> /// Returns the specified error from the filesystem, or throws an exception if it does not exist. /// </summary> public override ErrorLogEntry GetError(string id) { string[] fileList = Directory.GetFiles(LogPath, string.Format("*{0}.xml", id)); if (fileList.Length < 1) { throw new Exception(string.Format("Can't locate error file for errorId {0}", id)); } FileInfo f = new FileInfo(fileList[0]); FileStream s = f.OpenRead(); XmlTextReader r = new XmlTextReader(s); SimpleErrorHandler.Error error = new SimpleErrorHandler.Error(); error.FromXml(r); r.Close(); return(new ErrorLogEntry(this, id, error)); }
/// <summary> /// Answers the older exception that 'possibleDuplicate' matches, returning null if no match is found. /// </summary> private bool TryFindOriginalError(SimpleErrorHandler.Error possibleDuplicate, string messageHash, out SimpleErrorHandler.Error original) { string[] files = Directory.GetFiles(LogPath); if (files.Length > 0) { var earliestDate = DateTime.Now.Add(_ignoreSimilarExceptionsThreshold.Value); // order by newest Array.Sort(files); Array.Reverse(files); foreach (var filename in files) { if (File.GetCreationTime(filename) >= earliestDate) { var match = Regex.Match(filename, @"error[-\d]+Z-(?<hashCode>((?<!\d)-|\d)+)-(?<id>.+)\.xml", RegexOptions.IgnoreCase); if (match.Success) { var existingHash = match.Groups["hashCode"].Value; if (messageHash.Equals(existingHash)) { original = GetError(match.Groups["id"].Value).Error; return(true); } } } else { break; // no other files are newer, no use checking } } } original = null; return(false); }
/// <summary> /// Returns a page of errors from the folder in descending order of logged time as defined by the sortable filenames. /// </summary> public override int GetErrors(int pageIndex, int pageSize, IList errorEntryList) { if (pageIndex < 0) pageIndex = 0; if (pageSize < 0) pageSize = 25; string[] fileList = Directory.GetFiles(LogPath, "*.xml"); if (fileList.Length < 1) return 0; Array.Sort(fileList); Array.Reverse(fileList); int currentItem = pageIndex * pageSize; int lastItem = (currentItem + pageSize < fileList.Length) ? currentItem + pageSize : fileList.Length; for (int i = currentItem; i < lastItem; i++) { FileInfo f = new FileInfo(fileList[i]); FileStream s = f.OpenRead(); XmlTextReader r = new XmlTextReader(s); try { while (r.IsStartElement("error")) { SimpleErrorHandler.Error error = new SimpleErrorHandler.Error(); error.FromXml(r); error.IsProtected = f.IsReadOnly; // have we "protected" this file from deletion? errorEntryList.Add(new ErrorLogEntry(this, error.Id, error)); } } finally { r.Close(); } } return fileList.Length; }
/// <summary> /// Returns the specified error from the filesystem, or throws an exception if it does not exist. /// </summary> public override ErrorLogEntry GetError(string id) { string[] fileList = Directory.GetFiles(LogPath, string.Format("*{0}.xml", id)); if (fileList.Length < 1) throw new Exception(string.Format("Can't locate error file for errorId {0}", id)); FileInfo f = new FileInfo(fileList[0]); FileStream s = f.OpenRead(); XmlTextReader r = new XmlTextReader(s); SimpleErrorHandler.Error error = new SimpleErrorHandler.Error(); error.FromXml(r); r.Close(); return new ErrorLogEntry(this, id, error); }