App.xaml.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. using System;
  2. using System.Reflection;
  3. using Windows.ApplicationModel;
  4. using Windows.ApplicationModel.Activation;
  5. using Windows.UI.Xaml;
  6. using Windows.UI.Xaml.Controls;
  7. using Windows.UI.Xaml.Navigation;
  8. namespace Tests.Reactive.Uwp.DeviceRunner
  9. {
  10. public sealed partial class App : Application
  11. {
  12. /// <summary>
  13. /// Initializes the singleton application object. This is the first line of authored code
  14. /// executed, and as such is the logical equivalent of main() or WinMain().
  15. /// </summary>
  16. public App()
  17. {
  18. this.InitializeComponent();
  19. this.Suspending += OnSuspending;
  20. }
  21. /// <summary>
  22. /// Invoked when the application is launched normally by the end user. Other entry points
  23. /// will be used such as when the application is launched to open a specific file.
  24. /// </summary>
  25. /// <param name="e">Details about the launch request and process.</param>
  26. protected override void OnLaunched(LaunchActivatedEventArgs e)
  27. {
  28. #if DEBUG
  29. if (global::System.Diagnostics.Debugger.IsAttached)
  30. {
  31. this.DebugSettings.EnableFrameRateCounter = true;
  32. }
  33. #endif
  34. Frame rootFrame = Window.Current.Content as Frame;
  35. // Do not repeat app initialization when the Window already has content,
  36. // just ensure that the window is active
  37. if (rootFrame == null)
  38. {
  39. // Create a Frame to act as the navigation context and navigate to the first page
  40. rootFrame = new Frame();
  41. rootFrame.NavigationFailed += OnNavigationFailed;
  42. if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
  43. {
  44. //TODO: Load state from previously suspended application
  45. }
  46. // Place the frame in the current Window
  47. Window.Current.Content = rootFrame;
  48. }
  49. Microsoft.VisualStudio.TestPlatform.TestExecutor.UnitTestClient.CreateDefaultUI();
  50. // Ensure the current window is active
  51. Window.Current.Activate();
  52. Microsoft.VisualStudio.TestPlatform.TestExecutor.UnitTestClient.Run(e.Arguments);
  53. }
  54. /// <summary>
  55. /// Invoked when Navigation to a certain page fails
  56. /// </summary>
  57. /// <param name="sender">The Frame which failed navigation</param>
  58. /// <param name="e">Details about the navigation failure</param>
  59. void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
  60. {
  61. throw new Exception("Failed to load Page " + e.SourcePageType.FullName);
  62. }
  63. /// <summary>
  64. /// Invoked when application execution is being suspended. Application state is saved
  65. /// without knowing whether the application will be terminated or resumed with the contents
  66. /// of memory still intact.
  67. /// </summary>
  68. /// <param name="sender">The source of the suspend request.</param>
  69. /// <param name="e">Details about the suspend request.</param>
  70. private void OnSuspending(object sender, SuspendingEventArgs e)
  71. {
  72. var deferral = e.SuspendingOperation.GetDeferral();
  73. //TODO: Save application state and stop any background activity
  74. deferral.Complete();
  75. }
  76. }
  77. }