示例#1
0
 public WeChatAssociationUriMapper(UriMapperBase upperMapper = null) {
     upper = upperMapper;
 }
        private bool NavigateCore(Uri uri, NavigationMode mode, bool suppressJournalAdd, bool isRedirect)
        {
            try
            {
                if (uri == null)
                {
                    throw new ArgumentNullException("uri", Resource.NavigationService_NavigationToANullUriIsNotSupported);
                }

                // Make sure we're on the UI thread because of the DependencyProperties we use.
                if (!this.Host.Dispatcher.CheckAccess())
                {
                    // Move to UI thread
                    this.Host.Dispatcher.BeginInvoke(() => this.NavigateCore(uri, mode, suppressJournalAdd, isRedirect));
                    return(true);
                }

                Uri mappedUri = uri;
                // If the Uri is only a fragment, mapping does not take place
                if (!UriParsingHelper.InternalUriIsFragment(uri))
                {
                    UriMapperBase mapper = this.Host.UriMapper;
                    if (mapper != null)
                    {
                        Uri uriFromMapper = mapper.MapUri(uri);
                        if (uriFromMapper != null && !String.IsNullOrEmpty(uriFromMapper.OriginalString))
                        {
                            mappedUri = uriFromMapper;
                        }
                        else
                        {
                            mappedUri = uri;
                        }
                    }
                }

                Uri mergedUriAfterMapping = UriParsingHelper.InternalUriMerge(this._currentSourceAfterMapping, mappedUri) ?? mappedUri;
                Uri mergedUri             = UriParsingHelper.InternalUriMerge(this._currentSource, uri) ?? uri;

                // If we're navigating to just a fragment (i.e. "#frag1") or to a page which differs only in the fragment
                // (i.e. "Page.xaml?id=123" to "Page.xaml?id=123#frag1") then complete navigation without involving the content loader
                bool isFragmentNavigationOnly = (mode != NavigationMode.Refresh) &&
                                                (UriParsingHelper.InternalUriIsFragment(mappedUri) ||
                                                 UriParsingHelper.InternalUriGetAllButFragment(mergedUri) == UriParsingHelper.InternalUriGetAllButFragment(this._currentSource));

                // Check to see if anyone wants to cancel
                if (mode == NavigationMode.New || mode == NavigationMode.Refresh)
                {
                    if (this.RaiseNavigating(mergedUri, mode, isFragmentNavigationOnly) == true)
                    {
                        // Someone stopped us
                        this.RaiseNavigationStopped(null, mergedUri);
                        return(true);
                    }
                }

                // If the ContentLoader cannot load the new URI, throw an ArgumentException
                if (!this.ContentLoader.CanLoad(mappedUri, _currentSourceAfterMapping))
                {
                    throw new ArgumentException(Resource.NavigationService_CannotLoadUri, "uri");
                }

                if (isFragmentNavigationOnly && this.Host.Content == null)
                {
                    // It doesn't make sense to fragment navigate when there's no content, so raise NavigationFailed
                    throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture,
                                                                      Resource.NavigationService_FragmentNavigationRequiresContent,
                                                                      "Frame"));
                }

                if (isRedirect && this._currentNavigation != null &&
                    this._currentNavigation.UriForJournal == this._currentSource)
                {
                    // Do not record navigation in the journal in case of a redirection
                    // where the original target is the current URI.
                    suppressJournalAdd = true;
                }

                // Stop in-progress navigation
                this.StopLoadingCore(isRedirect);

                return(this.NavigateCore_StartNavigation(uri, mode, suppressJournalAdd, mergedUriAfterMapping, mergedUri, isFragmentNavigationOnly));
            }
            catch (Exception ex)
            {
                if (this.RaiseNavigationFailed(uri, ex))
                {
                    throw;
                }
                return(true);
            }
        }
示例#3
0
文件: UbpMapper.cs 项目: Bulow/ubp
 /// <summary>
 /// 
 /// </summary>
 /// <param name="baseUri">The base uri of the page that recieves the url, eg: "/MainPage.xaml?url="</param>
 /// <param name="secondaryUriMapper">If the uri doesn't use the ubp protocol, the uri will be sent to this UriMapper</param>
 public UbpMapper(string baseUri, UriMapperBase secondaryUriMapper = null)
 {
     this.baseUri = baseUri;
     this.secondaryUriMapper = secondaryUriMapper;
 }