private static IEnumerable <Bookmark> locateChildren(BaseElementNavigator nav, IEnumerable <string> path, bool partial) { var child = path.First(); var rest = path.Skip(1); var bm = nav.Bookmark(); if (nav.MoveToChild(child)) { var result = new List <Bookmark>(); do { if (!rest.Any()) { // Exact match! result.Add(nav.Bookmark()); } else if (!nav.HasChildren && partial) { // This is as far as we can get in this structure, // so this is a hit too if partial hits are OK result.Add(nav.Bookmark()); } else { // So, no hit, but we have children that might fit the bill. result.AddRange(locateChildren(nav, rest, partial)); } // Try this for the other matching siblings too... }while (nav.MoveToNext(child)); // We've scanned all my children and collected the results, // move the navigator back to where we were before nav.ReturnToBookmark(bm); return(result); } else { return(Enumerable.Empty <Bookmark>()); } }
public static IEnumerable <Bookmark> Approach(this BaseElementNavigator nav, string path) { var parts = path.Split('.'); var bm = nav.Bookmark(); nav.Reset(); var result = locateChildren(nav, parts, partial: true); nav.ReturnToBookmark(bm); return(result); }
public static bool DeleteChildren(this BaseElementNavigator nav) { var parent = nav.Bookmark(); if (nav.MoveToFirstChild()) { while (!nav.IsAtBookmark(parent)) { nav.DeleteTree(); } } return(true); }
public static bool MoveToPrevious(this BaseElementNavigator nav, string name) { var bm = nav.Bookmark(); while (nav.MoveToPrevious()) { if (nav.PathName == name) { return(true); } } nav.ReturnToBookmark(bm); return(false); }
private static void rebaseChildren(BaseElementNavigator nav, string path, List<string> newPaths) { var bm = nav.Bookmark(); if (nav.MoveToFirstChild()) { do { var newPath = path + "." + nav.Current.GetNameFromPath(); newPaths.Add(newPath); if(nav.HasChildren) rebaseChildren(nav, newPath, newPaths); } while (nav.MoveToNext()); nav.ReturnToBookmark(bm); } }
private static void rebaseChildren(BaseElementNavigator nav, string path, List <string> newPaths) { var bm = nav.Bookmark(); if (nav.MoveToFirstChild()) { do { var newPath = path + "." + nav.Current.GetNameFromPath(); newPaths.Add(newPath); if (nav.HasChildren) { rebaseChildren(nav, newPath, newPaths); } }while (nav.MoveToNext()); nav.ReturnToBookmark(bm); } }
public static bool AppendChild(this BaseElementNavigator nav, Profile.ElementComponent child) { var bm = nav.Bookmark(); if (nav.MoveToFirstChild()) { while (nav.MoveToNext()) { ; } var result = nav.InsertAfter(child); if (!result) { nav.ReturnToBookmark(bm); } return(result); } else { return(nav.InsertFirstChild(child)); } }
private static IEnumerable<Bookmark> locateChildren(BaseElementNavigator nav, IEnumerable<string> path, bool partial) { var child = path.First(); var rest = path.Skip(1); var bm = nav.Bookmark(); if (nav.MoveToChild(child)) { var result = new List<Bookmark>(); do { if (!rest.Any()) { // Exact match! result.Add(nav.Bookmark()); } else if (!nav.HasChildren && partial) { // This is as far as we can get in this structure, // so this is a hit too if partial hits are OK result.Add(nav.Bookmark()); } else { // So, no hit, but we have children that might fit the bill. result.AddRange(locateChildren(nav, rest, partial)); } // Try this for the other matching siblings too... } while (nav.MoveToNext(child)); // We've scanned all my children and collected the results, // move the navigator back to where we were before nav.ReturnToBookmark(bm); return result; } else return Enumerable.Empty<Bookmark>(); }