Example #1
0
        public CitiesCache(GeocoderApiInstance geocoderApi, ScheduleCityCodeApiInstance cityCodeApi, TimeSpan updateCachePeriod)
        {
            _cities      = new List <Item>();
            _geocoderApi = geocoderApi;
            _cityCodeApi = cityCodeApi;
            _syncRoot    = new SingleConcurrencyBlock();
            _timer       = new Timer(UpdateCache, null, updateCachePeriod, updateCachePeriod);

            CacheLimit       = 500;
            LastCacheUpdated = DateTime.Now;
        }
Example #2
0
        public async Task InitializationAsync(IServiceCollection services, IConfiguration configuration)
        {
            await Task.Run(() =>
            {
                var geocoderApiKey       = configuration["GeocoderApiKey"] ?? Guid.NewGuid().ToString();
                var yandexScheduleApiKey = configuration["YandexScheduleApiKey"] ?? Guid.NewGuid().ToString();
                var cacheUpdatePeriod    = configuration["CacheUpdatePeriod"];

                var geocoderApi = new GeocoderApiInstance(geocoderApiKey);
                var cityCodeApi = new ScheduleCityCodeApiInstance(yandexScheduleApiKey);
                var threadApi   = new ScheduleThreadApiInstance(yandexScheduleApiKey);

                services.AddSingleton(new CitiesCache(geocoderApi, cityCodeApi, ParseCacheUpatePeriod(cacheUpdatePeriod)));
                services.AddSingleton(new ScheduleApiInstance(yandexScheduleApiKey));
                services.AddSingleton(new ScheduleThreadApiInstance(yandexScheduleApiKey));
            })
            .ConfigureAwait(continueOnCapturedContext: false);
        }