Ejemplo n.º 1
0
        public CountryMetadataProviderImpl(IServiceProvider serviceProvider, ILogger <CountryMetadataProviderImpl> logger)
        {
            _logger = logger;

            _countryProvider = new CountryProvider();

            var countries = _countryProvider.GetCountries();

            foreach (var country in countries)
            {
                var alpha2Code = country.Alpha2Code;

                var countryCode = Enum.GetName(typeof(Alpha2Code), alpha2Code).ToLower();

                var countryNameEn = _countryProvider.GetCountryTranslatedName(alpha2Code, LanguageCode.EN);

                if (string.IsNullOrEmpty(countryNameEn))
                {
                    throw new Exception($"Country name for {alpha2Code} is missing (EN)");
                }

                var countryNameDe = _countryProvider.GetCountryTranslatedName(alpha2Code, LanguageCode.DE);

                if (string.IsNullOrEmpty(countryNameDe))
                {
                    throw new Exception($"Country name for {alpha2Code} is missing (DE)");
                }

                _localizedCountryNameMappings["en"].Add(new CountryCodeNameMapping()
                {
                    CountryCode = countryCode,
                    Name        = countryNameEn
                });

                _localizedCountryNameMappings["de"].Add(new CountryCodeNameMapping()
                {
                    CountryCode = countryCode,
                    Name        = countryNameDe
                });

                _validCountryCodes.Add(countryCode);
            }

            _localizedCountryNameMappings["en"].Sort((country1, country2) =>
            {
                return(string.Compare(country1.Name, country2.Name));
            });

            _localizedCountryNameMappings["de"].Sort((country1, country2) =>
            {
                return(string.Compare(country1.Name, country2.Name));
            });

            _geoIP2DatabaseReader = serviceProvider.GetRequiredService <IGeoIP2DatabaseReader>();
        }
Ejemplo n.º 2
0
 public MaxMind(IOptions <AppConfig> config)
 {
     _cityDb = new DatabaseReader(config.Value.MaxMindCityPath);
     _asnDb  = new DatabaseReader(config.Value.MaxMindAsnPath);
 }
Ejemplo n.º 3
0
 public ShortUrlLogger(IUrlRepository urlRepository, IGeoIP2DatabaseReader geoIp, Parser uaParser)
 {
     _urlRepository = urlRepository;
     _geoIp         = geoIp;
     _uaParser      = uaParser;
 }