Esempio n. 1
0
        public Task UpsertWeatherDtoAsync(List <WeatherDto> weatherDtos)
        {
            if (!weatherDtos.Any())
            {
                return(Task.CompletedTask);
            }
            var localeId = weatherDtos.First().LocaleId;

            var entity = _databaseContext.WeatherCache.FirstOrDefault(x => x.LocaleId == localeId);

            if (entity != null)
            {
                entity.Json = JsonConvert.SerializeObject(weatherDtos);
                _databaseContext.WeatherCache.Update(entity);
            }
            else
            {
                var newEntity = new WeatherCache()
                {
                    LocaleId = localeId,
                    Json     = JsonConvert.SerializeObject(weatherDtos)
                };
                _databaseContext.WeatherCache.Add(newEntity);
            }
            return(_databaseContext.SaveChangesAsync());
        }
Esempio n. 2
0
        private void InternalStart()
        {
            var clock = this.createClock();
            var cache = new WeatherCache(clock);

            this.m_processor = new ProcessingService(this.m_config.ServiceName,
                                                     new SensorMappingRepository(this.m_config.DsmrProductConnectionString),
                                                     new DataPointRepository(this.m_config.DsmrOlapConnectionString),
                                                     new ProcessingHistoryRepository(this.m_config.DsmrOlapConnectionString, clock),
                                                     this.createDataClient(),
                                                     clock,
                                                     new WeatherService(cache, new OpenWeatherMapClient(), this.m_config));
            this.m_timers.Add(new DataReloadService(this.m_processor,
                                                    TimeSpan.Zero,
                                                    TimeSpan.FromSeconds(60)));
        }