Click or drag to resize

JobTGetResultAsync Method

Gets the job's result

Namespace:  Esri.ArcGISRuntime.Tasks
Assembly:  Esri.ArcGISRuntime (in Esri.ArcGISRuntime.dll) Version: 100.7.0.0
Syntax
C#
public Task<T> GetResultAsync()

Return Value

Type: TaskT
A task that represents the asynchronous get result operation. The value of the task result is an object of type T.
Remarks

For a successfully completed job, the job's result returns an collection of SyncLayerResult, typically the collection is empty. If individual edits failed then the result collection provides these errors grouped by each table using SyncLayerResult instances which in turn contain each edit error.

Only errors are reported, the feature edit results do not contain information about successful adds, deletes or updates.

Examples

Android

Example Name: AnalyzeHotspots

Use a geoprocessing service and a set of features to identify statistically significant hot spots and cold spots.

Code example screen shot.

C#
// Copyright 2018 Esri.
// 
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
// You may obtain a copy of the License at: http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
// language governing permissions and limitations under the License.

using Android.App;
using Android.OS;
using Android.Views;
using Android.Widget;
using Esri.ArcGISRuntime.Geometry;
using Esri.ArcGISRuntime.Mapping;
using Esri.ArcGISRuntime.Tasks;
using Esri.ArcGISRuntime.Tasks.Geoprocessing;
using Esri.ArcGISRuntime.UI.Controls;
using System;
using System.Threading.Tasks;

namespace ArcGISRuntime.Samples.AnalyzeHotspots
{
    [Activity (ConfigurationChanges=Android.Content.PM.ConfigChanges.Orientation | Android.Content.PM.ConfigChanges.ScreenSize)]
    [ArcGISRuntime.Samples.Shared.Attributes.Sample(
        "Analyze hotspots",
        "Geoprocessing",
        "This sample demonstrates how to execute the GeoprocessingTask asynchronously to calculate a hotspot analysis based on the frequency of 911 calls. It calculates the frequency of these calls within a given study area during a specified constrained time period set between 1/1/1998 and 5/31/1998.",
        "To run the hotspot analysis, select a data range and click on the 'Run analysis' button. Note the larger the date range, the longer it may take for the task to run and send back the results.")]
    public class AnalyzeHotspots : Activity
    {
        // Hold a reference to the map view.
        private MapView _myMapView;

        // Button to define the start date for the date range.
        private Button _startDateButton;

        // Button to define the end date for the date range.
        private Button _endDateButton;

        // Alert dialog to show when the geoprocessing task is working.
        private AlertDialog _alert;

        // Url for the geoprocessing service.
        private const string _hotspotUrl = "https://sampleserver6.arcgisonline.com/arcgis/rest/services/911CallsHotspot/GPServer/911%20Calls%20Hotspot";

        // The geoprocessing task for hot spot analysis.
        private GeoprocessingTask _hotspotTask;

        // The job that handles the communication between the application and the geoprocessing task.
        private GeoprocessingJob _hotspotJob;

        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            Title = "Analyze Hotspots";

            // Create the UI, setup the control references and execute initialization .
            CreateLayout();
            Initialize();
        }

        private async void Initialize()
        {
            // Create a map with a topographic basemap.
            _myMapView.Map = new Map(Basemap.CreateTopographic());

            try
            {
                // Create a new geoprocessing task.
                _hotspotTask = await GeoprocessingTask.CreateAsync(new Uri(_hotspotUrl));

                // Zoom into Portland, Oregon.
                await _myMapView.SetViewpointCenterAsync(new MapPoint(-122.66, 45.52, SpatialReferences.Wgs84), 1000000);
            }
            catch (Exception e)
            {
                new AlertDialog.Builder(this).SetMessage(e.ToString()).SetTitle("Error").Show();
            }
        }

        private async void OnRunAnalysisClicked(object sender, EventArgs e)
        {
            // Get the 'from' and 'to' dates from the date edit text's for the geoprocessing analysis.
            DateTime myFromDate;
            DateTime myToDate;

            try
            {
                myFromDate = Convert.ToDateTime(_startDateButton.Text);
                myToDate = Convert.ToDateTime(_endDateButton.Text);
            }
            catch (Exception exception)
            {
                // Show error message and quit.
                new AlertDialog.Builder(this).SetMessage(exception.Message).Show();
                return;
            }

            // Clear any existing results.
            _myMapView.Map.OperationalLayers.Clear();

            // Show busy activity indication.
            _alert.Show();

            // The end date must be at least one day after the start date.
            if (myToDate <= myFromDate.AddDays(1))
            {
                _alert.Cancel();

                // Show error message.
                AlertDialog.Builder alertBuilder = new AlertDialog.Builder(this);
                alertBuilder.SetTitle("Invalid date range");
                alertBuilder.SetMessage("Please select valid time range.There has to be at least one day in between To and From dates.");
                alertBuilder.Show();
                return;
            }

            // Create the parameters that are passed to the used geoprocessing task.
            GeoprocessingParameters myHotspotParameters = new GeoprocessingParameters(GeoprocessingExecutionType.AsynchronousSubmit);

            // Construct the date query.
            string myQueryString = $"(\"DATE\" > date '{myFromDate:yyyy-MM-dd} 00:00:00' AND \"DATE\" < date '{myToDate:yyyy-MM-dd} 00:00:00')";

            // Add the query that contains the date range used in the analysis.
            myHotspotParameters.Inputs.Add("Query", new GeoprocessingString(myQueryString));

            // Create job that handles the communication between the application and the geoprocessing task.
            _hotspotJob = _hotspotTask.CreateJob(myHotspotParameters);
            try
            {
                // Execute the geoprocessing analysis and wait for the results.
                GeoprocessingResult myAnalysisResult = await _hotspotJob.GetResultAsync();

                // Add results to a map using map server from a geoprocessing task.
                // Load to get access to full extent.
                await myAnalysisResult.MapImageLayer.LoadAsync();

                // Add the analysis layer to the map view.
                _myMapView.Map.OperationalLayers.Add(myAnalysisResult.MapImageLayer);

                // Zoom to the results.
                await _myMapView.SetViewpointAsync(new Viewpoint(myAnalysisResult.MapImageLayer.FullExtent));

                // Remove the loading alert dialog.
                _alert.Cancel();
            }
            catch (TaskCanceledException)
            {
                // This is thrown if the task is canceled. Ignore.
            }
            catch (Exception ex)
            {
                // Remove the loading alert dialog.
                _alert.Cancel();

                // Display error messages if the geoprocessing task fails.
                if (_hotspotJob.Status == JobStatus.Failed && _hotspotJob.Error != null)
                {
                    AlertDialog.Builder alertBuilder = new AlertDialog.Builder(this);
                    alertBuilder.SetTitle("Geoprocessing error");
                    alertBuilder.SetMessage("Executing geoprocessing failed. " + _hotspotJob.Error.Message);
                    alertBuilder.Show();
                }
                else
                {
                    AlertDialog.Builder alertBuilder = new AlertDialog.Builder(this);
                    alertBuilder.SetTitle("Sample error");
                    alertBuilder.SetMessage("An error occurred. " + ex.ToString());
                    alertBuilder.Show();
                }
            }
        }

        private void OnDateClicked(object sender, EventArgs a)
        {
            // Get the date from the button text.
            DateTime buttonDate = Convert.ToDateTime(((Button)sender).Text);

            // Create a new DatePickerDialog using the date from the button.
            DatePickerDialog dialog = new DatePickerDialog(this, (EventHandler<DatePickerDialog.DateSetEventArgs>)null, buttonDate.Year, buttonDate.Month - 1, buttonDate.Day);

            // Add an event handler that changes the button text when a date is picked.
            dialog.DateSet += (s, e) => { ((Button)sender).Text = e.Date.ToShortDateString(); };

            // Display the dialog to the user.
            dialog.Show();
        }

        private void CreateLayout()
        {
            // Create a new vertical layout for the app.
            LinearLayout layout = new LinearLayout(this) { Orientation = Orientation.Vertical };

            LinearLayout.LayoutParams buttonParam = new LinearLayout.LayoutParams(
                ViewGroup.LayoutParams.MatchParent,
                ViewGroup.LayoutParams.MatchParent,
                1.0f
            );
            LinearLayout.LayoutParams labelParam = new LinearLayout.LayoutParams(
                ViewGroup.LayoutParams.MatchParent,
                ViewGroup.LayoutParams.MatchParent,
                3.0f
            );

            // Create a horizontal sub layout for the start date.
            LinearLayout startDateSubLayout = new LinearLayout(this) { Orientation = Orientation.Horizontal };

            // Label for the start date.
            TextView startDateLabel = new TextView(this)
            {
                Text = "Start Date:",
                LayoutParameters = labelParam,
                Gravity = GravityFlags.Center
            };
            startDateSubLayout.AddView(startDateLabel);

            // Button for the start date.
            _startDateButton = new Button(this)
            {
                Text = "1/01/1998",
                LayoutParameters = buttonParam
            };
            _startDateButton.Click += OnDateClicked;
            startDateSubLayout.AddView(_startDateButton);

            // Add the start date information to the general layout.
            layout.AddView(startDateSubLayout);

            // Create a horizontal sub layout for the end date.
            LinearLayout endDateSubLayout = new LinearLayout(this) { Orientation = Orientation.Horizontal };

            // Label for the end date.
            TextView endDateLabel = new TextView(this)
            {
                Text = "End Date:",
                LayoutParameters = labelParam,
                Gravity = GravityFlags.Center
            };

            endDateSubLayout.AddView(endDateLabel);

            // Button for the end date.
            _endDateButton = new Button(this)
            {
                Text = "1/31/1998",
                LayoutParameters = buttonParam
            };
            _endDateButton.Click += OnDateClicked;
            endDateSubLayout.AddView(_endDateButton);

            // Add the start date information to the general layout.
            layout.AddView(endDateSubLayout);

            // Add a button to the run the hot spot analysis; wire up the click event as well
            Button mapsButton = new Button(this)
            {
                Text = "Run Analysis"
            };
            mapsButton.Click += OnRunAnalysisClicked;
            layout.AddView(mapsButton);

            // Create a layout to be used to alert the user when processing is happening.
            LinearLayout alertLayout = new LinearLayout(this)
            {
                Orientation = Orientation.Vertical
            };

            // Create paramaters for the items in the alert layout.
            LinearLayout.LayoutParams alertParam = new LinearLayout.LayoutParams(
                ViewGroup.LayoutParams.MatchParent,
                ViewGroup.LayoutParams.MatchParent,
                1.0f
            );
            alertParam.SetMargins(0, 10, 0, 10);

            // Text for the processing alert.
            TextView processingText = new TextView(this)
            {
                Text = "Processing...",
                LayoutParameters = alertParam,
                Gravity = GravityFlags.Center,
            };

            // Add the progress bar to indicate the geoprocessing task is running.
            ProgressBar progressBar = new ProgressBar(this)
            {
                Indeterminate = true,
                LayoutParameters = alertParam,
                TextAlignment = TextAlignment.Center
            };

            // Add the text and progress bar to the Linear Layout.
            alertLayout.AddView(processingText);
            alertLayout.AddView(progressBar);

            // Create the alert dialog.
            _alert = new AlertDialog.Builder(this).Create();
            _alert.SetCanceledOnTouchOutside(false);
            _alert.Show();
            _alert.Cancel();

            // Add the layout to the alert.
            _alert.AddContentView(alertLayout, buttonParam);

            // Add the map view to the layout.
            _myMapView = new MapView(this);
            layout.AddView(_myMapView);

            // Show the layout in the app.
            SetContentView(layout);
        }
    }
}
Examples

Xamarin Forms Android

Example Name: ListGeodatabaseVersions

This sample calls a custom GeoprocessingTask to get a list of available versions for an enterprise geodatabase. The task returns a table of geodatabase version information, which is displayed in the app as a list.

Code example screen shot.

C#
// Copyright 2016 Esri.
// 
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
// You may obtain a copy of the License at: http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an 
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific 
// language governing permissions and limitations under the License.

using Esri.ArcGISRuntime.Data;
using Esri.ArcGISRuntime.Tasks;
using Esri.ArcGISRuntime.Tasks.Geoprocessing;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Text;
using Xamarin.Forms;

namespace ArcGISRuntime.Samples.ListGeodatabaseVersions
{
    [ArcGISRuntime.Samples.Shared.Attributes.Sample(
        "List geodatabase versions",
        "Geoprocessing",
        "This sample calls a custom GeoprocessingTask to get a list of available versions for an enterprise geodatabase. The task returns a table of geodatabase version information, which is displayed in the app as a list.",
        "")]
    public partial class ListGeodatabaseVersions : ContentPage
    {

        // Url to used geoprocessing service
        private const string ListVersionsUrl =
            "https://sampleserver6.arcgisonline.com/arcgis/rest/services/GDBVersions/GPServer/ListVersions";

        public ListGeodatabaseVersions()
        {
            InitializeComponent ();

            // Create the UI, setup the control references and execute initialization
            Initialize();
        }

        private async void Initialize()
        {
            // Set the UI to indicate that the geoprocessing is running
            SetBusy(true);

            try
            {
                // Get versions from a geodatabase
                IFeatureSet versionsFeatureSet = await GetGeodatabaseVersionsAsync();

                // Continue if we got a valid geoprocessing result
                if (versionsFeatureSet != null)
                {
                    // Create a string builder to hold all of the information from the geoprocessing 
                    // task to display in the UI 
                    StringBuilder myStringBuilder = new StringBuilder();

                    // Loop through each Feature in the FeatureSet 
                    foreach (Feature version in versionsFeatureSet)
                    {
                        // Get the attributes (a dictionary of <key,value> pairs) from the Feature
                        IDictionary<string,object> myDictionary = version.Attributes;

                        // Loop through each attribute (a <key,value> pair)
                        foreach (KeyValuePair<string,object> attribute in myDictionary)
                        {
                            // Add the key and value strings to the string builder 
                            myStringBuilder.AppendLine(attribute.Key + ": " + attribute.Value);
                        }

                        // Add a blank line after each Feature (the listing of geodatabase versions)
                        myStringBuilder.AppendLine();
                    }

                    // Display the results to the user
                    theTextBox.Text = myStringBuilder.ToString();
                }
            }
            catch (Exception e)
            {
                await Application.Current.MainPage.DisplayAlert("Error", e.ToString(), "OK");
            }

            // Set the UI to indicate that the geoprocessing is not running
            SetBusy(false);
        }

        private async Task<IFeatureSet> GetGeodatabaseVersionsAsync()
        {
            // Results will be returned as a feature set
            IFeatureSet results = null;

            // Create new geoprocessing task 
            GeoprocessingTask listVersionsTask = await GeoprocessingTask.CreateAsync(new Uri(ListVersionsUrl));

            // Create default parameters that are passed to the geoprocessing task
            GeoprocessingParameters listVersionsParameters = await listVersionsTask.CreateDefaultParametersAsync();

            // Create job that handles the communication between the application and the geoprocessing task
            GeoprocessingJob listVersionsJob = listVersionsTask.CreateJob(listVersionsParameters);
            try
            {
                // Execute analysis and wait for the results
                GeoprocessingResult analysisResult = await listVersionsJob.GetResultAsync();

                // Get results from the outputs
                GeoprocessingFeatures listVersionsResults = (GeoprocessingFeatures)analysisResult.Outputs["Versions"];

                // Set results
                results = listVersionsResults.Features;
            }
            catch (Exception ex)
            {
                // Error handling if something goes wrong
                if (listVersionsJob.Status == JobStatus.Failed && listVersionsJob.Error != null)
                {
                    await Application.Current.MainPage.DisplayAlert("Geoprocessing error", "Executing geoprocessing failed. " + listVersionsJob.Error.Message, "OK");
                }
                else
                {
                    await Application.Current.MainPage.DisplayAlert("Sample error", "An error occurred. " + ex.ToString(), "OK");
                }
            }
            finally
            {
                // Set the UI to indicate that the geoprocessing is not running
                SetBusy(false);
            }

            return results;
        }
        private void SetBusy(bool isBusy = true)
        {
            // This function toggles running of the 'progress' control feedback status to denote if 
            // the viewshed analysis is executing as a result of the user click on the map

            if (isBusy)
            {
                // Show busy activity indication
                MyActivityIndicator.IsVisible = true;
                MyActivityIndicator.IsRunning = true;
            }
            else
            {
                // Remove the busy activity indication
                MyActivityIndicator.IsRunning = false;
                MyActivityIndicator.IsVisible = false;

            }
        }
    }
}
XAML
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"             
             xmlns:esriUI="clr-namespace:Esri.ArcGISRuntime.Xamarin.Forms;assembly=Esri.ArcGISRuntime.Xamarin.Forms"
             xmlns:mapping="clr-namespace:Esri.ArcGISRuntime.Mapping;assembly=Esri.ArcGISRuntime" 
             x:Class="ArcGISRuntime.Samples.ListGeodatabaseVersions.ListGeodatabaseVersions">
  <Grid>
    <Grid.RowDefinitions>
      <RowDefinition Height="auto" />
      <RowDefinition Height="*" />
    </Grid.RowDefinitions>
    <StackLayout Orientation="Vertical">
      <StackLayout Orientation="Horizontal">
        <Label Margin="10,0,0,0">Current versions:</Label>
      </StackLayout>
    </StackLayout>
    <ActivityIndicator x:Name="MyActivityIndicator" IsVisible="False"/>
    <Editor x:Name="theTextBox" Grid.Row="1"/>
  </Grid>
</ContentPage>
See Also
Additional Examples
Hyperlink to ExampleDescription
AnalyzeHotspotsUse a geoprocessing service and a set of features to identify statistically significant hot spots and cold spots.
AnalyzeViewshedCalculate a viewshed using a geoprocessing service, in this case showing what parts of a landscape are visible from points on mountainous terrain.
ApplyScheduledUpdatesApply scheduled updates to a downloaded preplanned map area.
DownloadPreplannedMapTake a map offline using an available preplanned map area.
EditAndSyncFeaturesSynchronize offline edits with a feature service.
ExportTilesDownload tiles to a local tile cache file stored on the device.
GenerateGeodatabaseGenerate a local geodatabase from an online feature service.
GenerateOfflineMapTake a web map offline.
GenerateOfflineMapWithOverridesUse the `OfflineMapTask` with overrides to take a webmap offline. The overrides workflow allows you to adjust the settings used for taking each layer in the map offline. For a simple example of how you take a map offline, please consult the "Generate Offline Map" sample.
GeodatabaseTransactionsThis sample demonstrates how to manage edits to a local geodatabase inside of transactions.
ListGeodatabaseVersionsThis sample calls a custom GeoprocessingTask to get a list of available versions for an enterprise geodatabase. The task returns a table of geodatabase version information, which is displayed in the app as a list.
OfflineBasemapByReferenceUse the `OfflineMapTask` to take a web map offline, but instead of downloading an online basemap, use one which is already on the device.