Example #1
0
        public static void PreStartWebApplication()
        {
            if (isStarted)
            {
                return;
            }

            var logger = LogManager.GetCurrentClassLogger();

            try
            {
                logger.Info("Registering per web request lifetime manager module...");
                PerWebRequestLifetimeModule.DynamicModuleRegistration();
            }
            catch (Exception ex)
            {
                string message = "Failed to register per web request lifetime manager module.";
                logger.Fatal(message, ex);

                throw new CoreException(message, ex);
            }

            try
            {
                logger.Info("Load assemblies...");
                WebApplicationContext.LoadAssemblies();
            }
            catch (Exception ex)
            {
                string message = "Failed to load assemblies.";
                logger.Fatal(message, ex);

                throw new CoreException(message, ex);
            }

            try
            {
                logger.Info("Migrating database...");
                ApplicationContext.RunDatabaseMigrations();
            }
            catch (Exception ex)
            {
                string message = "Failed to run database migrations.";
                logger.Fatal(message, ex);

                throw new CoreException(message, ex);
            }

            isStarted = true;
        }
Example #2
0
        /// <summary>
        /// Method to run logic before application start (as PreApplicationStartMethod). Do not run this method from your code.
        /// </summary>
        public static void PreApplicationStart()
        {
            ILog logger;

            try
            {
                logger = LogManager.GetCurrentClassLogger();
                logger.Info("Starting Better CMS...");
            }
            catch (Exception ex)
            {
                throw new CmsException("Logging is not working. A reason may be that Common.Logging section is not configured in web.config.", ex);
            }

            if (!IsFullTrust)
            {
                string message = "Application should run under FullTrust .NET trust level.";
                logger.Fatal(message);

                throw new CmsException(message);
            }

            try
            {
                logger.Info("Creating Better CMS context dependencies container...");
                ContextScopeProvider.RegisterTypes(CmsContext.InitializeContainer());
            }
            catch (Exception ex)
            {
                string message = "Failed to create Better CMS context dependencies container.";
                logger.Fatal(message, ex);

                throw new CmsException(message, ex);
            }

            try
            {
                logger.Info("Registering per web request lifetime manager module...");
                PerWebRequestLifetimeModule.DynamicModuleRegistration();
            }
            catch (Exception ex)
            {
                string message = "Failed to register per web request lifetime manager module.";
                logger.Fatal(message, ex);

                throw new CmsException(message, ex);
            }

            try
            {
                logger.Info("Load assemblies...");
                CmsContext.LoadAssemblies();
            }
            catch (Exception ex)
            {
                string message = "Failed to load assemblies.";
                logger.Fatal(message, ex);

                throw new CmsException(message, ex);
            }

            try
            {
                // TODO: implement
            }
            catch (Exception ex)
            {
                string message = "Failed to initialize role provider.";
                logger.Fatal(message, ex);

                throw new CmsException(message, ex);
            }
        }