public Message FromMessage()

in edge-hub/core/src/Microsoft.Azure.Devices.Edge.Hub.CloudProxy/DeviceClientMessageConverter.cs [16:86]


        public Message FromMessage(IMessage inputMessage)
        {
            Preconditions.CheckNotNull(inputMessage, nameof(inputMessage));
            Preconditions.CheckArgument(inputMessage.Body != null, "IMessage.Body should not be null");

            var message = new Message(inputMessage.Body);

            if (inputMessage.Properties != null)
            {
                foreach (KeyValuePair<string, string> inputMessageProperty in inputMessage.Properties)
                {
                    message.Properties.Add(inputMessageProperty);
                }
            }

            if (inputMessage.SystemProperties != null)
            {
                if (inputMessage.SystemProperties.TryGetNonEmptyValue(SystemProperties.MessageId, out string messageId))
                {
                    message.MessageId = messageId;
                }

                if (inputMessage.SystemProperties.TryGetNonEmptyValue(SystemProperties.MsgCorrelationId, out string correlationId))
                {
                    message.CorrelationId = correlationId;
                }

                if (inputMessage.SystemProperties.TryGetNonEmptyValue(SystemProperties.UserId, out string userId))
                {
                    message.UserId = userId;
                }

                if (inputMessage.SystemProperties.TryGetNonEmptyValue(SystemProperties.ContentType, out string contentType))
                {
                    message.ContentType = contentType;
                }

                if (inputMessage.SystemProperties.TryGetNonEmptyValue(SystemProperties.ContentEncoding, out string contentEncoding))
                {
                    message.ContentEncoding = contentEncoding;
                }

                if (inputMessage.SystemProperties.TryGetNonEmptyValue(SystemProperties.To, out string to))
                {
                    message.To = to;
                }

                if (inputMessage.SystemProperties.TryGetNonEmptyValue(SystemProperties.CreationTime, out string creationTime))
                {
                    message.CreationTimeUtc = DateTime.ParseExact(creationTime, "o", CultureInfo.InvariantCulture);
                }

                if (inputMessage.SystemProperties.TryGetNonEmptyValue(SystemProperties.MessageSchema, out string messageSchema))
                {
                    message.MessageSchema = messageSchema;
                }

                if (inputMessage.SystemProperties.TryGetNonEmptyValue(SystemProperties.ComponentName, out string componentName))
                {
                    message.ComponentName = componentName;
                }

                if (inputMessage.SystemProperties.TryGetNonEmptyValue(SystemProperties.InterfaceId, out string interfaceId)
                    && interfaceId.Equals(Constants.SecurityMessageIoTHubInterfaceId, StringComparison.OrdinalIgnoreCase))
                {
                    message.SetAsSecurityMessage();
                }
            }

            return message;
        }