Пример #1
0
        private Task <string> SortAndFlush()
        {
            _fileCounter = _fileCounter + 1;

            var fileName = _fileCounter + ".txt";

            var closedChunk = _currentChunk;

            _currentChunk = new List <string>(_currentChunk.Count);

            return(Task.Factory.StartNew(() =>
            {
                Log.Debug($"Start sorting the file with name {fileName}");

                var sortedRecords = new List <SortedRecord>(closedChunk.Count);

                foreach (var line in closedChunk)
                {
                    var wordsinline = line.Split(". ", StringSplitOptions.RemoveEmptyEntries);

                    var word = wordsinline[1];
                    var number = int.Parse(wordsinline[0]);

                    var record = new SortedRecord(number, word, line);
                    sortedRecords.Add(record);
                }

                sortedRecords.Sort(SortedRecord.SortWordNumberAscending());
                Log.Debug($"Stop sorting the file with name {fileName}");

                var filePath = Path.Combine(folderName, fileName);
                using var currentFileStream = CreateNewFile(filePath);
                Log.Debug($"Start writing the file with name {fileName}");
                foreach (var record in sortedRecords)
                {
                    currentFileStream.WriteLine(record.OriginalString);
                }
                Log.Debug($"Stop writing the file with name {fileName}");

                _concurrencySemaphore.Release();

                return filePath;
            }, TaskCreationOptions.LongRunning));
        }
Пример #2
0
 public bool Equals(SortedRecord other)
 {
     return(OriginalString == other.OriginalString);
 }