public static ShellNavigationState GetNavigationState(ShellItem shellItem, ShellSection shellSection, ShellContent shellContent, IReadOnlyList <Page> sectionStack, IReadOnlyList <Page> modalStack) { List <string> routeStack = new List <string>(); bool stackAtRoot = sectionStack == null || sectionStack.Count <= 1; bool hasUserDefinedRoute = (Routing.IsUserDefined(shellItem)) || (Routing.IsUserDefined(shellSection)) || (Routing.IsUserDefined(shellContent)); if (shellItem != null) { var shellItemRoute = shellItem.Route; routeStack.Add(shellItemRoute); if (shellSection != null) { var shellSectionRoute = shellSection.Route; routeStack.Add(shellSectionRoute); if (shellContent != null) { var shellContentRoute = shellContent.Route; routeStack.Add(shellContentRoute); } if (!stackAtRoot) { for (int i = 1; i < sectionStack.Count; i++) { var page = sectionStack[i]; routeStack.AddRange(ShellUriHandler.CollapsePath(Routing.GetRoute(page), routeStack, hasUserDefinedRoute)); } } if (modalStack != null && modalStack.Count > 0) { for (int i = 0; i < modalStack.Count; i++) { var topPage = modalStack[i]; routeStack.AddRange(ShellUriHandler.CollapsePath(Routing.GetRoute(topPage), routeStack, hasUserDefinedRoute)); for (int j = 1; j < topPage.Navigation.NavigationStack.Count; j++) { routeStack.AddRange(ShellUriHandler.CollapsePath(Routing.GetRoute(topPage.Navigation.NavigationStack[j]), routeStack, hasUserDefinedRoute)); } } } } } if (routeStack.Count > 0) { routeStack.Insert(0, "/"); } return(new ShellNavigationState(String.Join("/", routeStack), true)); }
public bool AddMatch(ShellUriHandler.NodeLocation nodeLocation) { if (Item == null && !AddNode(nodeLocation.Item, NextSegment)) { return(false); } if (Section == null && !AddNode(nodeLocation.Section, NextSegment)) { return(false); } if (Content == null && !AddNode(nodeLocation.Content, NextSegment)) { return(false); } return(true); bool AddNode(BaseShellItem baseShellItem, string nextSegment) { if (Routing.IsUserDefined(baseShellItem.Route) && baseShellItem.Route != nextSegment) { return(false); } AddMatch(baseShellItem.Route, GetUserSegment(baseShellItem), baseShellItem); return(true); } string GetUserSegment(BaseShellItem baseShellItem) { if (Routing.IsUserDefined(baseShellItem)) { return(baseShellItem.Route); } return(String.Empty); } }
public static ShellNavigationState GetNavigationState(ShellItem shellItem, ShellSection shellSection, ShellContent shellContent, IReadOnlyList <Page> sectionStack, IReadOnlyList <Page> modalStack) { List <string> routeStack = new List <string>(); bool stackAtRoot = sectionStack == null || sectionStack.Count <= 1; bool hasUserDefinedRoute = (Routing.IsUserDefined(shellItem)) || (Routing.IsUserDefined(shellSection)) || (Routing.IsUserDefined(shellContent)); if (shellItem != null) { var shellItemRoute = shellItem.Route; routeStack.Add(shellItemRoute); if (shellSection != null) { var shellSectionRoute = shellSection.Route; routeStack.Add(shellSectionRoute); if (shellContent != null) { var shellContentRoute = shellContent.Route; routeStack.Add(shellContentRoute); } if (!stackAtRoot) { for (int i = 1; i < sectionStack.Count; i++) { var page = sectionStack[i]; routeStack.AddRange(CollapsePath(Routing.GetRoute(page), routeStack, hasUserDefinedRoute)); } } if (modalStack != null && modalStack.Count > 0) { for (int i = 0; i < modalStack.Count; i++) { var topPage = modalStack[i]; routeStack.AddRange(CollapsePath(Routing.GetRoute(topPage), routeStack, hasUserDefinedRoute)); for (int j = 1; j < topPage.Navigation.NavigationStack.Count; j++) { routeStack.AddRange(CollapsePath(Routing.GetRoute(topPage.Navigation.NavigationStack[j]), routeStack, hasUserDefinedRoute)); } } } } } if (routeStack.Count > 0) { routeStack.Insert(0, "/"); } return(new ShellNavigationState(String.Join("/", routeStack), true)); List <string> CollapsePath( string myRoute, IEnumerable <string> currentRouteStack, bool userDefinedRoute) { var localRouteStack = currentRouteStack.ToList(); for (var i = localRouteStack.Count - 1; i >= 0; i--) { var route = localRouteStack[i]; if (Routing.IsImplicit(route) || (Routing.IsDefault(route) && userDefinedRoute)) { localRouteStack.RemoveAt(i); } } var paths = myRoute.Split('/').ToList(); // collapse similar leaves int walkBackCurrentStackIndex = localRouteStack.Count - (paths.Count - 1); while (paths.Count > 1 && walkBackCurrentStackIndex >= 0) { if (paths[0] == localRouteStack[walkBackCurrentStackIndex]) { paths.RemoveAt(0); } else { break; } walkBackCurrentStackIndex++; } return(paths); } }
public void AddMatch(string shellSegment, string userSegment, object node) { if (node == null) { throw new ArgumentNullException(nameof(node)); } switch (node) { case ShellUriHandler.GlobalRouteItem globalRoute: if (globalRoute.IsFinished) { _globalRouteMatches.Add(globalRoute.SourceRoute); } break; case Shell shell: if (shell == Shell) { return; } Shell = shell; break; case ShellItem item: if (Item == item) { return; } Item = item; break; case ShellSection section: if (Section == section) { return; } Section = section; if (Item == null) { Item = Section.Parent as ShellItem; _fullSegments.Add(Item.Route); } break; case ShellContent content: if (Content == content) { return; } Content = content; if (Section == null) { Section = Content.Parent as ShellSection; _fullSegments.Add(Section.Route); } if (Item == null) { Item = Section.Parent as ShellItem; _fullSegments.Insert(0, Item.Route); } break; } if (Item?.Parent is Shell s) { Shell = s; } // if shellSegment == userSegment it means the implicit route is part of the request if (Routing.IsUserDefined(shellSegment) || shellSegment == userSegment || shellSegment == NextSegment) { _matchedSegments.Add(shellSegment); } _fullSegments.Add(shellSegment); }