Esempio n. 1
0
        private async Task InitializeAsync()
        {
            // Test if download path has been specified by user, if not, prompt
            // If download path exists, check if valid
            if (string.IsNullOrEmpty(Settings.Default.DownloadPath) || !Directory.Exists(Settings.Default.DownloadPath))
            {
                this.PromptUserForDownloadDirectory();
            }

            // Test if AppViewModel singleton instance exists
            if (AppViewModel.Instance == null)
            {
                // Set data context for the main screen and load main screen
                AppViewModel.Instance = AppViewModel.Create();
                this.DataContext      = AppViewModel.Instance;
            }

            // Make instance of the DownloadViewModel and set it as datacontext.
            // This will set the active view as the DownloadView
            try
            {
                var downloadViewModel = new DownloadViewModel();
                AppViewModel.Instance.DisplayViewModel = downloadViewModel;
                await downloadViewModel.ConnectToPortalAsync();
            }
            catch (Exception ex)
            {
                // If unexpected exception happens during download, ignore it and load existing map
                System.Windows.MessageBox.Show(
                    "An error has occured during the map download: " + ex.Message + " The previously downloaded map will now be loaded.",
                    "Unhandled Exception",
                    MessageBoxButton.OK,
                    MessageBoxImage.Error);
            }
            finally
            {
                await this.LoadMmpkAsync();
            }
        }