Example #1
0
 public void TryToDownloadAllFiles()
 {
     foreach (var file in SxGeoDownloader.SypexGeoDatabases)
     {
         SxGeoDownloader downloader = new SxGeoDownloader(file, "./Resources/SxGeo_tmp.dat", true);
         Assert.True(downloader.Download());
     }
     File.Delete("./Resources/SxGeo_tmp.dat");
 }
Example #2
0
        public ReadDBTestPhp()
        {
            SxGeoDownloader downloader = new SxGeoDownloader("https://sypexgeo.net/files/SxGeoCountry.zip",
                                                             "./Resources/SxGeo.dat");

            downloader.Download();
            downloader = new SxGeoDownloader("https://sypexgeo.net/files/SxGeoCity_utf8.zip",
                                             "./Resources/SxGeoCity.dat");
            downloader.Download();
        }
        public SxGeoProvider(ICountryResolverOptions options, ILogger <SxGeoProvider> logger)
        {
            this.logger = logger;
            if (options.DownloadOnStart || !File.Exists(options.Path))
            {
                SxGeoDownloader downloader = new SxGeoDownloader(options.URL, options.Path, true);
                if (!downloader.Download())
                {
                    // for strage case with certificate, use last database
                    if (File.Exists(options.Path))
                    {
                        logger?.LogError(new FileNotFoundException("Can't download database!"), "[ALERT] Can't download database! For strage case with certificate, use last database!");
                    }
                    else
                    {
                        // if you get a throw check this line
                        throw new FileNotFoundException("Can't download database!");
                    }
                }
            }

            sxGeo = new SxGeo(options.Path);
        }