private void InitializeDeviceClients() { _logger.LogInformation("Initializing device clients..."); var tenantConfiguration = new List <TenantConfiguration>(); _configuration.Bind("SimulatedDevices:Tenants", tenantConfiguration); foreach (var tenant in tenantConfiguration) { var deviceClients = new List <DeviceInfo>(); for (int i = 0; i < tenant.NumberOfDevices; i++) { deviceClients.Add(new DeviceInfo { DeviceId = TenantConfiguration.BuildDeviceName(tenant, i), DeviceClient = DeviceClient.CreateFromConnectionString( _configuration["IotHubConnectionString"], TenantConfiguration.BuildDeviceName(tenant, i)) }); } _tenantDeviceClients.Add(tenant, deviceClients); } _logger.LogInformation($"Registered {_tenantDeviceClients.Sum(t => t.Value.Count)} device clients"); }
public async Task RegisterDevicesAsync() { _logger.LogInformation("Preparing device registrations..."); Task[] tasks = new Task[_tenantConfigurations.Sum(t => t.NumberOfDevices)]; int i = 0; foreach (var tenant in _tenantConfigurations) { for (int j = 0; j < tenant.NumberOfDevices; j++) { tasks[i++] = RegisterDeviceAsync(TenantConfiguration.BuildDeviceName(tenant, j)); } } await Task.WhenAll(tasks).ConfigureAwait(false); _logger.LogInformation($"Registered {tasks.Length} devices"); }