public static void TestResults(string path) { using (var reader = new StreamReader(path)) { string firstLine = reader.ReadLine(); string secondLine = reader.ReadLine(); while (!reader.EndOfStream) { if (firstLine == null || secondLine == null) { Console.WriteLine("break;"); break; } var x = new LineHandler("1", firstLine); var y = new LineHandler("2", secondLine); if (x.CompareTo(y) > 0) { throw new Exception($"Line {x.Line} is greater than {y.Line}"); } firstLine = reader.ReadLine(); secondLine = reader.ReadLine(); } } Console.WriteLine($"File {path} has been checked!"); }
private static void MergeChunks(string chunksPath, string outputPath) { string[] filePaths = Directory.GetFiles(chunksPath); var readersHeap = new MinHeap <LineHandler>(filePaths.Length); var readersMap = new Dictionary <string, StreamReader>(filePaths.Length); foreach (string filePath in filePaths) { var reader = new StreamReader(filePath); if (!reader.EndOfStream) { readersMap.Add(filePath, reader); readersHeap.Insert(new LineHandler(filePath, reader.ReadLine())); } } using (var writer = new StreamWriter(outputPath)) { LineHandler min = readersHeap.ExtractMin(); while (min != null) { writer.WriteLine(min.Line); if (readersMap[min.ChunkPath].EndOfStream) { readersMap[min.ChunkPath].Close(); File.Delete(min.ChunkPath); } else { readersHeap.Insert(new LineHandler(min.ChunkPath, readersMap[min.ChunkPath].ReadLine())); } min = readersHeap.ExtractMin(); } } }