public ExternalMergeSorter(ExternalMergeSorterOptions options) { _totalFilesToMerge = 0; _mergeFilesProcessed = 0; _options = options ?? throw new ArgumentNullException(nameof(options)); _unsortedRows = Array.Empty <string>(); }
static async Task Main(string[] args) { Console.OutputEncoding = Encoding.UTF8; Console.InputEncoding = Encoding.UTF8; try { var unsortedFilePath = DisplayMenu(); var unsortedFileName = Path.GetFileNameWithoutExtension(unsortedFilePath); var sortedFilePath = Path.Combine( AppDomain.CurrentDomain.BaseDirectory, $"{unsortedFileName}-sorted.txt"); var cancellationTokenSource = new CancellationTokenSource(); var unsortedFile = File.OpenRead(unsortedFilePath); var targetFile = File.OpenWrite(sortedFilePath); var options = new ExternalMergeSorterOptions { FileLocation = AppDomain.CurrentDomain.BaseDirectory, Sort = new ExternalMergeSortSortOptions { Comparer = new CustomRowComparer() }, Split = new ExternalMergeSortSplitOptions { FileSize = 128 * 1024 * 1024 } }; var sorter = new ExternalMergeSorter(options); var watch = Stopwatch.StartNew(); await sorter.Sort(unsortedFile, targetFile, cancellationTokenSource.Token); watch.Stop(); Console.WriteLine($"Файл {unsortedFilePath} отсортирован за {watch.ElapsedMilliseconds/1000} cекунд"); Console.WriteLine($"Файл доступен по пути: {Environment.NewLine}{sortedFilePath}{Environment.NewLine}"); } catch (Exception e) { Console.WriteLine(e.Message); } Console.WriteLine("Нажмите любую клавишу для завершения работы программы"); Console.ReadKey(); }