Ejemplo n.º 1
0
    public override Uri MapUri(Uri uri)
    {
        string uriStr = uri.ToString();

        if (uriStr.Contains("/FileTypeAssociation"))
        {
            int    fileIDIndex       = uriStr.IndexOf("fileToken=") + 10;
            string fileID            = uriStr.Substring(fileIDIndex);
            string incommingFileName = SharedStorageAccessManager.GetSharedFileName(fileID);

            // Path.GetExtension will return String.Empty if no file extension found.
            int    extensionIndex   = incommingFileName.LastIndexOf('.') + 1;
            string incomingFileType = incommingFileName.Substring(extensionIndex).ToLower();

            if (incomingFileType == WeChat.appId)
            {
                return(new Uri("/WeChatCallbackPage.xaml?fileToken=" + fileID, UriKind.Relative));
            }
        }

        if (upper != null)
        {
            var upperResult = upper.MapUri(uri);

            if (upperResult != uri)
            {
                return(upperResult);
            }
        }

        return(new Uri("/MainPage.xaml", UriKind.Relative));
    }
Ejemplo n.º 2
0
        /// <summary>
        /// Called when the Frame.Loaded event fires.
        /// </summary>
        /// <param name="sender">The object raising the event</param>
        /// <param name="e">The event arguments</param>
        private void Frame_Loaded(object sender, RoutedEventArgs e)
        {
            this._navigationService.InitializeJournal();

            if (this.ContentLoader == null)
            {
                this.ContentLoader = new PageResourceContentLoader();
            }

            this._navigationService.InitializeNavigationCache();

            // Set loaded flag
            this._loaded = true;

            // Don't attempt to load anything at design-time
            if (!Frame.IsInDesignMode())
            {
                UriMapperBase mapper = this.UriMapper;

                // If there's a deeplink, don't check Source as the deeplink overrides it
                if (this.ApplyDeepLinks() == false)
                {
                    if (this._deferredNavigation != null)
                    {
                        this.Navigate(this._deferredNavigation);
                        this._deferredNavigation = null;
                    }

                    // Check if source property was set
                    else if (this.Source != null)
                    {
                        this.Navigate(this.Source);
                    }

                    // If no Source was set, we may still be able to use UriMapper to convert this to a navigable Uri
                    else if (mapper != null)
                    {
                        Uri emptyUri  = new Uri(String.Empty, UriKind.Relative);
                        Uri mappedUri = mapper.MapUri(emptyUri);
                        if (mappedUri != null && !String.IsNullOrEmpty(mappedUri.OriginalString))
                        {
                            this.Navigate(emptyUri);
                        }
                    }
                }
            }
            else
            {
                if (this.Source != null)
                {
                    this.Content = String.Format(CultureInfo.InvariantCulture, Resource.Frame_DefaultContent, this.Source.ToString());
                }
                else
                {
                    this.Content = typeof(Frame).Name;
                }
            }
        }
Ejemplo n.º 3
0
        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);
            }
        }