private DeviceModel GetDeviceModel(string id, Simulation.DeviceModelOverride overrides) { var modelDef = new DeviceModel(); if (id.ToLowerInvariant() != DeviceModels.CUSTOM_DEVICE_MODEL_ID.ToLowerInvariant()) { try { var task = this.deviceModels.GetAsync(id); task.Wait(TimeSpan.FromSeconds(30)); modelDef = task.Result; } catch (AggregateException ae) { throw new ExternalDependencyException("Unable to load device model", ae.InnerException); } } else { modelDef.Id = DeviceModels.CUSTOM_DEVICE_MODEL_ID; modelDef.Name = DeviceModels.CUSTOM_DEVICE_MODEL_ID; modelDef.Description = "Simulated device with custom list of sensors"; } return(this.deviceModelsOverriding.Generate(modelDef, overrides)); }
private Simulation.DeviceModelOverride GetDeviceModelOverride() { var deviceModelOverride = new Simulation.DeviceModelOverride() { Simulation = new Simulation.DeviceModelSimulationOverride(), Telemetry = new List <Simulation.DeviceModelTelemetryOverride>() }; return(deviceModelOverride); }
// Map service model to API model public static DeviceModelApiModelOverride FromServiceModel(Simulation.DeviceModelOverride value) { if (value == null) { return(null); } return(new DeviceModelApiModelOverride { Simulation = DeviceModelSimulationOverride.FromServiceModel(value.Simulation), Telemetry = DeviceModelTelemetryOverride.FromServiceModel(value.Telemetry) }); }
// Map API model to service model public Simulation.DeviceModelOverride ToServiceModel() { if (this.IsEmpty()) { return(null); } var result = new Simulation.DeviceModelOverride { Simulation = this.Simulation?.ToServiceModel() }; var items = this.Telemetry?.Where(x => !x.IsEmpty()).ToList(); if (items?.Count > 0) { result.Telemetry = this.Telemetry.Where( x => !x.IsEmpty()).Select(x => x.ToServiceModel()).ToList(); } return(result); }