Inheritance: System.Web.HttpApplication
Ejemplo n.º 1
0
        protected void Application_Start()
        {
            var msg = "WebRole: Application_Start";

            GenUtils.PriorityLogMsg("info", msg, null);

            ElmcityApp.wrd = WebRoleData.GetWrd();

            ElmcityApp.RegisterRoutes(RouteTable.Routes, ElmcityApp.wrd);
            GenUtils.PriorityLogMsg("info", RouteTable.Routes.Count + " routes registered", null);

            Utils.ScheduleTimer(PurgeCache, CalendarAggregator.Configurator.webrole_cache_purge_interval_minutes, name: "PurgeCache", startnow: false);
            Utils.ScheduleTimer(ReloadSettingsAndRoutes, minutes: CalendarAggregator.Configurator.webrole_reload_interval_minutes, name: "ReloadSettingsAndRoutes", startnow: true);
            Utils.ScheduleTimer(MakeTablesAndCharts, minutes: CalendarAggregator.Configurator.web_make_tables_and_charts_interval_minutes, name: "MakeTablesAndCharts", startnow: false);

            ElmcityUtils.Monitor.TryStartMonitor(CalendarAggregator.Configurator.process_monitor_interval_minutes, CalendarAggregator.Configurator.process_monitor_table);
        }
Ejemplo n.º 2
0
        public static void _ReloadSettingsAndRoutes()
        {
            GenUtils.LogMsg("status", "webrole _ReloadRoutes", null);

            bool new_routes = false;

            try
            {
                var settings = GenUtils.GetSettingsFromAzureTable();
                if (settings.Keys.Count == 0)
                {
                    GenUtils.PriorityLogMsg("exception", "ReloadSettings: no settings!", null);
                }
                else
                {
                    ElmcityController.settings = settings;
                }
            }
            catch (Exception e0)
            {
                var msg = "_ReloadSettingsAndRoutes: settings";
                GenUtils.PriorityLogMsg("exception", msg, e0.Message);
            }


            try
            {
                var themes = Utils.GetThemesDict();
                if (ObjectUtils.DictOfDictStrEqualsDictOfDictStr(themes, ElmcityController.themes) == false)
                {
                    GenUtils.LogMsg("status", "_ReloadSettingsAndRoutes", "reloading themes");
                    lock (ElmcityController.themes)
                    {
                        ElmcityController.themes = themes;
                    }
                }
            }
            catch (Exception e2)
            {
                var msg = "_ReloadSettingsAndRoutes: themes";
                GenUtils.PriorityLogMsg("exception", msg, e2.Message);
            }

            return;

            try
            {
                var new_wrd = WebRoleData.GetWrd();
                if (new_wrd == null || wrd.IsConsistent() == false)
                {
                    GenUtils.PriorityLogMsg("warning", "null or inconsistent WebRoleData!", null);
                    return;
                }

                if (new_wrd.ready_ids.Count != ElmcityApp.wrd.ready_ids.Count) // did # of hubs change? either on initial load or subsequently
                {
                    new_routes = true;                                         // force rebuild of route map
                    GenUtils.LogMsg("status", "Reload: found a new hub", null);
                    WebRoleData.SaveTimestampedWrd(ElmcityApp.wrd);
                    lock (ElmcityApp.wrd)
                    {
                        ElmcityApp.wrd = new_wrd;                               // update WebRoleData (todo: rewarm caches affected)
                    }
                }

                foreach (var id in ElmcityApp.wrd.ready_ids)                                  // did any hub's renderer change?
                {
                    var cached_renderer  = ElmcityApp.wrd.renderers[id];
                    var current_renderer = Utils.AcquireRenderer(id);

                    if (cached_renderer.timestamp != current_renderer.timestamp)                     // timestamp changed
                    {
                        if (!Utils.RenderersAreEqual(cached_renderer, current_renderer, except_keys: new List <string>()
                        {
                            "timestamp"
                        }))
                        {
                            GenUtils.LogMsg("status", "Reload: new renderer for " + id, null);
                            lock (ElmcityApp.wrd)
                            {
                                ElmcityApp.wrd.renderers[id] = current_renderer;                                                  // update the renderer
                                if (ElmcityApp.home_controller != null)                                                           // skip this if we found a change on startup, controller not ready
                                {
                                    var cache = new AspNetCache(ElmcityApp.home_controller.HttpContext.Cache);
                                    var url   = Utils.MakeBaseZonelessUrl(id);
                                    cache.Remove(url);                                                                                   // flush cached objects for id
                                    var obj = HttpUtils.FetchUrl(new Uri(url));                                                          // rewarm cache
                                }
                            }
                        }
                    }
                }
            }

            catch (Exception e1)
            {
                GenUtils.PriorityLogMsg("exception", "_ReloadSettingsAndRoutes: cannot check/update wrd", e1.Message + e1.StackTrace);
            }


            if (new_routes)
            {
                var existing_routes = RouteTable.Routes;
                var route_count     = existing_routes.Count;
                try
                {
                    GenUtils.LogMsg("status", "_ReloadSettingsAndRoutes: registering " + route_count + " routes", null);

                    lock (RouteTable.Routes)
                    {
                        var route_count_old = RouteTable.Routes.Count;
                        GenUtils.PriorityLogMsg("info", RouteTable.Routes.Count + " routes before reload", null);
                        RouteTable.Routes.Clear();
                        ElmcityApp.RegisterRoutes(RouteTable.Routes, ElmcityApp.wrd);
                        GenUtils.PriorityLogMsg("info", RouteTable.Routes.Count + " routes registered", null);
                        var route_count_new = RouteTable.Routes.Count;
                        if (route_count_new < route_count_old)
                        {
                            GenUtils.PriorityLogMsg("warning", "route count was " + route_count_old + ", is " + route_count_new, null);
                        }
                    }
                }
                catch (Exception e3)
                {
                    GenUtils.PriorityLogMsg("exception", "_ReloadSettingsAndRoutes: registering " + route_count + " routes", e3.Message + e3.StackTrace);
                    ElmcityApp.RegisterRoutes(existing_routes, ElmcityApp.wrd);
                }
            }
        }