// 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);
        }
        // Map service model to API model
        public static DeviceModelTelemetry FromServiceModel(DeviceModel.DeviceModelMessage value)
        {
            if (value == null)
            {
                return(null);
            }

            var result = new DeviceModelTelemetry
            {
                Interval        = value.Interval.ToString("c"),
                MessageTemplate = value.MessageTemplate,
                MessageSchema   = DeviceModelTelemetryMessageSchema.FromServiceModel(value.MessageSchema)
            };

            return(result);
        }
예제 #3
0
        // Map API model to service model
        public static DeviceModelMessage ToServiceModel(DeviceModelTelemetry value)
        {
            if (value == null)
            {
                return(null);
            }

            var result = new DeviceModelMessage
            {
                Interval        = TimeSpan.Parse(value.Interval),
                MessageTemplate = value.MessageTemplate,
                MessageSchema   = DeviceModelTelemetryMessageSchema.ToServiceModel(value.MessageSchema)
            };

            return(result);
        }