コード例 #1
0
        private NotificationMetadata(string ioTHubName, string deviceId, NotificationMessageSchemas messageSchema, string rawMessageSchema, string correlationId)
        {
            Guard.NotNullOrWhitespace(ioTHubName, nameof(ioTHubName));
            Guard.NotNullOrWhitespace(deviceId, nameof(deviceId));

            IoTHubName       = ioTHubName;
            DeviceId         = deviceId;
            MessageSchema    = messageSchema;
            RawMessageSchema = rawMessageSchema;
            CorrelationId    = correlationId;
        }
コード例 #2
0
        public async Task ProcessAsync(NotificationMessageSchemas messageSchema, NotificationMetadata notificationMetadata, string rawMessage)
        {
            IEventProcessor processor;

            switch (messageSchema)
            {
            case NotificationMessageSchemas.TwinChangeNotification:
                processor = _serviceProvider.GetRequiredService <TwinChangedNotificationProcessor>();
                break;

            default:
                _logger.LogWarning("Message schema {MessageSchema} is not supported and being ignored", notificationMetadata.RawMessageSchema);
                return;
            }

            await processor.ProcessAsync(notificationMetadata, rawMessage);
        }
コード例 #3
0
        public static NotificationMetadata Parse(EventData eventData)
        {
            Guard.NotNull(eventData, nameof(eventData));

            var deviceId         = eventData.Properties[EventProperties.DeviceId]?.ToString();
            var ioTHubName       = eventData.Properties[EventProperties.IoTHubName]?.ToString();
            var rawMessageSchema = eventData.Properties[EventProperties.MessageSchema]?.ToString();
            var correlationId    = eventData.SystemProperties[EventSystemProperties.CorrelationId].ToString();

            NotificationMessageSchemas messageSchema = NotificationMessageSchemas.Unknown;

            if (Enum.TryParse(rawMessageSchema, ignoreCase: true, out NotificationMessageSchemas parsedSchema))
            {
                messageSchema = parsedSchema;
            }

            return(new NotificationMetadata(ioTHubName, deviceId, messageSchema, rawMessageSchema, correlationId));
        }