Example #1
0
        public void ValidateInputRequest(ILogger log)
        {
            const string NO_INTERVAL         = "Device model telemetry must contains a valid interval";
            const string NO_MESSAGE_TEMPLATE = "Device model telemetry must contains a valid message template";
            const string NO_MESSAGE_SCHEMA   = "Device model telemetry must contains a valid message schema";

            try
            {
                IntervalHelper.ValidateInterval(this.Interval);
            }
            catch (InvalidIntervalException exception)
            {
                log.Error(NO_INTERVAL, () => new { deviceModelTelemetry = this, exception });
                throw new BadRequestException(NO_INTERVAL);
            }

            if (string.IsNullOrEmpty(this.MessageTemplate))
            {
                log.Error(NO_MESSAGE_TEMPLATE, () => new { deviceModelTelemetry = this });
                throw new BadRequestException(NO_MESSAGE_TEMPLATE);
            }

            if (this.MessageSchema.IsEmpty())
            {
                log.Error(NO_MESSAGE_SCHEMA, () => new { deviceModelTelemetry = this });
                throw new BadRequestException(NO_MESSAGE_SCHEMA);
            }
        }
Example #2
0
        // Validate device model simulation state:
        // Required fields: Interval and Scripts
        public void ValidateInputRequest(ILogger log)
        {
            const string NO_INTERVAL = "Device model simulation state must contains a valid interval";
            const string NO_SCRIPTS  = "Device model simulation state must contains a valid script";

            try
            {
                IntervalHelper.ValidateInterval(this.Interval);
            }
            catch (InvalidIntervalException exception)
            {
                log.Error(NO_INTERVAL, () => new { deviceModelSimulation = this, exception });
                throw new BadRequestException(NO_INTERVAL);
            }

            if (this.Scripts == null || this.Scripts.Count == 0)
            {
                log.Error(NO_SCRIPTS, () => new { deviceModelSimulation = this });
                throw new BadRequestException(NO_SCRIPTS);
            }
            else
            {
                foreach (var script in this.Scripts)
                {
                    script.ValidateInputRequest(log);
                }
            }
        }