public async Task <Maybe <Rant> > Handle(RandomRantCommand request, CancellationToken cancellationToken) { await EnsureContainerExists(); var blobResultSegment = await blobContainer.ListBlobsSegmentedAsync(new BlobContinuationToken()); var results = blobResultSegment.Results.OfType <CloudBlockBlob>().ToList(); if (!results.Any()) { return(Maybe <Rant> .None()); } var listBlobItem = results.ElementAt(new Random().Next(results.Count())); var content = await listBlobItem.DownloadTextAsync(); return(Maybe <Rant> .Some(JsonConvert.DeserializeObject <Rant>(content))); }
public Task <Maybe <Rant> > Handle(RandomRantCommand request, CancellationToken cancellationToken) { return(rants.Any() ? Task.FromResult(Maybe <Rant> .Some(rants.Values.ElementAt(new Random().Next(rants.Count)))) : Task.FromResult(Maybe <Rant> .None())); }