Example #1
0
        private async Task <Frame> EnsureRootFrameInitialization(ApplicationExecutionState previousExecutionState, Frame rootFrame)
        {
            // Do not repeat app initialization when the Window already has content,
            // just ensure that the window is active
            if (rootFrame == null)
            {
                // Create a Frame to act as the navigation context and navigate to the first page
                rootFrame = new Frame();
                NavigationService.Initialize(rootFrame);

                //Associate the frame with a SuspensionManager key
                SuspensionManager.RegisterFrame(rootFrame, "AppFrame");

                if (previousExecutionState == ApplicationExecutionState.Terminated)
                {
                    // Restore the saved session state only when appropriate
                    try
                    {
                        await SuspensionManager.RestoreAsync();
                    }
                    catch (SuspensionManagerException)
                    {
                        //Something went wrong restoring state.
                        //Assume there is no state and continue
                    }
                }

                // Place the frame in the current Window
                Window.Current.Content = rootFrame;
            }

            return(rootFrame);
        }
Example #2
0
        private async Task EnsureShell(ApplicationExecutionState previousState)
        {
            if (previousState == ApplicationExecutionState.Running)
            {
                Window.Current.Activate();
                ViewModelLocator.NavigationService.InitializeFrame(shell.Frame);
                return;
            }

            if (previousState == ApplicationExecutionState.Terminated || previousState == ApplicationExecutionState.ClosedByUser)
            {
                var settings = ViewModelLocator.Container.Resolve <ApplicationSettings>();
                await settings.RestoreAsync();
            }

            shell = new Shell();
            ViewModelLocator.NavigationService.InitializeFrame(shell.Frame);
            Window.Current.Content = shell;
            Window.Current.Activate();
            Dispatcher = Window.Current.CoreWindow.Dispatcher;

            MessagePumps.StartAll();

            ViewModelLocator.ShellViewModel.IsLoading = false;
        }
Example #3
0
        /// <summary>Called when a new instance of the application has been created. </summary>
        /// <param name="frame">The frame. </param>
        /// <param name="args">The launch arguments.</param>
        public override Task OnInitializedAsync(MtFrame frame, ApplicationExecutionState args)
        {
            frame.PageAnimation = new TurnstilePageAnimation();

            // TODO: Run when the app is started (not resumed)
            return null;
        }
Example #4
0
        /// <summary>
        /// 当应用离开后台时发现主界面内容为空时的操作
        /// </summary>
        /// <param name="previousExecutionState"></param>
        /// <param name="arguments"></param>
        void CreateRootFrame(ApplicationExecutionState previousExecutionState, string arguments)
        {
            Frame rootFrame = Window.Current.Content as Frame;

            if (rootFrame == null)
            {
                rootFrame                   = new Frame();
                rootFrame.Language          = Windows.Globalization.ApplicationLanguages.Languages[0];
                rootFrame.NavigationFailed += OnNavigationFailed;

                //重新实例化音乐及其信息服务
                musicInfomation = new MusicInfomation();
                musicService    = new MusicService();

                if (previousExecutionState == ApplicationExecutionState.Terminated)
                {
                    //TODO: 从之前挂起的应用程序加载状态
                    musicService.mediaPlayer.Volume = settings.MusicVolume;
                }
                Window.Current.Content = rootFrame;
            }
            if (rootFrame.Content == null)
            {
                rootFrame.Navigate(typeof(MainPage), arguments);
            }
            NotifyUserContectLost();
        }
Example #5
0
        /// <summary>
        /// Initializes root frame and resource loader.
        /// </summary>
        /// <param name="state">Application execution state.</param>
        /// <returns>Instance of <see cref="Frame"/>.</returns>
        private Frame InitializeRootFrameAndResourceLoader(ApplicationExecutionState state)
        {
            var rootFrame = Window.Current.Content as Frame;

            // Do not repeat app initialization when the Window already has content,
            // just ensure that the window is active
            if (rootFrame == null)
            {
                // Create a Frame to act as the navigation context and navigate to the first page
                rootFrame = new Frame();

                rootFrame.NavigationFailed += OnNavigationFailed;
                rootFrame.Background        = new SolidColorBrush(Colors.Black);

                if (state == ApplicationExecutionState.Terminated)
                {
                    //TODO: Load state from previously suspended application
                }

                // Place the frame in the current Window
                Window.Current.Content = rootFrame;
            }
            // Initialize resource loader then
            ResourceLoader = ResourceLoader.GetForCurrentView();

            return(rootFrame);
        }
Example #6
0
        /// <summary>Creates the application's root frame and loads the first page if needed.
        /// Also calls <see cref="OnInitializedAsync"/> when the application is instantiated the first time. </summary>
        /// <param name="executionState">The application execution state. </param>
        /// <returns>The task. </returns>
        protected async Task InitializeFrameAsync(ApplicationExecutionState executionState)
        {
            var rootFrame = Window.Current.Content as MtFrame;

            if (rootFrame == null)
            {
                rootFrame = CreateFrame();

                MtSuspensionManager.RegisterFrame(rootFrame, "AppFrame");
                if (executionState == ApplicationExecutionState.Terminated)
                {
                    await RestoreStateAsync();
                }

                var task = OnInitializedAsync(rootFrame, executionState);
                if (task != null)
                {
                    await task;
                }

                Window.Current.Content = rootFrame;
            }

            if (rootFrame.Content == null)
            {
                rootFrame.Initialize(StartPageType);
            }

            Window.Current.Activate();
        }
        /// <summary>
        /// Creates the frame containing the view
        /// </summary>
        /// <remarks>
        /// This is the same code that was in OnLaunched() initially.
        /// It is moved to a separate method so the view can be restored
        /// when leaving the background if it was unloaded when the app 
        /// entered the background.
        /// </remarks>
        void CreateRootFrame(ApplicationExecutionState previousExecutionState, string arguments)
        {
            Frame rootFrame = Window.Current.Content as Frame;

            // Do not repeat app initialization when the Window already has content,
            // just ensure that the window is active
            if (rootFrame == null)
            {
                System.Diagnostics.Debug.WriteLine("CreateFrame: Initializing root frame ...");

                // Create a Frame to act as the navigation context and navigate to the first page
                rootFrame = new Frame();

                // Set the default language
                rootFrame.Language = Windows.Globalization.ApplicationLanguages.Languages[0];

                rootFrame.NavigationFailed += OnNavigationFailed;

                if (previousExecutionState == ApplicationExecutionState.Terminated)
                {
                    //TODO: Load state from previously suspended application
                }

                // Place the frame in the current Window
                Window.Current.Content = rootFrame;
            }

            if (rootFrame.Content == null)
            {
                // When the navigation stack isn't restored navigate to the first page,
                // configuring the new page by passing required information as a navigation
                // parameter
                rootFrame.Navigate(typeof(MainPage), arguments);
            }
        }
Example #8
0
        private Frame InitRootFrame(ApplicationExecutionState previousExecutionState)
        {
            // Get the root frame
            Frame rootFrame = Window.Current.Content as Frame;

            // Do not repeat app initialization when the Window already has content,
            // just ensure that the window is active
            if (rootFrame == null)
            {
                // Create a Frame to act as the navigation context and navigate to the first page
                rootFrame = new Frame();

                rootFrame.NavigationFailed += OnNavigationFailed;

                if (previousExecutionState == ApplicationExecutionState.Terminated)
                {
                    //TODO: Load state from previously suspended application
                }

                // Place the frame in the current Window
                Window.Current.Content = rootFrame;
            }

            return(rootFrame);
        }
Example #9
0
        /// <summary>
        /// Determines how best to support navigation back to the previous application state.
        /// </summary>
        public static void Activate(String queryText, ApplicationExecutionState previousExecutionState)
        {
            var previousContent = Window.Current.Content;
            var frame           = previousContent as Frame;

            if (frame != null)
            {
                // If the app is already running and uses top-level frame navigation we can just
                // navigate to the search results
                frame.Navigate(typeof(SearchResultsPage), queryText);
            }
            else
            {
                // Otherwise bypass navigation and provide the tools needed to emulate the back stack

                SearchResultsPage page = new SearchResultsPage();
                page._previousContent        = previousContent;
                page._previousExecutionState = previousExecutionState;
                page.LoadState(queryText, null);
                Window.Current.Content = page;
            }

            // Either way, active the window
            Window.Current.Activate();
        }
		/// <summary>
		/// Invoked when the application is launched normally by the end user.  Other entry points
		/// will be used such as when the application is launched to open a specific file.
		/// </summary>
		/// <param name="e">Details about the launch request and process.</param>
		protected override void OnLaunched(LaunchActivatedEventArgs e)
		{

			Frame rootFrame = Window.Current.Content as Frame;

			// Do not repeat app initialization when the Window already has content,
			// just ensure that the window is active
			if (rootFrame == null)
			{
				// Create a Frame to act as the navigation context and navigate to the first page
				rootFrame = new Frame();

				rootFrame.NavigationFailed += OnNavigationFailed;

				PreviousExecutionState = e.PreviousExecutionState;
				if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
				{

				}

				// Place the frame in the current Window
				Window.Current.Content = rootFrame;
			}

			if (rootFrame.Content == null)
			{
				// When the navigation stack isn't restored navigate to the first page,
				// configuring the new page by passing required information as a navigation
				// parameter
				rootFrame.Navigate(typeof(MainPage), e.Arguments);
			}
			// Ensure the current window is active
			Window.Current.Activate();
		}
Example #11
0
        private async Task Launch(Func <Task> func, ApplicationExecutionState previousState)
        {
#if DEBUG
            if (Debugger.IsAttached)
            {
                this.DebugSettings.EnableFrameRateCounter = true;
            }
#endif

            await AppState.ReadSavedAppState();

            Frame rootFrame = Window.Current.Content as Frame;
            rootFrame = CreateRootFrame(rootFrame, previousState);

            if (rootFrame.Content == null)
            {
                // Removes the turnstile navigation for startup.
                if (rootFrame.ContentTransitions != null)
                {
                    this.transitions = new TransitionCollection();
                    foreach (var c in rootFrame.ContentTransitions)
                    {
                        this.transitions.Add(c);
                    }
                }

                rootFrame.ContentTransitions = null;
                rootFrame.Navigated         += this.RootFrame_FirstNavigated;

                await func();
            }

            // Ensure the current window is active
            Window.Current.Activate();
        }
Example #12
0
        private void CreateRootFrame(ApplicationExecutionState previousExecutionState, string arguments)
        {
            Frame rootFrame = Window.Current.Content as Frame;

            // Do not repeat app initialization when the Window already has content,
            // just ensure that the window is active
            if (rootFrame == null)
            {
                // Create a Frame to act as the navigation context and navigate to the first page
                rootFrame = new Frame
                {
                    // Set the default language
                    // Language = Windows.Globalization.ApplicationLanguages.Languages[0]
                };

                rootFrame.NavigationFailed -= OnNavigationFailed;
                rootFrame.NavigationFailed += OnNavigationFailed;

                if (previousExecutionState == ApplicationExecutionState.Terminated)
                {
                    //TODO: Load state from previously suspended application
                }

                // Place the frame in the current Window
                Window.Current.Content = rootFrame;
            }

            if (rootFrame.Content == null)
            {
                // When the navigation stack isn't restored navigate to the first page,
                // configuring the new page by passing required information as a navigation
                // parameter
                rootFrame.Navigate(typeof(MainPage), arguments);
            }
        }
Example #13
0
        void CreateRootFrame(ApplicationExecutionState previousExecutionState, string arguments)
        {
            var shell = Window.Current.Content as AppShell;

            // Do not repeat app initialization when the Window already has content,
            // just ensure that the window is active
            if (shell == null)
            {
                shell = new AppShell();

                // Set the default language
                shell.Language = ApplicationLanguages.Languages[0];

                shell.AppFrame.NavigationFailed += OnNavigationFailed;
            }

            // Place our app shell in the current Window
            Window.Current.Content = shell;

            if (shell.AppFrame.Content == null)
            {
                // When the navigation stack isn't restored navigate to the first page,
                // configuring the new page by passing required information as a navigation
                // parameter
                shell.AppFrame.Navigate(typeof(MainPage), arguments);
            }
        }
Example #14
0
        /// <summary>Creates the application's root frame and loads the first page if needed.
        /// Also calls <see cref="OnInitializedAsync"/> when the application is instantiated the first time. </summary>
        /// <param name="executionState">The application execution state. </param>
        /// <returns>The task. </returns>
        protected async Task InitializeFrameAsync(ApplicationExecutionState executionState)
        {
            if (Window.Current.Content == null)
            {
                WindowContent = CreateWindowContentElement();
                RootFrame     = GetFrame(WindowContent);

                MtSuspensionManager.RegisterFrame(RootFrame, "AppFrame");
                if (executionState == ApplicationExecutionState.Terminated)
                {
                    await RestoreStateAsync();
                }

                var task = OnInitializedAsync(RootFrame, executionState);
                if (task != null)
                {
                    await task;
                }

                Window.Current.Content = WindowContent;
            }
            else
            {
                RootFrame = GetFrame(Window.Current.Content);
            }

            if (RootFrame.Content == null)
            {
                RootFrame.Initialize(StartPageType);
            }

            Window.Current.Activate();
        }
Example #15
0
        private async Task RestoreCatrobatStateAsync(ApplicationExecutionState executionState)
        {
            await((SystemInformationServiceWindowsShared)ServiceLocator.SystemInformationService).Initialize();

            if (ViewModelBase.IsInDesignModeStatic)
            {
                return;
            }

            if (executionState == ApplicationExecutionState.NotRunning ||
                executionState == ApplicationExecutionState.ClosedByUser ||
                executionState == ApplicationExecutionState.Terminated)
            {
                Core.App.SetNativeApp(Application.Current.Resources["App"]
                                      as AppWindowsShared);
                ServiceLocator.Register(new DispatcherServiceWindowsShared(Dispatcher));
                await Core.App.Initialize();

                //ServiceLocator.Register(new DispatcherServiceWindowsShared(Dispatcher));

                //var width = ServiceLocator.SystemInformationService.ScreenWidth; // preload width
                //var height = ServiceLocator.SystemInformationService.ScreenHeight; // preload height

                var image = new BitmapImage(
                    new Uri("ms-appx:///Content/Images/Screenshot/NoScreenshot.png",
                            UriKind.Absolute))
                {
                    CreateOptions = BitmapCreateOptions.None
                };

                ManualImageCache.NoScreenshotImage = image;
            }

            await InitializationFinished(_activationArguments);
        }
Example #16
0
 private void BroadcastResumeStateMessageIfNeeded(ApplicationExecutionState previousExecutionState)
 {
     if (previousExecutionState == ApplicationExecutionState.Terminated)
     {
         EventAggregator.PublishOnUIThread(new ResumeStateMessage());
     }
 }
        private async Task EnsureShellAsync(ApplicationExecutionState previousState)
        {
            // Do not repeat app initialization when already running, just ensure that
            // the window is active
            if (previousState == ApplicationExecutionState.Running)
            {
                Window.Current.Activate();
                ViewModelLocator.NavigationService.Navigate(typeof(Shell));
                return;
            }

            _shell = new Shell();
            ViewModelLocator.NavigationService.InitializeFrame(_shell.Frame);
            Window.Current.Content = _shell;
            Window.Current.Activate();
            ViewModelLocator.NavigationService.Navigate(typeof(Shell));

            //Terminated - Restore session data
            if (previousState == ApplicationExecutionState.Terminated)
            {
                await ViewModelLocator.NavigationService.LoadSavedSession();
            }
            else // ClosedByUser - Start with default data; NotRunning - Start with default data
            {
                await ViewModelLocator.Hub.Send <ShowStartPageMessage>(new ShowStartPageMessage());
            }
            App.Dispatcher = Window.Current.CoreWindow.Dispatcher;
        }
Example #18
0
        /// <summary>Creates the application's root frame and loads the first page if needed. 
        /// Also calls <see cref="OnInitializedAsync"/> when the application is instantiated the first time. </summary>
        /// <param name="executionState">The application execution state. </param>
        /// <returns>The task. </returns>
        protected async Task InitializeFrameAsync(ApplicationExecutionState executionState)
        {
            if (Window.Current.Content == null)
            {
                WindowContent = CreateWindowContentElement();
                RootFrame = GetFrame(WindowContent);

                MtSuspensionManager.RegisterFrame(RootFrame, "AppFrame");
                if (executionState == ApplicationExecutionState.Terminated)
                    await RestoreStateAsync();

                var task = OnInitializedAsync(RootFrame, executionState);
                if (task != null)
                    await task;

                Window.Current.Content = WindowContent;
            }
            else
                RootFrame = GetFrame(Window.Current.Content);

            if (RootFrame.Content == null)
                RootFrame.Initialize(StartPageType);

            Window.Current.Activate();
        }
Example #19
0
        private Frame CreateRootFrame(ApplicationExecutionState previousExecutionState, string arguments, Type page)
        {
            Frame rootFrame = Window.Current.Content as Frame;

            // Do not repeat app initialization when the Window already has content,
            // just ensure that the window is active
            if (rootFrame == null)
            {
                Debug.WriteLine("CreateFrame: Initializing root frame ...");

                // Create a Frame to act as the navigation context and navigate to the first page
                rootFrame = new Frame();

                // Set the default language
                rootFrame.Language = Windows.Globalization.ApplicationLanguages.Languages[0];

                rootFrame.NavigationFailed += OnNavigationFailed;

                if (previousExecutionState == ApplicationExecutionState.Terminated)
                {
                    //TODO: Load state from previously suspended application
                }

                // Place the frame in the current Window
                Window.Current.Content = rootFrame;
            }

            return(rootFrame);
        }
Example #20
0
        /// <summary>
        /// Invoked when the application is launched normally by the end user.  Other entry points
        /// will be used such as when the application is launched to open a specific file.
        /// </summary>
        /// <param name="e">Details about the launch request and process.</param>
        protected override void OnLaunched(LaunchActivatedEventArgs e)
        {
            // How did the app exit the last time it was run (if at all)
            ApplicationExecutionState previousState = e.PreviousExecutionState;

            // What kind of launch is this?
            ActivationKind activationKind = e.Kind;

            //..

            Frame rootFrame = Window.Current.Content as Frame;

            // Do not repeat app initialization when the Window already has content,
            // just ensure that the window is active
            if (rootFrame == null)
            {
                // Create a Frame to act as the navigation context and navigate to the first page
                rootFrame = new Frame();

                rootFrame.NavigationFailed += OnNavigationFailed;

                if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
                {
                    // Set the frame navigation state that was serialized as a string when we suspended
                    if (ApplicationData.Current.LocalSettings.Values.ContainsKey("NavigationState"))
                    {
                        rootFrame.SetNavigationState((string)ApplicationData.Current.LocalSettings.Values["NavigationState"]);
                    }
                }

                // Place the frame in the current Window
                Window.Current.Content = rootFrame;
            }

            if (rootFrame.Content == null)
            {
                // When the navigation stack isn't restored navigate to the first page,
                // configuring the new page by passing required information as a navigation
                // parameter
                rootFrame.Navigate(typeof(MainPage), e.Arguments);
            }
            // Ensure the current window is active
            Window.Current.Activate();

            Windows.UI.Core.SystemNavigationManager.GetForCurrentView().BackRequested += OnBackRequested;

            // Every time the Frame navigates, set the visibility of the Shell-drawn back button
            // appropriate to whether there is anywhere to go back to
            rootFrame.Navigated += (s, a) => {
                if (rootFrame.CanGoBack)
                {
                    // Setting this visible is ignored on Mobile and when in tablet mode! 
                    SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible;
                }
                else
                {
                    SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Collapsed;
                }
            };
        }
Example #21
0
        private void CreateRootFrame(ApplicationExecutionState running, string empty)
        {
            Frame rootFrame = Window.Current.Content as Frame;

            // Do not repeat app initialization when the Window already has content,
            // just ensure that the window is active
            if (rootFrame == null)
            {
                // Create a Frame to act as the navigation context and navigate to the first page
                rootFrame = new Frame();

                rootFrame.NavigationFailed += OnNavigationFailed;

                if (running == ApplicationExecutionState.Terminated)
                {
                    //TODO: Load state from previously suspended application
                }

                // Place the frame in the current Window
                Window.Current.Content = rootFrame;
            }

            if (rootFrame.Content == null)
            {
                // When the navigation stack isn't restored navigate to the first page,
                // configuring the new page by passing required information as a navigation
                // parameter
                rootFrame.Navigate(typeof(MainPage), empty);
            }
            // Ensure the current window is active
            Window.Current.Activate();
        }
Example #22
0
        /// <summary>Called when a new instance of the application has been created. </summary>
        /// <param name="frame">The frame. </param>
        /// <param name="args">The launch arguments.</param>
        public override Task OnInitializedAsync(MtFrame frame, ApplicationExecutionState args)
        {
            frame.PageAnimation = new TurnstilePageAnimation();

            // TODO: Run when the app is started (not resumed)
            return(null);
        }
        async void RestoreStateAsync(ApplicationExecutionState executionState)
        {
            DateTime beforLoading = DateTime.UtcNow;
            await Task.Delay(100);

            await RestoreCatrobatStateAsync(executionState);

            if (executionState == ApplicationExecutionState.Terminated)
            {
                await SuspensionManager.RestoreAsync();
            }

            var loadingDuration = DateTime.UtcNow.Subtract(beforLoading);
            var timeToWait = MinimalLoadingTime.Subtract(loadingDuration);

            if (timeToWait > new TimeSpan())
                await Task.Delay(timeToWait);


            Window.Current.Content = _rootFrame;
            ServiceLocator.NavigationService = new NavigationServiceWindowsShared(_rootFrame);

            if (_activationArguments.Kind == ActivationKind.Protocol)
            {
                ServiceLocator.NavigationService.NavigateTo<UploadProgramNewPasswordViewModel>();
            }
            else
            {
                ServiceLocator.NavigationService.NavigateTo<MainViewModel>();
            }
        }
Example #24
0
        async void RestoreStateAsync(ApplicationExecutionState executionState)
        {
            DateTime beforLoading = DateTime.UtcNow;
            await Task.Delay(100);

            await RestoreCatrobatStateAsync(executionState);

            if (executionState == ApplicationExecutionState.Terminated)
            {
                await SuspensionManager.RestoreAsync();
            }

            var loadingDuration = DateTime.UtcNow.Subtract(beforLoading);
            var timeToWait      = MinimalLoadingTime.Subtract(loadingDuration);

            if (timeToWait > new TimeSpan())
            {
                await Task.Delay(timeToWait);
            }


            Window.Current.Content           = _rootFrame;
            ServiceLocator.NavigationService = new NavigationServiceWindowsShared(_rootFrame);

            if (_activationArguments.Kind == ActivationKind.Protocol)
            {
                ServiceLocator.NavigationService.NavigateTo <UploadProgramNewPasswordViewModel>();
            }
            else
            {
                ServiceLocator.NavigationService.NavigateTo <MainViewModel>();
            }
        }
        /// <summary>
        /// Determines how best to support navigation back to the previous application state.
        /// </summary>
        public static void Activate(String queryText, ApplicationExecutionState previousExecutionState)
        {
            var previousContent = Window.Current.Content;
            var frame = previousContent as Frame;

            if (frame != null)
            {
                // If the app is already running and uses top-level frame navigation we can just
                // navigate to the search results
                frame.Navigate(typeof(SearchResultsPage), queryText);
            }
            else
            {
                // Otherwise bypass navigation and provide the tools needed to emulate the back stack
             //   SearchResultsPage page = new SearchResultsPage();
            //    page._previousContent = previousContent;
            //    page._previousExecutionState = previousExecutionState;
            //    page.LoadState(queryText, null);
            ///    Window.Current.Content = page;
    frame = new Frame();
                Window.Current.Content = frame;
                SettingsPane.GetForCurrentView().CommandsRequested += (Application.Current as App).OnCommandsRequested;
                frame.Navigate(typeof(SearchResultsPage), queryText);

            }

            // Either way, active the window
            Window.Current.Activate();
        }
Example #26
0
        private void LaunchUi(bool prelaunched, ApplicationExecutionState previousState)
        {
            var tcs = new TaskCompletionSource <bool> ();

            GetStarted(tcs.Task);

            this.rootFrame = Window.Current.Content as Frame;
            if (rootFrame == null)
            {
                rootFrame = new Frame();
                rootFrame.NavigationFailed += OnNavigationFailed;

                if (previousState == ApplicationExecutionState.Terminated)
                {
                    //TODO: Load state from previously suspended application
                }

                Window.Current.Content = rootFrame;
            }

            if (!prelaunched)
            {
                if (rootFrame.Content == null)
                {
                    // When the navigation stack isn't restored navigate to the first page,
                    // configuring the new page by passing required information as a navigation
                    // parameter
                    rootFrame.Navigate(typeof(MainPage));
                }

                Window.Current.Activate();
            }

            tcs.SetResult(true);
        }
        public AppShell(ApplicationExecutionState modoExecucao)
        {
            this.InitializeComponent();
            //BannerAD.Visibility = App.ExibirAds ? Visibility.Visible : Visibility.Collapsed;
            ModoExecucao = modoExecucao;

            var vm = new ShellViewModel();

            this.ViewModel = vm;

            //vm.MenuItems.Add(new MenuItem { Icon = "", Title = "Page 1", PageType = typeof(Page1) });
            //vm.MenuItems.Add(new MenuItem { Icon = "", Title = "Page 2", PageType = typeof(Page2) });
            //vm.MenuItems.Add(new MenuItem { Icon = "", Title = "Page 3", PageType = typeof(Page3) });

            if (App.LoginConfigurado && !App.AppLogado)
            {
                vm.SelectedMenuItem = new MenuItem()
                {
                    Icon = "", PageType = typeof(LoginPage), Title = "Login"
                };
            }
            else
            {
                CarregarMenus();

                if (ModoExecucao != ApplicationExecutionState.Terminated)
                {
                    vm.SelectedMenuItem = vm.MenuItems.First();
                }


                //  this.AppFrame.GoBack();
            }
            Loaded += AppShell_Loaded;
        }
Example #28
0
        private void CheckPreviousExecutionState(ApplicationExecutionState previousExecutionState)
        {
            AppLog.Write(previousExecutionState.ToString());
            switch (previousExecutionState)
            {
            case ApplicationExecutionState.NotRunning:
                break;

            case ApplicationExecutionState.Running:
                break;

            case ApplicationExecutionState.Suspended:
                break;

            case ApplicationExecutionState.Terminated:
                //try to recover state, if it makes sense (time since last run?)
                break;

            case ApplicationExecutionState.ClosedByUser:
                //probably revert to clean state
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(previousExecutionState), previousExecutionState, null);
            }
        }
Example #29
0
        public static void Init(IActivatedEventArgs launchActivatedEventArgs, IEnumerable <Assembly> rendererAssemblies = null)
        {
            if (IsInitialized)
            {
                return;
            }

            var accent = (SolidColorBrush)Windows.UI.Xaml.Application.Current.Resources["SystemColorControlAccentBrush"];

            Color.SetAccent(accent.ToFormsColor());

            Log.Listeners.Add(new DelegateLogListener((c, m) => Debug.WriteLine(LogFormat, c, m)));

            Windows.UI.Xaml.Application.Current.Resources.MergedDictionaries.Add(GetTabletResources());

            Device.SetIdiom(TargetIdiom.Tablet);
            Device.SetFlowDirection(GetFlowDirection());
            Device.PlatformServices = new WindowsPlatformServices(Window.Current.Dispatcher);
            Device.SetFlags(s_flags);
            Device.Info = new WindowsDeviceInfo();

            switch (Windows.System.Profile.AnalyticsInfo.VersionInfo.DeviceFamily)
            {
            case "Windows.Desktop":
                if (Windows.UI.ViewManagement.UIViewSettings.GetForCurrentView().UserInteractionMode ==
                    Windows.UI.ViewManagement.UserInteractionMode.Touch)
                {
                    Device.SetIdiom(TargetIdiom.Tablet);
                }
                else
                {
                    Device.SetIdiom(TargetIdiom.Desktop);
                }
                break;

            case "Windows.Mobile":
                Device.SetIdiom(TargetIdiom.Phone);
                break;

            case "Windows.Xbox":
                Device.SetIdiom(TargetIdiom.TV);
                break;

            default:
                Device.SetIdiom(TargetIdiom.Unsupported);
                break;
            }

            ExpressionSearch.Default = new WindowsExpressionSearch();

            Registrar.ExtraAssemblies = rendererAssemblies?.ToArray();

            Registrar.RegisterAll(new[] { typeof(ExportRendererAttribute), typeof(ExportCellAttribute), typeof(ExportImageSourceHandlerAttribute) });

            IsInitialized = true;
            s_state       = launchActivatedEventArgs.PreviousExecutionState;

            Platform.UWP.Platform.SubscribeAlertsAndActionSheets();
        }
Example #30
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ShareEventArgs"/> class.
        /// </summary>
        /// <param name="previousExecutionState">The <see cref="ApplicationExecutionState">execution state</see> of the application before sharing began.</param>
        /// <param name="shareOperation">The representation of the <see cref="ShareOperation">share operation</see>.</param>
        public ShareEventArgs( ApplicationExecutionState previousExecutionState, ShareOperation shareOperation )
        {
            Arg.NotNull( shareOperation, nameof( shareOperation ) );

            PreviousExecutionState = previousExecutionState;
            adapted = shareOperation;
            dataPackageView = new Lazy<IDataPackageView>( () => new DataPackageViewAdapter( adapted.Data ) );
        }
Example #31
0
 private async Task InitializeStateManager(ApplicationExecutionState previousState)
 {
     this.StateManager = this.container.Resolve <IStateManager>();
     if (previousState == ApplicationExecutionState.Terminated)
     {
         await this.StateManager.RestoreAsync();
     }
 }
Example #32
0
        private void RunApp(ApplicationExecutionState previousExecutionState)
        {
            Frame rootFrame = Window.Current.Content as Frame;

            // Do not repeat app initialization when the Window already has content,
            // just ensure that the window is active
            if (rootFrame == null)
            {
                // Create a Frame to act as the navigation context and navigate to the first page
                rootFrame = new Frame();

                rootFrame.NavigationFailed += OnNavigationFailed;

                if (previousExecutionState == ApplicationExecutionState.Terminated)
                {
                    //TODO: Load state from previously suspended application
                }

                // Place the frame in the current Window
                Window.Current.Content = rootFrame;
            }

            if (rootFrame.Content == null)
            {
                // When the navigation stack isn't restored navigate to the first page,
                // configuring the new page by passing required information as a navigation
                // parameter
                bool loginAgain = false;

                Task.Run(() =>
                {
                    var x = new ViewModelLocator();
                    loginAgain = ServiceLocator.Current.GetInstance<IStorageService>().LoadLastUser();
                }).Wait();

                if (loginAgain)
                {
                    rootFrame.Navigate(typeof(NotificationListPage));
                    BackgroundTaskManager b = new BackgroundTaskManager();
                    b.Register();
                }
                else
                {
                    rootFrame.Navigate(typeof(LoginPage));
                }
            }
            else
            {

            }
            // Ensure the current window is active
            Window.Current.Activate();
            DispatcherHelper.Initialize();

            Messenger.Default.Register<NotificationMessageAction<string>>(
                this,
                HandleNotificationMessage);
        }
Example #33
0
        private void InitializeMainPage(ApplicationExecutionState previousExecutionState, string arguments)
        {
            Frame rootFrame = CreateRootFrame();

            if (rootFrame.Content == null || !String.IsNullOrEmpty(arguments))
            {
                rootFrame.Navigate(typeof(MainPage), arguments);
            }
        }
Example #34
0
        /// <summary>
        /// 在应用程序由最终用户正常启动时进行调用。
        /// 将在启动应用程序以打开特定文件等情况下使用。
        /// </summary>
        /// <param name="e">有关启动请求和过程的详细信息。</param>
        protected override void OnLaunched(LaunchActivatedEventArgs e)
        {
            ApplicationExecutionState previousState = e.PreviousExecutionState;

            // What kind of launch is this?
            ActivationKind activationKind = e.Kind;

            Frame rootFrame = Window.Current.Content as Frame;

            // 不要在窗口已包含内容时重复应用程序初始化,
            // 只需确保窗口处于活动状态
            if (rootFrame == null)
            {
                // 创建要充当导航上下文的框架,并导航到第一页
                rootFrame = new Frame();

                rootFrame.NavigationFailed += OnNavigationFailed;

                if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
                {
                    //TODO: 从之前挂起的应用程序加载状态
                    if (ApplicationData.Current.LocalSettings.Values.ContainsKey("NavigationState"))
                    {
                        rootFrame.SetNavigationState((string)ApplicationData.Current.LocalSettings.Values["NavigationState"]);
                    }
                }

                // 将框架放在当前窗口中
                Window.Current.Content = rootFrame;
            }

            if (rootFrame.Content == null)
            {
                // 当导航堆栈尚未还原时,导航到第一页,
                // 并通过将所需信息作为导航参数传入来配置
                // 参数
                rootFrame.Navigate(typeof(MainPage), e.Arguments);
            }
            // 确保当前窗口处于活动状态
            Window.Current.Activate();
            Windows.UI.Core.SystemNavigationManager.GetForCurrentView().BackRequested += OnBackRequested;

            // Every time the Frame navigates, set the visibility of the Shell-drawn back button
            // appropriate to whether there is anywhere to go back to
            rootFrame.Navigated += (s, a) =>
            {
                if (rootFrame.CanGoBack)
                {
                    // Setting this visible is ignored on Mobile and when in tablet mode! 
                    SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible;
                }
                else
                {
                    SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Collapsed;
                }
            };
        }
Example #35
0
        private void CreateRootFrame(ApplicationExecutionState state, string launchArguments = null)
        {
            Frame rootFrame = Window.Current.Content as Frame;

            // Do not repeat app initialization when the Window already has content
            if (rootFrame == null)
            {
                // Create a Frame to act as the navigation context and navigate to the first page
                rootFrame = new Frame();
                rootFrame.Background = new Windows.UI.Xaml.Media.SolidColorBrush(Windows.UI.Colors.Black);

                // TODO: change this value to a cache size that is appropriate for your application
                rootFrame.CacheSize = 0;

                if (state == ApplicationExecutionState.Terminated)
                {
                    SessionModel.Instance.Restore();

                    var settings = Windows.Storage.ApplicationData.Current.LocalSettings;

                    if (settings.Values.ContainsKey("NavigationState"))
                    {
                        rootFrame.SetNavigationState(settings.Values["NavigationState"] as string);
                    }
                }

                // Place the frame in the current Window
                Window.Current.Content = rootFrame;

                Windows.UI.ViewManagement.StatusBar.GetForCurrentView().HideAsync().AsTask().Wait();
            }

            if (rootFrame.Content == null)
            {
                // Removes the turnstile navigation for startup.
                if (rootFrame.ContentTransitions != null)
                {
                    this.transitions = new TransitionCollection();
                    foreach (var c in rootFrame.ContentTransitions)
                    {
                        this.transitions.Add(c);
                    }
                }

                rootFrame.ContentTransitions = null;
                rootFrame.Navigated += this.RootFrame_FirstNavigated;

                // When the navigation stack isn't restored navigate to the first page,
                // configuring the new page by passing required information as a navigation
                // parameter
                if (!rootFrame.Navigate(typeof(Views.StreamPage), launchArguments))
                {
                    throw new Exception("Failed to create initial page");
                }
            }
        }
Example #36
0
        public static void Init(IActivatedEventArgs launchActivatedEventArgs)
#endif
        {
            if (IsInitialized)
            {
                return;
            }

            var accent = (SolidColorBrush)Windows.UI.Xaml.Application.Current.Resources["SystemColorControlAccentBrush"];

            Color.SetAccent(Color.FromRgba(accent.Color.R, accent.Color.G, accent.Color.B, accent.Color.A));

            Log.Listeners.Add(new DelegateLogListener((c, m) => Debug.WriteLine(LogFormat, c, m)));

            Windows.UI.Xaml.Application.Current.Resources.MergedDictionaries.Add(GetTabletResources());

            Device.SetIdiom(TargetIdiom.Tablet);
            Device.SetFlowDirection(GetFlowDirection());
            Device.PlatformServices = new WindowsPlatformServices(Window.Current.Dispatcher);
#if WINDOWS_UWP
            Device.SetFlags(s_flags);
#endif
            Device.Info = new WindowsDeviceInfo();

#if WINDOWS_UWP
            switch (DetectPlatform())
            {
            case Windows.Foundation.Metadata.Platform.Windows:
                Device.SetIdiom(TargetIdiom.Desktop);
                break;

            case Windows.Foundation.Metadata.Platform.WindowsPhone:
                Device.SetIdiom(TargetIdiom.Phone);
                break;

            default:
                Device.SetIdiom(TargetIdiom.Tablet);
                break;
            }
#endif
            ExpressionSearch.Default = new WindowsExpressionSearch();

#if WINDOWS_UWP
            Registrar.ExtraAssemblies = rendererAssemblies?.ToArray();
#endif

            Registrar.RegisterAll(new[] { typeof(ExportRendererAttribute), typeof(ExportCellAttribute), typeof(ExportImageSourceHandlerAttribute) });

            IsInitialized = true;
            s_state       = launchActivatedEventArgs.PreviousExecutionState;

#if WINDOWS_UWP
            SystemNavigationManager.GetForCurrentView().BackRequested += OnBackRequested;
            Platform.UWP.Platform.SubscribeAlertsAndActionSheets();
#endif
        }
Example #37
0
        private void CreateRootFrame(ApplicationExecutionState state, string launchArguments = null)
        {
            Frame rootFrame = Window.Current.Content as Frame;

            // Do not repeat app initialization when the Window already has content
            if (rootFrame == null)
            {
                // Create a Frame to act as the navigation context and navigate to the first page
                rootFrame            = new Frame();
                rootFrame.Background = new Windows.UI.Xaml.Media.SolidColorBrush(Windows.UI.Colors.Black);

                // TODO: change this value to a cache size that is appropriate for your application
                rootFrame.CacheSize = 0;

                if (state == ApplicationExecutionState.Terminated)
                {
                    SessionModel.Instance.Restore();

                    var settings = Windows.Storage.ApplicationData.Current.LocalSettings;

                    if (settings.Values.ContainsKey("NavigationState"))
                    {
                        rootFrame.SetNavigationState(settings.Values["NavigationState"] as string);
                    }
                }

                // Place the frame in the current Window
                Window.Current.Content = rootFrame;

                Windows.UI.ViewManagement.StatusBar.GetForCurrentView().HideAsync().AsTask().Wait();
            }

            if (rootFrame.Content == null)
            {
                // Removes the turnstile navigation for startup.
                if (rootFrame.ContentTransitions != null)
                {
                    this.transitions = new TransitionCollection();
                    foreach (var c in rootFrame.ContentTransitions)
                    {
                        this.transitions.Add(c);
                    }
                }

                rootFrame.ContentTransitions = null;
                rootFrame.Navigated         += this.RootFrame_FirstNavigated;

                // When the navigation stack isn't restored navigate to the first page,
                // configuring the new page by passing required information as a navigation
                // parameter
                if (!rootFrame.Navigate(typeof(Views.StreamPage), launchArguments))
                {
                    throw new Exception("Failed to create initial page");
                }
            }
        }
Example #38
0
        /// <summary>Called when a new instance of the application has been created. </summary>
        /// <param name="frame">The frame. </param><param name="args">The launch arguments.</param>
        public override Task OnInitializedAsync(MtFrame frame, ApplicationExecutionState args)
        {
            // TODO: Initialize application and register more message types if needed. 

            var mapper = RegexViewModelToViewMapper.CreateDefaultMapper(GetType().GetTypeInfo().Assembly);
            Messenger.Default.Register(DefaultActions.GetNavigateMessageAction(mapper, frame));
            Messenger.Default.Register(DefaultActions.GetGoBackMessageAction(frame));
            Messenger.Default.Register(DefaultActions.GetTextMessageAction());

            return base.OnInitializedAsync(frame, args);
        }
Example #39
0
        private async void InitializeMainPage(ApplicationExecutionState previousExecutionState, String arguments)
        {
            Frame rootFrame = Window.Current.Content as Frame;

            // Do not repeat app initialization when the Window already has content,
            // just ensure that the window is active

            if (rootFrame == null)
            {
                mainDispatcher = Window.Current.Dispatcher;
                mainViewId = ApplicationView.GetForCurrentView().Id;
                // Create a Frame to act as the navigation context and navigate to the first page
                rootFrame = new Frame();
                // Associate the frame with a SuspensionManager key                                
                SuspensionManager.RegisterFrame(rootFrame, "AppFrame");

                if (previousExecutionState == ApplicationExecutionState.Terminated)
                {
                    // Restore the saved session state only when appropriate
                    try
                    {
                        await SuspensionManager.RestoreAsync();
                    }
                    catch (SuspensionManagerException)
                    {
                        //Something went wrong restoring state.
                        //Assume there is no state and continue
                    }
                }

                // Place the frame in the current Window
                Window.Current.Content = rootFrame;
            }
            if (rootFrame.Content == null || !String.IsNullOrEmpty(arguments))
            {
                // This is encountered on the first launch of the app. Make sure to call
                // DisableShowingMainViewOnActivation before the first call to Window::Activate

                var shouldDisable = Windows.Storage.ApplicationData.Current.LocalSettings.Values[App.DISABLE_MAIN_VIEW_KEY];
                if (shouldDisable != null && (bool)shouldDisable)
                {
                    ApplicationViewSwitcher.DisableShowingMainViewOnActivation();
                }

                // When the navigation stack isn't restored or there are launch arguments
                // indicating an alternate launch (e.g.: via toast or secondary tile), 
                // navigate to the appropriate page, configuring the new page by passing required 
                // information as a navigation parameter
                if (!rootFrame.Navigate(typeof(MainPage), arguments))
                {
                    throw new Exception("Failed to create initial page");
                }
            }
        }
Example #40
0
        private void OnLaunched(bool preLaunch, string arguments, ApplicationExecutionState previousState = ApplicationExecutionState.NotRunning)
        {
            var       channelId          = 0ul;
            Exception themeLoadException = null;
            var       args = ParseArgs(arguments);

            // Do not repeat app initialization when the Window already has content,
            // just ensure that the window is active
            if (!(Window.Current.Content is Frame rootFrame))
            {
                UpgradeSettings();

                Analytics.TrackEvent("Unicord_Launch");

                try
                {
                    ThemeManager.LoadCurrentTheme(Resources);
                }
                catch (Exception ex)
                {
                    Logger.LogError(ex);
                    themeLoadException = ex;
                }

                // Create a Frame to act as the navigation context and navigate to the first page
                rootFrame = new Frame();
                rootFrame.NavigationFailed += OnNavigationFailed;

                if (previousState == ApplicationExecutionState.Terminated)
                {
                    channelId = LocalSettings.Read("LastViewedChannel", 0ul);
                }

                WindowingService.Current.SetMainWindow(rootFrame);
                // Place the frame in the current Window
                Window.Current.Content = rootFrame;
            }

            if (args.TryGetValue("channelId", out var id) && ulong.TryParse(id, out var pId))
            {
                channelId = pId;
            }

            if (rootFrame.Content == null || channelId != 0)
            {
                rootFrame.Navigate(typeof(MainPage), new MainPageArgs()
                {
                    ChannelId = channelId, ThemeLoadException = themeLoadException
                });
            }

            // Ensure the current window is active
            Window.Current.Activate();
        }
Example #41
0
        private async void InitializeMainPage(ApplicationExecutionState previousExecutionState, String arguments)
        {
            Frame rootFrame = Window.Current.Content as Frame;

            // Do not repeat app initialization when the Window already has content,
            // just ensure that the window is active

            if (rootFrame == null)
            {
                mainDispatcher = Window.Current.Dispatcher;
                mainViewId     = ApplicationView.GetForCurrentView().Id;
                // Create a Frame to act as the navigation context and navigate to the first page
                rootFrame = new Frame();
                // Associate the frame with a SuspensionManager key
                SuspensionManager.RegisterFrame(rootFrame, "AppFrame");

                if (previousExecutionState == ApplicationExecutionState.Terminated)
                {
                    // Restore the saved session state only when appropriate
                    try
                    {
                        await SuspensionManager.RestoreAsync();
                    }
                    catch (SuspensionManagerException)
                    {
                        //Something went wrong restoring state.
                        //Assume there is no state and continue
                    }
                }

                // Place the frame in the current Window
                Window.Current.Content = rootFrame;
            }
            if (rootFrame.Content == null || !String.IsNullOrEmpty(arguments))
            {
                // This is encountered on the first launch of the app. Make sure to call
                // DisableShowingMainViewOnActivation before the first call to Window::Activate

                var shouldDisable = Windows.Storage.ApplicationData.Current.LocalSettings.Values[App.DISABLE_MAIN_VIEW_KEY];
                if (shouldDisable != null && (bool)shouldDisable)
                {
                    ApplicationViewSwitcher.DisableShowingMainViewOnActivation();
                }

                // When the navigation stack isn't restored or there are launch arguments
                // indicating an alternate launch (e.g.: via toast or secondary tile),
                // navigate to the appropriate page, configuring the new page by passing required
                // information as a navigation parameter
                if (!rootFrame.Navigate(typeof(MainPage), arguments))
                {
                    throw new Exception("Failed to create initial page");
                }
            }
        }
Example #42
0
        public override Task OnInitializedAsync(MtFrame frame, ApplicationExecutionState args)
        {
            // TODO: Called when the app is started (not resumed)

            //frame.PageAnimation = new TurnstilePageAnimation { UseBitmapCacheMode = true };
            //frame.PageAnimation = new PushPageAnimation();

            var mapper = RegexViewModelToViewMapper.CreateDefaultMapper(typeof(App).GetTypeInfo().Assembly);
            Messenger.Default.Register(DefaultActions.GetNavigateMessageAction(mapper, frame));

            return null;
        }
        private void InitializeMainPage(ApplicationExecutionState previousExecutionState, String arguments)
        {
            Frame rootFrame = CreateRootFrame();

            if (rootFrame.Content == null || !string.IsNullOrEmpty(arguments))
            {
                // When the navigation stack isn't restored or there are launch arguments
                // indicating an alternate launch (e.g.: via toast or secondary tile), 
                // navigate to the appropriate page, configuring the new page by passing required 
                // information as a navigation parameter
                rootFrame.Navigate(typeof(MainPage), arguments);
            }
        }
Example #44
0
        private void Launch(ApplicationExecutionState previousState)
        {
            // Do not repeat app initialization when already running, just ensure that
            // the window is active
            if (previousState == ApplicationExecutionState.Running)
            {
                Window.Current.Activate();
                return;
            }

            _mainPage = new MainPage();
            Window.Current.Content = _mainPage;
            Window.Current.Activate();
        }
Example #45
0
        private void Init(ApplicationExecutionState previousExecutionState, object arguments = null, bool forceNavigationToMain = false)
        {

#if DEBUG
            if (System.Diagnostics.Debugger.IsAttached)
            {
                //this.DebugSettings.EnableFrameRateCounter = true;
            }
#endif

            Frame rootFrame = Window.Current.Content as Frame;

            // Do not repeat app initialization when the Window already has content,
            // just ensure that the window is active
            if (rootFrame == null)
            {
                // Create a Frame to act as the navigation context and navigate to the first page
                rootFrame = new Frame();

                rootFrame.NavigationFailed += OnNavigationFailed;
                rootFrame.Navigated += OnNavigated; // Back button guide: http://www.wintellect.com/devcenter/jprosise/handling-the-back-button-in-windows-10-uwp-apps

                if (previousExecutionState == ApplicationExecutionState.Terminated)
                {
                    //TODO: Load state from previously suspended application
                }
                // Place the frame in the current Window
                Window.Current.Content = rootFrame;

                // Register a handler for BackRequested events and set the
                // visibility of the Back button
                SystemNavigationManager.GetForCurrentView().BackRequested += OnBackRequested;

                SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility =
                    rootFrame.CanGoBack ?
                    AppViewBackButtonVisibility.Visible :
                    AppViewBackButtonVisibility.Collapsed;
            }

            if (rootFrame.Content == null || forceNavigationToMain)
            {
                // When the navigation stack isn't restored navigate to the first page,
                // configuring the new page by passing required information as a navigation
                // parameter
                rootFrame.Navigate(typeof (MainPage), arguments);
            }
            // Ensure the current window is active
            Window.Current.Activate();
            DispatcherHelper.Initialize();
        }
 private async Task RestoreStatusAsync(ApplicationExecutionState previousExecutionState)
 {
     // Do not repeat app initialization when the Window already has content,
     // just ensure that the window is active
     if (previousExecutionState == ApplicationExecutionState.Terminated)
     {
         // Restore the saved session state only when appropriate
         try
         {
             await SuspensionManager.RestoreAsync();
         }
         catch (SuspensionManagerException)
         {
             //Something went wrong restoring state.
             //Assume there is no state and continue
         }
     }
 }
Example #47
0
        private async Task EnsureRootFrame(ApplicationExecutionState state)
        {
            if (Window.Current.Content == null)
            {
                OverwriteCalendarForVietNam();

                LiveTile.LiveTileManager.Instance.Start();

                await AntaresBaseFolder.Instance.InitializeBaseFolder();
                LanguageProvider.InitDisplayResources();
                InputLocalizationManager.Instance.UserResourceMap =
                    ResourceManager.Current.MainResourceMap.GetSubtree("Resources");


                // Create a Frame to act as the navigation context and navigate to the first page
                // Place the frame in the current Window
                var mainPage = new MainPage();
                Window.Current.Content = mainPage;
                Window.Current.Activate();
                //Associate the frame with a SuspensionManager key                                
                SuspensionManager.RegisterFrame(mainPage.RootFrame, "AppFrame");
                WeatherRepository.Instance.GetWeatherInfoAsync(); //TODO: What is the purpose of this call?
                Navigator.Instance.SetRootFrame(mainPage.RootFrame);

                Navigator.Instance.NavigateTo(typeof(TimelineWeekPage));

                SearchPane.GetForCurrentView().SearchHistoryEnabled = true;

                if (state == ApplicationExecutionState.Terminated)
                {
                    // Restore the saved session state only when appropriate
                    try
                    {
                        await SuspensionManager.RestoreAsync();
                    }
                    catch (SuspensionManagerException)
                    {
                        //Something went wrong restoring state.
                        //Assume there is no state and continue
                    }
                }
            }
        }
Example #48
0
        private void CreateRootFrame(ApplicationExecutionState state, string launchArguments = null)
        {
            Frame rootFrame = Window.Current.Content as Frame;

            // Do not repeat app initialization when the Window already has content
            if (rootFrame == null)
            {
                // Create a Frame to act as the navigation context and navigate to the first page
                rootFrame = new Frame();
                rootFrame.CacheSize = 0;

                // Set the default language
                rootFrame.Language = Windows.Globalization.ApplicationLanguages.Languages[0];

                rootFrame.NavigationFailed += OnNavigationFailed;

                if (state == ApplicationExecutionState.Terminated)
                {
                    SessionModel.Instance.Restore();

                    var settings = Windows.Storage.ApplicationData.Current.LocalSettings;

                    if (settings.Values.ContainsKey("NavigationState"))
                    {
                        rootFrame.SetNavigationState(settings.Values["NavigationState"] as string);
                    }
                }

                // Place the frame in the current Window
                Window.Current.Content = rootFrame;
            }

            if (rootFrame.Content == null)
            {
                // When the navigation stack isn't restored navigate to the first page,
                // configuring the new page by passing required information as a navigation
                // parameter
                rootFrame.Navigate(typeof(Views.StreamPage), launchArguments);
            }
        }
Example #49
0
        /// <summary>
        /// Determines how best to support navigation back to the previous application state.
        /// </summary>
        public static void Activate(String queryText, ApplicationExecutionState previousExecutionState)
        {
            var previousContent = Window.Current.Content;
            var frame = previousContent as Frame;

            if (frame != null)
            {
                  // frame.Navigate(typeof(ScheduleDayView));
            }
            else
            {
                // Otherwise bypass navigation and provide the tools needed to emulate the back stack
                ScheduleDayView page = new ScheduleDayView();
                page._previousContent = previousContent;
                page._previousExecutionState = previousExecutionState;
               // page.LoadState(, null);
                Window.Current.Content = page;
            }

            // Either way, active the window
            Window.Current.Activate();
        }
Example #50
0
        /// <summary>Creates the application's root frame and loads the first page if needed. 
        /// Also calls <see cref="OnInitializedAsync"/> when the application is instantiated the first time. </summary>
        /// <param name="executionState">The application execution state. </param>
        /// <returns>The task. </returns>
        protected async Task InitializeFrameAsync(ApplicationExecutionState executionState)
        {
            var rootFrame = Window.Current.Content as MtFrame;
            if (rootFrame == null)
            {
                rootFrame = CreateFrame();

                MtSuspensionManager.RegisterFrame(rootFrame, "AppFrame");
                if (executionState == ApplicationExecutionState.Terminated)
                    await RestoreStateAsync();

                var task = OnInitializedAsync(rootFrame, executionState);
                if (task != null)
                    await task;

                Window.Current.Content = rootFrame;
            }

            if (rootFrame.Content == null)
                rootFrame.Initialize(StartPageType);
            
            Window.Current.Activate();
        }
		/// <summary>
		/// Both the OnLaunched and OnActivated event handlers need to make sure the root frame has been created, so the common 
		/// code to do that is factored into this method and called from both.
		/// </summary>
		private async void EnsureRootFrame(ApplicationExecutionState previousExecutionState)
		{
			this.rootFrame = Window.Current.Content as Frame;

			// Do not repeat app initialization when the Window already has content,
			// just ensure that the window is active
			if (this.rootFrame == null)
			{
				// Create a Frame to act as the navigation context and navigate to the first page
				this.rootFrame = new Frame();

				//Associate the frame with a SuspensionManager key                                
				SuspensionManager.RegisterFrame(this.rootFrame, "AppFrame");

				this.rootFrame.CacheSize = 1;

				if (previousExecutionState == ApplicationExecutionState.Terminated)
				{
					// Load state from previously suspended application
					try
					{
						await SuspensionManager.RestoreAsync();
					}
					catch (SuspensionManagerException)
					{
						//Something went wrong restoring state.
						//Assume there is no state and continue
					}
				}

				// Place the frame in the current Window
				Window.Current.Content = this.rootFrame;
			}

			// Ensure the current window is active
			Window.Current.Activate();
		}
Example #52
0
        /// <summary>
        /// Invoked when the application is launched normally by the end user.  Other entry points
        /// will be used when the application is launched to open a specific file, to display
        /// search results, and so forth.
        /// </summary>
        /// <param name="e">Details about the launch request and process.</param>
        ///
        private async Task<Frame> CreateRootFrameAndRestore(ApplicationExecutionState previousExecutionState)
        {
            Frame rootFrame = Window.Current.Content as Frame;

            // Do not repeat app initialization when the Window already has content,
            // just ensure that the window is active.
            if (rootFrame == null)
            {
                // Create a Frame to act as the navigation context and navigate to the first page.
                rootFrame = new Frame();

                // Associate the frame with a SuspensionManager key.
                SuspensionManager.RegisterFrame(rootFrame, "AppFrame");

                // TODO: Change this value to a cache size that is appropriate for your application.
                rootFrame.CacheSize = 1;

                if (previousExecutionState == ApplicationExecutionState.Terminated)
                {
                    // Restore the saved session state only when appropriate.
                    try
                    {
                        await SuspensionManager.RestoreAsync();
                    }
                    catch (SuspensionManagerException)
                    {
                        // Something went wrong restoring state.
                        // Assume there is no state and continue.
                    }
                }

                // Place the frame in the current Window.
                Window.Current.Content = rootFrame;
            }

            return rootFrame;
        }
		/// <summary>
		/// Determines how best to support navigation back to the previous application state.
		/// </summary>
		public static void Activate(String queryText, ApplicationExecutionState previousExecutionState)
		{
			var previousContent = Window.Current.Content;
			var frame = previousContent as Frame;

			if (frame != null)
			{
				// If the app is already running and uses top-level frame navigation we can just
				// navigate to the search results
				frame.Navigate(typeof(MovieSearchResultsPage), queryText);
			}
			else
			{
				// Otherwise bypass navigation and provide the tools needed to emulate the back stack
				MovieSearchResultsPage page = new MovieSearchResultsPage();
				page._previousContent = previousContent;
				page._previousExecutionState = previousExecutionState;
				page.LoadState(queryText, null);
				Window.Current.Content = page;
			}

			// Either way, active the window
			Window.Current.Activate();
		}
Example #54
0
 public override async Task OnInitializedAsync(MtFrame frame, ApplicationExecutionState args)
 {
     //await HideStatusBarAsync();
 }
Example #55
0
 private Frame BuildRootFrame(ApplicationExecutionState state)
 {
     var rootFrame = Window.Current.Content as Frame;
     if (rootFrame == null)
     {
         rootFrame = new Frame {CacheSize = 3};
         _appExceptionHandle.RegisterExceptionHandlingSynchronizationContext();
         if (state == ApplicationExecutionState.Terminated)
         {
         }
         Window.Current.Content = rootFrame;
     }
     return rootFrame;
 }
Example #56
0
        private async Task<Frame> EnsureRootFrameInitialization(ApplicationExecutionState previousExecutionState, Frame rootFrame)
        {
            // Do not repeat app initialization when the Window already has content,
            // just ensure that the window is active
            if (rootFrame == null)
            {
                // Create a Frame to act as the navigation context and navigate to the first page
                rootFrame = new Frame();
                NavigationService.Initialize(rootFrame);

                //Associate the frame with a SuspensionManager key                                
                SuspensionManager.RegisterFrame(rootFrame, "AppFrame");

                if (previousExecutionState == ApplicationExecutionState.Terminated)
                {
                    // Restore the saved session state only when appropriate
                    try
                    {
                        await SuspensionManager.RestoreAsync();
                    }
                    catch (SuspensionManagerException)
                    {
                        //Something went wrong restoring state.
                        //Assume there is no state and continue
                    }
                }

                // Place the frame in the current Window
                Window.Current.Content = rootFrame;
            }

            return rootFrame;
        }
Example #57
0
        private async Task HandlePreviousExecutionState(ApplicationExecutionState previousExecutionState)
        {
            if (previousExecutionState == ApplicationExecutionState.Terminated ||
                previousExecutionState == ApplicationExecutionState.ClosedByUser ||
                previousExecutionState == ApplicationExecutionState.NotRunning)
            {
                var successfulRestoration = true;
                try
                {
                    await ToxModel.Instance.RestoreDataAsync();
                }
                catch
                {
                    successfulRestoration = false;
                }
                // If the restoration was unsuccessful, it means that we are starting up the app the
                // very firs time or something went wrong restoring data.
                // So we save the current Tox instance (newly created, not loaded) as the default one.
                if (!successfulRestoration)
                    await ToxModel.Instance.SaveDataAsync();

                if (previousExecutionState != ApplicationExecutionState.NotRunning)
                    // We only have to restore session state in the other two cases.
                    // See: https://msdn.microsoft.com/en-us/library/ie/windows.applicationmodel.activation.applicationexecutionstate
                {
                    try
                    {
                        await SuspensionManager.RestoreAsync();
                    }
                    catch (SuspensionManagerException)
                    {
                        // Something went wrong restoring state.
                        // Assume there is no state and continue.
                    }
                }
            }
        }
Example #58
0
 /// <summary>Called when a new instance of the application has been created. </summary>
 /// <param name="frame">The frame. </param>
 /// <param name="args">The launch arguments.</param>
 public virtual Task OnInitializedAsync(MtFrame frame, ApplicationExecutionState args)
 {
     return null; // Must be empty
 }
Example #59
0
        private async Task EnsureShell(ApplicationExecutionState previousState)
        {
            if (previousState == ApplicationExecutionState.Running)
            {
                Window.Current.Activate();
                ViewModelLocator.NavigationService.InitializeFrame(shell.Frame);
                return;
            }

            if (previousState == ApplicationExecutionState.Terminated || previousState == ApplicationExecutionState.ClosedByUser || previousState == ApplicationExecutionState.NotRunning)
            {
                var settings = ViewModelLocator.Container.Resolve<ApplicationSettings>();
                await settings.RestoreAsync();
            }

            shell = new Main();
            ViewModelLocator.NavigationService.InitializeFrame(shell.Frame);
            Window.Current.Content = shell;
            Window.Current.Activate();
            Dispatcher = Window.Current.CoreWindow.Dispatcher;

            //MessagePumps.StartAll();

            ViewModelLocator.MainViewModel.IsLoading = false;
        }
Example #60
0
        private async void StartApp(string args, ApplicationExecutionState previousState)
        {
            MainOuterFrame = Window.Current.Content as _1_1.Views.OuterFrame;

            // Do not repeat app initialization when the Window already has content,
            // just ensure that the window is active
            if (MainOuterFrame == null)
            {
                RootFrame = new ApplicationFrame();
                RootFrame.NavigationFailed += OnNavigationFailed;

                MainOuterFrame = new _1_1.Views.OuterFrame(RootFrame);
                Window.Current.Content = MainOuterFrame;// MainHamburgerBar;
                MainOuterFrame.SizeChanged += (s, e) =>
                {
                    CurrentWidth = e.NewSize.Width;
                    ContentWidthChanged?.Invoke(s, e);
                };
                await Initialize();
                // Create a Frame to act as the navigation context and navigate to the first page
                Common.SuspensionManager.RegisterFrame(RootFrame, "appFrame");

                // Place the frame in the current Window
                //MainHamburgerBar.Content = RootFrame;
                //MainHamburgerBar.SetRootFrame(RootFrame);
                if (previousState == ApplicationExecutionState.Terminated)
                {
                    await Common.SuspensionManager.RestoreAsync();
                }
            }

            if (RootFrame.Content == null)
            {
                // When the navigation stack isn't restored navigate to the first page,
                // configuring the new page by passing required information as a navigation
                // parameter

                //if (BandwidthManager.EffectiveBandwidthOptions == BandwidthOptions.Low)
                //{
                //    switch (SettingsManager.GetSetting<int>("LimitedData.LaunchPage", false, 0))
                //    {
                //        case 0:
                //            RootFrame.Navigate(typeof(BusMapPage), "CurrentLocation");
                //            break;
                //        case 1:
                //            RootFrame.Navigate(typeof(FavoritesPage));
                //            break;
                //        case 2:
                //            RootFrame.Navigate(typeof(RoutesPage));
                //            break;
                //    }
                //}
                //else
                //{
                //    switch (SettingsManager.GetSetting<int>("LaunchPage", false, 0))
                //    {
                //        case 0:
                //            RootFrame.Navigate(typeof(BusMapPage), "CurrentLocation");
                //            break;
                //        case 1:
                //            RootFrame.Navigate(typeof(FavoritesPage));
                //            break;
                //        case 2:
                //            RootFrame.Navigate(typeof(RoutesPage));
                //            break;
                //    }
                //}

                //Test Page
                //RootFrame.Navigate(typeof(_1_1.Views.Pages.TransitMapPage));
                RootFrame.Navigate(typeof(_1_1.Views.Pages.TestPage1));
            }
            Window.Current.Activate();

            Message.ShowMessage(new Message() { ShortSummary = "Public transit data powered by OneBusAway.", Caption = "Welcome!", FullText = "This app uses data provided by the OneBusAway api. OneBusAway also provides its own app for this platform, and is available for free. This app builds on the functions of the official app, and provides additional functionality not available in OneBusAway's own app.", Id = 1 });
            //if (CurrentApp.LicenseInformation.IsTrial)
            //    MainHamburgerBar.ShowAds = true;

            //using (var db = FileManager.GetDatabase())
            //{
            //    db.CreateTable<BusTrip>();
            //    db.Insert(new BusTrip() { Destination = "Federal Way", Route = "187", Shape = "Square" });
            //}
        }