ArcGISRuntime.WPF.Samples.AuthorEditSaveMap.AuthorEditSaveMap.OnSaveMapClick C# (CSharp) Метод

OnSaveMapClick() приватный Метод

private OnSaveMapClick ( object sender, RoutedEventArgs e ) : void
sender object
e System.Windows.RoutedEventArgs
Результат void
        private async void OnSaveMapClick(object sender, RoutedEventArgs e)
        {
            try
            {
                // Create a challenge request for portal credentials (OAuth credential request for arcgis.com)
                CredentialRequestInfo challengeRequest = new CredentialRequestInfo();

                // Use the OAuth implicit grant flow
                challengeRequest.GenerateTokenOptions = new GenerateTokenOptions
                {
                    TokenAuthenticationType = TokenAuthenticationType.OAuthImplicit
                };

                // Indicate the url (portal) to authenticate with (ArcGIS Online)
                challengeRequest.ServiceUri = new Uri("https://www.arcgis.com/sharing/rest");

                // Call GetCredentialAsync on the AuthenticationManager to invoke the challenge handler
                await AuthenticationManager.Current.GetCredentialAsync(challengeRequest, false);

                // Get information for the new portal item
                var title = TitleTextBox.Text;
                var description = DescriptionTextBox.Text;
                var tags = TagsTextBox.Text.Split(',');

                // Throw an exception if the text is null or empty for title or description
                if (string.IsNullOrEmpty(title) || string.IsNullOrEmpty(description))
                {
                    throw new Exception("Title and description are required");
                }

                // Get current map extent (viewpoint) for the map initial extent
                var currentViewpoint = MyMapView.GetCurrentViewpoint(Esri.ArcGISRuntime.Mapping.ViewpointType.BoundingGeometry);
                
                // See if the map has already been saved
                if (!_mapViewModel.MapIsSaved)
                {
                    // Call the SaveNewMapAsync method on the view model, pass in the required info
                    await _mapViewModel.SaveNewMapAsync(currentViewpoint, title, description, tags);

                    // Report success
                    MessageBox.Show("Map '" + title + "' was saved to your portal");
                }
                else
                {
                    // Map has previously been saved as a portal item, update it (title, description, and tags will remain the same)
                    _mapViewModel.UpdateMapItem();

                    // Report success
                    MessageBox.Show("Changes to '" + title + "' were updated to the portal.");
                }
            }
            catch (Exception ex)
            {
                // Report error
                MessageBox.Show("Error while saving: " + ex.Message);
            }
        }