Exemple #1
0
        private async Task ProcessSensorData(
            SensorDataDto sensorData,
            CancellationToken cancellationToken)
        {
            Console.WriteLine($"Consumer with id: {_consumerId} " +
                              $"received SensorData with id: {sensorData.Id}");

            if (sensorData.Type != "SensorData")
            {
                Console.WriteLine(
                    $"Type '{sensorData.Type}' is not supported yet. " +
                    $"Only 'SensorData' can be processed. " +
                    $"Message will be ignored.");

                return;
            }


            var entity = new SensorDataEntity
            {
                Id        = sensorData.Id,
                Timestamp = sensorData.Timestamp,
                Data      = FilterSensorsData(sensorData.Data)
            };

            await _database.InsertSensorData(
                entity,
                cancellationToken);
        }
Exemple #2
0
        public async Task InsertSensorData(
            SensorDataEntity entity,
            CancellationToken cancellationToken)
        {
            await using var dbContext = new SensorsContext(
                            _connectionString);

            await dbContext.AddAsync(
                entity,
                cancellationToken);

            await dbContext.SaveChangesAsync(
                cancellationToken);
        }