Esempio n. 1
0
        /// <summary>
        ///     Creates the window and performs any protocol logic needed
        /// </summary>
        /// <param name="parameters">Param string, (soundbyte://core/user?id=454345)</param>
        /// <returns></returns>
        private async Task InitializeShellAsync(string parameters = null)
        {
            LoggingService.Log(LoggingService.LogType.Debug, "Initialize Main App Shell...");

            _isInit = true;

            // Live tile helpers
            TileHelper.Init();

            // Before we init the v3 service, we must check to see if we have the required API keys
            if (!AppKeysHelper.KeysValid)
            {
                LoggingService.Log(LoggingService.LogType.Info, "App keys are not valid. Requesting new keys.");

                // If this fails getting the keys, we have an issue and must close the app
                if (!await UWPAuthorizationHelpers.OnlineAppInitAsync(true))
                {
                    return;
                }

                OnlineAppInitComplete = true;
            }

            // Init service
            InitV3Service();

            // Init the telemetry service
            await Telemetry.InitAsync(AppKeysHelper.GoogleAnalyticsTrackerId, AppKeysHelper.HockeyAppClientId,
                                      AppKeysHelper.AppCenterClientId);

            // Get the main shell
            var shell = Window.Current.Content as AppShell;

            // If the shell is null, we need to set it up.
            if (shell == null)
            {
                LoggingService.Log(LoggingService.LogType.Debug, "Shell does not exist, creating new shell");
                shell = new AppShell(parameters);

                // Hook the key pressed event for the global app
                Window.Current.CoreWindow.KeyDown += CoreWindowOnKeyDown;
                Window.Current.CoreWindow.KeyUp   += (s, e) =>
                {
                    if (e.VirtualKey == VirtualKey.Control)
                    {
                        _isCtrlKeyPressed = false;
                    }
                };
            }
            else
            {
                LoggingService.Log(LoggingService.LogType.Debug, "Shell exists, running protocol logic");
                await shell.HandleProtocolAsync(parameters);
            }

            // Set the root shell as the window content
            Window.Current.Content = shell;

            // If on xbox display the screen to the full width and height
            if (DeviceHelper.IsXbox)
            {
                ApplicationView.GetForCurrentView().SetDesiredBoundsMode(ApplicationViewBoundsMode.UseCoreWindow);
            }

            // Activate the window
            LoggingService.Log(LoggingService.LogType.Debug, "Activiating Window");
            Window.Current.Activate();
        }