// Map service model to API model public static DeviceModelTelemetryMessageSchemaOverride FromServiceModel(Simulation.DeviceModelTelemetryMessageSchemaOverride value) { if (value == null) { return(null); } var result = new DeviceModelTelemetryMessageSchemaOverride { Name = !string.IsNullOrEmpty(value.Name) ? value.Name : null, Format = value.Format?.ToString() }; if (value.Fields != null && value.Fields.Count > 0) { result.Fields = new Dictionary <string, string>(); foreach (var field in value.Fields) { result.Fields.Add(field.Key, field.Value.ToString()); } } return(result); }
// Map API model to service model public Simulation.DeviceModelTelemetryMessageSchemaOverride ToServiceModel() { if (this.IsEmpty()) { return(null); } var result = new Simulation.DeviceModelTelemetryMessageSchemaOverride { Name = !string.IsNullOrEmpty(this.Name) ? this.Name : null, Format = null, Fields = null }; // Map the list of fields if (this.Fields != null && this.Fields.Count > 0) { result.Fields = new Dictionary <string, DeviceModel.DeviceModelMessageSchemaType>(); foreach (KeyValuePair <string, string> field in this.Fields) { var fieldType = Enum.TryParse(field.Value, true, out DeviceModel.DeviceModelMessageSchemaType schemaType) ? schemaType : DeviceModel.DeviceModelMessageSchemaType.Object; result.Fields.Add(field.Key, fieldType); } } // Map the message format if (!string.IsNullOrEmpty(this.Format) && Enum.TryParse(this.Format, true, out DeviceModel.DeviceModelMessageSchemaFormat format)) { result.Format = format; } return(result); }
private Simulation.DeviceModelTelemetryMessageSchemaOverride GetMessageSchemaOverride() { var messageSchemaOverride = new Simulation.DeviceModelTelemetryMessageSchemaOverride(); return(messageSchemaOverride); }