public GeoIpMiddleware(RequestDelegate next, IGeoIpProvider provider, IGeoIpCache cache) { this.next = next; this.provider = provider ?? throw new Exception("No geoIp provider was injected"); this.cache = cache; }
public GeolocationByIpController ( IGeoIpProvider provider, ILogger <GeolocationByIpController>?logger = null ) { _provider = provider; _logger = logger; }
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); }
/// <summary> /// Default constructor /// </summary> /// <param name="hostingEnvironment">IHostingEnvironment instance</param> /// <param name="settingsProvider">ISettingsProvider instance</param> /// <param name="geoIpProvider">IGeoIpProvider instance</param> /// <param name="logger">ILogger instance</param> public DefaultUserSessionService(IHostingEnvironment hostingEnvironment, ISettingsProvider settingsProvider, IGeoIpProvider geoIpProvider, ILogger logger) : this() { if (hostingEnvironment == null) { throw new ArgumentNullException(nameof(hostingEnvironment)); } if (settingsProvider == null) { throw new ArgumentNullException(nameof(settingsProvider)); } _geoIpProvider = geoIpProvider ?? throw new ArgumentNullException(nameof(geoIpProvider)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); UserSessionSettings settings = settingsProvider.GetSettings <UserSessionSettings>(Constants.UserSessionConfiguration); if (!settings.EnableDefaultSessionService) { return; } _enabled = true; ContinueIfGlobalException = true; if (String.IsNullOrEmpty(settings.SessionRootPath)) { settings.SessionRootPath = hostingEnvironment.ContentRootPath; } _rootPath = Path.Combine(settings.SessionRootPath, "UserSession"); _activeSessionPath = GetPath("ActiveSessions"); _pageViewFile = GetFile(Path.Combine(_rootPath, "Sessions"), "PageViews.dat"); _referrerFile = GetFile(Path.Combine(_rootPath, "Sessions"), "InitialReferrer.dat"); _sessionHourlyFile = GetFile(Path.Combine(_rootPath, "Sessions"), "Hourly.dat"); _sessionDailyFile = GetFile(Path.Combine(_rootPath, "Sessions"), "Daily.dat"); _sessionWeeklyFile = GetFile(Path.Combine(_rootPath, "Sessions"), "Weekly.dat"); _sessionMonthlyFile = GetFile(Path.Combine(_rootPath, "Sessions"), "Monthly.dat"); _sessionYearlyFile = GetFile(Path.Combine(_rootPath, "Sessions"), "Yearly.dat"); _maxHours = settings.MaxHourlyData; _maxDays = settings.MaxDailyData; _maxWeeks = settings.MaxWeeklyData; _maxMonths = settings.MaxMonthlyData; _maxYears = settings.MaxYearlyData; LoadSessionData(_pageViewFile, ref _sessionPageViews); LoadSessionData(_referrerFile, ref _initialReferrers); LoadSessionData(_sessionHourlyFile, ref _hourlySessionData); LoadSessionData(_sessionDailyFile, ref _dailySessionData); LoadSessionData(_sessionWeeklyFile, ref _weeklySessionData); LoadSessionData(_sessionMonthlyFile, ref _monthlySessionData); LoadSessionData(_sessionYearlyFile, ref _yearlySessionData); ThreadManager.ThreadStart(this, "Default User Session Service", System.Threading.ThreadPriority.BelowNormal); }