public override ErrorLogEntry GetError(string id) { string entryId; try { entryId = new Guid(id).ToString(); } catch (FormatException exception) { throw new ArgumentException(exception.Message, id, exception); } var logRoot = GetLogRoot(); var filePattern = string.Format("error-*-{0}.xml", entryId); var fileQuery = new UnifiedSearchQuery {FileNamePattern = filePattern, FreeTextQuery = "" }; fileQuery.MatchSummary.Add("*", ""); var fileHits = logRoot.Search(fileQuery); if (fileHits.Count < 1) { throw new FileNotFoundException(string.Format("Cannot locate error file for error with ID {0}.", entryId)); } return ReadError(fileHits[0]); }
/// <summary> /// Finds the last modified files. /// </summary> protected IList <UnifiedFile> FindLastModifiedFiles(string rootFolder, int maxCount) { var files = new List <UnifiedFile>(); UnifiedDirectory directory = null; try { directory = HostingEnvironment.VirtualPathProvider.GetDirectory(rootFolder) as UnifiedDirectory; } catch (UnauthorizedAccessException) {} // If directory not found or access not granted for directory // return empty list if (directory == null) { ShowErrorMessage(Translate("/workroom/filelist/errormessage")); return(files); } UnifiedSearchQuery query = new UnifiedSearchQuery { ModifiedFrom = DateTime.MinValue, ModifiedTo = DateTime.Now, Path = rootFolder, FreeTextQuery = String.Empty }; UnifiedSearchHitCollection hits; try { hits = directory.Search(query); } catch (IOException) { ShowErrorMessage(Translate("/workroom/filelist/errormissingindex")); return(files); } for (int i = 0; i < hits.Count; i++) { try { files.Add((UnifiedFile)HostingEnvironment.VirtualPathProvider.GetFile(hits[i].Path)); } catch (UnauthorizedAccessException) { // If user has limited access right we still want to show files with access granted. } } files.Sort(new FileModifiedComparer()); if (files.Count > maxCount) { files.RemoveRange(maxCount - 1, files.Count - maxCount); } return(files); }
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); } var logRoot = GetLogRoot(); var fileQuery = new UnifiedSearchQuery { FileNamePattern = "error*", FreeTextQuery = ""}; fileQuery.MatchSummary.Add("*", ""); var fileHits = logRoot.Search(fileQuery); int totalCount = fileHits.Count; if (totalCount < 1) { return 0; } var errors = fileHits.OfType<UnifiedSearchHit>().Take(pageSize).Skip(pageIndex * pageSize).Select(ReadError).ToList(); foreach(var error in errors) { if(error != null) { errorEntryList.Add(error); } } return totalCount; }