Ejemplo n.º 1
0
        public async Task Execute(object state)
        {
            var keys = redisCacheService.GetKeys();

            foreach (var key in keys)
            {
                try
                {
                    var len = await redisCacheService.LengthAsync(key);

                    for (var i = 0; i < len; i++)
                    {
                        var value = await redisCacheService.PopBackAsync(key);

                        var message = MqttBroadcastMessage.ParseFromJson(value);
                        switch (message.Topic)
                        {
                        case Topics.HomeTemperatureHumidity:
                            await temperatureHumidityRepository.CreateAsync(message.ToTemperatureHumidityModel());

                            break;

                        case Topics.HomeMotionSense:
                            await motionDetectionRepository.CreateAsync(message.ToMotionDetectionModel());

                            break;
                        }
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }
        }