コード例 #1
0
        /// <summary>
        /// Binds the details.
        /// </summary>
        private void BindDetails()
        {
            var descriptionList = new DescriptionList();

            var transport = RockMessageBus.GetTransportName();

            if (!transport.IsNullOrWhiteSpace())
            {
                descriptionList.Add("Transport", transport);
            }

            descriptionList.Add("NodeName", RockMessageBus.NodeName);

            var statLog = RockMessageBus.StatLog;

            if (statLog != null)
            {
                if (statLog.MessagesConsumedLastMinute.HasValue)
                {
                    descriptionList.Add("Messages Per Minute", statLog.MessagesConsumedLastMinute);
                }

                if (statLog.MessagesConsumedLastHour.HasValue)
                {
                    descriptionList.Add("Messages Per Hour", statLog.MessagesConsumedLastHour);
                }

                if (statLog.MessagesConsumedLastDay.HasValue)
                {
                    descriptionList.Add("Messages Per Day", statLog.MessagesConsumedLastDay);
                }
            }

            lDetails.Text = descriptionList.Html;
        }
コード例 #2
0
        /// <summary>
        /// Runs various startup operations that need to run prior to RockWeb startup
        /// </summary>
        internal static void RunApplicationStartup()
        {
            // Indicate to always log to file during initialization.
            ExceptionLogService.AlwaysLogToFile = true;

            InitializeRockOrgTimeZone();

            StartDateTime = RockDateTime.Now;
            RockInstanceConfig.SetApplicationStartedDateTime(StartDateTime);

            // If there are Task.Runs that don't handle their exceptions, this will catch those
            // so that we can log it. Note that this event won't fire until the Task is disposed.
            // In most cases, that'll be when GC is collected. So it won't happen immediately.
            TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException;

            LogStartupMessage("Application Starting");

            var runMigrationFileInfo = new FileInfo(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "App_Data\\Run.Migration"));

            bool hasPendingEFMigrations = runMigrationFileInfo.Exists || HasPendingEFMigrations();

            bool ranEFMigrations = MigrateDatabase(hasPendingEFMigrations);

            ShowDebugTimingMessage("EF Migrations");

            ConfigureEntitySaveHooks();

            ShowDebugTimingMessage("Configure Entity SaveHooks");

            // Now that EF Migrations have gotten the Schema in sync with our Models,
            // get the RockContext initialized (which can take several seconds)
            // This will help reduce the chances of multiple instances RockWeb causing problems,
            // like creating duplicate attributes, or running the same migration in parallel
            using (var rockContext = new RockContext())
            {
                new AttributeService(rockContext).Get(0);
                ShowDebugTimingMessage("Initialize RockContext");
            }

            // Configure the values for RockDateTime.
            RockDateTime.FirstDayOfWeek = Rock.Web.SystemSettings.StartDayOfWeek;
            InitializeRockGraduationDate();

            if (runMigrationFileInfo.Exists)
            {
                // fileInfo.Delete() won't do anything if the file doesn't exist (it doesn't throw an exception if it is not there )
                // but do the fileInfo.Exists to make this logic more readable
                runMigrationFileInfo.Delete();
            }

            // Run any plugin migrations
            bool anyPluginMigrations = MigratePlugins();

            ShowDebugTimingMessage("Plugin Migrations");

            /* 2020-05-20 MDP
             * Plugins use Direct SQL to update data,
             * or other things could have done data updates
             * So, just in case, clear the cache (which could be Redis) since anything that is in there could be stale
             */

            RockCache.ClearAllCachedItems(false);

            using (var rockContext = new RockContext())
            {
                LoadCacheObjects(rockContext);

                ShowDebugTimingMessage("Load Cache Objects");

                UpdateAttributesFromRockConfig(rockContext);
            }

            if (ranEFMigrations || anyPluginMigrations)
            {
                // If any migrations ran (version was likely updated)
                SendVersionUpdateNotifications();
                ShowDebugTimingMessage("Send Version Update Notifications");
            }

            // Start the message bus
            RockMessageBus.StartAsync().Wait();
            var busTransportName = RockMessageBus.GetTransportName();

            if (busTransportName.IsNullOrWhiteSpace())
            {
                ShowDebugTimingMessage("Message Bus");
            }
            else
            {
                ShowDebugTimingMessage($"Message Bus ({busTransportName})");
            }

            // Start stage 1 of the web farm
            RockWebFarm.StartStage1();
            ShowDebugTimingMessage("Web Farm (stage 1)");

            RegisterHttpModules();
            ShowDebugTimingMessage("Register HTTP Modules");

            // Initialize the Lava engine.
            InitializeLava();
            ShowDebugTimingMessage($"Initialize Lava Engine ({LavaService.CurrentEngineName})");

            // setup and launch the jobs infrastructure if running under IIS
            bool runJobsInContext = Convert.ToBoolean(ConfigurationManager.AppSettings["RunJobsInIISContext"]);

            if (runJobsInContext)
            {
                StartJobScheduler();
                ShowDebugTimingMessage("Start Job Scheduler");
            }

            // Start stage 2 of the web farm
            RockWebFarm.StartStage2();
            ShowDebugTimingMessage("Web Farm (stage 2)");
        }