示例#1
0
        public IRoutingMessage FromMessage(IMessage edgeMessage)
        {
            Preconditions.CheckNotNull(edgeMessage, nameof(edgeMessage));
            Preconditions.CheckNotNull(edgeMessage.Body, nameof(edgeMessage.Body));
            Preconditions.CheckNotNull(edgeMessage.Properties, nameof(edgeMessage.Properties));
            Preconditions.CheckNotNull(edgeMessage.SystemProperties, nameof(edgeMessage.SystemProperties));

            IMessageSource messageSource  = this.GetMessageSource(edgeMessage.SystemProperties);
            var            routingMessage = new RoutingMessage(messageSource, edgeMessage.Body, edgeMessage.Properties, edgeMessage.SystemProperties);

            return(routingMessage);
        }
        public static IEnumerable <object[]> GetRoutingMessages()
        {
            var routingMessages = new List <object[]>();

            var data = new
            {
                temperature = 100,
                scale       = "Celsius"
            };
            string dataString = JsonConvert.SerializeObject(data);

            byte[] messageBytes = Encoding.UTF8.GetBytes(dataString);
            var    properties   = new Dictionary <string, string>()
            {
                { "model", "temperature" },
                { "level", "one" }
            };

            var systemProperties = new Dictionary <string, string>()
            {
                { SystemProperties.MessageId, "12345" },
                { SystemProperties.UserId, "UserId10" },
                { SystemProperties.ConnectionDeviceId, "Device10" },
                { SystemProperties.MsgCorrelationId, "CorrId10" },
                { "InvalidSystemProperty", "SomeValue" }
            };
            var routingMessage1 = new RoutingMessage(TelemetryMessageSource.Instance, messageBytes, properties, systemProperties);

            routingMessages.Add(new object[] { routingMessage1 });

            var routingMessage2 = new RoutingMessage(
                TwinChangeEventMessageSource.Instance,
                messageBytes,
                properties,
                systemProperties,
                100,
                DateTime.Today.Subtract(TimeSpan.FromDays(1)),
                DateTime.Today);

            routingMessages.Add(new object[] { routingMessage2 });

            var emptyProperties       = new Dictionary <string, string>();
            var emptySystemProperties = new Dictionary <string, string>();
            var routingMessage3       = new RoutingMessage(TelemetryMessageSource.Instance, messageBytes, emptyProperties, emptySystemProperties);

            routingMessages.Add(new object[] { routingMessage3 });

            return(routingMessages);
        }