private async Task ProcessEvent(ProcessEventArgs eventArgs) { // Note there is a bug with the HasEvent property in Preview 6, so check if Data is not null as work around. // https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/eventhub/Azure.Messaging.EventHubs.Processor/samples/Sample08_EventProcessingHeartbeat.cs#L85 if (eventArgs.Data != null) { var totalCount = 0; var cancellationToken = _cancellationTokenSource.Token; var blobName = Encoding.UTF8.GetString(eventArgs.Data.Body.Span); var blobClient = _blobContainerClient.GetBlobClient(blobName); var downloadInfo = await blobClient.DownloadAsync(cancellationToken); _logger.LogInformation("Processing {blob}", blobName); var newLineCountingStream = new NewLineCountingStream(); await downloadInfo.Value.Content.CopyToAsync(newLineCountingStream, cancellationToken); var newLineCount = newLineCountingStream.NewLineCount; await blobClient.SetMetadataAsync( new Dictionary <string, string>() { { "whitespacecount", newLineCount.ToString() } }, cancellationToken : cancellationToken); _logger.LogInformation("{blob} had {lines} lines", blobName, newLineCount); totalCount += newLineCount; using EventDataBatch eventBatch = await _resultsClient.CreateBatchAsync(); eventBatch.TryAdd(new EventData(BitConverter.GetBytes(totalCount))); await _resultsClient.SendAsync(eventBatch, cancellationToken); await eventArgs.UpdateCheckpointAsync(); } }
private async Task ProcessEvent(ProcessEventArgs eventArgs) { if (eventArgs.HasEvent) { var totalCount = 0; var cancellationToken = _cancellationTokenSource.Token; var blobName = Encoding.UTF8.GetString(eventArgs.Data.Body.Span); var blobClient = _blobContainerClient.GetBlobClient(blobName); var downloadInfo = await blobClient.DownloadAsync(cancellationToken); _logger.LogInformation("Processing {blob}", blobName); var newLineCountingStream = new NewLineCountingStream(); await downloadInfo.Value.Content.CopyToAsync(newLineCountingStream, cancellationToken); var newLineCount = newLineCountingStream.NewLineCount; await blobClient.SetMetadataAsync( new Dictionary <string, string>() { { "whitespacecount", newLineCount.ToString() } }, cancellationToken : cancellationToken); _logger.LogInformation("{blob} had {lines} lines", blobName, newLineCount); totalCount += newLineCount; using EventDataBatch eventBatch = await _resultsClient.CreateBatchAsync(); eventBatch.TryAdd(new EventData(BitConverter.GetBytes(totalCount))); await _resultsClient.SendAsync(eventBatch, cancellationToken); await eventArgs.UpdateCheckpointAsync(); } }