/// <exception cref="FileNotFoundException">If no files are available.</exception> /// <exception cref="DirectoryNotFoundException">If the PDF directory is missing or could not be read (e. g. due to network issues).</exception>" private string GetNextFileName(bool includeCurrentFile = false) { IEnumerable <string> availableFiles = repository.ListAllFiles(); if (availableFiles == null) { // connection lost or currentFile = null; throw new DirectoryNotFoundException("Could not read directory."); } if (!availableFiles.Any()) { currentFile = null; throw new FileNotFoundException("No files available!"); } if (currentFile != null) { // determine which files come alphabetically after currentFile IEnumerable <string> alphabeticallyNextFiles; if (includeCurrentFile) { // ">=" ensures that currentFile itself is included if available alphabeticallyNextFiles = availableFiles.Where(f => f.CompareTo(currentFile) >= 0); } else { alphabeticallyNextFiles = availableFiles.Where(f => f.CompareTo(currentFile) > 0); } if (alphabeticallyNextFiles.Any()) { // if there are any files after currentFile, use the next file (i.e. the file that comes first in the alphabet) currentFile = alphabeticallyNextFiles.Min(); } else { // otherwise, take the first file (i.e. roll over to the beginning) currentFile = availableFiles.Min(); } } else { // First Call -> return first file name in the culture-dependent alphabet currentFile = availableFiles.Min(); } return(currentFile); }