예제 #1
0
 public void TestInit()
 {
     Startup.InitApp();
     _app            = Startup.BooksApp;
     _timersControl  = _app.GetService <ITimerServiceControl>();
     _jobDiagService = _app.GetService <IJobDiagnosticsService>();
 }
예제 #2
0
 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); 
 }
예제 #3
0
 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));
 }
예제 #4
0
 public LogFileWriter(EntityApp app, string logPath)
 {
     _app                 = app;
     LogPath              = logPath;
     _logService          = app.GetService <IOperationLogService>();
     _saveService         = app.GetService <IBackgroundSaveService>();
     _saveService.Saving += SaveService_Saving;
 }
예제 #5
0
 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;
 }
예제 #6
0
 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;
 }
예제 #7
0
 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);
 }
예제 #8
0
        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);
        }
예제 #9
0
 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;
 }
예제 #10
0
 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;
 }
예제 #11
0
 public DbUpgradeManager(Database database, ILog log)
 {
     _database      = database;
     _log           = log;
     _app           = _database.DbModel.EntityApp;
     _dbInfoService = (IDbInfoService)_app.GetService(typeof(IDbInfoService));
 }
예제 #12
0
        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;
        }
예제 #13
0
 public DbUpgradeManager(Database database, IActivationLog log)
 {
     _database      = database;
     _log           = log;
     _app           = _database.DbModel.EntityApp;
     _dbInfoService = _app.GetService <IDbInfoService>(throwIfNotFound: false);
 }
예제 #14
0
        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;
        }
예제 #15
0
 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;
 }
예제 #16
0
 public DefaultOperationLogService(EntityApp app, LogLevel logLevel = Services.LogLevel.Details)
 {
     LogLevel = logLevel;
       _timerService = app.GetService<ITimerService>();
       _timerService.Elapsed1Second += TimerService_Elapsed1Second;
       app.AppEvents.FlushRequested += Events_FlushRequested;
 }
예제 #17
0
 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;
 }
예제 #18
0
 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;
 }
예제 #19
0
 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;
 }
예제 #20
0
 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>();
 }
예제 #21
0
 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;
 }
예제 #22
0
 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>();
 }
예제 #23
0
 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;
 }
예제 #24
0
        private static void EnableAppTimers(EntityApp app, bool enable)
        {
            var timers = app.GetService <ITimerServiceControl>();

            if (timers != null)
            {
                timers.EnableAutoFire(enable);
            }
        }
예제 #25
0
 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);
     }
 }
예제 #26
0
        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
        }
예제 #27
0
        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);
        }
예제 #28
0
            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
예제 #29
0
        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);
            }
        }
예제 #30
0
 public void Init(EntityApp app)
 {
     _app         = app;
     _taskService = app.GetService <IBackgroundTaskService>();
 }
예제 #31
0
 public void Init(EntityApp app)
 {
     _errorLog = app.GetService <IErrorLogService>();
 }
예제 #32
0
 public BufferedOperationLog(EntityApp app = null)
 {
     _logService = app?.GetService <ILogService>();
 }
예제 #33
0
 public void Init(EntityApp app) {
   _errorLog = app.GetService<IErrorLogService>();
 }
예제 #34
0
        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);
        }
예제 #35
0
 public void Init(EntityApp app)
 {
     _saveService = app.GetService <IBackgroundSaveService>();
 }
예제 #36
0
파일: DbExtensions.cs 프로젝트: radtek/vita
        public static DataSource GetDefaultDataSource(this EntityApp app)
        {
            var da = app.GetService <IDataAccessService>();

            return(da.GetDataSources().FirstOrDefault());
        }