コード例 #1
0
        public GeoIpService(ISettingsProvider settingsProvider, INotificationService notificationService, ILogger logger)
        {
            _notificationService = notificationService ?? throw new InvalidOperationException();
            _logger = logger ?? throw new ArgumentNullException(nameof(logger));

            ThreadManager.Initialise();
            _geoIpSettings = settingsProvider.GetSettings <GeoIpPluginSettings>("SieraDeltaGeoIpPluginConfiguration");

            // if the connection string is a file, it contains the actual connection string, load it
            if (_geoIpSettings.DatabaseConnectionString.IndexOfAny(Path.GetInvalidPathChars()) == -1 &&
                File.Exists(_geoIpSettings.DatabaseConnectionString))
            {
                using (StreamReader rdr = new StreamReader(_geoIpSettings.DatabaseConnectionString))
                {
                    _geoIpSettings.DatabaseConnectionString = rdr.ReadToEnd();
                }
            }

            ThreadManager dataThread = null;

            switch (_geoIpSettings.GeoIpProvider)
            {
            case Enums.GeoIpProvider.Firebird:
                dataThread = new FirebirdDataProvider(_geoIpSettings, _tempIpCity);
                break;

            case Enums.GeoIpProvider.MySql:
                dataThread = new MySqlProvider(_geoIpSettings, _tempIpCity);
                break;

            case Enums.GeoIpProvider.MSSql:
                dataThread = new MSSQLProvider(_geoIpSettings, _tempIpCity);
                break;

            default:
                throw new InvalidOperationException();
            }

            _geoIpProvider = dataThread as IGeoIpProvider;

            if (_geoIpSettings.CacheAllData)
            {
                dataThread.ThreadFinishing += Thread_ThreadFinishing;
                ThreadManager.ThreadStart(dataThread, "Load GeoIp Data", System.Threading.ThreadPriority.Highest);
            }

            // create the cache
            _geoIpCache = new CacheManager("GeoIp Data Cache", new TimeSpan(24, 0, 0), true, false);
        }
コード例 #2
0
 public MSSQLProvider(GeoIpPluginSettings settings, List <IpCity> ipRangeData)
     : base(ipRangeData, new TimeSpan(24, 0, 0))
 {
     base.ContinueIfGlobalException = true;
     _settings = settings ?? throw new ArgumentNullException(nameof(settings));
 }