Example #1
0
        /// <summary>
        /// Initialize the App launch.
        /// </summary>
        /// <returns>The AppShell of the app.</returns>
        private AppShell Initialize()
        {
            var shell = Window.Current.Content as AppShell;

            if (shell == null)
            {
                UnityBootstrapper.Init();
                UnityBootstrapper.ConfigureRegistries();

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

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

                shell.AppFrame.NavigationFailed += OnNavigationFailed;
            }

            return(shell);
        }
Example #2
0
        /// <summary>
        /// Initialize the App launch.
        /// </summary>
        /// <returns>The AppShell of the app.</returns>
        private async Task <AppShell> Initialize()
        {
            var 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)
            {
                UnityBootstrapper.Init();
                UnityBootstrapper.ConfigureRegistries();

                await AppInitialization.DoInitialization();

                // Create a AppShell to act as the navigation context and navigate to the first page
                shell = new AppShell()
                {
                    // Set the default language
                    Language = ApplicationLanguages.Languages[0]
                };
                shell.AppFrame.NavigationFailed += OnNavigationFailed;
            }
            return(shell);
        }
Example #3
0
        /// <summary>
        /// Invoked when the application is activated through sharing association.
        /// </summary>
        /// <param name="args">Event data for the event.</param>
        protected override async void OnShareTargetActivated(ShareTargetActivatedEventArgs args)
        {
            IAppEnvironment        mainAppEnvironment        = null;
            IUploadFinishedHandler mainUploadFinishedHandler = null;

            if (UnityBootstrapper.Container != null)
            {
                // We need to save the app environment from the current app.
                mainAppEnvironment        = ServiceLocator.Current.GetInstance <IAppEnvironment>();
                mainUploadFinishedHandler = ServiceLocator.Current.GetInstance <IUploadFinishedHandler>();
            }
            else
            {
                // We only configure unity if the main app is not already launched.
                UnityBootstrapper.Init();
                UnityBootstrapper.ConfigureRegistries();
            }

            // Overwrite existing app environment instance.
            UnityBootstrapper.Container.RegisterInstance(typeof(IAppEnvironment), new AppEnvironment());

            // Do initializations, trying restoring current user into the
            // provided app environment.
            await AppInitialization.DoInitializations();

            // Overwrite existing upload finished handler to make sure, the app
            // does not navigate to the categories page after successful upload,
            // but closes the share target window instead.
            var uploadFinishedHandler =
                new ShareTargetUploadFinishedHandler(() =>
            {
                // Restore original app environment.
                if (mainAppEnvironment != null)
                {
                    UnityBootstrapper.Container.RegisterInstance(typeof(IAppEnvironment), mainAppEnvironment);
                }

                // Restore original upload finished handler.
                if (mainUploadFinishedHandler != null)
                {
                    var uploadFinishedHandlerType = mainUploadFinishedHandler.GetType();
                    UnityBootstrapper.Container.RegisterType(typeof(IUploadFinishedHandler),
                                                             uploadFinishedHandlerType);
                }

                args.ShareOperation.ReportCompleted();
            });

            UnityBootstrapper.Container.RegisterInstance(typeof(IUploadFinishedHandler), uploadFinishedHandler);

            // Access data that has been shared.
            var data = args.ShareOperation.Data;

            if (data.Contains(StandardDataFormats.StorageItems))
            {
                try
                {
                    var items = await data.GetStorageItemsAsync();

                    // We expect the shared data to be a StorageFile.
                    var file = items.FirstOrDefault() as StorageFile;

                    if (file != null)
                    {
                        GetOrCreateRootFrame();

                        var navigationFacade = ServiceLocator.Current.GetInstance <INavigationFacade>();
                        navigationFacade.NavigateToCropView(file);

                        Window.Current.Activate();
                    }
                }
                catch (Exception)
                {
                    args.ShareOperation.ReportCompleted();
                }
            }
        }