Example #1
0
 public ShellNavigationRequest(RequestDefinition definition, WhatToDoWithTheStack stackRequest, string query, string fragment)
 {
     StackRequest = stackRequest;
     Query        = query;
     Fragment     = fragment;
     Request      = definition;
 }
Example #2
0
        internal static NavigationRequest GetNavigationRequest(Shell shell, Uri uri, bool enableRelativeShellRoutes = false, bool throwNavigationErrorAsException = true, ShellNavigationParameters shellNavigationParameters = null)
        {
            uri = FormatUri(uri, shell);

            // figure out the intent of the Uri
            NavigationRequest.WhatToDoWithTheStack whatDoIDo = CalculateStackRequest(uri);

            Uri request = ConvertToStandardFormat(shell, uri);


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

            if (possibleRouteMatches.Count == 0)
            {
                if (throwNavigationErrorAsException)
                {
                    throw new ArgumentException($"unable to figure out route for: {uri}", nameof(uri));
                }

                return(null);
            }
            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);

                if (throwNavigationErrorAsException)
                {
                    throw new ArgumentException($"Ambiguous routes matched for: {uri} matches found: {matchesFound}", nameof(uri));
                }

                return(null);
            }

            var theWinningRoute = possibleRouteMatches[0];

            RequestDefinition definition =
                new RequestDefinition(theWinningRoute, shell);

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

            return(navigationRequest);
        }