private Task <FileInfo> FindFile(DirectoryInfo directory, string name) { if (!directory.Exists) { var dirException = new JournalDirectoryNotFoundException("The journal directory does not exist"); dirException.Data.Add("Path", directory.FullName); return(Task.FromException <FileInfo>(dirException)); } var files = directory.GetFiles(name); if (files.Length > 0) { return(Task.FromResult(files.First())); } var path = Path.Combine(directory.FullName, name); var fileException = new SupportFileNotFoundException($"The {name} could not be found"); fileException.Data.Add("Path", path); return(Task.FromException <FileInfo>(fileException)); }
private Exception CheckDirectoryValidity(DirectoryInfo directory) { if (directory == null) { return(new NullReferenceException()); } if (!directory.Exists) { var exception = new JournalDirectoryNotFoundException("The journal directory does not exist"); exception.Data.Add("Path", directory.FullName); return(exception); } if (directory.GetFiles("Journal.*.log").Length == 0) { var exception = new JournalFileNotFoundException("No journal files could be found in the directory"); exception.Data.Add("Path", directory.FullName); return(exception); } return(null); }