ArcGISRuntime.UWP.Samples.AuthorEditSaveMap.AuthorEditSaveMap.OnSaveMapClick C# (CSharp) Method

OnSaveMapClick() private method

private OnSaveMapClick ( object sender, RoutedEventArgs e ) : void
sender object
e Windows.UI.Xaml.RoutedEventArgs
return 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(',');

                // Return if the text is null or empty
                if (string.IsNullOrEmpty(title) || string.IsNullOrEmpty(description))
                {
                    return;
                }

                // Get current map extent (viewpoint) for the map initial extent
                var currentViewpoint = MyMapView.GetCurrentViewpoint(ViewpointType.BoundingGeometry);

                // See if the map has already been saved
                if (!ViewModel.MapIsSaved)
                {
                    // Call the SaveNewMapAsync method on the view model, pass in the required info
                    await ViewModel.SaveNewMapAsync(currentViewpoint, title, description, tags);

                    // Report success
                    MessageDialog dialog = new MessageDialog("Map '" + title + "' was saved to the portal.", "Saved Map");
                    dialog.ShowAsync();
                }
                else
                {
                    // Map has previously been saved as a portal item, update it (title and description will remain the same)
                    ViewModel.UpdateMapItem();

                    // Report success
                    MessageDialog dialog = new MessageDialog("Changes to '" + title + "' were updated to the portal.");
                    dialog.ShowAsync();
                }
            }
            catch (OperationCanceledException)
            {
                // Report canceled login
                MessageDialog dialog = new MessageDialog("Login to the portal was canceled.", "Save canceled");
                dialog.ShowAsync();
            }
            catch (Exception ex)
            {
                // Report error
                MessageDialog dialog = new MessageDialog("Error while saving: " + ex.Message, "Cannot save");
                dialog.ShowAsync();
            }
        }