示例#1
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:
                Shell = shell;
                break;

            case ShellItem item:
                Item = item;
                break;

            case ShellSection section:
                Section = section;

                if (Item == null)
                {
                    Item = Section.Parent as ShellItem;
                    _fullSegments.Add(Item.Route);
                }

                break;

            case ShellContent content:
                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 shellSegment == userSegment it means the implicit route is part of the request
            if (!Routing.IsImplicit(shellSegment) || shellSegment == userSegment)
            {
                _matchedSegments.Add(shellSegment);
            }

            _fullSegments.Add(shellSegment);
        }
示例#2
0
            public Uri GetUri()
            {
                List <string> paths = new List <string>();

                paths.Add(Shell.RouteHost);
                paths.Add(Shell.Route);
                if (Item != null && !Routing.IsImplicit(Item))
                {
                    paths.Add(Item.Route);
                }
                if (Section != null && !Routing.IsImplicit(Section))
                {
                    paths.Add(Section.Route);
                }
                if (Content != null && !Routing.IsImplicit(Content))
                {
                    paths.Add(Content.Route);
                }

                string uri = String.Join(_pathSeparator, paths);

                return(new Uri($"{Shell.RouteScheme}://{uri}"));
            }
示例#3
0
        static void SearchPath(
            object node,
            RouteRequestBuilder currentMatchedPath,
            string[] segments,
            List <RouteRequestBuilder> possibleRoutePaths,
            int depthToStart,
            int myDepth = -1,
            NodeLocation currentLocation = null,
            bool ignoreGlobalRoutes      = true)
        {
            if (node is GlobalRouteItem && ignoreGlobalRoutes)
            {
                return;
            }

            ++myDepth;
            currentLocation = currentLocation ?? new NodeLocation();
            currentLocation.SetNode(node);

            IEnumerable items = null;

            if (depthToStart > myDepth)
            {
                items = GetItems(node);
                if (items == null)
                {
                    return;
                }

                foreach (var nextNode in items)
                {
                    SearchPath(nextNode, null, segments, possibleRoutePaths, depthToStart, myDepth, currentLocation, ignoreGlobalRoutes);
                }
                return;
            }

            string shellSegment = GetRoute(node);
            string userSegment  = null;

            if (currentMatchedPath == null)
            {
                userSegment = segments[0];
            }
            else
            {
                userSegment = currentMatchedPath.NextSegment;
            }

            if (userSegment == null)
            {
                return;
            }

            RouteRequestBuilder builder = null;

            if (shellSegment == userSegment || Routing.IsImplicit(shellSegment))
            {
                if (currentMatchedPath == null)
                {
                    builder = new RouteRequestBuilder(shellSegment, userSegment, node, segments);
                }
                else
                {
                    builder = new RouteRequestBuilder(currentMatchedPath);
                    builder.AddMatch(shellSegment, userSegment, node);
                }

                if (!Routing.IsImplicit(shellSegment) || shellSegment == userSegment)
                {
                    possibleRoutePaths.Add(builder);
                }
            }

            items = GetItems(node);
            if (items == null)
            {
                return;
            }

            foreach (var nextNode in items)
            {
                SearchPath(nextNode, builder, segments, possibleRoutePaths, depthToStart, myDepth, currentLocation, ignoreGlobalRoutes);
            }
        }