async Task <T> GetValue() { using (Stream valueStream = await _repository.Get(_address, _cancellationToken).ConfigureAwait(false)) { return(await _converter.Convert(valueStream, _cancellationToken).ConfigureAwait(false)); } }
async Task <T> GetValue() { using (Stream valueStream = await _repository.Get(_address, _transformContext.CancellationToken)) { return(await _converter.Convert(valueStream, _transformContext.CancellationToken)); } }
public async Task <Stream> Get(Uri address, CancellationToken cancellationToken = new CancellationToken()) { var stream = await _repository.Get(address, cancellationToken).ConfigureAwait(false); address.TryGetValueFromQueryString("keyId", out var keyId); return(_streamProvider.GetDecryptStream(stream, keyId, CryptoStreamMode.Read)); }
public static Document ToDocument(this DocumentDto documentDto, IMessageDataRepository messageDataRepository) { var document = documentDto.ToDocument(); if (documentDto.Content.HasValue) { document.Content = GetArrayFromStream(messageDataRepository.Get(documentDto.Content.Address).Result); } return(document); }
public static async Task <MessageData <string> > GetString(this IMessageDataRepository repository, Uri address, CancellationToken cancellationToken = default(CancellationToken)) { if (repository == null) { throw new ArgumentNullException(nameof(repository)); } using (var ms = new MemoryStream()) { Stream stream = await repository.Get(address, cancellationToken).ConfigureAwait(false); await stream.CopyToAsync(ms).ConfigureAwait(false); return(new ConstantMessageData <string>(address, Encoding.UTF8.GetString(ms.ToArray()))); } }
public static async Task <MessageData <byte[]> > GetBytes(this IMessageDataRepository repository, Uri address, CancellationToken cancellationToken = default(CancellationToken)) { if (repository == null) { throw new ArgumentNullException(nameof(repository)); } using (var ms = new MemoryStream()) { Stream stream = await repository.Get(address, cancellationToken); await stream.CopyToAsync(ms); return(new ConstantMessageData <byte[]>(address, ms.ToArray())); } }
async Task <T> GetValue() { // To prevent the stream message data convertor from having to copy the stream, the stream // is not disposed if the converter is a StreamMessageDataConverter Stream valueStream = null; try { valueStream = await _repository.Get(Address, _cancellationToken).ConfigureAwait(false); return(await _converter.Convert(valueStream, _cancellationToken).ConfigureAwait(false)); } finally { if (_converter.GetType() != typeof(StreamMessageDataConverter)) { valueStream?.Dispose(); } } }