} // end DownloadBtn_Click // Download imagery to a local directory private async void DownloadImagery() { DialogResult result = new DialogResult(); FolderBrowserDialog dialog = new FolderBrowserDialog(); // If a local download - get download directory if (imageFileRB.IsChecked == true) { if (imageFileRB.IsChecked == true) { dialog.Description = "Select download directory"; } else { dialog.Description = "Select temporary download directory"; } dialog.UseDescriptionForTitle = true; result = dialog.ShowDialog(); if (result.ToString() == "OK") { downloadDir = dialog.SelectedPath; } // show progress bar adn hide dowload window mainWin.DownloadPanel.Visibility = Visibility.Visible; downloading = true; Hide(); } else { // Seting up the authorization Debug.WriteLine("Get portal authorization"); agolUser.OAuthPortal(); // Get user credentials Debug.WriteLine("Setting credential request parameters"); CredentialRequestInfo loginInfo = new CredentialRequestInfo { // Use the OAuth implicit grant flow GenerateTokenOptions = new GenerateTokenOptions { TokenAuthenticationType = TokenAuthenticationType.OAuthImplicit }, // Indicate the url (portal) to authenticate with (ArcGIS Online) ServiceUri = new Uri(agolUser.serviceUrl) }; Debug.WriteLine("Getting credentials"); try { Debug.WriteLine("In GetUserPortal - Getting AM"); // Get a reference to the (singleton) AuthenticationManager for the app Esri.ArcGISRuntime.Security.AuthenticationManager thisAM = Esri.ArcGISRuntime.Security.AuthenticationManager.Current; // Call GetCredentialAsync on the AuthenticationManager to invoke the challenge handler Debug.WriteLine("Getting credentials"); await thisAM.GetCredentialAsync(loginInfo, false); Debug.WriteLine("Got credentials"); Debug.WriteLine("In GetUserPortal - login service uri " + loginInfo.ServiceUri); } catch (OperationCanceledException) { // user canceled the login throw new Exception("Portal log in was canceled."); } // show progress bar adn hide dowload window mainWin.DownloadPanel.Visibility = Visibility.Visible; downloading = true; Hide(); // Create the portal // Get the ArcGIS Online portal (will use credential from login above) Debug.WriteLine("Creating the portal"); agolUser.portal = await ArcGISPortal.CreateAsync(); Debug.WriteLine("Portal Created"); /* * var t = Task.Run(() => agolUser.GetUserPortal()); * t.Wait(); */ } // Set up the background worker // for fetching the data dataFetcher = new BackgroundWorker(); if (imageFileRB.IsChecked == true) { dataFetcher.DoWork += Worker_FetchFiles; } else { dataFetcher.DoWork += Worker_AGOL_KMZ; } dataFetcher.WorkerReportsProgress = false; dataFetcher.RunWorkerCompleted += FileFetchCompleted; //Start the worker dataFetcher.RunWorkerAsync(); Debug.WriteLine("leaving DownloadImagery"); } // end DownloadImagery
} // end DownloadBtn_Click // Download imagery to a local directory private async void DownloadImagery() { DialogResult result = new DialogResult(); FolderBrowserDialog dialog = new FolderBrowserDialog(); Debug.WriteLine("in DownloadBtn_Click"); // If a local download - get download directory if (imageFileRB.IsChecked == true) { dialog.Description = "Select download directory"; dialog.UseDescriptionForTitle = true; result = dialog.ShowDialog(); if (result.ToString() == "OK") { downloadDir = dialog.SelectedPath; } else if (result.ToString() == "Cancel") { return; } } // otherwise get AGOL authorization else { Debug.WriteLine("\nAGOL login selected"); // Setting up the authorization Debug.WriteLine("Get portal authorization"); agolUser.OAuthPortal(); // Get user credentials Debug.WriteLine("Setting credential request parameters"); CredentialRequestInfo loginInfo = new CredentialRequestInfo { // Use the OAuth implicit grant flow GenerateTokenOptions = new GenerateTokenOptions { TokenAuthenticationType = TokenAuthenticationType.OAuthImplicit }, // Indicate the url (portal) to authenticate with (ArcGIS Online) ServiceUri = new Uri(agolUser.serviceUrl) }; Debug.WriteLine("Getting credentials"); try { Debug.WriteLine("Getting Authentication Manager"); // Get a reference to the (singleton) AuthenticationManager for the app Esri.ArcGISRuntime.Security.AuthenticationManager thisAM = Esri.ArcGISRuntime.Security.AuthenticationManager.Current; // Call GetCredentialAsync on the AuthenticationManager to invoke the challenge handler Debug.WriteLine("Getting credentials"); await thisAM.GetCredentialAsync(loginInfo, false); Debug.WriteLine("Got credentials"); } catch (OperationCanceledException) { // user canceled the login throw new Exception("Portal log in was canceled."); } Debug.WriteLine("Credential request info set"); Debug.WriteLine("Have Credential - continuing"); try { // Create the portal // Get the ArcGIS Online portal (will use credential from login above) Debug.WriteLine("Creating the portal"); agolUser.portal = await ArcGISPortal.CreateAsync(); // Get the user's content (items in the root folder and a collection of sub-folders) Debug.WriteLine("getting User content"); agolUser.userContent = await agolUser.portal.User.GetContentAsync(); } catch (Exception ex) { // user canceled the login MessageBox.Show("2. Portal Login exception: " + ex.Message, "ArcGIS Online Login Exception"); Debug.WriteLine("Exception: " + ex.Message); await Esri.ArcGISRuntime.Security.AuthenticationManager.Current.RemoveAndRevokeAllCredentialsAsync(); return; } } // end else // Set up the background worker // for fetching the data dataFetcher = new BackgroundWorker(); if (imageFileRB.IsChecked == true) { dataFetcher.DoWork += Worker_FetchFiles; } else { dataFetcher.DoWork += Worker_AGOL_KMZ; } dataFetcher.WorkerReportsProgress = false; dataFetcher.RunWorkerCompleted += FileFetchCompleted; // Show progress bar/main window and hide download window mainWin.DownloadPanel.Visibility = Visibility.Visible; mainWin.aoiWin.Visibility = Visibility.Visible; //mainWin.aoiWin.Show(); downloading = true; //Start the worker dataFetcher.RunWorkerAsync(); } // end DownloadImagery