/// <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()); } }
/// <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(); }