public void TestInit() { Startup.InitApp(); _app = Startup.BooksApp; _timersControl = _app.GetService <ITimerServiceControl>(); _jobDiagService = _app.GetService <IJobDiagnosticsService>(); }
public WebCallContextHandler(EntityApp app, WebCallContextHandlerSettings settings) { App = app; Settings = settings ?? new WebCallContextHandlerSettings(); App.RegisterConfig(Settings); _webCallLog = App.GetService<IWebCallLogService>(); _errorLog = App.GetService<IErrorLogService>(); App.RegisterService<IWebCallNotificationService>(this); }
public void Init(EntityApp app) { _smtpService = _app.GetService <ISmtpService>(); Util.Check(_smtpService != null, "EmailNotificationProvider: failed to retrieve {0} instance.", typeof(ISmtpService)); _templateService = _app.GetService <ITemplateTransformService>(); Util.Check(_templateService != null, "EmailNotificationProvider: failed to retrieve {0} instance, add Template module to your app.", typeof(ITemplateTransformService)); }
public LogFileWriter(EntityApp app, string logPath) { _app = app; LogPath = logPath; _logService = app.GetService <IOperationLogService>(); _saveService = app.GetService <IBackgroundSaveService>(); _saveService.Saving += SaveService_Saving; }
public void Init(EntityApp app) { _app = app; _errorLog = _app.GetService<IErrorLogService>(); _operationLog = _app.GetService<IOperationLogService>(); _timerService = _app.GetService<ITimerService>(); _timerService.Elapsed1Second += TimerService_Elapsed1Second; _app.AppEvents.FlushRequested += Events_FlushRequested; }
public void Init(EntityApp app) { _app = app; _errorLog = _app.GetService <IErrorLogService>(); _operationLog = _app.GetService <IOperationLogService>(); _timerService = _app.GetService <ITimerService>(); _timerService.Elapsed1Second += TimerService_Elapsed1Second; _app.AppEvents.FlushRequested += Events_FlushRequested; }
public WebCallContextHandler(EntityApp app, WebCallContextHandlerSettings settings) { App = app; Settings = settings ?? new WebCallContextHandlerSettings(); App.RegisterConfig(Settings); _webCallLog = App.GetService <IWebCallLogService>(); _errorLog = App.GetService <IErrorLogService>(); _sessionService = App.GetService <IUserSessionService>(); App.RegisterService <IWebCallNotificationService>(this); }
public DbVersionInfo LoadDbVersionInfo(DbModelLoader loader) { var infoProvider = _app.GetService <IDbInfoService>(); if (infoProvider == null) { return(null); } var versionInfo = infoProvider.LoadDbInfo(_database.Settings, _app.AppName, loader); loader.VersionInfo = versionInfo; return(versionInfo); }
public FullSetEntityCache(EntityApp app, CacheSettings settings, IDataStore dataStore, StringCaseMode caseMode) { _app = app; _settings = settings; _dataStore = dataStore; _caseMode = caseMode; _queryCache = new ObjectCache <string, EntityCacheQuery> (expirationSeconds: 5 * 60, maxLifeSeconds: 10 * 60); _timeService = _app.GetService <ITimeService>(); _errorLog = _app.GetService <IErrorLogService>(); OpContext = new OperationContext(_app, UserInfo.System); CurrentVersion = 0; _loadStatus = CacheLoadStatus.NonCurrent; }
public EntityCache(EntityApp app, CacheSettings settings, Database database) { _app = app; Settings = settings; _dataStore = database; _sparseCache = new SparseEntityCache(Settings); var dbIsCaseInsensitive = database.Settings.Driver.Features.IsSet(Data.Driver.DbFeatures.DefaultCaseInsensitive); var caseMode = dbIsCaseInsensitive ? StringCaseMode.CaseInsensitive : StringCaseMode.CaseSensitive; _fullSetCache = new FullSetEntityCache(_app, Settings, _dataStore, caseMode); _timeService = _app.GetService<ITimeService>(); _logService = _app.GetService<IOperationLogService>(); _errorLog = _app.GetService<IErrorLogService>(); MarkCachedEntities(); _app.AppEvents.SavedChanges += Events_SavedChanges; }
public DbUpgradeManager(Database database, ILog log) { _database = database; _log = log; _app = _database.DbModel.EntityApp; _dbInfoService = (IDbInfoService)_app.GetService(typeof(IDbInfoService)); }
public EntityCache(EntityApp app, CacheSettings settings, Database database) { _app = app; Settings = settings; _dataStore = database; _sparseCache = new SparseEntityCache(Settings); var dbIsCaseInsensitive = database.Settings.Driver.Features.IsSet(Data.Driver.DbFeatures.DefaultCaseInsensitive); var caseMode = dbIsCaseInsensitive ? StringCaseMode.CaseInsensitive : StringCaseMode.CaseSensitive; _fullSetCache = new FullSetEntityCache(_app, Settings, _dataStore, caseMode); _timeService = _app.GetService <ITimeService>(); _logService = _app.GetService <IOperationLogService>(); _errorLog = _app.GetService <IErrorLogService>(); MarkCachedEntities(); _app.AppEvents.SavedChanges += Events_SavedChanges; }
public DbUpgradeManager(Database database, IActivationLog log) { _database = database; _log = log; _app = _database.DbModel.EntityApp; _dbInfoService = _app.GetService <IDbInfoService>(throwIfNotFound: false); }
public void Init(EntityApp app) { if (_initialized) { return; //prevent double initialization } var timers = app.GetService <ITimerService>(); // create buffer and hook it _buffer = new ActiveBatchingBuffer <LogEntry>(timers, _batchSize, _interval); var logService = app.GetService <ILogService>(); logService.Subscribe(_buffer); // logService -> _buffer _buffer.Subscribe(Buffer_OnBatchProduced); // _buffer produces batches _initialized = true; }
public void Init(EntityApp app) { _errorLog = app.GetService <IErrorLogService>(); _timeService = TimeService.Instance; _timer = new Timer(Timer_Elapsed, null, 100, 100); app.AppEvents.Initializing += Events_Initializing; }
public DefaultOperationLogService(EntityApp app, LogLevel logLevel = Services.LogLevel.Details) { LogLevel = logLevel; _timerService = app.GetService<ITimerService>(); _timerService.Elapsed1Second += TimerService_Elapsed1Second; app.AppEvents.FlushRequested += Events_FlushRequested; }
public void Init(EntityApp app) { _log = app.GetService <ILogService>(); app.AppEvents.Initializing += Events_Initializing; _timer = new System.Timers.Timer(BaseTimerIntervalMs); _timer.Elapsed += Timer_Elapsed; _timer.Enabled = true; }
public void Init(EntityApp app) { _timerContext = app.CreateSystemContext(); _logService = app.GetService<IOperationLogService>(); _timer = new Timer(100); _timer.Elapsed += Timer_Elapsed; app.AppEvents.Initializing += Events_Initializing; }
public NotificationListener(EntityApp app, Func<NotificationMessage, bool> filter = null, bool blockAll = false, int maxMessages = 100) { _blockAll = blockAll; _filter = filter; _maxMessages = maxMessages; _notificationService = app.GetService<INotificationService>(); Util.Check(_notificationService != null, "Notification service is not registered."); _notificationService.Sending += NotificationService_Sending; }
public DbUpgradeManager(DataSource dataSource) { _dataSource = dataSource; _dataAccess = (DataAccessService) _dataSource.App.DataAccess; _database = _dataSource.Database; _app = _database.DbModel.EntityApp; _log = _app.ActivationLog; _timeService = _app.GetService<ITimeService>(); }
public LogFileWriter(EntityApp app, string logPath) { _app = app; LogPath = logPath; _logService = app.GetService<IOperationLogService>(); Util.Check(_logService != null, "OperationLog service not registered, cannot attach LogFileWriter."); if (_logService != null) _logService.Saving += logService_Saving; }
public DbUpgradeManager(DataSource dataSource) { _dataSource = dataSource; _dataAccess = (DataAccessService)_dataSource.App.DataAccess; _database = _dataSource.Database; _app = _database.DbModel.EntityApp; _log = _app.SystemLog; _timeService = _app.GetService <ITimeService>(); }
public NotificationListener(EntityApp app, Func <NotificationMessage, bool> filter = null, bool blockAll = false, int maxMessages = 100) { _blockAll = blockAll; _filter = filter; _maxMessages = maxMessages; _notificationService = app.GetService <INotificationService>(); Util.Check(_notificationService != null, "Notification service is not registered."); _notificationService.Sending += NotificationService_Sending; }
private static void EnableAppTimers(EntityApp app, bool enable) { var timers = app.GetService <ITimerServiceControl>(); if (timers != null) { timers.EnableAutoFire(enable); } }
public ActivationLog(string fileName, int maxEntries = 1000, EntityApp app = null) { _fileName = fileName; MaxEntries = maxEntries; if (app != null) { _globalLog = app.GetService <ILogService>(); _systemContext = new OperationContext(app, UserInfo.System); } }
public EntityModelBuilder(EntityApp app) { _app = app; Log = _app.ActivationLog; _customization = (EntityModelCustomizationService)_app.GetService <IEntityModelCustomizationService>(); Model = _app.Model = new EntityModel(_app); #if DEBUG RandomizeAttributesOrder = true; #endif }
public static ILogBatchingService GetCreateLogBatchingService(EntityApp app) { var iServ = (ILogBatchingService)app.GetService(typeof(ILogBatchingService)); if (iServ != null) { return(iServ); } // create and register it var batchingServ = new LogBatchingService(); app.RegisterService <ILogBatchingService>(batchingServ); batchingServ.Init(app); return(batchingServ); }
public void TestModuleIntegration() { var schema = "usr"; // Runs integrated app by Randy _app = new EntityApp(); var area = _app.AddArea(schema); var persModule = new Bob.PersonModule(area); var loginModule = new Alice.LoginModule(area, typeof(IPersonExt)); // Now replace original entities with new interfaces; // Alice's IUserStub is already replaced by Randy's IPersonExt. var custModelService = _app.GetService <IEntityModelCustomizationService>(); custModelService.ReplaceEntity(typeof(Alice.ILogin), typeof(IAppLogin)); custModelService.ReplaceEntity(typeof(Bob.IPerson), typeof(IPersonExt)); // activate Startup.ActivateApp(_app); //Test the resulting solution var session = _app.OpenSession(); var pers = session.NewEntity <IPersonExt>(); pers.FirstName = "John"; pers.LastName = "Dow"; pers.BirthDate = new DateTime(1970, 5, 1); pers.Gender = Gender.Male; var login = session.NewEntity <IAppLogin>(); var loginId = login.Id; login.User = pers; login.UserName = "******"; login.FriendlyName = "JohnD"; login.PasswordHash = 123; login.EmployeeNumber = "E111"; session.SaveChanges(); //Let's try to login the user we created using Alice's method session = _app.OpenSession(); var johnLogin = Alice.LoginModule.Login(session, "johnd", 123); var cmd = session.GetLastCommand(); Assert.IsNotNull(johnLogin, "Login failed"); } //method
private void OnUpgraded(List <DbUpgradeScript> appliedScripts, Exception exception = null, DbUpgradeScript failedScript = null) { DbUpgradeEventType eventType = exception == null ? DbUpgradeEventType.DbModelUpgraded : DbUpgradeEventType.Error; var args = new DbUpgradeEventArgs(_database, eventType, _upgradeInfo, exception, failedScript); _app.DataSourceEvents.OnDbUpgraded(args); var logService = (IDbUpgradeLogService)_app.GetService(typeof(IDbUpgradeLogService)); if (logService != null) { var oldVersionInfo = _upgradeInfo.OldDbModel.VersionInfo; var oldVersion = oldVersionInfo == null ? DbVersionInfo.ZeroVersion : oldVersionInfo.Version; var report = new DbUpgradeReport() { Version = _database.DbModel.VersionInfo.Version, OldDbVersion = oldVersion, MachineName = "(Unknown)",// Environment.MachineName, UserName = "******", Scripts = appliedScripts, StartedOn = _upgradeInfo.StartedOn, CompletedOn = _upgradeInfo.EndedOn, Exception = exception, FailedScript = failedScript }; logService.LogDbUpgrade(report); } }
public void Init(EntityApp app) { _app = app; _taskService = app.GetService <IBackgroundTaskService>(); }
public void Init(EntityApp app) { _errorLog = app.GetService <IErrorLogService>(); }
public BufferedOperationLog(EntityApp app = null) { _logService = app?.GetService <ILogService>(); }
public void Init(EntityApp app) { _errorLog = app.GetService<IErrorLogService>(); }
public override void OnNewIncident(IIncidentLog newEntry) { //if login failed with user name that matches a login in database, we log this loginId in KeyId1 var failedUserName = newEntry.Key1; if (string.IsNullOrWhiteSpace(failedUserName)) { return; } var tenantId = newEntry.KeyId2; var utcNow = _app.TimeService.UtcNow; var session = _app.OpenSystemSession(); var fromDate = utcNow.Subtract(Settings.TimeWindow); var strLoginFailed = LoginEventType.LoginFailed.ToString(); var qryRecentFailures = from lg in session.EntitySet <IIncidentLog>() where lg.CreatedOn >= fromDate && lg.Key1 == failedUserName && lg.Type == LoginModule.LoginIncidentType && lg.SubType == strLoginFailed select lg; //Note: currently LINQ translator does not handle correctly comparing nullable values, so adding this separately if (tenantId != null) { qryRecentFailures = qryRecentFailures.Where(lg => lg.KeyId2 == tenantId.Value); } var failCount = qryRecentFailures.Count(); if (failCount < Settings.FailureCount) { return; //not yet } // We have repeated login failures in short period of time; this might be an attack - suspend account(s) for several minutes // find Login(s) - might be more than one - we may have the same username for different tenants var loginSet = session.EntitySet <ILogin>(); var loginQuery = from lg in loginSet where lg.UserName == failedUserName select lg; if (tenantId != null) { loginQuery = loginQuery.Where(lg => lg.TenantId == tenantId.Value); } var logins = loginQuery.ToList(); if (logins.Count == 0) { return; //it might happen if user name is not known } //Suspend login var suspendedUntil = utcNow.Add(Settings.SuspensionPeriod); var loginLogService = _app.GetService <ILoginLogService>(); var msg = StringHelper.SafeFormat("{0} login failures. Login {1} suspended until {2}", failCount, failedUserName, suspendedUntil); var loginModule = _app.GetModule <LoginModule>(); foreach (var lg in logins) { // if already suspended or disabled, do not suspend again if (lg.Flags.IsSet(LoginFlags.Disabled | LoginFlags.Suspended)) { continue; } lg.Flags |= LoginFlags.Suspended; lg.SuspendedUntil = suspendedUntil; //raise event - it will log to login log loginModule.OnLoginEvent(session.Context, LoginEventType.LoginSuspended, lg, msg, failedUserName); } session.SaveChanges(); var incService = _app.GetService <IIncidentLogService>(); incService.LogIncident(LoginModule.LoginIncidentType, msg, LoginEventType.LoginSuspended.ToString(), key1: failedUserName, keyId2: tenantId); }
public void Init(EntityApp app) { _saveService = app.GetService <IBackgroundSaveService>(); }
public static DataSource GetDefaultDataSource(this EntityApp app) { var da = app.GetService <IDataAccessService>(); return(da.GetDataSources().FirstOrDefault()); }