public void Sort() { ISortStrategy sortStrategy; using (var reader = new DataRecordReader(_options.Input)) { var fileLength = reader.Length; sortStrategy = fileLength < 1_000_000_000 // 1GB ? (ISortStrategy) new SmallFileStrategy() : new DefaultStrategy(); SplitData(sortStrategy, reader, fileLength); } WriteResults(sortStrategy); }
private void SplitData(ISortStrategy sortStrategy, DataRecordReader reader, long fileLength) { var timer = Stopwatch.StartNew(); var readerPositionPrev = 0L; foreach (var dataRecord in reader) { var readerPosition = reader.Position; if (readerPosition - readerPositionPrev > Constants.HundredMegabytes) { ShowProgress(readerPosition, fileLength, timer.Elapsed.TotalSeconds); readerPositionPrev = readerPosition; } sortStrategy.Aggregate(dataRecord); } ShowProgress(reader.Position, fileLength, timer.Elapsed.TotalSeconds); Console.WriteLine(); Console.WriteLine($"Splitting executed at {timer.Elapsed}"); }