protected virtual async Task ReadSegmentAsync(ISegmentReader segmentReader, CancellationToken cancellationToken) { WorkBuffer buffer = (WorkBuffer)null; try { while (!segmentReader.IsEof) { if (null == buffer) { buffer = await this._bufferPool.AllocateAsync(cancellationToken).ConfigureAwait(false); } Debug.Assert(null != buffer); WorkBuffer localBuffer = buffer; int length = await segmentReader.ReadAsync(buffer.Buffer, 0, buffer.Buffer.Length, (Action <ISegmentMetadata>)(metadata => localBuffer.Metadata = metadata), cancellationToken).ConfigureAwait(false); buffer.Length = length; buffer.ReadCount = ++this._readCount; if (buffer.Length > 0) { this._total += (long)buffer.Length; this._enqueue(buffer); buffer = (WorkBuffer)null; } } } finally { if (null != buffer) { this._bufferPool.Free(buffer); } } }
protected virtual async Task ReadSegmentsAsync(CancellationToken cancellationToken) { bool lockTaken = false; TaskCompletionSource <long> readResultTask; object obj; try { Monitor.Enter(obj = this._readerLock, ref lockTaken); readResultTask = this._readResultTask; } finally { if (lockTaken) { Monitor.Exit(obj); } } this._total = 0L; try { using (IAsyncEnumerator <ISegmentReader> enumerator = this._segmentReaders.GetEnumerator()) { while (true) { if (await enumerator.MoveNextAsync().ConfigureAwait(false)) { ISegmentReader segmentReader = enumerator.Current; DateTimeOffset start = DateTimeOffset.Now; Debug.WriteLine("++++ Starting {0} at {1}. Total memory: {2:F} MiB", (object)segmentReader, (object)start, (object)ByteConversion.BytesToMiB(GC.GetTotalMemory(false))); await this.ReadSegmentAsync(segmentReader, cancellationToken).ConfigureAwait(false); DateTimeOffset complete = DateTimeOffset.Now; Debug.WriteLine("---- Completed {0} at {1} ({2}). Total memory: {3:F} MiB", (object)segmentReader, (object)complete, (object)(complete - start), (object)ByteConversion.BytesToMiB(GC.GetTotalMemory(false))); } else { break; } } } this._enqueue((WorkBuffer)null); } catch (OperationCanceledException ex) { readResultTask.TrySetCanceled(); } catch (Exception ex) { Debug.WriteLine("CallbackReader.ReadAsync() failed: " + ExceptionExtensions.ExtendedMessage(ex)); readResultTask.TrySetException(ex); } finally { if (!readResultTask.Task.IsCompleted) { readResultTask.TrySetResult(this._total); } } }
public PoFileWriter(IFileHelper fileHelper, ISegmentReader segmentReader, ILineParser lineParser, IEntryBuilder entryBuilder) { _fileHelper = fileHelper; _segmentReader = segmentReader; _lineParser = lineParser; _entryBuilder = entryBuilder; }
protected virtual async Task ReadSegmentsAsync(CancellationToken cancellationToken) { TaskCompletionSource <long> readResultTask; lock (_readerLock) { readResultTask = _readResultTask; } _total = 0L; try { using (IAsyncEnumerator <ISegmentReader> enumerator = _segmentReaders.GetEnumerator()) { while (true) { if (await enumerator.MoveNextAsync().ConfigureAwait(false)) { ISegmentReader segmentReader = enumerator.Current; DateTimeOffset start = DateTimeOffset.Now; Debug.WriteLine("++++ Starting {0} at {1}. Total memory: {2:F} MiB", segmentReader, start, ByteConversion.BytesToMiB(GC.GetTotalMemory(false))); await ReadSegmentAsync(segmentReader, cancellationToken).ConfigureAwait(false); DateTimeOffset complete = DateTimeOffset.Now; Debug.WriteLine("---- Completed {0} at {1} ({2}). Total memory: {3:F} MiB", segmentReader, complete, (complete - start), ByteConversion.BytesToMiB(GC.GetTotalMemory(false))); } else { break; } } } _enqueue(null); } catch (OperationCanceledException ex) { readResultTask.TrySetCanceled(); } catch (Exception ex) { Debug.WriteLine("CallbackReader.ReadAsync() failed: " + ExceptionExtensions.ExtendedMessage(ex)); readResultTask.TrySetException(ex); } finally { if (!readResultTask.Task.IsCompleted) { readResultTask.TrySetResult(_total); } } }
public void SetUp() { _streamWriterMock = A.Fake <IStreamWriter>(); _segmentReaderMock = A.Fake <ISegmentReader>(); _lineParserMock = A.Fake <ILineParser>(); _entryBuilderMock = A.Fake <IEntryBuilder>(); _lineParsingSessionMock = A.Fake <ILineParsingSession>(); A.CallTo(() => _lineParserMock.StartLineParsingSession()).Returns(_lineParsingSessionMock); MathParseResultWithEntry(null, new ParseResult(LineType.Empty, string.Empty), null); MathParseResultWithEntry("entryComplete", new ParseResult(LineType.MessageString, "message string"), new Entry { MessageId = "message id", MessageString = "message string" }); MathParseResultWithEntry("emptyMsgidEntryComplete", new ParseResult(LineType.MessageId, string.Empty), new Entry { MessageId = string.Empty, MessageString = "message string" }); MathParseResultWithEntry("msgstrPluralEntryComplete", new ParseResult(LineType.MessageStringPlural, "message string 2"), new Entry { MessageId = "message id", MessageIdPlural = "message id plural", MessageStringPlurals = new List <string> { "message string 0", "message string 1", "message string 2" } }); A.CallTo(() => _segmentReaderMock.GetTargetText(A <ISegmentPair> .Ignored)).Returns("message string"); }
protected virtual async Task ReadSegmentAsync(ISegmentReader segmentReader, CancellationToken cancellationToken) { WorkBuffer buffer = null; try { while (!segmentReader.IsEof) { if (null == buffer) buffer = await _bufferPool.AllocateAsync(cancellationToken).ConfigureAwait(false); Debug.Assert(null != buffer); var localBuffer = buffer; var length = await segmentReader.ReadAsync(buffer.Buffer, 0, buffer.Buffer.Length, metadata => localBuffer.Metadata = metadata, cancellationToken).ConfigureAwait(false); buffer.Length = length; #if DEBUG buffer.ReadCount = ++_readCount; #endif if (buffer.Length > 0) { _total += buffer.Length; _enqueue(buffer); buffer = null; } } } finally { if (null != buffer) _bufferPool.Free(buffer); } }
public YamlFileWriter(IYamlFactory yamlFactory, ISegmentReader segmentReader) { _yamlFactory = yamlFactory; _segmentReader = segmentReader; }
public JsonFileWriter(IJsonFactory jsonFactory, IFileHelper fileHelper, ISegmentReader segmentReader) { _jsonFactory = jsonFactory; _fileHelper = fileHelper; _segmentReader = segmentReader; }