public static G EnsureByPath <G> (string path, CacheEntityCollection <G> cache) where G : GroupBase <G>, ICacheableEntity <G>, new () { string [] pathParts = path.Split(new [] { pathSeparator }, StringSplitOptions.RemoveEmptyEntries); G g = null; foreach (string part in pathParts) { G last = g; g = last != null? last.Children.FirstOrDefault(c => c.name == part) : cache.GetByName(part); if (g != null) { continue; } g = new G { Parent = last, Name = part }; g.CommitChanges(); if (last != null) { last.children.Add(g); } } return(g); }
public static G GetByPath <G> (string path, CacheEntityCollection <G> cache) where G : GroupBase <G>, ICacheableEntity <G>, new () { string [] pathParts = path.Split(new [] { pathSeparator }, StringSplitOptions.RemoveEmptyEntries); G g = null; foreach (string part in pathParts) { G last = g; g = last != null? last.Children.FirstOrDefault(c => c.name == part) : cache.GetByName(part); if (g == null) { return(null); } } return(g); }
public static string GetPath <G> (long groupId, CacheEntityCollection <G> cache) where G : GroupBase <G>, ICacheableEntity <G>, new () { if (groupId < 0) { return(null); } cache.EnsureCompleteLoad(); G g = cache.GetById(groupId); StringBuilder ret = new StringBuilder(); while (g != null) { ret.Insert(0, g.name); ret.Insert(0, pathSeparator); g = g.parent ?? cache.GetByCode(g.ParentCode); } return(ret.ToString()); }