From f4bd0cd1f54f7dfe2ebca410ee7c07bb1bc0ffa8 Mon Sep 17 00:00:00 2001 From: leekelleher Date: Fri, 29 Mar 2019 12:06:23 +0000 Subject: [PATCH 1/6] Swapped all `System.Root` string conversions to use the `System.RootString` constant. This saves on integer parsing and reduces the number of new strings being created. Since the `System.Root` is `-1`, it didn't need the culture invariant conversion. --- src/Umbraco.Core/Models/UserExtensions.cs | 6 +++--- .../Repositories/Implement/ContentTypeRepositoryBase.cs | 2 +- src/Umbraco.Core/Services/Implement/ContentService.cs | 2 +- src/Umbraco.Web/Editors/CodeFileController.cs | 4 ++-- src/Umbraco.Web/Models/Trees/TreeRootNode.cs | 2 +- src/Umbraco.Web/Trees/ApplicationTreeController.cs | 6 +++--- src/Umbraco.Web/Trees/ContentBlueprintTreeController.cs | 4 ++-- src/Umbraco.Web/Trees/ContentTreeController.cs | 2 +- src/Umbraco.Web/Trees/ContentTreeControllerBase.cs | 8 ++++---- src/Umbraco.Web/Trees/ContentTypeTreeController.cs | 2 +- src/Umbraco.Web/Trees/DataTypeTreeController.cs | 2 +- src/Umbraco.Web/Trees/DictionaryTreeController.cs | 4 ++-- src/Umbraco.Web/Trees/FileSystemTreeController.cs | 8 ++++---- src/Umbraco.Web/Trees/MacrosTreeController.cs | 4 ++-- src/Umbraco.Web/Trees/MediaTreeController.cs | 2 +- src/Umbraco.Web/Trees/MediaTypeTreeController.cs | 2 +- src/Umbraco.Web/Trees/MemberTreeController.cs | 4 ++-- .../Trees/MemberTypeAndGroupTreeControllerBase.cs | 2 +- src/Umbraco.Web/Trees/RelationTypeTreeController.cs | 4 ++-- src/Umbraco.Web/Trees/TemplatesTreeController.cs | 4 ++-- src/Umbraco.Web/Trees/TreeControllerBase.cs | 2 +- 21 files changed, 38 insertions(+), 38 deletions(-) diff --git a/src/Umbraco.Core/Models/UserExtensions.cs b/src/Umbraco.Core/Models/UserExtensions.cs index f9aa1113b3c8..14f3cdaca89a 100644 --- a/src/Umbraco.Core/Models/UserExtensions.cs +++ b/src/Umbraco.Core/Models/UserExtensions.cs @@ -151,7 +151,7 @@ internal static CultureInfo GetUserCulture(string userLanguage, ILocalizedTextSe internal static bool HasContentRootAccess(this IUser user, IEntityService entityService) { - return ContentPermissionsHelper.HasPathAccess(Constants.System.Root.ToInvariantString(), user.CalculateContentStartNodeIds(entityService), Constants.System.RecycleBinContent); + return ContentPermissionsHelper.HasPathAccess(Constants.System.RootString, user.CalculateContentStartNodeIds(entityService), Constants.System.RecycleBinContent); } internal static bool HasContentBinAccess(this IUser user, IEntityService entityService) @@ -161,7 +161,7 @@ internal static bool HasContentBinAccess(this IUser user, IEntityService entityS internal static bool HasMediaRootAccess(this IUser user, IEntityService entityService) { - return ContentPermissionsHelper.HasPathAccess(Constants.System.Root.ToInvariantString(), user.CalculateMediaStartNodeIds(entityService), Constants.System.RecycleBinMedia); + return ContentPermissionsHelper.HasPathAccess(Constants.System.RootString, user.CalculateMediaStartNodeIds(entityService), Constants.System.RecycleBinMedia); } internal static bool HasMediaBinAccess(this IUser user, IEntityService entityService) @@ -327,7 +327,7 @@ internal static int[] CombineStartNodes(UmbracoObjectTypes objectType, int[] gro ? entityService.GetAllPaths(objectType, asn).ToDictionary(x => x.Id, x => x.Path) : new Dictionary(); - paths[Constants.System.Root] = Constants.System.Root.ToString(); // entityService does not get that one + paths[Constants.System.Root] = Constants.System.RootString; // entityService does not get that one var binPath = GetBinPath(objectType); diff --git a/src/Umbraco.Core/Persistence/Repositories/Implement/ContentTypeRepositoryBase.cs b/src/Umbraco.Core/Persistence/Repositories/Implement/ContentTypeRepositoryBase.cs index e9b952f11d3d..924efa1e1109 100644 --- a/src/Umbraco.Core/Persistence/Repositories/Implement/ContentTypeRepositoryBase.cs +++ b/src/Umbraco.Core/Persistence/Repositories/Implement/ContentTypeRepositoryBase.cs @@ -61,7 +61,7 @@ public IEnumerable> Move(TEntity moving, EntityContainer // move to parent (or -1), update path, save moving.ParentId = parentId; var movingPath = moving.Path + ","; // save before changing - moving.Path = (container == null ? Constants.System.Root.ToString() : container.Path) + "," + moving.Id; + moving.Path = (container == null ? Constants.System.RootString : container.Path) + "," + moving.Id; moving.Level = container == null ? 1 : container.Level + 1; Save(moving); diff --git a/src/Umbraco.Core/Services/Implement/ContentService.cs b/src/Umbraco.Core/Services/Implement/ContentService.cs index f2bef5292280..ef1d61d4a80c 100644 --- a/src/Umbraco.Core/Services/Implement/ContentService.cs +++ b/src/Umbraco.Core/Services/Implement/ContentService.cs @@ -533,7 +533,7 @@ public IEnumerable GetAncestors(IContent content) //null check otherwise we get exceptions if (content.Path.IsNullOrWhiteSpace()) return Enumerable.Empty(); - var rootId = Constants.System.Root.ToInvariantString(); + var rootId = Constants.System.RootString; var ids = content.Path.Split(',') .Where(x => x != rootId && x != content.Id.ToString(CultureInfo.InvariantCulture)).Select(int.Parse).ToArray(); if (ids.Any() == false) diff --git a/src/Umbraco.Web/Editors/CodeFileController.cs b/src/Umbraco.Web/Editors/CodeFileController.cs index bd6b837c2ce3..3f1ffa55d928 100644 --- a/src/Umbraco.Web/Editors/CodeFileController.cs +++ b/src/Umbraco.Web/Editors/CodeFileController.cs @@ -94,7 +94,7 @@ public HttpResponseMessage PostCreateContainer(string type, string parentId, str // if the parentId is root (-1) then we just need an empty string as we are // creating the path below and we don't want -1 in the path - if (parentId == Core.Constants.System.Root.ToInvariantString()) + if (parentId == Core.Constants.System.RootString) { parentId = string.Empty; } @@ -276,7 +276,7 @@ public CodeFileDisplay GetScaffold(string type, string id, string snippetName = // Make sure that the root virtual path ends with '/' codeFileDisplay.VirtualPath = codeFileDisplay.VirtualPath.EnsureEndsWith("/"); - if (id != Core.Constants.System.Root.ToInvariantString()) + if (id != Core.Constants.System.RootString) { codeFileDisplay.VirtualPath += id.TrimStart("/").EnsureEndsWith("/"); //if it's not new then it will have a path, otherwise it won't diff --git a/src/Umbraco.Web/Models/Trees/TreeRootNode.cs b/src/Umbraco.Web/Models/Trees/TreeRootNode.cs index 730f6e29629e..e26dffe5e40d 100644 --- a/src/Umbraco.Web/Models/Trees/TreeRootNode.cs +++ b/src/Umbraco.Web/Models/Trees/TreeRootNode.cs @@ -26,7 +26,7 @@ namespace Umbraco.Web.Models.Trees [DataContract(Name = "node", Namespace = "")] public sealed class TreeRootNode : TreeNode { - private static readonly string RootId = Core.Constants.System.Root.ToString(CultureInfo.InvariantCulture); + private static readonly string RootId = Core.Constants.System.RootString; private bool _isGroup; private bool _isSingleNodeTree; diff --git a/src/Umbraco.Web/Trees/ApplicationTreeController.cs b/src/Umbraco.Web/Trees/ApplicationTreeController.cs index 007fd53e6038..f0a860496e99 100644 --- a/src/Umbraco.Web/Trees/ApplicationTreeController.cs +++ b/src/Umbraco.Web/Trees/ApplicationTreeController.cs @@ -71,7 +71,7 @@ public async Task GetApplicationTrees(string application, string t //if there are no trees defined for this section but the section is defined then we can have a simple //full screen section without trees var name = Services.TextService.Localize("sections/" + application); - return TreeRootNode.CreateSingleTreeRoot(Constants.System.Root.ToInvariantString(), null, null, name, TreeNodeCollection.Empty, true); + return TreeRootNode.CreateSingleTreeRoot(Constants.System.RootString, null, null, name, TreeNodeCollection.Empty, true); } // handle request for a specific tree / or when there is only one tree @@ -114,7 +114,7 @@ public async Task GetApplicationTrees(string application, string t // otherwise it's a section with all empty trees, aka a fullscreen section // todo is this true? what if we just failed to TryGetRootNode on all of them? SD: Yes it's true but we should check the result of TryGetRootNode and throw? - return TreeRootNode.CreateSingleTreeRoot(Constants.System.Root.ToInvariantString(), null, null, name, TreeNodeCollection.Empty, true); + return TreeRootNode.CreateSingleTreeRoot(Constants.System.RootString, null, null, name, TreeNodeCollection.Empty, true); } // for many groups @@ -180,7 +180,7 @@ private async Task GetTreeRootNode(Tree tree, int id, FormDataColl var rootNode = await GetRootNode(tree, querystring); var sectionRoot = TreeRootNode.CreateSingleTreeRoot( - Constants.System.Root.ToInvariantString(), + Constants.System.RootString, rootNode.ChildNodesUrl, rootNode.MenuUrl, rootNode.Name, diff --git a/src/Umbraco.Web/Trees/ContentBlueprintTreeController.cs b/src/Umbraco.Web/Trees/ContentBlueprintTreeController.cs index 87a707102d82..8c23a91d5aa4 100644 --- a/src/Umbraco.Web/Trees/ContentBlueprintTreeController.cs +++ b/src/Umbraco.Web/Trees/ContentBlueprintTreeController.cs @@ -44,7 +44,7 @@ protected override TreeNodeCollection GetTreeNodes(string id, FormDataCollection var entities = Services.EntityService.GetChildren(Constants.System.Root, UmbracoObjectTypes.DocumentBlueprint).ToArray(); //check if we're rendering the root in which case we'll render the content types that have blueprints - if (id == Constants.System.Root.ToInvariantString()) + if (id == Constants.System.RootString) { //get all blueprint content types var contentTypeAliases = entities.Select(x => ((ContentEntitySlim) x).ContentTypeAlias).Distinct(); @@ -91,7 +91,7 @@ protected override MenuItemCollection GetMenuForNode(string id, FormDataCollecti { var menu = new MenuItemCollection(); - if (id == Constants.System.Root.ToInvariantString()) + if (id == Constants.System.RootString) { // root actions menu.Items.Add(Services.TextService, opensDialog: true); diff --git a/src/Umbraco.Web/Trees/ContentTreeController.cs b/src/Umbraco.Web/Trees/ContentTreeController.cs index b90e1964b8e1..4249d1639e0f 100644 --- a/src/Umbraco.Web/Trees/ContentTreeController.cs +++ b/src/Umbraco.Web/Trees/ContentTreeController.cs @@ -109,7 +109,7 @@ protected override TreeNode GetSingleTreeNode(IEntitySlim entity, string parentI protected override MenuItemCollection PerformGetMenuForNode(string id, FormDataCollection queryStrings) { - if (id == Constants.System.Root.ToInvariantString()) + if (id == Constants.System.RootString) { var menu = new MenuItemCollection(); diff --git a/src/Umbraco.Web/Trees/ContentTreeControllerBase.cs b/src/Umbraco.Web/Trees/ContentTreeControllerBase.cs index e521deca405e..0c02dd6e46e5 100644 --- a/src/Umbraco.Web/Trees/ContentTreeControllerBase.cs +++ b/src/Umbraco.Web/Trees/ContentTreeControllerBase.cs @@ -120,7 +120,7 @@ protected virtual TreeNodeCollection PerformGetTreeNodes(string id, FormDataColl { var nodes = new TreeNodeCollection(); - var rootIdString = Constants.System.Root.ToString(CultureInfo.InvariantCulture); + var rootIdString = Constants.System.RootString; var hasAccessToRoot = UserStartNodes.Contains(Constants.System.Root); var startNodeId = queryStrings.HasKey(TreeQueryStringParameters.StartNodeId) @@ -256,7 +256,7 @@ protected bool HasPathAccess(IUmbracoEntity entity, FormDataCollection queryStri protected sealed override TreeNodeCollection GetTreeNodes(string id, FormDataCollection queryStrings) { //check if we're rendering the root - if (id == Constants.System.Root.ToInvariantString() && UserStartNodes.Contains(Constants.System.Root)) + if (id == Constants.System.RootString && UserStartNodes.Contains(Constants.System.Root)) { var altStartId = string.Empty; @@ -264,7 +264,7 @@ protected sealed override TreeNodeCollection GetTreeNodes(string id, FormDataCol altStartId = queryStrings.GetValue(TreeQueryStringParameters.StartNodeId); //check if a request has been made to render from a specific start node - if (string.IsNullOrEmpty(altStartId) == false && altStartId != "undefined" && altStartId != Constants.System.Root.ToString(CultureInfo.InvariantCulture)) + if (string.IsNullOrEmpty(altStartId) == false && altStartId != "undefined" && altStartId != Constants.System.RootString) { id = altStartId; } @@ -272,7 +272,7 @@ protected sealed override TreeNodeCollection GetTreeNodes(string id, FormDataCol var nodes = GetTreeNodesInternal(id, queryStrings); //only render the recycle bin if we are not in dialog and the start id id still the root - if (IsDialog(queryStrings) == false && id == Constants.System.Root.ToInvariantString()) + if (IsDialog(queryStrings) == false && id == Constants.System.RootString) { nodes.Add(CreateTreeNode( RecycleBinId.ToInvariantString(), diff --git a/src/Umbraco.Web/Trees/ContentTypeTreeController.cs b/src/Umbraco.Web/Trees/ContentTypeTreeController.cs index 66cb9fe36e76..b8374f9d944a 100644 --- a/src/Umbraco.Web/Trees/ContentTypeTreeController.cs +++ b/src/Umbraco.Web/Trees/ContentTypeTreeController.cs @@ -72,7 +72,7 @@ protected override MenuItemCollection GetMenuForNode(string id, FormDataCollecti { var menu = new MenuItemCollection(); - if (id == Constants.System.Root.ToInvariantString()) + if (id == Constants.System.RootString) { //set the default to create menu.DefaultMenuAlias = ActionNew.ActionAlias; diff --git a/src/Umbraco.Web/Trees/DataTypeTreeController.cs b/src/Umbraco.Web/Trees/DataTypeTreeController.cs index 8a0a83d94fa6..a9e29697fcad 100644 --- a/src/Umbraco.Web/Trees/DataTypeTreeController.cs +++ b/src/Umbraco.Web/Trees/DataTypeTreeController.cs @@ -96,7 +96,7 @@ protected override MenuItemCollection GetMenuForNode(string id, FormDataCollecti { var menu = new MenuItemCollection(); - if (id == Constants.System.Root.ToInvariantString()) + if (id == Constants.System.RootString) { //set the default to create menu.DefaultMenuAlias = ActionNew.ActionAlias; diff --git a/src/Umbraco.Web/Trees/DictionaryTreeController.cs b/src/Umbraco.Web/Trees/DictionaryTreeController.cs index 5f0b7b5df0f2..3f7b89bcdfb1 100644 --- a/src/Umbraco.Web/Trees/DictionaryTreeController.cs +++ b/src/Umbraco.Web/Trees/DictionaryTreeController.cs @@ -58,7 +58,7 @@ protected override TreeNodeCollection GetTreeNodes(string id, FormDataCollection Func ItemSort() => item => item.ItemKey; - if (id == Constants.System.Root.ToInvariantString()) + if (id == Constants.System.RootString) { nodes.AddRange( Services.LocalizationService.GetRootDictionaryItems().OrderBy(ItemSort()).Select( @@ -104,7 +104,7 @@ protected override MenuItemCollection GetMenuForNode(string id, FormDataCollecti menu.Items.Add(Services.TextService, opensDialog: true); - if (id != Constants.System.Root.ToInvariantString()) + if (id != Constants.System.RootString) menu.Items.Add(Services.TextService, true, opensDialog: true); menu.Items.Add(new RefreshNode(Services.TextService, true)); diff --git a/src/Umbraco.Web/Trees/FileSystemTreeController.cs b/src/Umbraco.Web/Trees/FileSystemTreeController.cs index 9aea6e03dd82..6e21c8114fd2 100644 --- a/src/Umbraco.Web/Trees/FileSystemTreeController.cs +++ b/src/Umbraco.Web/Trees/FileSystemTreeController.cs @@ -35,7 +35,7 @@ protected virtual void OnRenderFolderNode(ref TreeNode treeNode) { protected override TreeNodeCollection GetTreeNodes(string id, FormDataCollection queryStrings) { - var path = string.IsNullOrEmpty(id) == false && id != Constants.System.Root.ToInvariantString() + var path = string.IsNullOrEmpty(id) == false && id != Constants.System.RootString ? HttpUtility.UrlDecode(id).TrimStart("/") : ""; @@ -84,7 +84,7 @@ protected override TreeNode CreateRootNode(FormDataCollection queryStrings) { var root = base.CreateRootNode(queryStrings); //check if there are any children - root.HasChildren = GetTreeNodes(Constants.System.Root.ToInvariantString(), queryStrings).Any(); + root.HasChildren = GetTreeNodes(Constants.System.RootString, queryStrings).Any(); return root; } @@ -139,14 +139,14 @@ protected virtual MenuItemCollection GetMenuForFile(string path, FormDataCollect protected override MenuItemCollection GetMenuForNode(string id, FormDataCollection queryStrings) { //if root node no need to visit the filesystem so lets just create the menu and return it - if (id == Constants.System.Root.ToInvariantString()) + if (id == Constants.System.RootString) { return GetMenuForRootNode(queryStrings); } var menu = new MenuItemCollection(); - var path = string.IsNullOrEmpty(id) == false && id != Constants.System.Root.ToInvariantString() + var path = string.IsNullOrEmpty(id) == false && id != Constants.System.RootString ? HttpUtility.UrlDecode(id).TrimStart("/") : ""; diff --git a/src/Umbraco.Web/Trees/MacrosTreeController.cs b/src/Umbraco.Web/Trees/MacrosTreeController.cs index 77b13416ff43..02636cbea805 100644 --- a/src/Umbraco.Web/Trees/MacrosTreeController.cs +++ b/src/Umbraco.Web/Trees/MacrosTreeController.cs @@ -29,7 +29,7 @@ protected override TreeNodeCollection GetTreeNodes(string id, FormDataCollection { var nodes = new TreeNodeCollection(); - if (id == Constants.System.Root.ToInvariantString()) + if (id == Constants.System.RootString) { foreach (var macro in Services.MacroService.GetAll()) { @@ -50,7 +50,7 @@ protected override MenuItemCollection GetMenuForNode(string id, FormDataCollecti { var menu = new MenuItemCollection(); - if (id == Constants.System.Root.ToInvariantString()) + if (id == Constants.System.RootString) { //Create the normal create action menu.Items.Add(Services.TextService); diff --git a/src/Umbraco.Web/Trees/MediaTreeController.cs b/src/Umbraco.Web/Trees/MediaTreeController.cs index 5797dd930d80..fc3d23f09208 100644 --- a/src/Umbraco.Web/Trees/MediaTreeController.cs +++ b/src/Umbraco.Web/Trees/MediaTreeController.cs @@ -86,7 +86,7 @@ protected override MenuItemCollection PerformGetMenuForNode(string id, FormDataC //set the default menu.DefaultMenuAlias = ActionNew.ActionAlias; - if (id == Constants.System.Root.ToInvariantString()) + if (id == Constants.System.RootString) { // if the user's start node is not the root then the only menu item to display is refresh if (UserStartNodes.Contains(Constants.System.Root) == false) diff --git a/src/Umbraco.Web/Trees/MediaTypeTreeController.cs b/src/Umbraco.Web/Trees/MediaTypeTreeController.cs index 30db2ea12aee..bb6b86775168 100644 --- a/src/Umbraco.Web/Trees/MediaTypeTreeController.cs +++ b/src/Umbraco.Web/Trees/MediaTypeTreeController.cs @@ -65,7 +65,7 @@ protected override MenuItemCollection GetMenuForNode(string id, FormDataCollecti { var menu = new MenuItemCollection(); - if (id == Constants.System.Root.ToInvariantString()) + if (id == Constants.System.RootString) { // set the default to create menu.DefaultMenuAlias = ActionNew.ActionAlias; diff --git a/src/Umbraco.Web/Trees/MemberTreeController.cs b/src/Umbraco.Web/Trees/MemberTreeController.cs index 6107540c0c79..bb0091af5486 100644 --- a/src/Umbraco.Web/Trees/MemberTreeController.cs +++ b/src/Umbraco.Web/Trees/MemberTreeController.cs @@ -121,7 +121,7 @@ protected override TreeNodeCollection GetTreeNodes(string id, FormDataCollection { var nodes = new TreeNodeCollection(); - if (id == Constants.System.Root.ToInvariantString()) + if (id == Constants.System.RootString) { nodes.Add( CreateTreeNode(Constants.Conventions.MemberTypes.AllMembersListId, id, queryStrings, Services.TextService.Localize("member/allMembers"), "icon-users", true, @@ -148,7 +148,7 @@ protected override MenuItemCollection GetMenuForNode(string id, FormDataCollecti { var menu = new MenuItemCollection(); - if (id == Constants.System.Root.ToInvariantString()) + if (id == Constants.System.RootString) { // root actions if (_provider.IsUmbracoMembershipProvider()) diff --git a/src/Umbraco.Web/Trees/MemberTypeAndGroupTreeControllerBase.cs b/src/Umbraco.Web/Trees/MemberTypeAndGroupTreeControllerBase.cs index d3f9ee77c9c4..5e71266bcabb 100644 --- a/src/Umbraco.Web/Trees/MemberTypeAndGroupTreeControllerBase.cs +++ b/src/Umbraco.Web/Trees/MemberTypeAndGroupTreeControllerBase.cs @@ -21,7 +21,7 @@ protected override MenuItemCollection GetMenuForNode(string id, FormDataCollecti { var menu = new MenuItemCollection(); - if (id == Constants.System.Root.ToInvariantString()) + if (id == Constants.System.RootString) { // root actions menu.Items.Add(new CreateChildEntity(Services.TextService)); diff --git a/src/Umbraco.Web/Trees/RelationTypeTreeController.cs b/src/Umbraco.Web/Trees/RelationTypeTreeController.cs index 82e07c522688..ab6dd39820ea 100644 --- a/src/Umbraco.Web/Trees/RelationTypeTreeController.cs +++ b/src/Umbraco.Web/Trees/RelationTypeTreeController.cs @@ -18,7 +18,7 @@ protected override MenuItemCollection GetMenuForNode(string id, FormDataCollecti { var menu = new MenuItemCollection(); - if (id == Constants.System.Root.ToInvariantString()) + if (id == Constants.System.RootString) { //Create the normal create action menu.Items.Add(Services.TextService.Localize("actions", ActionNew.ActionAlias)); @@ -41,7 +41,7 @@ protected override TreeNodeCollection GetTreeNodes(string id, FormDataCollection { var nodes = new TreeNodeCollection(); - if (id == Constants.System.Root.ToInvariantString()) + if (id == Constants.System.RootString) { nodes.AddRange(Services.RelationService.GetAllRelationTypes() .Select(rt => CreateTreeNode(rt.Id.ToString(), id, queryStrings, rt.Name, diff --git a/src/Umbraco.Web/Trees/TemplatesTreeController.cs b/src/Umbraco.Web/Trees/TemplatesTreeController.cs index 916e5d4b4d1f..601964c30d09 100644 --- a/src/Umbraco.Web/Trees/TemplatesTreeController.cs +++ b/src/Umbraco.Web/Trees/TemplatesTreeController.cs @@ -44,7 +44,7 @@ protected override TreeNodeCollection GetTreeNodes(string id, FormDataCollection { var nodes = new TreeNodeCollection(); - var found = id == Constants.System.Root.ToInvariantString() + var found = id == Constants.System.RootString ? Services.FileService.GetTemplates(-1) : Services.FileService.GetTemplates(int.Parse(id)); @@ -77,7 +77,7 @@ protected override MenuItemCollection GetMenuForNode(string id, FormDataCollecti var item = menu.Items.Add(Services.TextService, opensDialog: true); item.NavigateToRoute($"{queryStrings.GetRequiredValue("application")}/templates/edit/{id}?create=true"); - if (id == Constants.System.Root.ToInvariantString()) + if (id == Constants.System.RootString) { //refresh action menu.Items.Add(new RefreshNode(Services.TextService, true)); diff --git a/src/Umbraco.Web/Trees/TreeControllerBase.cs b/src/Umbraco.Web/Trees/TreeControllerBase.cs index 4e43e6c09349..daa8300b4f96 100644 --- a/src/Umbraco.Web/Trees/TreeControllerBase.cs +++ b/src/Umbraco.Web/Trees/TreeControllerBase.cs @@ -173,7 +173,7 @@ public MenuItemCollection GetMenu(string id, [ModelBinder(typeof(HttpQueryString /// protected virtual TreeNode CreateRootNode(FormDataCollection queryStrings) { - var rootNodeAsString = Constants.System.Root.ToString(CultureInfo.InvariantCulture); + var rootNodeAsString = Constants.System.RootString; var currApp = queryStrings.GetValue(TreeQueryStringParameters.Application); var node = new TreeNode( From 13564c72ef9342f520001f89f1459fa2a135072c Mon Sep 17 00:00:00 2001 From: leekelleher Date: Fri, 29 Mar 2019 12:13:38 +0000 Subject: [PATCH 2/6] Replaced hardcoded "-1" with `Constants.System.RootString` --- src/Umbraco.Core/Services/Implement/ContentService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Umbraco.Core/Services/Implement/ContentService.cs b/src/Umbraco.Core/Services/Implement/ContentService.cs index ef1d61d4a80c..5e1e0529b697 100644 --- a/src/Umbraco.Core/Services/Implement/ContentService.cs +++ b/src/Umbraco.Core/Services/Implement/ContentService.cs @@ -1922,7 +1922,7 @@ private void PerformMoveLocked(IContent content, int parentId, IContent parent, // if uow is not immediate, content.Path will be updated only when the UOW commits, // and because we want it now, we have to calculate it by ourselves //paths[content.Id] = content.Path; - paths[content.Id] = (parent == null ? (parentId == Constants.System.RecycleBinContent ? "-1,-20" : "-1") : parent.Path) + "," + content.Id; + paths[content.Id] = (parent == null ? (parentId == Constants.System.RecycleBinContent ? "-1,-20" : Constants.System.RootString) : parent.Path) + "," + content.Id; const int pageSize = 500; var page = 0; From a4c96678e5abc142f3c973183b5e9b04808d49e9 Mon Sep 17 00:00:00 2001 From: leekelleher Date: Fri, 29 Mar 2019 12:14:27 +0000 Subject: [PATCH 3/6] Swapped `System.RecycleBinContent` string conversions to use the `System.RecycleBinContentString` constant. This saves on integer parsing and reduces the number of new strings being created. Since the `System.RecycleBinContentString` is `-20`, it didn't need the culture invariant conversion. --- src/Umbraco.Core/Compose/RelateOnTrashComponent.cs | 2 +- src/Umbraco.Core/Models/UserExtensions.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Umbraco.Core/Compose/RelateOnTrashComponent.cs b/src/Umbraco.Core/Compose/RelateOnTrashComponent.cs index 501907a6e708..1b32d36a7146 100644 --- a/src/Umbraco.Core/Compose/RelateOnTrashComponent.cs +++ b/src/Umbraco.Core/Compose/RelateOnTrashComponent.cs @@ -22,7 +22,7 @@ public void Terminate() private static void ContentService_Moved(IContentService sender, MoveEventArgs e) { - foreach (var item in e.MoveInfoCollection.Where(x => x.OriginalPath.Contains(Constants.System.RecycleBinContent.ToInvariantString()))) + foreach (var item in e.MoveInfoCollection.Where(x => x.OriginalPath.Contains(Constants.System.RecycleBinContentString))) { var relationService = Current.Services.RelationService; const string relationTypeAlias = Constants.Conventions.RelationTypes.RelateParentDocumentOnDeleteAlias; diff --git a/src/Umbraco.Core/Models/UserExtensions.cs b/src/Umbraco.Core/Models/UserExtensions.cs index 14f3cdaca89a..b76f2656add3 100644 --- a/src/Umbraco.Core/Models/UserExtensions.cs +++ b/src/Umbraco.Core/Models/UserExtensions.cs @@ -156,7 +156,7 @@ internal static bool HasContentRootAccess(this IUser user, IEntityService entity internal static bool HasContentBinAccess(this IUser user, IEntityService entityService) { - return ContentPermissionsHelper.HasPathAccess(Constants.System.RecycleBinContent.ToInvariantString(), user.CalculateContentStartNodeIds(entityService), Constants.System.RecycleBinContent); + return ContentPermissionsHelper.HasPathAccess(Constants.System.RecycleBinContentString, user.CalculateContentStartNodeIds(entityService), Constants.System.RecycleBinContent); } internal static bool HasMediaRootAccess(this IUser user, IEntityService entityService) From b44360aa99f33dcd8ae701fbc159c461e4447a5f Mon Sep 17 00:00:00 2001 From: leekelleher Date: Fri, 29 Mar 2019 12:17:12 +0000 Subject: [PATCH 4/6] Swapped `System.RecycleBinMedia` string conversions to use the `System.RecycleBinMediaString` constant. This saves on integer parsing and reduces the number of new strings being created. Since the `System.RecycleBinMedia` is `-21`, it didn't need the culture invariant conversion. --- src/Umbraco.Core/Compose/RelateOnTrashComponent.cs | 2 +- src/Umbraco.Core/Models/UserExtensions.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Umbraco.Core/Compose/RelateOnTrashComponent.cs b/src/Umbraco.Core/Compose/RelateOnTrashComponent.cs index 1b32d36a7146..8371f9b27913 100644 --- a/src/Umbraco.Core/Compose/RelateOnTrashComponent.cs +++ b/src/Umbraco.Core/Compose/RelateOnTrashComponent.cs @@ -37,7 +37,7 @@ private static void ContentService_Moved(IContentService sender, MoveEventArgs e) { - foreach (var item in e.MoveInfoCollection.Where(x => x.OriginalPath.Contains(Constants.System.RecycleBinMedia.ToInvariantString()))) + foreach (var item in e.MoveInfoCollection.Where(x => x.OriginalPath.Contains(Constants.System.RecycleBinMediaString))) { var relationService = Current.Services.RelationService; const string relationTypeAlias = Constants.Conventions.RelationTypes.RelateParentMediaFolderOnDeleteAlias; diff --git a/src/Umbraco.Core/Models/UserExtensions.cs b/src/Umbraco.Core/Models/UserExtensions.cs index b76f2656add3..0f83cf78a417 100644 --- a/src/Umbraco.Core/Models/UserExtensions.cs +++ b/src/Umbraco.Core/Models/UserExtensions.cs @@ -166,7 +166,7 @@ internal static bool HasMediaRootAccess(this IUser user, IEntityService entitySe internal static bool HasMediaBinAccess(this IUser user, IEntityService entityService) { - return ContentPermissionsHelper.HasPathAccess(Constants.System.RecycleBinMedia.ToInvariantString(), user.CalculateMediaStartNodeIds(entityService), Constants.System.RecycleBinMedia); + return ContentPermissionsHelper.HasPathAccess(Constants.System.RecycleBinMediaString, user.CalculateMediaStartNodeIds(entityService), Constants.System.RecycleBinMedia); } internal static bool HasPathAccess(this IUser user, IContent content, IEntityService entityService) From 533d2cf8ddf4c312c44dfebf486fd5bd6ae847b0 Mon Sep 17 00:00:00 2001 From: leekelleher Date: Fri, 29 Mar 2019 12:18:52 +0000 Subject: [PATCH 5/6] Replaced hardcoded "-1" with `Constants.System.RootString` --- src/Umbraco.Core/Services/Implement/MediaService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Umbraco.Core/Services/Implement/MediaService.cs b/src/Umbraco.Core/Services/Implement/MediaService.cs index a1aea45f11dc..fa7289623976 100644 --- a/src/Umbraco.Core/Services/Implement/MediaService.cs +++ b/src/Umbraco.Core/Services/Implement/MediaService.cs @@ -995,7 +995,7 @@ private void PerformMoveLocked(IMedia media, int parentId, IMedia parent, int us // if uow is not immediate, content.Path will be updated only when the UOW commits, // and because we want it now, we have to calculate it by ourselves //paths[media.Id] = media.Path; - paths[media.Id] = (parent == null ? (parentId == Constants.System.RecycleBinMedia ? "-1,-21" : "-1") : parent.Path) + "," + media.Id; + paths[media.Id] = (parent == null ? (parentId == Constants.System.RecycleBinMedia ? "-1,-21" : Constants.System.RootString) : parent.Path) + "," + media.Id; const int pageSize = 500; var page = 0; From 0a687ab7ce59a16960d3c4be3e900c3ec369a4fd Mon Sep 17 00:00:00 2001 From: leekelleher Date: Fri, 29 Mar 2019 12:26:42 +0000 Subject: [PATCH 6/6] Whitespace formatting in the Constants classes Also removed unused namespaces. --- src/Umbraco.Core/Constants-AppSettings.cs | 1 - src/Umbraco.Core/Constants-Applications.cs | 4 +- src/Umbraco.Core/Constants-Conventions.cs | 116 +++++++++--------- src/Umbraco.Core/Constants-Icons.cs | 12 +- src/Umbraco.Core/Constants-Indexes.cs | 5 +- src/Umbraco.Core/Constants-ObjectTypes.cs | 1 - .../Constants-PackageRepository.cs | 2 +- src/Umbraco.Core/Constants-PropertyEditors.cs | 1 - src/Umbraco.Core/Constants-Web.cs | 6 +- .../Persistence/Constants-DatabaseSchema.cs | 2 +- src/Umbraco.Core/UdiEntityType.cs | 2 +- 11 files changed, 66 insertions(+), 86 deletions(-) diff --git a/src/Umbraco.Core/Constants-AppSettings.cs b/src/Umbraco.Core/Constants-AppSettings.cs index ac0cbde8dead..509be46b6137 100644 --- a/src/Umbraco.Core/Constants-AppSettings.cs +++ b/src/Umbraco.Core/Constants-AppSettings.cs @@ -93,7 +93,6 @@ public static class AppSettings /// public const string DisableElectionForSingleServer = "Umbraco.Core.DisableElectionForSingleServer"; - /// /// Debug specific web.config AppSetting keys for Umbraco /// diff --git a/src/Umbraco.Core/Constants-Applications.cs b/src/Umbraco.Core/Constants-Applications.cs index b53a2b8eafa6..cf4f80d87bf3 100644 --- a/src/Umbraco.Core/Constants-Applications.cs +++ b/src/Umbraco.Core/Constants-Applications.cs @@ -145,11 +145,11 @@ public static class Trees public const string PartialViewMacros = "partialViewMacros"; - public const string LogViewer = "logViewer"; + public const string LogViewer = "logViewer"; public static class Groups { - public const string Settings = "settingsGroup"; + public const string Settings = "settingsGroup"; public const string Templating = "templatingGroup"; diff --git a/src/Umbraco.Core/Constants-Conventions.cs b/src/Umbraco.Core/Constants-Conventions.cs index d49244d9f9ef..6c9407667ae2 100644 --- a/src/Umbraco.Core/Constants-Conventions.cs +++ b/src/Umbraco.Core/Constants-Conventions.cs @@ -92,10 +92,10 @@ public static class Media /// public const string Extension = "umbracoExtension"; - /// - /// The default height/width of an image file if the size can't be determined from the metadata - /// - public const int DefaultSize = 200; + /// + /// The default height/width of an image file if the size can't be determined from the metadata + /// + public const int DefaultSize = 200; } /// @@ -209,71 +209,71 @@ public static class Member public static Dictionary GetStandardPropertyTypeStubs() { return new Dictionary + { { + Comments, + new PropertyType(PropertyEditors.Aliases.TextArea, ValueStorageType.Ntext, true, Comments) { - Comments, - new PropertyType(PropertyEditors.Aliases.TextArea, ValueStorageType.Ntext, true, Comments) - { - Name = CommentsLabel - } - }, + Name = CommentsLabel + } + }, + { + FailedPasswordAttempts, + new PropertyType(PropertyEditors.Aliases.Label, ValueStorageType.Integer, true, FailedPasswordAttempts) { - FailedPasswordAttempts, - new PropertyType(PropertyEditors.Aliases.Label, ValueStorageType.Integer, true, FailedPasswordAttempts) - { - Name = FailedPasswordAttemptsLabel - } - }, + Name = FailedPasswordAttemptsLabel + } + }, + { + IsApproved, + new PropertyType(PropertyEditors.Aliases.Boolean, ValueStorageType.Integer, true, IsApproved) { - IsApproved, - new PropertyType(PropertyEditors.Aliases.Boolean, ValueStorageType.Integer, true, IsApproved) - { - Name = IsApprovedLabel - } - }, + Name = IsApprovedLabel + } + }, + { + IsLockedOut, + new PropertyType(PropertyEditors.Aliases.Boolean, ValueStorageType.Integer, true, IsLockedOut) { - IsLockedOut, - new PropertyType(PropertyEditors.Aliases.Boolean, ValueStorageType.Integer, true, IsLockedOut) - { - Name = IsLockedOutLabel - } - }, + Name = IsLockedOutLabel + } + }, + { + LastLockoutDate, + new PropertyType(PropertyEditors.Aliases.Label, ValueStorageType.Date, true, LastLockoutDate) { - LastLockoutDate, - new PropertyType(PropertyEditors.Aliases.Label, ValueStorageType.Date, true, LastLockoutDate) - { - Name = LastLockoutDateLabel - } - }, + Name = LastLockoutDateLabel + } + }, + { + LastLoginDate, + new PropertyType(PropertyEditors.Aliases.Label, ValueStorageType.Date, true, LastLoginDate) { - LastLoginDate, - new PropertyType(PropertyEditors.Aliases.Label, ValueStorageType.Date, true, LastLoginDate) - { - Name = LastLoginDateLabel - } - }, + Name = LastLoginDateLabel + } + }, + { + LastPasswordChangeDate, + new PropertyType(PropertyEditors.Aliases.Label, ValueStorageType.Date, true, LastPasswordChangeDate) { - LastPasswordChangeDate, - new PropertyType(PropertyEditors.Aliases.Label, ValueStorageType.Date, true, LastPasswordChangeDate) - { - Name = LastPasswordChangeDateLabel - } - }, + Name = LastPasswordChangeDateLabel + } + }, + { + PasswordAnswer, + new PropertyType(PropertyEditors.Aliases.Label, ValueStorageType.Nvarchar, true, PasswordAnswer) { - PasswordAnswer, - new PropertyType(PropertyEditors.Aliases.Label, ValueStorageType.Nvarchar, true, PasswordAnswer) - { - Name = PasswordAnswerLabel - } - }, + Name = PasswordAnswerLabel + } + }, + { + PasswordQuestion, + new PropertyType(PropertyEditors.Aliases.Label, ValueStorageType.Nvarchar, true, PasswordQuestion) { - PasswordQuestion, - new PropertyType(PropertyEditors.Aliases.Label, ValueStorageType.Nvarchar, true, PasswordQuestion) - { - Name = PasswordQuestionLabel - } + Name = PasswordQuestionLabel } - }; + } + }; } } diff --git a/src/Umbraco.Core/Constants-Icons.cs b/src/Umbraco.Core/Constants-Icons.cs index f74b44b70bb0..d3e8b4ad3be5 100644 --- a/src/Umbraco.Core/Constants-Icons.cs +++ b/src/Umbraco.Core/Constants-Icons.cs @@ -1,17 +1,9 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Umbraco.Core +namespace Umbraco.Core { public static partial class Constants { public static class Icons { - - /// /// System contenttype icon /// @@ -42,12 +34,10 @@ public static class Icons /// public const string MemberType = "icon-users"; - /// /// System member icon /// public const string Template = "icon-layout"; - } } } diff --git a/src/Umbraco.Core/Constants-Indexes.cs b/src/Umbraco.Core/Constants-Indexes.cs index c73a170b6239..1add0f721b94 100644 --- a/src/Umbraco.Core/Constants-Indexes.cs +++ b/src/Umbraco.Core/Constants-Indexes.cs @@ -1,7 +1,4 @@ -using System; -using System.ComponentModel; - -namespace Umbraco.Core +namespace Umbraco.Core { public static partial class Constants { diff --git a/src/Umbraco.Core/Constants-ObjectTypes.cs b/src/Umbraco.Core/Constants-ObjectTypes.cs index 4bf944e1e1b2..9a6a1a063283 100644 --- a/src/Umbraco.Core/Constants-ObjectTypes.cs +++ b/src/Umbraco.Core/Constants-ObjectTypes.cs @@ -123,7 +123,6 @@ public static class Strings public static readonly Guid Template = new Guid(Strings.Template); public static readonly Guid ContentItem = new Guid(Strings.ContentItem); - } } } diff --git a/src/Umbraco.Core/Constants-PackageRepository.cs b/src/Umbraco.Core/Constants-PackageRepository.cs index 59005b3e2c81..42cf61f9823a 100644 --- a/src/Umbraco.Core/Constants-PackageRepository.cs +++ b/src/Umbraco.Core/Constants-PackageRepository.cs @@ -3,7 +3,7 @@ public static partial class Constants { /// - /// Defines the constants used for the Umbraco package repository + /// Defines the constants used for the Umbraco package repository /// public static class PackageRepository { diff --git a/src/Umbraco.Core/Constants-PropertyEditors.cs b/src/Umbraco.Core/Constants-PropertyEditors.cs index 32f94076169c..0c2e246721c2 100644 --- a/src/Umbraco.Core/Constants-PropertyEditors.cs +++ b/src/Umbraco.Core/Constants-PropertyEditors.cs @@ -34,7 +34,6 @@ public static class Aliases /// public const string ContentPicker = "Umbraco.ContentPicker"; - /// /// DateTime. /// diff --git a/src/Umbraco.Core/Constants-Web.cs b/src/Umbraco.Core/Constants-Web.cs index 0da5431e91d6..64216ba57178 100644 --- a/src/Umbraco.Core/Constants-Web.cs +++ b/src/Umbraco.Core/Constants-Web.cs @@ -1,7 +1,4 @@ -using System; -using System.ComponentModel; - -namespace Umbraco.Core +namespace Umbraco.Core { public static partial class Constants { @@ -22,7 +19,6 @@ public static class Web public const string PreviewCookieName = "UMB_PREVIEW"; public const string InstallerCookieName = "umb_installId"; - } } } diff --git a/src/Umbraco.Core/Persistence/Constants-DatabaseSchema.cs b/src/Umbraco.Core/Persistence/Constants-DatabaseSchema.cs index b62a99ce83d5..272158551d0b 100644 --- a/src/Umbraco.Core/Persistence/Constants-DatabaseSchema.cs +++ b/src/Umbraco.Core/Persistence/Constants-DatabaseSchema.cs @@ -69,7 +69,7 @@ public static class Tables public const string Tag = /*TableNamePrefix*/ "cms" + "Tags"; public const string TagRelationship = /*TableNamePrefix*/ "cms" + "TagRelationship"; - + public const string KeyValue = TableNamePrefix + "KeyValue"; public const string AuditEntry = TableNamePrefix + "Audit"; diff --git a/src/Umbraco.Core/UdiEntityType.cs b/src/Umbraco.Core/UdiEntityType.cs index 86197ce6a855..75a137bd2e48 100644 --- a/src/Umbraco.Core/UdiEntityType.cs +++ b/src/Umbraco.Core/UdiEntityType.cs @@ -20,7 +20,7 @@ public static class UdiEntityType internal static Dictionary GetTypes() { - return new Dictionary + return new Dictionary { { Unknown, UdiType.Unknown },