Beispiel #1
0
        public void AddGlobalRoute(string routeName, string segment)
        {
            _globalRouteMatches.Add(routeName);

            foreach (string path in ShellUriHandler.RetrievePaths(segment))
            {
                _fullSegments.Add(path);
                _matchedSegments.Add(path);
            }
        }
Beispiel #2
0
        public string GetNextSegmentMatch(string matchMe)
        {
            var segmentsToMatch = ShellUriHandler.RetrievePaths(matchMe).ToList();

            // if matchMe is an absolute route then we only match
            // if there are no routes already present
            if (matchMe.StartsWith("/", StringComparison.Ordinal) ||
                matchMe.StartsWith("\\", StringComparison.Ordinal))
            {
                for (var i = 0; i < _matchedSegments.Count; i++)
                {
                    var seg = _matchedSegments[i];
                    if (segmentsToMatch.Count <= i || segmentsToMatch[i] != seg)
                    {
                        return(String.Empty);
                    }

                    segmentsToMatch.Remove(seg);
                }
            }

            List <string> matches    = new List <string>();
            List <string> currentSet = new List <string>(_matchedSegments);

            foreach (var split in segmentsToMatch)
            {
                string next = GetNextSegment(currentSet);
                if (next == split)
                {
                    currentSet.Add(split);
                    matches.Add(split);
                }
                else
                {
                    return(String.Empty);
                }
            }

            return(String.Join(_uriSeparator, matches));
        }
Beispiel #3
0
        public static ShellNavigationSource CalculateNavigationSource(Shell shell, ShellNavigationState current, NavigationRequest request)
        {
            if (request.StackRequest == NavigationRequest.WhatToDoWithTheStack.PushToIt)
            {
                return(ShellNavigationSource.Push);
            }

            if (current == null)
            {
                return(ShellNavigationSource.ShellItemChanged);
            }

            var targetUri  = ShellUriHandler.ConvertToStandardFormat(shell, request.Request.FullUri);
            var currentUri = ShellUriHandler.ConvertToStandardFormat(shell, current.FullLocation);

            var targetPaths  = ShellUriHandler.RetrievePaths(targetUri.PathAndQuery);
            var currentPaths = ShellUriHandler.RetrievePaths(currentUri.PathAndQuery);

            var targetPathsLength  = targetPaths.Length;
            var currentPathsLength = currentPaths.Length;

            if (targetPathsLength < 4 || currentPathsLength < 4)
            {
                return(ShellNavigationSource.Unknown);
            }

            if (targetPaths[1] != currentPaths[1])
            {
                return(ShellNavigationSource.ShellItemChanged);
            }
            if (targetPaths[2] != currentPaths[2])
            {
                return(ShellNavigationSource.ShellSectionChanged);
            }
            if (targetPaths[3] != currentPaths[3])
            {
                return(ShellNavigationSource.ShellContentChanged);
            }

            if (targetPathsLength == currentPathsLength)
            {
                return(ShellNavigationSource.Unknown);
            }

            if (targetPathsLength < currentPathsLength)
            {
                for (var i = 0; i < targetPathsLength; i++)
                {
                    var targetPath = targetPaths[i];
                    if (targetPath != currentPaths[i])
                    {
                        break;
                    }

                    if (i == targetPathsLength - 1)
                    {
                        if (targetPathsLength == 4)
                        {
                            return(ShellNavigationSource.PopToRoot);
                        }

                        return(ShellNavigationSource.Pop);
                    }
                }

                if (targetPaths[targetPathsLength - 1] == currentPaths[currentPathsLength - 1])
                {
                    return(ShellNavigationSource.Remove);
                }

                if (targetPathsLength == 4)
                {
                    return(ShellNavigationSource.PopToRoot);
                }

                return(ShellNavigationSource.Pop);
            }
            else if (targetPathsLength > currentPathsLength)
            {
                for (var i = 0; i < currentPathsLength; i++)
                {
                    if (targetPaths[i] != currentPaths[i])
                    {
                        break;
                    }

                    if (i == targetPathsLength - 1)
                    {
                        return(ShellNavigationSource.Push);
                    }
                }
            }

            if (targetPaths[targetPathsLength - 1] == currentPaths[currentPathsLength - 1])
            {
                return(ShellNavigationSource.Insert);
            }

            return(ShellNavigationSource.Push);
        }