// Map service model to API model public static DeviceModelApiModel FromServiceModel(DeviceModel value) { if (value == null) { return(null); } var result = new DeviceModelApiModel { Id = value.Id, Version = value.Version, Name = value.Name, Description = value.Description, Protocol = value.Protocol.ToString(), Simulation = DeviceModelSimulation.FromServiceModel(value.Simulation) }; foreach (var property in value.Properties) { result.Properties.Add(property.Key, property.Value); } foreach (var message in value.Telemetry) { result.Telemetry.Add(DeviceModelTelemetry.FromServiceModel(message)); } foreach (var method in value.CloudToDeviceMethods) { result.CloudToDeviceMethods.Add(method.Key, DeviceModelSimulationScript.FromServiceModel(method.Value)); } return(result); }
private Microsoft.Azure.IoTSolutions.DeviceSimulation.WebService.v1.Models.DeviceModelApiModel.DeviceModelApiModel GetValidDeviceModelApiModel() { var deviceModelApiModel = new Microsoft.Azure.IoTSolutions.DeviceSimulation.WebService.v1.Models.DeviceModelApiModel.DeviceModelApiModel { Id = "id", Type = "Custom", ETag = "Etag_1", Protocol = "AMQP", Telemetry = new List <DeviceModelTelemetry>() { new DeviceModelTelemetry() { Interval = "00:00:10", MessageTemplate = "template", MessageSchema = new DeviceModelTelemetryMessageSchema() { Name = "name", Format = "JSON", Fields = new Dictionary <string, string>() { { "key", "value" } } } } }, Simulation = new DeviceModelSimulation() { Interval = "00:00:10", Scripts = new List <DeviceModelSimulationScript>() { new DeviceModelSimulationScript() { Type = "type", Path = "path", Params = JObject.Parse("{\"ccc\":{\"Min\":\"1\",\"Max\":\"11\",\"Step\":1,\"Unit\":\"y\"}}") } } } }; return(deviceModelApiModel); }