public static bool JumpToFirst(this BaseElementNavigator nav, string path) { var matches = Find(nav, path); if (matches.Any()) { nav.ReturnToBookmark(matches.First()); return(true); } return(false); }
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); }
public static bool MoveToChild(this BaseElementNavigator nav, string name) { if (nav.MoveToFirstChild()) { do { if (nav.PathName == name) { return(true); } }while (nav.MoveToNext()); nav.MoveToParent(); } return(false); }
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>()); } }
/// <summary> /// Insert the children of the current source node under the node pointed to by the destination. /// </summary> /// <param name="dest"></param> /// <param name="source"></param> /// <returns></returns> public static bool CopyChildren(this BaseElementNavigator dest, ElementNavigator source) { if (dest.HasChildren) { return(false); // Protect children from being overwritten } if (!source.MoveToFirstChild()) { return(true); // Nothing to copy, but successful anyway } bool firstChild = true; do { var copiedChild = (Profile.ElementComponent)source.Current.DeepCopy(); if (firstChild) { // The first time, create a new child in the destination dest.InsertFirstChild(copiedChild); firstChild = false; } else { // Then insert other childs after that dest.InsertAfter(copiedChild); } // If there are nested children in the source, insert them under // the newly inserted node in the destination if (source.HasChildren) { dest.CopyChildren(source); } }while (source.MoveToNext()); // Bring both source & destination back one step to the original parents source.MoveToParent(); dest.MoveToParent(); return(true); }
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>(); }