From 550d690a31cb3520a7ea524a1294d61912c29540 Mon Sep 17 00:00:00 2001 From: Shannon Date: Mon, 27 Apr 2015 12:41:19 +1000 Subject: [PATCH] Fixes: U4-6559 ServerVariables parsing - An Item with the same key has already been added --- .../Editors/BackOfficeController.cs | 302 +++++++++--------- .../UI/JavaScript/ServerVariablesParser.cs | 3 +- 2 files changed, 156 insertions(+), 149 deletions(-) diff --git a/src/Umbraco.Web/Editors/BackOfficeController.cs b/src/Umbraco.Web/Editors/BackOfficeController.cs index 37fbd32e22..13afce3f26 100644 --- a/src/Umbraco.Web/Editors/BackOfficeController.cs +++ b/src/Umbraco.Web/Editors/BackOfficeController.cs @@ -189,170 +189,176 @@ namespace Umbraco.Web.Editors [MinifyJavaScriptResult(Order = 1)] public JavaScriptResult ServerVariables() { - Func> getResult = () => new Dictionary - { + Func getResult = () => + { + var defaultVals = new Dictionary { - "umbracoUrls", new Dictionary { - {"legacyTreeJs", Url.Action("LegacyTreeJs", "BackOffice")}, - {"manifestAssetList", Url.Action("GetManifestAssetList", "BackOffice")}, - {"gridConfig", Url.Action("GetGridConfig", "BackOffice")}, - {"serverVarsJs", Url.Action("Application", "BackOffice")}, - //API URLs + "umbracoUrls", new Dictionary { - "embedApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl( - controller => controller.GetEmbed("", 0, 0)) - }, - { - "userApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl( - controller => controller.PostDisableUser(0)) - }, - { - "contentApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl( - controller => controller.PostSave(null)) - }, - { - "mediaApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl( - controller => controller.GetRootMedia()) - }, - { - "imagesApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl( - controller => controller.GetBigThumbnail(0)) - }, - { - "sectionApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl( - controller => controller.GetSections()) - }, - { - "treeApplicationApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl( - controller => controller.GetApplicationTrees(null, null, null)) - }, - { - "contentTypeApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl( - controller => controller.GetAllowedChildren(0)) - }, - { - "mediaTypeApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl( - controller => controller.GetAllowedChildren(0)) - }, - { - "macroApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl( - controller => controller.GetMacroParameters(0)) - }, - { - "authenticationApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl( - controller => controller.PostLogin(null)) - }, - { - "currentUserApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl( - controller => controller.GetMembershipProviderConfig()) - }, - { - "legacyApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl( - controller => controller.DeleteLegacyItem(null, null, null)) - }, - { - "entityApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl( - controller => controller.GetById(0, UmbracoEntityTypes.Media)) - }, - { - "dataTypeApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl( - controller => controller.GetById(0)) - }, - { - "dashboardApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl( - controller => controller.GetDashboard(null)) - }, - { - "logApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl( - controller => controller.GetEntityLog(0)) - }, - { - "memberApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl( - controller => controller.GetByKey(Guid.Empty)) - }, - { - "packageInstallApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl( - controller => controller.Fetch(string.Empty)) - }, - { - "rteApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl( - controller => controller.GetConfiguration()) - }, - { - "stylesheetApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl( - controller => controller.GetAll()) - }, - { - "memberTypeApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl( - controller => controller.GetAllTypes()) - }, - { - "updateCheckApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl( - controller => controller.GetCheck()) - }, - { - "tagApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl( - controller => controller.GetAllTags(null)) - }, - { - "memberTreeBaseUrl", Url.GetUmbracoApiServiceBaseUrl( - controller => controller.GetNodes("-1", null)) - }, - { - "mediaTreeBaseUrl", Url.GetUmbracoApiServiceBaseUrl( - controller => controller.GetNodes("-1", null)) - }, - { - "contentTreeBaseUrl", Url.GetUmbracoApiServiceBaseUrl( - controller => controller.GetNodes("-1", null)) - }, - { - "tagsDataBaseUrl", Url.GetUmbracoApiServiceBaseUrl( - controller => controller.GetTags("")) - }, - { - "examineMgmtBaseUrl", Url.GetUmbracoApiServiceBaseUrl( - controller => controller.GetIndexerDetails()) - }, - { - "xmlDataIntegrityBaseUrl", Url.GetUmbracoApiServiceBaseUrl( - controller => controller.CheckContentXmlTable()) + {"legacyTreeJs", Url.Action("LegacyTreeJs", "BackOffice")}, + {"manifestAssetList", Url.Action("GetManifestAssetList", "BackOffice")}, + {"gridConfig", Url.Action("GetGridConfig", "BackOffice")}, + {"serverVarsJs", Url.Action("Application", "BackOffice")}, + //API URLs + { + "embedApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl( + controller => controller.GetEmbed("", 0, 0)) + }, + { + "userApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl( + controller => controller.PostDisableUser(0)) + }, + { + "contentApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl( + controller => controller.PostSave(null)) + }, + { + "mediaApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl( + controller => controller.GetRootMedia()) + }, + { + "imagesApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl( + controller => controller.GetBigThumbnail(0)) + }, + { + "sectionApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl( + controller => controller.GetSections()) + }, + { + "treeApplicationApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl( + controller => controller.GetApplicationTrees(null, null, null)) + }, + { + "contentTypeApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl( + controller => controller.GetAllowedChildren(0)) + }, + { + "mediaTypeApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl( + controller => controller.GetAllowedChildren(0)) + }, + { + "macroApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl( + controller => controller.GetMacroParameters(0)) + }, + { + "authenticationApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl( + controller => controller.PostLogin(null)) + }, + { + "currentUserApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl( + controller => controller.GetMembershipProviderConfig()) + }, + { + "legacyApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl( + controller => controller.DeleteLegacyItem(null, null, null)) + }, + { + "entityApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl( + controller => controller.GetById(0, UmbracoEntityTypes.Media)) + }, + { + "dataTypeApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl( + controller => controller.GetById(0)) + }, + { + "dashboardApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl( + controller => controller.GetDashboard(null)) + }, + { + "logApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl( + controller => controller.GetEntityLog(0)) + }, + { + "memberApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl( + controller => controller.GetByKey(Guid.Empty)) + }, + { + "packageInstallApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl( + controller => controller.Fetch(string.Empty)) + }, + { + "rteApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl( + controller => controller.GetConfiguration()) + }, + { + "stylesheetApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl( + controller => controller.GetAll()) + }, + { + "memberTypeApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl( + controller => controller.GetAllTypes()) + }, + { + "updateCheckApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl( + controller => controller.GetCheck()) + }, + { + "tagApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl( + controller => controller.GetAllTags(null)) + }, + { + "memberTreeBaseUrl", Url.GetUmbracoApiServiceBaseUrl( + controller => controller.GetNodes("-1", null)) + }, + { + "mediaTreeBaseUrl", Url.GetUmbracoApiServiceBaseUrl( + controller => controller.GetNodes("-1", null)) + }, + { + "contentTreeBaseUrl", Url.GetUmbracoApiServiceBaseUrl( + controller => controller.GetNodes("-1", null)) + }, + { + "tagsDataBaseUrl", Url.GetUmbracoApiServiceBaseUrl( + controller => controller.GetTags("")) + }, + { + "examineMgmtBaseUrl", Url.GetUmbracoApiServiceBaseUrl( + controller => controller.GetIndexerDetails()) + }, + { + "xmlDataIntegrityBaseUrl", Url.GetUmbracoApiServiceBaseUrl( + controller => controller.CheckContentXmlTable()) + } } - } - }, - { - "umbracoSettings", new Dictionary + }, { - {"umbracoPath", GlobalSettings.Path}, - {"mediaPath", IOHelper.ResolveUrl(SystemDirectories.Media).TrimEnd('/')}, - {"appPluginsPath", IOHelper.ResolveUrl(SystemDirectories.AppPlugins).TrimEnd('/')}, + "umbracoSettings", new Dictionary { - "imageFileTypes", - string.Join(",", UmbracoConfig.For.UmbracoSettings().Content.ImageFileTypes) - }, - {"keepUserLoggedIn", UmbracoConfig.For.UmbracoSettings().Security.KeepUserLoggedIn}, - } - }, - { - "umbracoPlugins", new Dictionary + {"umbracoPath", GlobalSettings.Path}, + {"mediaPath", IOHelper.ResolveUrl(SystemDirectories.Media).TrimEnd('/')}, + {"appPluginsPath", IOHelper.ResolveUrl(SystemDirectories.AppPlugins).TrimEnd('/')}, + { + "imageFileTypes", + string.Join(",", UmbracoConfig.For.UmbracoSettings().Content.ImageFileTypes) + }, + {"keepUserLoggedIn", UmbracoConfig.For.UmbracoSettings().Security.KeepUserLoggedIn}, + } + }, { - {"trees", GetTreePluginsMetaData()} - } - }, - {"isDebuggingEnabled", HttpContext.IsDebuggingEnabled}, - {"application", GetApplicationState()} + "umbracoPlugins", new Dictionary + { + {"trees", GetTreePluginsMetaData()} + } + }, + {"isDebuggingEnabled", HttpContext.IsDebuggingEnabled}, + {"application", GetApplicationState()} + }; + + //Parse the variables to a string + return ServerVariablesParser.Parse(defaultVals); }; //cache the result if debugging is disabled var result = HttpContext.IsDebuggingEnabled ? getResult() - : ApplicationContext.ApplicationCache.RuntimeCache.GetCacheItem>( + : ApplicationContext.ApplicationCache.RuntimeCache.GetCacheItem( typeof(BackOfficeController) + "ServerVariables", () => getResult(), new TimeSpan(0, 10, 0)); - return JavaScript(ServerVariablesParser.Parse(result)); + return JavaScript(result); } /// diff --git a/src/Umbraco.Web/UI/JavaScript/ServerVariablesParser.cs b/src/Umbraco.Web/UI/JavaScript/ServerVariablesParser.cs index fa34fb3ee9..ac47becb33 100644 --- a/src/Umbraco.Web/UI/JavaScript/ServerVariablesParser.cs +++ b/src/Umbraco.Web/UI/JavaScript/ServerVariablesParser.cs @@ -8,7 +8,7 @@ namespace Umbraco.Web.UI.JavaScript { /// - /// Could allow developers to add custom variables on startup + /// Allows developers to add custom variables on parsing /// public static event EventHandler> Parsing; @@ -18,6 +18,7 @@ namespace Umbraco.Web.UI.JavaScript { var vars = Resources.ServerVariables; + //Raise event for developers to add custom variables if (Parsing != null) { Parsing(null, items);