예제 #1
0
        private async Task <string> GetUserNameAsync()
        {
            var contact = await ContactHelper.CreateContactFromCurrentUserAsync();

            var userName = AppSettings.Current.UserName;

            if (userName == null)
            {
                userName = contact.DisplayName;
            }
            return(userName);
        }
예제 #2
0
        public async Task ActivateAsync(object activationArgs)
        {
            if (IsInteractive(activationArgs))
            {
                // Initialize things like registering background task before the app is loaded
                await InitializeAsync();

                // Retrieve current user if available
                if (activationArgs is IActivatedEventArgsWithUser argsWithUser)
                {
                    CurrentUser = argsWithUser.User;
                    await ContactHelper.CreateContactFromCurrentUserAsync();
                }
                // Do not repeat app initialization when the Window already has content,
                // just ensure that the window is active
                if (Window.Current.Content == null)
                {
                    // Create a Frame to act as the navigation context and navigate to the first page
                    Window.Current.Content              = _shell?.Value ?? new Frame();
                    NavigationService.NavigationFailed += (sender, e) =>
                    {
                        throw e.Exception;
                    };
                    NavigationService.Navigated += OnNavigated;
                    if (SystemNavigationManager.GetForCurrentView() != null)
                    {
                        SystemNavigationManager.GetForCurrentView().BackRequested += ActivationService_BackRequested;
                    }
                }
            }
            var activationHandler = GetActivationHandlers()
                                    .FirstOrDefault(h => h.CanHandle(activationArgs));

            if (activationHandler != null)
            {
                await activationHandler.HandleAsync(activationArgs);
            }

            if (IsInteractive(activationArgs))
            {
                var defaultHandler = new DefaultLaunchActivationHandler(_defaultNavItem);
                if (defaultHandler.CanHandle(activationArgs))
                {
                    await defaultHandler.HandleAsync(activationArgs);
                }

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

                // Tasks after activation
                await StartupAsync();
            }
        }
예제 #3
0
        public async Task ActivateAsync(IActivatedEventArgs activationArgs)
        {
            bool isLaunch = false;

            if (IsInteractive(activationArgs))
            {
                // Retrieve current user if available
                if (activationArgs is IActivatedEventArgsWithUser argsWithUser)
                {
                    CurrentUser = argsWithUser.User;
                    await ContactHelper.CreateContactFromCurrentUserAsync();
                }

                // Do not repeat app initialization when the Window already has content,
                // just ensure that the window is active
                if (Window.Current.Content == null)
                {
                    isLaunch = true;

                    // Initialize things like registering background task before the app is loaded
                    await InitializeAsync();

                    // Create a Frame to act as the navigation context to navigate to the first page
                    var frame = new Frame();
                    frame.ContentTransitions = new TransitionCollection();
                    frame.ContentTransitions.Add(new NavigationThemeTransition());
                    Window.Current.Content = frame;

                    NavigationService.MainFrame         = frame;
                    NavigationService.NavigationFailed += OnNavigationFailed;
                    NavigationService.Navigated        += OnNavigated;

                    if (CurrentView != null)
                    {
                        CurrentView.BackRequested += OnBackRequested;
                    }
                }
            }

            ActivationState activationState   = null;
            var             activationHandler = GetActivationHandlers().FirstOrDefault(h => h.CanHandle(activationArgs));

            if (activationHandler != null)
            {
                activationState = await activationHandler.HandleAsync(activationArgs);
            }
            activationState = activationState ?? _activationState;

            if (IsInteractive(activationArgs))
            {
                if (isLaunch)
                {
                    NavigationService.Navigate(_view.FullName, activationState, mainFrame: true);

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

                    // Tasks after activation
                    await StartupAsync();
                }
                else
                {
                    NavigationService.Navigate(activationState.ViewModel.ToString(), activationState.Parameter);

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