public async Task ReadCloudSchedulerData()

in processing-pipelines/common/csharp/CloudEventReader.cs [103:140]


        public async Task<string> ReadCloudSchedulerData(HttpContext context)
        {
            _logger.LogInformation("Reading cloud scheduler data");

            string country = null;
            CloudEvent cloudEvent;
            CloudEventFormatter formatter;
            var ceType = context.Request.Headers["ce-type"];

            switch (ceType)
            {
                case MessagePublishedData.MessagePublishedCloudEventType:
                    formatter = CloudEventFormatterAttribute.CreateFormatter(typeof(MessagePublishedData));
                    cloudEvent = await context.Request.ToCloudEventAsync(formatter);
                    _logger.LogInformation($"Received CloudEvent\n{cloudEvent.GetLog()}");

                    var messagePublishedData = (MessagePublishedData)cloudEvent.Data;
                    var pubSubMessage = messagePublishedData.Message;
                    _logger.LogInformation($"Type: {ceType} data: {pubSubMessage.Data.ToBase64()}");

                    country = pubSubMessage.Data.ToStringUtf8();
                    break;
                case SchedulerJobData.ExecutedCloudEventType:
                    // Data: {"custom_data":"Q3lwcnVz"}
                    formatter = CloudEventFormatterAttribute.CreateFormatter(typeof(SchedulerJobData));
                    cloudEvent = await context.Request.ToCloudEventAsync(formatter);
                    _logger.LogInformation($"Received CloudEvent\n{cloudEvent.GetLog()}");

                    var schedulerJobData = (SchedulerJobData)cloudEvent.Data;
                    _logger.LogInformation($"Type: {ceType} data: {schedulerJobData.CustomData.ToBase64()}");

                    country = schedulerJobData.CustomData.ToStringUtf8();
                    break;
            }

            _logger.LogInformation($"Extracted country: {country}");
            return country;
        }