diff --git a/src/Orchard.Web/Modules/Orchard.Taxonomies/Models/TermPart.cs b/src/Orchard.Web/Modules/Orchard.Taxonomies/Models/TermPart.cs index 6ddad4785e..5e7f12d247 100644 --- a/src/Orchard.Web/Modules/Orchard.Taxonomies/Models/TermPart.cs +++ b/src/Orchard.Web/Modules/Orchard.Taxonomies/Models/TermPart.cs @@ -1,4 +1,3 @@ -using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; @@ -83,83 +82,5 @@ public static IEnumerable Sort(IEnumerable terms) { return terms.OrderBy(term => term.FullWeight); } - - [Obsolete] - public static IEnumerable SortObsolete(IEnumerable terms) - { - var list = terms.ToList(); - var index = list.ToDictionary(x => x.FullPath); - return list.OrderBy(x => x, new TermsComparer(index)); - } - - [Obsolete] - private class TermsComparer : IComparer - { - private readonly IDictionary _index; - - public TermsComparer(IDictionary index) - { - _index = index; - } - - public int Compare(TermPart x, TermPart y) - { - - // if two nodes have the same parent, then compare by weight, then by path - // /1/2/3 vs /1/2/4 => 3 vs 4 - if (x.Path == y.Path) - { - var weight = y.Weight.CompareTo(x.Weight); - - if (weight != 0) - { - return weight; - } - - // if same parent path and same weight, compare by name - return string.Compare(x.Name, y.Name, StringComparison.OrdinalIgnoreCase); - } - - // if two nodes have different parents - - // if the two nodes have the same root, the deeper is after (i.e. one starts with the other) - // /1/2 vs /1/2/3 => /1/2 first - - if (x.FullPath.StartsWith(y.FullPath, StringComparison.OrdinalIgnoreCase)) - { - return 1; - } - - if (y.FullPath.StartsWith(x.FullPath, StringComparison.OrdinalIgnoreCase)) - { - return -1; - } - - // otherwise compare first none matching parent - // /1/2 vs /1/3 => 2 vs 3 - // /2/3 vs /4 => 2 vs 4 - - var xPath = x.FullPath.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries); - var yPath = y.FullPath.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries); - - string xFullPath = "", yFullPath = ""; - - for (var i = 0; i < Math.Min(xPath.Length, yPath.Length); i++) - { - xFullPath += "/" + xPath[i]; - yFullPath += "/" + yPath[i]; - - if (!xFullPath.Equals(yFullPath, StringComparison.OrdinalIgnoreCase)) - { - var xParent = _index[xFullPath]; - var yParent = _index[yFullPath]; - - return Compare(xParent, yParent); - } - } - - return 0; - } - } } -} \ No newline at end of file +}