Ejemplo n.º 1
0
        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));
        }
Ejemplo n.º 2
0
        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)
            {
                _ = baseShellItem ?? throw new ArgumentNullException(nameof(baseShellItem));

                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);
            }
        }
Ejemplo n.º 3
0
        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);
        }