GetUniqueNodeName

Message: [TreePathUtils.GetUniqueNodeName]: The maximum number of tries to get a unique node name was reached. Please validate URL settings to make sure the restrictions aren't too strict. Exception type: System.Exception Stack trace: at CMS.DocumentEngine.TreePathUtils.GetUniqueNodeName(String nodeName, Int32 parentNodeId, Int32 currentNodeId, String className) at CMS.DocumentEngine.TreeNode.InsertNode(TreeNode parent) at CMS.DocumentEngine.TreeNode.Insert(TreeNode parent, Boolean useDocumentHelper) at CMS.DocumentEngine.DocumentHelper.InsertDocument(TreeNode node, TreeNode parentNode, TreeProvider tree, Boolean allowCheckOut)


SELECT NodeClassID,* FROM  dbo.CMS_Tree
WHERE NodeName LIKE '%am%'
ORDER BY NodeID DESC


SELECT ClassNodeNameSource,* FROM dbo.CMS_Class
WHERE  ClassDisplayName LIKE '%%'   --class id is 2968

 

SELECT NodeClassID,* FROM  dbo.CMS_Tree
WHERE NodeName LIKE '%am%'
ORDER BY NodeID DESC

 

public static string GetUniqueNodeName(string nodeName, int parentNodeId, int currentNodeId, string className)
        {
            // If name not specified, do not process
            if (string.IsNullOrEmpty(nodeName))
            {
                return string.Empty;
            }

            // Ensure maximal length
            nodeName = nodeName.Trim();
            nodeName = EnsureMaxNodeNameLength(nodeName, className);

            // There is only one root node, no need to check uniqueness
            if (parentNodeId <= 0)
            {
                return nodeName;
            }

            // Prepare base name
            var baseName = nodeName;
            if (baseName.EndsWith(")", StringComparison.Ordinal))
            {
                baseName = Regex.Replace(baseName, "[ ](\\(\\d+\\))$", string.Empty);
                if (baseName == string.Empty)
                {
                    baseName = nodeName;
                }
            }

            // Get candidates
            var maxNameLength = GetMaxNameLength(className);
            var searchName = TextHelper.LimitLength(baseName, maxNameLength - UNIQUE_SUFFIX_MAX_LENGTH, string.Empty);
            var data = DocumentNodeDataInfoProvider.GetDocumentNodes()
                                                   .Distinct()
                                                   .Columns("NodeName")
                                                   .WhereEquals("NodeParentID", parentNodeId)
                                                   .WhereStartsWith("NodeName", searchName)
                                                   .WhereNotEquals("NodeID", currentNodeId)
                // Linked documents have same node name as their originals
                                                   .WhereNull("NodeLinkedNodeID")
                                                   .Result;

            // No candidates available, the node name is unique
            if (DataHelper.DataSourceIsEmpty(data))
            {
                return nodeName;
            }

            var candidates = data.Tables[0];
            var uniqueIndex = 1;

            do
            {
                // Get matching duplicate
                var match = candidates.Select($"NodeName = '{SqlHelper.EscapeQuotes(nodeName)}'");
                if (match.Length == 0)
                {
                    // If not match, consider as unique
                    return nodeName;
                }

                // Prepare next candidate
                var uniqueString = $" ({uniqueIndex})";

                // Get the available length for the name without the unique suffix
                int availableLength = maxNameLength - uniqueString.Length;

                // Trim the name if necessary
                nodeName = (baseName.Length > availableLength) ? baseName.Substring(0, availableLength) : baseName;

                // Ensure unique suffix
                nodeName += uniqueString;

                // Maximal number of attemps reached
                if (uniqueIndex >= MAX_UNIQUE_INDEX)
                {
                    throw new Exception("[TreePathUtils.GetUniqueNodeName]: The maximum number of tries to get a unique node name was reached. Please validate URL settings to make sure the restrictions aren't too strict.");
                }

                uniqueIndex++;
            }
            while (true);
        }

 

作者:Chuck Lu    GitHub    
posted @   ChuckLu  阅读(20)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
历史上的今天:
2021-06-09 How to use git commands after enable gitlab's second-factor authentication
2021-06-09 WCF: DataMember attribute on property vs. member
2021-06-09 Why does the C# DataMember attribute allow serialization of private fields and properties?
2020-06-09 Package version is always 1.0.0 with dotnet pack
2020-06-09 CA1005: Avoid excessive parameters on generic types
2015-06-09 C#和.net之间的关系
2015-06-09 Visual C#每一次新版本的变化
点击右上角即可分享
微信分享提示