Ejemplo n.º 1
0
        protected virtual void ConnectToDatabase(DbSettings dbSettings)
        {
            try {
                switch (this.Status)
                {
                case EntityAppStatus.Created:
                    this.Init();
                    break;

                case EntityAppStatus.Shutdown:
                    return;
                }
                ActivationLog.WriteMessage("  Connecting to data source {0}.", dbSettings.DataSourceName);
                dbSettings.CheckConnectivity(rethrow: true);
                var dbModel = GetCreateDbModel(dbSettings);
                var db      = new Database(dbModel, dbSettings);
                var ds      = new DataSource(dbSettings.DataSourceName, db);
                this.DataAccess.RegisterDataSource(ds);
                this.DataSourceEvents.OnDataSourceChange(new DataSourceEventArgs(db, dbSettings.DataSourceName, DataSourceEventType.Connecting));
                CheckUpgradeDatabase(db);
                LogService.Flush();
                this.Status = EntityAppStatus.Connected;
                this.DataSourceEvents.OnDataSourceChange(new DataSourceEventArgs(db, dbSettings.DataSourceName, DataSourceEventType.Connected));
                ActivationLog.WriteMessage("Connected to {0}.", dbSettings.DataSourceName);
            } finally {
                LogService.Flush();
            }
        }
Ejemplo n.º 2
0
        protected virtual void InitApp()
        {
            Status = EntityAppStatus.Initializing;
            SetupLogFileWriters();
            ActivationLog.WriteMessage("Initializing EntityApp {0}.====================================", this.AppName);
            this.AppEvents.OnInitializing(EntityAppInitStep.Initializing);
            //Check dependencies
            foreach (var mod in this.Modules)
            {
                var depList = mod.GetDependencies();
                foreach (var dep in depList)
                {
                    var ok = Modules.Any(m => dep.IsTypeOrSubType(m));
                    if (!ok)
                    {
                        ActivationLog.LogError($"Module {mod.Name} requires dependent module {dep} which is not included in the app.");
                    }
                }
            }
            CheckActivationErrors();

            //Build model
            var builder = new EntityModelBuilder(this);

            builder.BuildModel();
            CheckActivationErrors();

            //Notify modules that entity app is constructed
            foreach (var module in this.Modules)
            {
                module.Init();
            }
            //init services; note that service might be registered more than once, under different interface
            var servList = this.GetAllServices().Distinct().ToList();

            for (int i = 0; i < servList.Count; i++)
            {
                var service      = servList[i];
                var iServiceInit = service as IEntityServiceBase;
                if (iServiceInit != null)
                {
                    iServiceInit.Init(this);
                }
            }
            //complete initialization
            this.AppEvents.OnInitializing(EntityAppInitStep.Initialized);
            foreach (var module in this.Modules)
            {
                module.AppInitComplete();
            }

            builder.CheckErrors();
            Status = EntityAppStatus.Initialized;
            ActivationLog.WriteMessage("App {0} initialized.", this.AppName);
        }
Ejemplo n.º 3
0
        }     //method

        public void CheckUpgradeDatabase(Database db)
        {
            //Invoke upgrade
            // Update db model
            if (db.Settings.UpgradeMode == DbUpgradeMode.Never)
            {
                ActivationLog.WriteMessage("Data source upgrade mode set to Never, skipping db upgrade.");
                return;
            }
            // upgrade
            var updateMgr   = new DbUpgradeManager(db, ActivationLog);
            var upgradeInfo = updateMgr.UpgradeDatabase(); //it might throw exception
            // _events.OnDataSourceStatusChanging(new DataSourceEventArgs(dataSource, DataSourceEventType.Connected));
        }