private async Task <Tuple <Stream, string> > GetRandomTumblrImage(string tumblrUsername) { if (!_tumblrImageUrlCaches.ContainsKey(tumblrUsername)) { _tumblrImageUrlCaches[tumblrUsername] = new TumblrImageUrlCache(tumblrUsername, TUMBLR_API_KEY, TimeSpan.FromHours(12)); } string imageUrl = await _tumblrImageUrlCaches[tumblrUsername].Pop(); // Store image in RAM and pass back. MemoryStream imageStream = await _httpClient.GetStreamAndBufferToMemory(imageUrl); // TODO: C# 7.0 when VS15 is RTM. return(new Tuple <Stream, string>(imageStream, imageUrl)); }
private async Task <Tuple <Stream, string> > GetRandomTumblrImage(string tumblrUsername) { if (!_tumblrImageUrlCaches.ContainsKey(tumblrUsername)) { _tumblrImageUrlCaches[tumblrUsername] = new TumblrImageUrlCache(tumblrUsername, TUMBLR_API_KEY, TimeSpan.FromHours(12)); } string imageUrl = await _tumblrImageUrlCaches[tumblrUsername].Pop(); // Store image in RAM and pass back. MemoryStream ms = new MemoryStream(); using (Stream httpImageStream = await _httpClient.GetStreamAsync(imageUrl)) { httpImageStream.CopyTo(ms); } ms.Seek(0, SeekOrigin.Begin); // TODO: C# 7.0 when VS15 is RTM. return(new Tuple <Stream, string>(ms, imageUrl)); }