public async Task Run([EventGridTrigger] JObject eventGridEvent, ILogger log) { var e = eventGridEvent.ToObject <EventGridEvent>(); if (e.EventType != BlobCreated) { log.Log(LogLevel.Information, $"Unsupported event {e.EventType}, skipping."); return; } var blobPath = e.Subject.Replace(ContainerPrefix, string.Empty); if (!blobPath.Contains(_blobPrefix)) { log.Log(LogLevel.Information, $"Blob path {blobPath} doesn't match function configuration, skipping."); return; } var messages = await _storageHelper.ListMessagesAsync(blobPath.Replace(_blobPrefix, string.Empty)); // TODO: group notify all readings var firstMessage = messages.FirstOrDefault(); if (firstMessage != null) { await _appNotifier.NotifyNewReadingAsync(firstMessage.EnqueuedTimeUtc, firstMessage.Body, log); } }
public async Task <IEnumerable <IotMessage <Reading> > > ListSensorDetailsAsync(DateTimeOffset @from, DateTimeOffset to) { var dateDirectories = await _storageHelper.ListDateDirectoriesAsync(); var matchingDirectories = dateDirectories.Where(d => d.Date >= from.Date && d.Date <= to.Date); var timeBlobs = await Task.WhenAll(matchingDirectories.Select(d => _storageHelper.ListTimeBlobsAsync(d))); var messages = await Task.WhenAll(timeBlobs.SelectMany(b => b) .Where(b => b.DateTime >= from && b.DateTime <= to).Select(b => _storageHelper.ListMessagesAsync(b))); return(messages.SelectMany(m => m)); }