public async Task ValidateInputRequestAsync(ILogger log, IConnectionStringValidation connectionStringValidation) { const string NO_DEVICE_MODEL = "The simulation doesn't contain any device model"; const string ZERO_DEVICES = "The simulation has zero devices"; const string END_TIME_BEFORE_START_TIME = "The simulation End Time must be after the Start Time"; const string INVALID_DATE = "Invalid date format"; const string CANNOT_RUN_IN_THE_PAST = "The simulation end date is in the past"; const string NO_IOTHUB_CONNSTRING = "The simulation doesn't contain any IoTHub connection string"; // A simulation must contain at least one device model if (this.DeviceModels.Count < 1) { log.Error(NO_DEVICE_MODEL, () => new { simulation = this }); throw new BadRequestException(NO_DEVICE_MODEL); } // A simulation must use at least one device if (this.DeviceModels.Sum(x => x.Count) < 1) { log.Error(ZERO_DEVICES, () => new { simulation = this }); throw new BadRequestException(ZERO_DEVICES); } try { var now = DateTimeOffset.UtcNow; var startTime = DateHelper.ParseDateExpression(this.StartTime, now); var endTime = DateHelper.ParseDateExpression(this.EndTime, now); // The start time must be before the end time if (startTime.HasValue && endTime.HasValue && startTime.Value.Ticks >= endTime.Value.Ticks) { log.Error(END_TIME_BEFORE_START_TIME, () => new { simulation = this }); throw new BadRequestException(END_TIME_BEFORE_START_TIME); } // The end time cannot be in the past if (endTime.HasValue && endTime.Value.Ticks <= now.Ticks) { log.Error(CANNOT_RUN_IN_THE_PAST, () => new { simulation = this }); throw new BadRequestException(CANNOT_RUN_IN_THE_PAST); } } catch (InvalidDateFormatException e) { log.Error(INVALID_DATE, () => new { simulation = this }); throw new BadRequestException(INVALID_DATE, e); } // A simulation contains at least one iothub connect string if (this.IotHubs.Count == 0) { throw new BadRequestException(NO_IOTHUB_CONNSTRING); } foreach (var iotHub in this.IotHubs) { await connectionStringValidation.TestAsync(iotHub.ConnectionString, true); } }
public ConnectionStrings( IServicesConfig config, IConnectionStringValidation connectionStringValidation, IFactory factory, IDiagnosticsLogger diagnosticsLogger, ILogger logger) { this.config = config; this.connectionStringValidation = connectionStringValidation; this.mainStorage = factory.Resolve <IStorageRecords>().Init(config.MainStorage); this.log = logger; this.diagnosticsLogger = diagnosticsLogger; }
public ConnectionStrings( IServicesConfig config, IConnectionStringValidation connectionStringValidation, IEngines engines, IDiagnosticsLogger diagnosticsLogger, ILogger logger) { this.config = config; this.connectionStringValidation = connectionStringValidation; this.mainStorage = engines.Build(config.MainStorage); this.log = logger; this.diagnosticsLogger = diagnosticsLogger; }
public SimulationsController( ISimulations simulationsService, IConnectionStringValidation connectionStringValidation, IIothubMetrics iothubMetrics, IRateLimitingConfig defaultRatingConfig, IPreprovisionedIotHub preprovisionedIotHub, ISimulationAgent simulationAgent, IFactory factory, ILogger logger) { this.simulationsService = simulationsService; this.connectionStringValidation = connectionStringValidation; this.iothubMetrics = iothubMetrics; this.defaultRatingConfig = defaultRatingConfig; this.simulationAgent = simulationAgent; this.factory = factory; this.log = logger; }