IEnumerable <LogEvent> ReadUsing(StreamReader reader, string filePath, CancellationToken cancellationToken, bool throwWhenCancelled) { var fileNumber = FileSnap.Create(filePath).FileNumber; var lineCounter = 0; try { using (reader) { string line; var firstIteration = true; while ((line = reader.ReadLine()) != null) { if (throwWhenCancelled) { cancellationToken.ThrowIfCancellationRequested(); } else if (cancellationToken.IsCancellationRequested) { yield break; } if (!line.EndsWith("#")) { _logger.Verbose($"Line {line} did not end with #"); yield break; } lineCounter++; if (firstIteration) { _logger.Verbose($"Successfully initiated read operation from file {filePath}"); firstIteration = false; } var position = reader.GetBytePosition(); var data = Convert.FromBase64String(line.Substring(0, line.Length - 1)); yield return(new LogEvent(data, fileNumber, position)); } } } finally { if (lineCounter > 0) { _logger.Verbose($"Successfully read {lineCounter} lines from file {filePath}"); } } }
async Task DeleteFile(FileSnap file, CancellationToken cancellationToken) { var filePath = file.FilePath; try { File.Delete(filePath); _logger.Verbose($"Deleted file {filePath}"); } catch (Exception exception) { throw new IOException($"Could not delete file {filePath}", exception); } }