public Generator(GenerateOptions options) { _options = options; if (string.IsNullOrWhiteSpace(_options.FileName)) { throw new ArgumentException("Empty file name"); } _size = SizeHelper.GetBytesFromSizeString(_options.SizeStr); }
public Sorter(SortOptions options) { _options = options; if (string.IsNullOrWhiteSpace(_options.InputFileName)) { throw new ArgumentException("Empty input file name"); } if (string.IsNullOrWhiteSpace(_options.OutputFileName)) { throw new ArgumentException("Empty output file name"); } _maxDataSize = SizeHelper.GetBytesFromSizeString(_options.MaxDataSizeStr); _chunkSize = SizeHelper.GetBytesFromSizeString(_options.ChunkSizeStr); _minChunkPartLoadSize = SizeHelper.GetBytesFromSizeString(_options.MinChunkPartLoadSizeStr); _mergeOutputBufferMaxSize = SizeHelper.GetBytesFromSizeString(_options.MergeOutputBufferMaxSizeStr); _sortUnitMaxLinesCount = _options.SortUnitMaxLinesCount; _sortThreadsCount = _options.SortThreadsCount <= 0 ? Environment.ProcessorCount - 2 : _options.SortThreadsCount; _sortChunkBlock = new TransformBlock <ChunkWriter, ChunkWriter>(SortChunk, new ExecutionDataflowBlockOptions { MaxDegreeOfParallelism = _sortThreadsCount }); // Сортируем многопоточно _writeChunkBlock = new ActionBlock <ChunkWriter>(WriteChunk, new ExecutionDataflowBlockOptions { MaxDegreeOfParallelism = 1 }); // Записываем чанки в один поток _sortChunkBlock.LinkTo(_writeChunkBlock); _writeResultPartBlock = new ActionBlock <List <string> >(WriteResultPartBlock, new ExecutionDataflowBlockOptions { EnsureOrdered = true, MaxDegreeOfParallelism = 1 }); // Записываем результат в один поток }