예제 #1
0
 public NavigationRequest(RequestDefinition definition, WhatToDoWithTheStack stackRequest, string query, string fragment)
 {
     StackRequest = stackRequest;
     Query        = query;
     Fragment     = fragment;
     Request      = definition;
 }
예제 #2
0
        internal static NavigationRequest GetNavigationRequest(Shell shell, Uri uri, bool enableRelativeShellRoutes = false)
        {
            uri = FormatUri(uri, shell);
            // figure out the intent of the Uri
            NavigationRequest.WhatToDoWithTheStack whatDoIDo = NavigationRequest.WhatToDoWithTheStack.PushToIt;
            if (uri.IsAbsoluteUri)
            {
                whatDoIDo = NavigationRequest.WhatToDoWithTheStack.ReplaceIt;
            }
            else if (uri.OriginalString.StartsWith("//", StringComparison.Ordinal) || uri.OriginalString.StartsWith("\\\\", StringComparison.Ordinal))
            {
                whatDoIDo = NavigationRequest.WhatToDoWithTheStack.ReplaceIt;
            }
            else
            {
                whatDoIDo = NavigationRequest.WhatToDoWithTheStack.PushToIt;
            }

            Uri request = ConvertToStandardFormat(shell, uri);

            var possibleRouteMatches = GenerateRoutePaths(shell, request, uri, enableRelativeShellRoutes);


            if (possibleRouteMatches.Count == 0)
            {
                throw new ArgumentException($"unable to figure out route for: {uri}", nameof(uri));
            }
            else if (possibleRouteMatches.Count > 1)
            {
                string[] matches = new string[possibleRouteMatches.Count];
                int      i       = 0;
                foreach (var match in possibleRouteMatches)
                {
                    matches[i] = match.PathFull;
                    i++;
                }

                string matchesFound = String.Join(",", matches);
                throw new ArgumentException($"Ambiguous routes matched for: {uri} matches found: {matchesFound}", nameof(uri));
            }

            var theWinningRoute          = possibleRouteMatches[0];
            RequestDefinition definition =
                new RequestDefinition(
                    ConvertToStandardFormat(shell, CreateUri(theWinningRoute.PathFull)),
                    theWinningRoute.Item,
                    theWinningRoute.Section,
                    theWinningRoute.Content,
                    theWinningRoute.GlobalRouteMatches);

            NavigationRequest navigationRequest = new NavigationRequest(definition, whatDoIDo, request.Query, request.Fragment);

            return(navigationRequest);
        }