Beispiel #1
0
        /// <summary>
        /// Creates a new NavigationService from the gived Frame to the
        /// WindowWrapper collection. In addition, it optionally will setup the
        /// shell back button to react to the nav of the Frame.
        /// A developer should call this when creating a new/secondary frame.
        /// The shell back button should only be setup one time.
        /// </summary>
        public INavigationService NavigationServiceFactory(BackButton backButton, ExistingContent existingContent, Frame frame)
        {
            DebugWrite($"{nameof(backButton)}:{backButton} {nameof(existingContent)}:{existingContent} {nameof(frame)}:{frame}");

            frame.Content = (existingContent == ExistingContent.Include) ? Window.Current.Content : null;

            // if the service already exists for this frame, use the existing one.
            foreach (var nav in WindowWrapper.ActiveWrappers.SelectMany(x => x.NavigationServices))
            {
                if (nav.FrameFacade.Frame.Equals(frame))
                {
                    return(nav as INavigationService);
                }
            }

            var navigationService = CreateNavigationService(frame);

            navigationService.FrameFacade.BackButtonHandling = backButton;
            WindowWrapper.Current().NavigationServices.Add(navigationService);

            if (backButton == BackButton.Attach)
            {
                // TODO: unattach others

                // update shell back when backstack changes
                // only the default frame in this case because secondary should not dismiss the app
                frame.RegisterPropertyChangedCallback(Frame.BackStackDepthProperty, (s, args) => UpdateShellBackButton());

                // update shell back when navigation occurs
                // only the default frame in this case because secondary should not dismiss the app
                frame.Navigated += (s, args) => UpdateShellBackButton();
            }

            // this is always okay to check, default or not
            // expire any state (based on expiry)
            DateTime cacheDate;
            // default the cache age to very fresh if not known
            var otherwise = DateTime.MinValue.ToString();

            if (DateTime.TryParse(navigationService.FrameFacade.GetFrameState(CacheDateKey, otherwise), out cacheDate))
            {
                var cacheAge = DateTime.Now.Subtract(cacheDate);
                if (cacheAge >= CacheMaxDuration)
                {
                    // clear state in every nav service in every view
                    foreach (var nav in WindowWrapper.ActiveWrappers.SelectMany(x => x.NavigationServices))
                    {
                        nav.FrameFacade.ClearFrameState();
                    }
                }
            }
            else
            {
                // no date, that's okay
            }

            return(navigationService);
        }
        public INavigationService NavigationServiceFactory(
            BackButton backButton,
            ExistingContent existingContent,
            Frame frame)
        {
            Bootstrapper.DebugWrite(
                $"{nameof(BackButton)}:{backButton} {nameof(ExistingContent)}:{existingContent} {nameof(Frame)}:{frame}");

            frame.Content = (existingContent == ExistingContent.Include) ? Window.Current.Content : null;

            foreach (var nav in WindowWrapper.ActiveWrappers.SelectMany(x => x.NavigationServices))
            {
                if (nav.FrameFacade.Frame.Equals(frame))
                {
                    return(nav as INavigationService);
                }
            }

            var navigationService = CreateNavigationService(frame);

            navigationService.FrameFacade.BackButtonHandling = backButton;
            WindowWrapper.Current().NavigationServices.Add(navigationService);

            if (backButton == BackButton.Attach)
            {
                frame.RegisterPropertyChangedCallback(
                    Frame.BackStackDepthProperty,
                    (s, args) => this.UpdateShellBackButton());

                frame.Navigated += (s, args) => this.UpdateShellBackButton();
            }


            var otherwise = DateTime.MinValue.ToString(CultureInfo.InvariantCulture);

            if (!DateTime.TryParse(navigationService.FrameFacade.GetFrameState(Bootstrapper.cachingService.CacheDateKey, otherwise), out var cacheDate))
            {
                return(navigationService);
            }

            var cacheAge = DateTime.Now.Subtract(cacheDate);

            if (cacheAge < Bootstrapper.cachingService.CacheMaxDuration)
            {
                return(navigationService);
            }

            foreach (var nav in WindowWrapper.ActiveWrappers.SelectMany(x => x.NavigationServices))
            {
                nav.FrameFacade.ClearFrameState();
            }


            return(navigationService);
        }
Beispiel #3
0
        /// <summary>
        ///     Creates a new NavigationService from the gived Frame to the
        ///     WindowWrapper collection. In addition, it optionally will setup the
        ///     shell back button to react to the nav of the Frame.
        ///     A developer should call this when creating a new/secondary frame.
        ///     The shell back button should only be setup one time.
        /// </summary>
        public INavigationService NavigationServiceSetup(
            BackButton backButton,
            ExistingContent existingContent,
            Frame frame)
        {
            frame.Language = ApplicationLanguages.Languages[0];
            frame.Content  = existingContent == ExistingContent.Include ? Window.Current.Content : null;

            var navigationService = new NavigationService(frame);

            navigationService.FrameFacade.BackButtonHandling = backButton;
            WindowWrapper.Current().NavigationServices.Add(navigationService);

            if (backButton == BackButton.Attach)
            {
                // TODO: unattach others

                // update shell back when backstack changes
                // only the default frame in this case because secondary should not dismiss the app
                frame.RegisterPropertyChangedCallback(Frame.BackStackDepthProperty, (s, args) => UpdateShellBackButton());

                // update shell back when navigation occurs
                // only the default frame in this case because secondary should not dismiss the app
                frame.Navigated += (s, args) => UpdateShellBackButton();
            }

            // this is always okay to check, default or not
            // expire any state (based on expiry)
            DateTime cacheDate;
            // default the cache age to very fresh if not known
            var otherwise = DateTime.MinValue.ToString(CultureInfo.InvariantCulture);

            if (DateTime.TryParse(navigationService.FrameFacade.GetFrameState(CacheDateKey, otherwise), out cacheDate))
            {
                var cacheAge = DateTime.Now.Subtract(cacheDate);
                if (cacheAge >= CacheMaxDuration)
                {
                    // clear state in every nav service in every view
                    foreach (var service in WindowWrapper.ActiveWrappers.SelectMany(x => x.NavigationServices))
                    {
                        service.FrameFacade.ClearFrameState();
                    }
                }
            }

            return(navigationService);
        }
Beispiel #4
0
        /// <summary>
        /// Creates a new Frame and adds the resulting NavigationService to the
        /// WindowWrapper collection. In addition, it optionally will setup the
        /// shell back button to react to the nav of the Frame.
        /// A developer should call this when creating a new/secondary frame.
        /// The shell back button should only be setup one time.
        /// </summary>
        public INavigationService NavigationServiceFactory(BackButton backButton, ExistingContent existingContent)
        {
            DebugWrite($"{nameof(backButton)}:{backButton} {nameof(ExistingContent)}:{existingContent}");

            return(NavigationServiceFactory(backButton, existingContent, new Frame()));
        }
Beispiel #5
0
 /// <summary>
 /// Creates a new Frame and adds the resulting NavigationService to the
 /// WindowWrapper collection. In addition, it optionally will setup the
 /// shell back button to react to the nav of the Frame.
 /// A developer should call this when creating a new/secondary frame.
 /// The shell back button should only be setup one time.
 /// </summary>
 public Services.NavigationService.NavigationService NavigationServiceFactory(BackButton backButton, ExistingContent existingContent)
 {
     return(NavigationServiceFactory(backButton, existingContent, new Frame()));
 }
Beispiel #6
0
        /// <summary>
        /// Creates a new Frame and adds the resulting NavigationService to the
        /// WindowWrapper collection. In addition, it optionally will setup the
        /// shell back button to react to the nav of the Frame.
        /// A developer should call this when creating a new/secondary frame.
        /// The shell back button should only be setup one time.
        /// </summary>
        public INavigationService NavigationServiceFactory(BackButton backButton, ExistingContent existingContent, int session, string id, bool root)
        {
            DebugWrite($"{nameof(backButton)}:{backButton} {nameof(ExistingContent)}:{existingContent}");

            return(NavigationServiceFactory(backButton, existingContent, new Frame(), session, id, root));
        }
        /// <summary>
        /// Craetes a new FamFrame and adds the resulting NavigationService to the 
        /// WindowWrapper collection. In addition, it optionally will setup the 
        /// shell back button to react to the nav of the Frame.
        /// A developer should call this when creating a new/secondary frame.
        /// The shell back button should only be setup one time.
        /// </summary>
        public Services.NavigationService.NavigationService NavigationServiceFactory(BackButton backButton, ExistingContent existingContent)
        {
            var frame = new Frame
            {
                Language = Windows.Globalization.ApplicationLanguages.Languages[0],
                Content = (existingContent == ExistingContent.Include) ? Window.Current.Content : null,
            };

            var navigationService = new Services.NavigationService.NavigationService(frame);
            WindowWrapper.Current().NavigationServices.Add(navigationService);

            if (backButton == BackButton.Attach)
            {
                // TODO: unattach others

                // update shell back when backstack changes
                // only the default frame in this case because secondary should not dismiss the app
                frame.RegisterPropertyChangedCallback(Frame.BackStackDepthProperty, (s, args) => UpdateShellBackButton());

                // update shell back when navigation occurs
                // only the default frame in this case because secondary should not dismiss the app
                frame.Navigated += (s, args) => UpdateShellBackButton();
            }

            // this is always okay to check, default or not
            // expire any state (based on expiry)
            DateTime cacheDate;
            // default the cache age to very fresh if not known
            var otherwise = DateTime.MinValue.ToString();
            if (DateTime.TryParse(navigationService.FrameFacade.GetFrameState(CacheDateKey, otherwise), out cacheDate))
            {
                var cacheAge = DateTime.Now.Subtract(cacheDate);
                if (cacheAge >= CacheMaxDuration)
                {
                    // clear state in every nav service in every view
                    foreach (var service in WindowWrapper.ActiveWrappers.SelectMany(x => x.NavigationServices))
                    {
                        service.FrameFacade.ClearFrameState();
                    }
                }
            }
            else
            {
                // no date, that's okay
            }

            return navigationService;
        }