From c4f1235f0b96258f6479c04efd78711486bc2b42 Mon Sep 17 00:00:00 2001 From: Shannon Deminick Date: Thu, 11 Oct 2012 03:02:23 +0500 Subject: [PATCH] Fixes issues with ApplicationRegistrar and ApplicationTreeRegistrar during install, they now check if the application is configured, if not then they exit otherwise exceptions will be logged every time the app starts during install. Added a log on application end with the reason for shutdown and nicer methods to override in global.asax. --- src/Umbraco.Web/UmbracoApplication.cs | 33 +++++++++++++++++-- .../ApplicationRegistrar.cs | 32 +++++++++++------- .../ApplicationTreeRegistrar.cs | 4 +++ 3 files changed, 54 insertions(+), 15 deletions(-) diff --git a/src/Umbraco.Web/UmbracoApplication.cs b/src/Umbraco.Web/UmbracoApplication.cs index 81f3e019d8..de200db55c 100644 --- a/src/Umbraco.Web/UmbracoApplication.cs +++ b/src/Umbraco.Web/UmbracoApplication.cs @@ -3,7 +3,10 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; +using System.Web; +using System.Web.Hosting; using Umbraco.Core; +using Umbraco.Core.Logging; using Umbraco.Web.Routing; using umbraco.businesslogic; @@ -60,14 +63,38 @@ namespace Umbraco.Web ApplicationStarted(sender, e); } - protected virtual void Application_Error(object sender, EventArgs e) + /// + /// A method that can be overridden to invoke code when the application has an error. + /// + /// + /// + protected virtual void OnApplicationError(object sender, EventArgs e) { - + } - protected virtual void Application_End(object sender, EventArgs e) + protected void Application_Error(object sender, EventArgs e) { + OnApplicationError(sender, e); + } + /// + /// A method that can be overridden to invoke code when the application shuts down. + /// + /// + /// + protected virtual void OnApplicationEnd(object sender, EventArgs e) + { + + } + + protected void Application_End(object sender, EventArgs e) + { + if (SystemUtilities.GetCurrentTrustLevel() == AspNetHostingPermissionLevel.Unrestricted) + { + LogHelper.Info("Application shutdown. Reason: " + HostingEnvironment.ShutdownReason); + } + OnApplicationEnd(sender, e); } } } diff --git a/src/umbraco.businesslogic/ApplicationRegistrar.cs b/src/umbraco.businesslogic/ApplicationRegistrar.cs index d29d50d90f..2432ad783c 100644 --- a/src/umbraco.businesslogic/ApplicationRegistrar.cs +++ b/src/umbraco.businesslogic/ApplicationRegistrar.cs @@ -1,4 +1,6 @@ -using System.Linq; +using System; +using System.Data.SqlClient; +using System.Linq; using System.Xml.Linq; using Umbraco.Core; using umbraco.BusinessLogic.Utils; @@ -29,6 +31,11 @@ namespace umbraco.BusinessLogic public ApplicationRegistrar() { + + //don't do anything if the application is not configured! + if (!ApplicationContext.Current.IsConfigured) + return; + // Load all Applications by attribute and add them to the XML config var types = PluginManager.Current.ResolveApplications(); @@ -40,7 +47,7 @@ namespace umbraco.BusinessLogic var allAliases = Application.getAll().Select(x => x.alias).Concat(attrs.Select(x => x.Alias)); var inString = "'" + string.Join("','", allAliases) + "'"; - + Application.LoadXml(doc => { foreach (var attr in attrs) @@ -51,16 +58,17 @@ namespace umbraco.BusinessLogic new XAttribute("icon", attr.Icon), new XAttribute("sortOrder", attr.SortOrder))); } - - var dbApps = SqlHelper.ExecuteReader("SELECT * FROM umbracoApp WHERE appAlias NOT IN ("+ inString +")"); - while (dbApps.Read()) - { - doc.Root.Add(new XElement("add", - new XAttribute("alias", dbApps.GetString("appAlias")), - new XAttribute("name", dbApps.GetString("appName")), - new XAttribute("icon", dbApps.GetString("appIcon")), - new XAttribute("sortOrder", dbApps.GetByte("sortOrder")))); - } + + var dbApps = SqlHelper.ExecuteReader("SELECT * FROM umbracoApp WHERE appAlias NOT IN (" + inString + ")"); + while (dbApps.Read()) + { + doc.Root.Add(new XElement("add", + new XAttribute("alias", dbApps.GetString("appAlias")), + new XAttribute("name", dbApps.GetString("appName")), + new XAttribute("icon", dbApps.GetString("appIcon")), + new XAttribute("sortOrder", dbApps.GetByte("sortOrder")))); + } + }, true); diff --git a/src/umbraco.businesslogic/ApplicationTreeRegistrar.cs b/src/umbraco.businesslogic/ApplicationTreeRegistrar.cs index 70f709c84f..97628bbacd 100644 --- a/src/umbraco.businesslogic/ApplicationTreeRegistrar.cs +++ b/src/umbraco.businesslogic/ApplicationTreeRegistrar.cs @@ -30,6 +30,10 @@ namespace umbraco.BusinessLogic public ApplicationTreeRegistrar() { + //don't do anything if the application is not configured! + if (!ApplicationContext.Current.IsConfigured) + return; + // Load all Trees by attribute and add them to the XML config var types = PluginManager.Current.ResolveAttributedTrees();