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); } } }
public static void _ReloadSettingsAndRoutes() { GenUtils.LogMsg("info", "webrole _ReloadRoutes", null); bool new_routes = false; try { ElmcityController.settings = GenUtils.GetSettingsFromAzureTable(); } catch (Exception e0) { var msg = "_ReloadSettingsAndRoutes: settings"; GenUtils.PriorityLogMsg("exception", msg, e0.Message); } try { var _wrd = WebRoleData.GetWrd(); if (_wrd.ready_ids.Count != ElmcityApp.wrd.ready_ids.Count) // did # of hubs change? { new_routes = true; // force rebuild of route map GenUtils.LogMsg("info", "Reload: found a new hub", null); lock (ElmcityApp.wrd) { ElmcityApp.wrd = _wrd; // update WebRoleData } } foreach (var id in ElmcityApp.wrd.ready_ids) // did any hub's CalendarRenderer.Calinfo change? { var cached_calinfo = ElmcityApp.wrd.renderers[id].calinfo; var current_calinfo = Utils.AcquireCalinfo(id); var cached_dict = ObjectUtils.ObjToDictStr(cached_calinfo); var current_dict = ObjectUtils.ObjToDictStr(current_calinfo); if (ObjectUtils.DictStrEqualsDictStr(cached_dict, current_dict) == false) // calinfo.obj on blob store is different { GenUtils.LogMsg("info", "Reload: new calinfo+renderer for " + id, null); lock (ElmcityApp.wrd) { var renderer = Utils.AcquireRenderer(id); // load new renderer, maybe custom for this hub GenUtils.LogMsg("info", "renderer.calinfo.version_description: " + renderer.calinfo.version_description, null); ElmcityApp.wrd.renderers[id] = renderer; // update the renderer (and its calinfo) 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); try { var __wrd = ElmcityApp.wrd = WebRoleData.MakeWebRoleData(); lock (ElmcityApp.wrd) { ElmcityApp.wrd = __wrd; } } catch (Exception e2) { GenUtils.PriorityLogMsg("exception", "_ReloadSettingsAndRoutes: cannot remake wrd", e2.Message); } } try { var themes = Utils.GetThemesDict(); if (ObjectUtils.DictOfDictStrEqualsDictOfDictStr(themes, ElmcityController.themes) == false) { lock (ElmcityController.themes) { ElmcityController.themes = themes; } } } catch (Exception e2) { var msg = "_ReloadSettingsAndRoutes: themes"; GenUtils.PriorityLogMsg("exception", msg, e2.Message); } if (new_routes) { try { lock (RouteTable.Routes) { RouteTable.Routes.Clear(); ElmcityApp.RegisterRoutes(RouteTable.Routes, ElmcityApp.wrd); // RouteDebug.RouteDebugger.RewriteRoutesForTesting(RouteTable.Routes); } } catch (Exception e3) { GenUtils.PriorityLogMsg("exception", "_ReloadSettingsAndRoutes: registering routes", e3.Message); } } }