Ejemplo n.º 1
0
        /// <summary>
        /// Invoked when application execution is being suspended.  Application state is saved
        /// without knowing whether the application will be terminated or resumed with the contents
        /// of memory still intact.
        /// </summary>
        /// <param name="sender">The source of the suspend request.</param>
        /// <param name="e">Details about the suspend request.</param>
        private async void OnSuspending(object sender, SuspendingEventArgs e)
        {
            SuspendingDeferral deferral = null;

            try
            {
                // Wait for below code to complete
                deferral = e.SuspendingOperation.GetDeferral();

                // Indicate ui is supended
                StorageSettings.IsUISuspended = true;

                // Register background tasks if not registered
                SyncMailBackgroundTask.Register();

                // Unload and disconnect mailboxes
                MainPage.Current.UnloadAndDisconnectMailboxes();

                // Save state
                await SuspensionManager.SaveAsync();

                LogFile.Instance.LogInformation("", "", string.Format("Suspended: IsUISuspended - {0}, IsTaskRunning - {1}.", StorageSettings.IsUISuspended, StorageSettings.IsTaskRunning));
            }
            catch (Exception ex)
            {
                LogFile.Instance.LogInformation("", "", ex.ToString());
            }
            finally
            {
                // Indicate app can be suspended
                deferral.Complete();
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Invoked when application execution is being resumed.
        /// </summary>
        /// <param name="sender">The source of the resume request.</param>
        /// <param name="e">Details about the resume request.</param>
        private void OnResuming(object sender, object e)
        {
            try
            {
                // Indicate ui is not supended
                StorageSettings.IsUISuspended = false;

                // Unregister background tasks if registered
                SyncMailBackgroundTask.Unregister();

                // Wait for background task to complete
                WaitForBackgroundTaskToComplete();

                // If MailHeadersItemsSource
                MainPage.Current.BindMailHeader(StorageSettings.AccountSettingsDataDictionary[MainPage.Current.MailboxTreeDataContext.Value.Key.EmailAddress], ((MailboxListViewItem)SuspensionManager.SessionState["MailboxTreeSelectedItem"]).Mailbox, MainPage.Current.QueryText);
                LogFile.Instance.LogInformation("", "", string.Format("Resumed: IsUISuspended - {0}, IsTaskRunning - {1}.", StorageSettings.IsUISuspended, StorageSettings.IsTaskRunning));
            }
            catch (Exception ex)
            {
                LogFile.Instance.LogInformation("", "", ex.ToString());
            }
        }
Ejemplo n.º 3
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="args">Details about the launch request and process.</param>
        protected async override void OnLaunched(LaunchActivatedEventArgs args)
        {
            // Indicate ui is not supended
            StorageSettings.IsUISuspended = false;

            // Unregister background tasks if registered
            SyncMailBackgroundTask.Unregister();

            // Wait for background task to complete
            WaitForBackgroundTaskToComplete();

            try
            {
                EmailToastNotificationContext = (string.IsNullOrEmpty(args.Arguments) ? null : IOUtil.Deserialize <EmailToastNotificationContext>(args.Arguments));
            }
            catch (Exception ex)
            {
                LogFile.Instance.LogError("", "", ex.ToString());
            }

            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();
                SuspensionManager.RegisterFrame(rootFrame, "appFrame");

                if (args.PreviousExecutionState == ApplicationExecutionState.Terminated ||
                    args.PreviousExecutionState == ApplicationExecutionState.ClosedByUser ||
                    args.PreviousExecutionState == ApplicationExecutionState.NotRunning)
                {
                    try
                    {
                        await SuspensionManager.RestoreAsync();

                        if (StorageSettings.MailHeaderDictionary.AllEmailCount == 0)
                        {
                            throw new Exception("Mail header dictionary data missing.");
                        }

                        IsSessionStateCorrupted = false;
                    }
                    catch
                    {
                        IsSessionStateCorrupted = true;
                    }
                }

                // Place the frame in the current Window
                Window.Current.Content = rootFrame;
            }
            else
            {
                try
                {
                    // If toast notification
                    if (App.EmailToastNotificationContext != null)
                    {
                        // Set the selected items
                        MainPage.Current.SelectedAccount             = StorageSettings.AccountSettingsDataDictionary.Single(o => o.Key.Equals(App.EmailToastNotificationContext.EmailAddress, StringComparison.OrdinalIgnoreCase));
                        MainPage.Current.SelectedMailboxListViewItem = MainPage.Current.MailboxTreeDataContext.Value.Value.Single(o => o.Mailbox.FullName.Equals(App.EmailToastNotificationContext.MailboxFullName));
                        MainPage.Current.SelectedMailHeader          = StorageSettings.MailHeaderDictionary[App.EmailToastNotificationContext.EmailAddress][App.EmailToastNotificationContext.MailboxFullName].Single(o => o.Uid.Equals(App.EmailToastNotificationContext.Uid, StringComparison.OrdinalIgnoreCase));
                    }
                }
                catch (Exception ex)
                {
                    LogFile.Instance.LogError("", "", ex.ToString());
                }
            }

            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 (!rootFrame.Navigate(typeof(MainPage), args.Arguments))
                {
                    throw new Exception("Failed to create initial page");
                }
            }

            LogFile.Instance.LogInformation("", "", string.Format("Launched: IsUISuspended - {0}, IsTaskRunning - {1}.", StorageSettings.IsUISuspended, StorageSettings.IsTaskRunning));

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