예제 #1
0
 /// <summary>
 /// Checks activation log messages and throws exception if there were any errors during application initialization.
 /// </summary>
 public void CheckActivationErrors()
 {
     if (SystemLog.HasErrors)
     {
         var allErrors = SystemLog.GetAllAsText();
         throw new StartupFailureException("Application activation failed.", allErrors);
     }
 }
예제 #2
0
        }//method

        private void CheckErrors()
        {
            if (_log.HasErrors)
            {
                var errors = _log.GetAllAsText();
                throw new StartupFailureException("DbModel construction failed.", errors);
            }
        }
예제 #3
0
        public static DbModel LoadDbModel(string schema, SystemLog log)
        {
            if (Driver == null)
            {
                SetupForTestExplorerMode();
            }
            var dbSettings = new DbSettings(Driver, DbOptions, ConnectionString);

            dbSettings.SetSchemas(new[] { schema });
            var loader  = Driver.CreateDbModelLoader(dbSettings, log);
            var dbModel = loader.LoadModel();

            if (log.HasErrors)
            {
                Util.Throw("Model loading errors: \r\n" + log.GetAllAsText());
            }
            return(dbModel);
        }
예제 #4
0
        /// <summary>Initializes the entity app. </summary>
        /// <remarks>Call this method after you finished composing entity application of modules.
        /// The method is called automatically when you connect the application to the database
        /// with <c>ConnectTo()</c> extension method.</remarks>
        public virtual void Init()
        {
            if (Status != EntityAppStatus.Created)
            {
                return;
            }
            Status = EntityAppStatus.Initializing;
            SystemLog.Info("Initializing app {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)
                    {
                        this.SystemLog.Error("Module {0} requires dependent module {1} which is not included in the app.", mod.GetType(), dep);
                    }
                }
            }
            this.CheckActivationErrors();
            // Init linked apps
            foreach (var linkedApp in LinkedApps)
            {
                linkedApp.Init();
            }
            // create default services, possibly importing from LinkedApps
            CreateDefaultServices();
            // Create log file writer
            if (!string.IsNullOrWhiteSpace(_logFilePath))
            {
                _logFileWriter = new LogFileWriter(this, _logFilePath);
            }

            //Build model
            SystemLog.Info("  Building entity model...", this.AppName);
            var modelBuilder = new EntityModelBuilder(this);

            modelBuilder.BuildModel();
            if (SystemLog.HasErrors)
            {
                var errors = SystemLog.GetAllAsText();
                throw new StartupFailureException("Entity model build failed.", errors);
            }
            //Notify modules that entity app is constructed
            foreach (var module in this.Modules)
            {
                module.Init();
            }
            //init services
            var servList = this.GetAllServices();

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

            CheckActivationErrors();
            Status = EntityAppStatus.Initialized;
            SystemLog.Info("  App {0} initialized.", this.AppName);
        }