Example #1
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 async void OnLaunched(LaunchActivatedEventArgs e)
        {

#if DEBUG
            if (System.Diagnostics.Debugger.IsAttached)
            {
                this.DebugSettings.EnableFrameRateCounter = true;
            }
#endif
            var tc = new Microsoft.ApplicationInsights.TelemetryClient();

            var navigation = new NavigationController(launchScreenCallback);
            CoreWindow.GetForCurrentThread().KeyDown += navigation.GlobalKeyDown;

            await SettingsController.LoadSettings();

            try
            {
                var clockModel = new ClockModel();
                Task.Run(() => clockModel.Update());
                (Resources["clockViewModel"] as ClockViewModel).Initialize(clockModel);
                TimerController.RegisterModel(clockModel);
                navigation.RegisterView(typeof(ClockView));
                clockModel.NightFallDelegate += TimeOfDayChangedHandler;
            }
            catch (Exception ex)
            {
                var properties = new Dictionary<String, string> { { "Module", "Clock" } };
                tc.TrackException(ex, properties);
                System.Diagnostics.Debugger.Break();
            }

            try
            { 
                var weatherModel = new WeatherModel_wunderground();
                Task.Run(() => weatherModel.Update());
                TimerController.RegisterModel(weatherModel);
                (Resources["weatherThisWeekViewModel"] as WeatherThisWeekViewModel).Initialize(weatherModel);
                (Resources["weatherTodayViewModel"] as WeatherTodayViewModel).Initialize(weatherModel);
                navigation.RegisterView(typeof(WeatherThisWeekView));
                navigation.RegisterView(typeof(WeatherTodayView));
            }
            catch (Exception ex)
            {
                var properties = new Dictionary<String, string> { { "Module", "Weather" } };
                tc.TrackException(ex, properties);
                System.Diagnostics.Debugger.Break();
            }

            try
            { 
                var transitModel = new TransitModel_translink();
                Task.Run(() => transitModel.Update());
                TimerController.RegisterModel(transitModel);
                (Resources["transitViewModel"] as TransitViewModel).Initialize(transitModel);
                TimerController.RegisterViewModel((Resources["transitViewModel"] as TransitViewModel));
                navigation.RegisterView(typeof(TransitView));
            }
            catch (Exception ex)
            {
                var properties = new Dictionary<String, string> { { "Module", "Transit" } };
                tc.TrackException(ex, properties);
                System.Diagnostics.Debugger.Break();
            }

            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 ThemeAwareFrame(ElementTheme.Light);

                rootFrame.NavigationFailed += OnNavigationFailed;

                if (e.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(ClockView), e.Arguments);
            }
            // Ensure the current window is active
            Window.Current.Activate();
            tc.TrackEvent("Smart Mirror has loaded.");

            setupAutoScroll(navigation);
        }
Example #2
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 async void OnLaunched(LaunchActivatedEventArgs e)
        {

#if DEBUG
            if (System.Diagnostics.Debugger.IsAttached)
            {
                this.DebugSettings.EnableFrameRateCounter = true;
            }
#endif
            var navigation = new NavigationController(launchScreenCallback);
            CoreWindow.GetForCurrentThread().KeyDown += navigation.GlobalKeyDown;

            await SettingsController.LoadSettings();

            try
            {
                var clockModel = new ClockModel();
                await clockModel.Update();
                (Resources["clockViewModel"] as ClockViewModel).Initialize(clockModel);
                TimerController.RegisterModel(clockModel);
                navigation.RegisterView(typeof(ClockView));
            }
            catch (Exception ex)
            {
                // TODO: appInsights
                System.Diagnostics.Debugger.Break();
            }

            try
            { 
                var weatherModel = new WeatherModel_wunderground();
                await weatherModel.Update();
                TimerController.RegisterModel(weatherModel);
                (Resources["weatherThisWeekViewModel"] as WeatherThisWeekViewModel).Initialize(weatherModel);
                (Resources["weatherTodayViewModel"] as WeatherTodayViewModel).Initialize(weatherModel);
                navigation.RegisterView(typeof(WeatherThisWeekView));
                navigation.RegisterView(typeof(WeatherTodayViewModel));
            }
            catch (Exception ex)
            {
                // TODO: appInsights
                System.Diagnostics.Debugger.Break();
            }

            try
            { 
                var transitModel = new TransitModel_translink();
                await transitModel.Update();
                TimerController.RegisterModel(transitModel);
                (Resources["transitViewModel"] as TransitViewModel).Initialize(transitModel);
                TimerController.RegisterViewModel((Resources["transitViewModel"] as TransitViewModel));
                navigation.RegisterView(typeof(TransitView));
            }
            catch (Exception ex)
            {
                // TODO: appInsights
                System.Diagnostics.Debugger.Break();
            }

            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)
                {
                    //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(ClockView), e.Arguments);
            }
            // Ensure the current window is active
            Window.Current.Activate();
        }