Пример #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)
        {
            LogService.Write();

            // Check if this is the first time the app is being launched
            // If OnLaunched is called again when the app is still running (e.g. selecting "Switch to" in WDP
            // while the app is running), the initialization code should not run again
            if (!(Window.Current.Content is Frame rootFrame))
            {
                // Create a Frame to act as the navigation context and navigate to the first page
                rootFrame = new Frame();
                rootFrame.NavigationFailed += OnNavigationFailed;

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

                // Try to set the map token from file located in LocalState folder
                await WeatherHelper.SetMapTokenFromFileAsync("MapToken.config");

                // Enable kiosk mode if file is detected
                Settings.KioskMode = await FileUtil.ReadFileAsync("kiosk_mode") != null;

                // Use MEF to import features and components from other assemblies in the appx package.
                foreach (var feature in AppComposer.Imports.Features)
                {
                    try
                    {
                        LogService.Write($"Loading Feature: {feature.FeatureName}");
                        feature.OnLoaded(this);
                    }
                    catch (Exception ex)
                    {
                        LogService.Write(ex.ToString());
                    }
                }

                // Enable multi-view
                MultiViewManager            = new MultiViewManager(Window.Current.Dispatcher, ApplicationView.GetForCurrentView().Id);
                MultiViewManager.ViewAdded += MultiViewManager_ViewAdded;

                // Subscribe for IoT Hub property updates if available
                var iotHubService = GetForCurrentContext().GetRegisteredService <IIoTHubService>();
                if (iotHubService != null)
                {
                    iotHubService.DesiredPropertyUpdated += App_DesiredPropertyUpdated;
                }

                // Make sure we weren't launched in the background
                if (e != null && e.PrelaunchActivated == false)
                {
                    // 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 !FORCE_OOBE_WELCOME_SCREEN
                    if (ApplicationData.Current.LocalSettings.Values.ContainsKey(Constants.HasDoneOOBEKey))
                    {
                        rootFrame.Navigate(typeof(MainPage), e.Arguments);
                    }
                    else
#endif
                    {
                        rootFrame.Navigate(typeof(OOBEWelcomePage), e.Arguments);
                    }
                }
            }

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

            // Update asynchronously
            var updateAsyncTask = NetworkPresenter.UpdateAvailableNetworksAsync(false);
        }