Exemple #1
0
        // Change the device model simulation details, using the override information
        public DeviceModel Generate(DeviceModel source, Models.Simulation.DeviceModelOverride overrideInfo)
        {
            // Generate a clone, so that the original instance remains untouched
            var result = CloneObject(source);

            if (overrideInfo == null)
            {
                return(result);
            }

            this.UpdateDeviceModelSimulationScriptsCount(overrideInfo.Simulation?.Scripts, result);
            this.UpdateDeviceModelTelemetryCount(overrideInfo.Telemetry, result);

            this.SetSimulationInitialState(overrideInfo.Simulation?.InitialState, result);
            this.SetSimulationInterval(overrideInfo.Simulation?.Interval, result);
            this.SetSimulationScripts(overrideInfo.Simulation?.Scripts, result);
            this.SetTelemetry(overrideInfo.Telemetry, result);

            return(result);
        }
Exemple #2
0
        /// <summary>
        /// Get a device model and apply the overrides from the given simulation.
        /// </summary>
        public async Task <DeviceModel> GetWithOverrideAsync(string id, Models.Simulation simulation)
        {
            var modelDef = new DeviceModel();

            var equals = new Func <string, string, bool>(
                (x, y) => string.Equals(x, y, StringComparison.InvariantCultureIgnoreCase));

            if (equals(id, CUSTOM_DEVICE_MODEL_ID))
            {
                modelDef.Id          = CUSTOM_DEVICE_MODEL_ID;
                modelDef.Name        = CUSTOM_DEVICE_MODEL_ID;
                modelDef.Description = "Simulated device with custom list of sensors";
            }
            else
            {
                modelDef = await this.GetAsync(id);
            }

            Models.Simulation.DeviceModelOverride overrides = simulation.DeviceModels
                                                              .Where(x => equals(x.Id, id))
                                                              .Select(x => x.Override).FirstOrDefault();

            return(this.deviceModelsOverriding.Generate(modelDef, overrides));
        }