Ejemplo n.º 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 void OnLaunched(LaunchActivatedEventArgs e)
        {
#if DEBUG
            if (System.Diagnostics.Debugger.IsAttached)
            {
                // This just gets in the way.
                //this.DebugSettings.EnableFrameRateCounter = true;
            }
#endif

            AppShell shell = Window.Current.Content as AppShell;

            // Do not repeat app initialization when the Window already has content,
            // just ensure that the window is active
            if (shell == null)
            {
                // propogate settings to the core library
                SettingsHelper.Instance.SettingsChanged += (target, args) =>
                {
                    FaceServiceHelper.ApiKey                     = SettingsHelper.Instance.FaceApiKey;
                    FaceServiceHelper.ApiEndpoint                = SettingsHelper.Instance.FaceApiKeyEndpoint;
                    VisionServiceHelper.ApiKey                   = SettingsHelper.Instance.VisionApiKey;
                    VisionServiceHelper.ApiEndpoint              = SettingsHelper.Instance.VisionApiKeyEndpoint;
                    BingSearchHelper.SearchApiKey                = SettingsHelper.Instance.BingSearchApiKey;
                    BingSearchHelper.AutoSuggestionApiKey        = SettingsHelper.Instance.BingAutoSuggestionApiKey;
                    TextAnalyticsHelper.ApiKey                   = SettingsHelper.Instance.TextAnalyticsKey;
                    TextAnalyticsHelper.ApiEndpoint              = SettingsHelper.Instance.TextAnalyticsApiKeyEndpoint;
                    TextAnalyticsHelper.ApiKey                   = SettingsHelper.Instance.TextAnalyticsKey;
                    ImageAnalyzer.PeopleGroupsUserDataFilter     = SettingsHelper.Instance.WorkspaceKey;
                    FaceListManager.FaceListsUserDataFilter      = SettingsHelper.Instance.WorkspaceKey;
                    CoreUtil.MinDetectableFaceCoveragePercentage = SettingsHelper.Instance.MinDetectableFaceCoveragePercentage;
                };

                // callbacks for core library
                FaceServiceHelper.Throttled        = () => ShowToastNotification("The Face API is throttling your requests. Consider upgrading to a Premium Key.");
                VisionServiceHelper.Throttled      = () => ShowToastNotification("The Vision API is throttling your requests. Consider upgrading to a Premium Key.");
                ErrorTrackingHelper.TrackException = (ex, msg) => LogException(ex, msg);
                ErrorTrackingHelper.GenericApiCallExceptionHandler = Util.GenericApiCallExceptionHandler;

                SettingsHelper.Instance.Initialize();

                // Create a AppShell to act as the navigation context and navigate to the first page
                shell = new AppShell();

                // Set the default language
                shell.Language = Windows.Globalization.ApplicationLanguages.Languages[0];

                shell.AppFrame.NavigationFailed += OnNavigationFailed;

                if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
                {
                    //TODO: Load state from previously suspended application
                }

                // Set the TitleBar to Dark Theme
                var appView  = Windows.UI.ViewManagement.ApplicationView.GetForCurrentView();
                var titleBar = appView.TitleBar;
                titleBar.BackgroundColor       = Windows.UI.Colors.Black;
                titleBar.ForegroundColor       = Windows.UI.Colors.White;
                titleBar.ButtonBackgroundColor = Windows.UI.Colors.Black;
                titleBar.ButtonForegroundColor = Windows.UI.Colors.White;

                CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBar = false;
            }

            // Place our app shell in the current Window
            Window.Current.Content = shell;

            if (shell.AppFrame.Content == null)
            {
                // When the navigation stack isn't restored, navigate to the first page
                // suppressing the initial entrance animation.
                shell.AppFrame.Navigate(typeof(DemoLauncherPage), e.Arguments, new Windows.UI.Xaml.Media.Animation.SuppressNavigationTransitionInfo());
            }

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

            // Trigger a test of the api keys in the background to alert the user if any of them are bad (e.g. expired, out of quota, etc)
            TestApiKeysAsync();
        }
Ejemplo n.º 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 void OnLaunched(LaunchActivatedEventArgs e)
        {
#if DEBUG
            if (System.Diagnostics.Debugger.IsAttached)
            {
                // This just gets in the way.
                //this.DebugSettings.EnableFrameRateCounter = true;
            }
#endif

            AppShell shell = Window.Current.Content as AppShell;

            // Do not repeat app initialization when the Window already has content,
            // just ensure that the window is active
            if (shell == null)
            {
                // propogate settings to the core library
                SettingsHelper.Instance.SettingsChanged += (target, args) =>
                {
                    EmotionServiceHelper.ApiKey = SettingsHelper.Instance.EmotionApiKey;
                    FaceServiceHelper.ApiKey    = SettingsHelper.Instance.FaceApiKey;
                    VisionServiceHelper.ApiKey  = SettingsHelper.Instance.VisionApiKey;
                    ImageAnalyzer.PeopleGroupsUserDataFilter     = SettingsHelper.Instance.WorkspaceKey;
                    FaceListManager.FaceListsUserDataFilter      = SettingsHelper.Instance.WorkspaceKey;
                    CoreUtil.MinDetectableFaceCoveragePercentage = SettingsHelper.Instance.MinDetectableFaceCoveragePercentage;
                };

                // callbacks for core library
                FaceServiceHelper.Throttled        = () => ShowThrottlingToast("Face");
                EmotionServiceHelper.Throttled     = () => ShowThrottlingToast("Emotion");
                VisionServiceHelper.Throttled      = () => ShowThrottlingToast("Vision");
                ErrorTrackingHelper.TrackException = (ex, msg) => LogException(ex, msg);
                ErrorTrackingHelper.GenericApiCallExceptionHandler = Util.GenericApiCallExceptionHandler;

                SettingsHelper.Instance.Initialize();

                // Since it can be a pain to enter these keys in an IoT device, this is a good place to hardcode them if necessary.
                //SettingsHelper.Instance.WorkspaceKey = "";
                //SettingsHelper.Instance.FaceApiKey = "";
                //SettingsHelper.Instance.EmotionApiKey = "";
                //SettingsHelper.Instance.VisionApiKey = "";

                // Create a AppShell to act as the navigation context and navigate to the first page
                shell = new AppShell();

                // Set the default language
                shell.Language = Windows.Globalization.ApplicationLanguages.Languages[0];

                shell.AppFrame.NavigationFailed += OnNavigationFailed;

                if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
                {
                    //TODO: Load state from previously suspended application
                }

                // Set the TitleBar to Dark Theme
                var appView  = Windows.UI.ViewManagement.ApplicationView.GetForCurrentView();
                var titleBar = appView.TitleBar;
                titleBar.BackgroundColor       = Windows.UI.Colors.Black;
                titleBar.ForegroundColor       = Windows.UI.Colors.White;
                titleBar.ButtonBackgroundColor = Windows.UI.Colors.Black;
                titleBar.ButtonForegroundColor = Windows.UI.Colors.White;
            }

            // Place our app shell in the current Window
            Window.Current.Content = shell;

            if (shell.AppFrame.Content == null)
            {
                // When the navigation stack isn't restored, navigate to the first page
                // suppressing the initial entrance animation.
                shell.AppFrame.Navigate(typeof(DemoLauncherPage), e.Arguments, new Windows.UI.Xaml.Media.Animation.SuppressNavigationTransitionInfo());
            }

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