in iothub/device/src/Transport/AmqpIot/AmqpIotMessageConverter.cs [184:270]
public static void UpdateAmqpMessageHeadersAndProperties(AmqpMessage amqpMessage, Message data, bool copyUserProperties = true)
{
amqpMessage.Properties.MessageId = data.MessageId;
if (data.To != null)
{
amqpMessage.Properties.To = data.To;
}
if (!data.ExpiryTimeUtc.Equals(default))
{
amqpMessage.Properties.AbsoluteExpiryTime = data.ExpiryTimeUtc;
}
if (data.CorrelationId != null)
{
amqpMessage.Properties.CorrelationId = data.CorrelationId;
}
if (data.UserId != null)
{
amqpMessage.Properties.UserId = new ArraySegment<byte>(Encoding.UTF8.GetBytes(data.UserId));
}
if (amqpMessage.ApplicationProperties == null)
{
amqpMessage.ApplicationProperties = new ApplicationProperties();
}
if (data.SystemProperties.TryGetValue(MessageSystemPropertyNames.Ack, out object propertyValue))
{
amqpMessage.ApplicationProperties.Map["iothub-ack"] = (string)propertyValue;
}
if (data.SystemProperties.TryGetValue(MessageSystemPropertyNames.MessageSchema, out propertyValue))
{
amqpMessage.ApplicationProperties.Map[MessageSystemPropertyNames.MessageSchema] = (string)propertyValue;
}
if (data.SystemProperties.TryGetValue(MessageSystemPropertyNames.CreationTimeUtc, out propertyValue))
{
// Convert to string that complies with ISO 8601
amqpMessage.ApplicationProperties.Map[MessageSystemPropertyNames.CreationTimeUtc] = ((DateTime)propertyValue).ToString("o", CultureInfo.InvariantCulture);
}
if (data.SystemProperties.TryGetValue(MessageSystemPropertyNames.ContentType, out propertyValue))
{
amqpMessage.Properties.ContentType = (string)propertyValue;
}
if (data.SystemProperties.TryGetValue(MessageSystemPropertyNames.ContentEncoding, out propertyValue))
{
amqpMessage.Properties.ContentEncoding = (string)propertyValue;
}
if (data.SystemProperties.TryGetValue(MessageSystemPropertyNames.OutputName, out propertyValue))
{
amqpMessage.ApplicationProperties.Map[MessageSystemPropertyNames.OutputName] = (string)propertyValue;
}
if (data.SystemProperties.TryGetValue(MessageSystemPropertyNames.InterfaceId, out propertyValue))
{
amqpMessage.MessageAnnotations.Map[MessageSystemPropertyNames.InterfaceId] = (string)propertyValue;
}
if (data.SystemProperties.TryGetValue(MessageSystemPropertyNames.ComponentName, out propertyValue))
{
amqpMessage.MessageAnnotations.Map[MessageSystemPropertyNames.ComponentName] = (string)propertyValue;
}
if (copyUserProperties && data.Properties.Count > 0)
{
foreach (KeyValuePair<string, string> pair in data.Properties)
{
if (TryGetAmqpObjectFromNetObject(pair.Value, MappingType.ApplicationProperty, out object amqpObject))
{
amqpMessage.ApplicationProperties.Map[pair.Key] = amqpObject;
}
}
}
if (IotHubClientDiagnostic.HasDiagnosticProperties(data))
{
amqpMessage.MessageAnnotations.Map[AmqpDiagIdKey] = data.SystemProperties[MessageSystemPropertyNames.DiagId];
amqpMessage.MessageAnnotations.Map[AmqpDiagCorrelationContextKey] = data.SystemProperties[MessageSystemPropertyNames.DiagCorrelationContext];
}
}