public static Decode ( XmlReader reader ) : Error | ||
reader | XmlReader | |
Résultat | Error |
/// <summary> /// Returns the specified error from the filesystem, or throws an exception if it does not exist. /// </summary> public override ErrorLogEntry GetError(string id) { try { id = (new Guid(id)).ToString(); // validate GUID } catch (FormatException e) { throw new ArgumentException(e.Message, id, e); } var file = new DirectoryInfo(LogPath).GetFiles(string.Format("error-*-{0}.xml", id)) .FirstOrDefault(); if (file == null) { return(null); } if (!IsUserFile(file.Attributes)) { return(null); } using (var reader = XmlReader.Create(file.FullName)) return(new ErrorLogEntry(this, id, ErrorXml.Decode(reader))); }
private void ErrorsXmlToList(XmlReader reader, IList errorEntryList) { Debug.Assert(reader != null); if (errorEntryList != null) { while (reader.IsStartElement("error")) { string id = reader.GetAttribute("errorId"); Error error = ErrorXml.Decode(reader); errorEntryList.Add(new ErrorLogEntry(this, id, error)); } } }
private ErrorLogEntry LoadErrorLogEntry(string path) { using (var reader = XmlReader.Create(path)) { if (!reader.IsStartElement("error")) { return(null); } var id = reader.GetAttribute("errorId"); var error = ErrorXml.Decode(reader); return(new ErrorLogEntry(this, id, error)); } }
/// <summary> /// Returns the specified error from the filesystem, or throws an exception if it does not exist. /// </summary> public override ErrorLogEntry GetError(string id) { try { /* Make sure the identifier is a valid GUID */ id = (new Guid(id)).ToString(); } catch (FormatException e) { throw new ArgumentException(e.Message, id, e); } /* Get the file folder list - should only return one ever */ DirectoryInfo dir = new DirectoryInfo(LogPath); FileInfo[] files = dir.GetFiles(string.Format("error-*-{0}.xml", id)); if (files.Length < 1) { return(null); } FileInfo file = files[0]; if (!IsUserFile(file.Attributes)) { return(null); } XmlTextReader reader = new XmlTextReader(file.FullName); try { Error error = ErrorXml.Decode(reader); return(new ErrorLogEntry(this, id, error)); } finally { reader.Close(); } }
/// <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) { throw new ArgumentOutOfRangeException("pageIndex", pageIndex, null); } if (pageSize < 0) { throw new ArgumentOutOfRangeException("pageSize", pageSize, null); } /* Get all files in directory */ string logPath = LogPath; DirectoryInfo dir = new DirectoryInfo(logPath); if (!dir.Exists) { return(0); } FileSystemInfo[] infos = dir.GetFiles("error-*.xml"); if (infos.Length < 1) { return(0); } string[] files = new string[infos.Length]; int count = 0; /* Get files that are not marked with system and hidden attributes */ foreach (FileSystemInfo info in infos) { if (IsUserFile(info.Attributes)) { files[count++] = Path.Combine(logPath, info.Name); } } InvariantStringArray.Sort(files, 0, count); Array.Reverse(files, 0, count); if (errorEntryList != null) { /* Find the proper page */ int firstIndex = pageIndex * pageSize; int lastIndex = (firstIndex + pageSize < count) ? firstIndex + pageSize : count; /* Open them up and rehydrate the list */ for (int i = firstIndex; i < lastIndex; i++) { XmlTextReader reader = new XmlTextReader(files[i]); try { while (reader.IsStartElement("error")) { string id = reader.GetAttribute("errorId"); Error error = ErrorXml.Decode(reader); errorEntryList.Add(new ErrorLogEntry(this, id, error)); } } finally { reader.Close(); } } } /* Return how many are total */ return(count); }