/// <summary> /// Process an event asynchronously. /// </summary> /// <param name="e">event to process</param> /// <returns> /// Task to wait on. /// </returns> public async Task HandleAsync(IMessageContext context, ReportAddedToIncident e) { if (e == null) { throw new ArgumentNullException("e"); } _logger.Debug("doing collections"); var collections = await _repository.GetCollectionsAsync(e.Incident.ApplicationId); foreach (var collectionDto in e.Report.ContextCollections) { var isNew = false; var meta = collections.FirstOrDefault(x => x.Name.Equals(collectionDto.Name, StringComparison.OrdinalIgnoreCase)); if (meta == null) { isNew = true; meta = new CollectionMetadata(e.Incident.ApplicationId, collectionDto.Name); } foreach (var property in collectionDto.Properties) { meta.AddOrUpdateProperty(property.Key); } if (!meta.IsUpdated) { continue; } if (isNew) { await _repository.CreateAsync(meta); } else { await _repository.UpdateAsync(meta); } } _logger.Debug("collections done"); }