Beispiel #1
0
                public SourceText ReadText(CancellationToken cancellationToken)
                {
                    if (memoryMappedInfo == null)
                    {
                        throw new InvalidOperationException();
                    }

                    using (Logger.LogBlock(FeatureId.TemporaryStorage, FunctionId.Host_TemporaryStorageServiceFactory_ReadText, cancellationToken))
                    {
                        using (var stream = memoryMappedInfo.CreateReadableStream())
                        {
                            return(this.service.textFactory.CreateText(stream, Encoding.Unicode, cancellationToken));
                        }
                    }
                }
Beispiel #2
0
                public Stream ReadStream(CancellationToken cancellationToken)
                {
                    if (_memoryMappedInfo == null)
                    {
                        throw new InvalidOperationException();
                    }

                    using (Logger.LogBlock(FunctionId.TemporaryStorageServiceFactory_ReadStream, cancellationToken))
                    {
                        cancellationToken.ThrowIfCancellationRequested();

                        return(_memoryMappedInfo.CreateReadableStream());
                    }
                }
                public SourceText ReadText(CancellationToken cancellationToken)
                {
                    if (_memoryMappedInfo == null)
                    {
                        throw new InvalidOperationException();
                    }

                    using (Logger.LogBlock(FunctionId.TemporaryStorageServiceFactory_ReadText, cancellationToken))
                    {
                        using (var stream = _memoryMappedInfo.CreateReadableStream())
                        {
                            return(_service._textFactory.CreateText(stream, _encoding, cancellationToken));
                        }
                    }
                }
Beispiel #4
0
                public SourceText ReadText(CancellationToken cancellationToken)
                {
                    if (_memoryMappedInfo == null)
                    {
                        throw new InvalidOperationException();
                    }

                    using (Logger.LogBlock(FunctionId.TemporaryStorageServiceFactory_ReadText, cancellationToken))
                    {
                        using var stream = _memoryMappedInfo.CreateReadableStream();
                        using var reader = CreateTextReaderFromTemporaryStorage((ISupportDirectMemoryAccess)stream, (int)stream.Length);

                        // we pass in encoding we got from original source text even if it is null.
                        return(_service._textFactory.CreateText(reader, _encoding, cancellationToken));
                    }
                }
Beispiel #5
0
                public SourceText ReadText(CancellationToken cancellationToken)
                {
                    if (_memoryMappedInfo == null)
                    {
                        throw new InvalidOperationException();
                    }

                    using (Logger.LogBlock(FunctionId.TemporaryStorageServiceFactory_ReadText, cancellationToken))
                    {
                        // unfortunately, there is no way to re-use stream reader. it will repeatedly re-allocate its buffer(1K).
                        // but most of time, this shouldn't be used that much since we consume tree directly rather than text.
                        using (var stream = _memoryMappedInfo.CreateReadableStream())
                            using (var reader = new StreamReader(stream, Encoding.Unicode, detectEncodingFromByteOrderMarks: false))
                            {
                                return(_service._textFactory.CreateText(reader, _encoding, cancellationToken));
                            }
                    }
                }