Click or drag to resize

GeoprocessingJob Class

Geoprocessing job is used to run the geoprocessing task on the service.
Inheritance Hierarchy
SystemObject
  Esri.ArcGISRuntime.TasksJobGeoprocessingResult
    Esri.ArcGISRuntime.Tasks.GeoprocessingGeoprocessingJob

Namespace:  Esri.ArcGISRuntime.Tasks.Geoprocessing
Assembly:  Esri.ArcGISRuntime (in Esri.ArcGISRuntime.dll) Version: 100.7.0.0
Syntax
public sealed class GeoprocessingJob : Job<GeoprocessingResult>

The GeoprocessingJob type exposes the following members.

Properties
  NameDescription
Public propertyCredential
Gets or sets the security credential used to access the web service that provides the job's functionality
(Inherited from JobT.)
Public propertyCode exampleError
Gets the error if one occurred during execution of the job. If no error has occurred, then null is returned.
(Inherited from JobT.)
Public propertyCode exampleMessages
Gets the job's status messages
(Inherited from JobT.)
Public propertyParameters
Gets the input GeoprocessingParameters as passed to this job via CreateJob(GeoprocessingParameters).
Public propertyCode exampleProgress
Gets the current progress of the job as a percentage toward completion
(Inherited from JobT.)
Public propertyCode exampleServerJobId
Gets the server job ID of the job
(Inherited from JobT.)
Public propertyCode exampleStatus
Gets the status of the job
(Inherited from JobT.)
Top
Methods
Events
Examples

WPF

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.Text;
using System.Threading.Tasks;
using System.Windows;

namespace ArcGISRuntime.WPF.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
    {
        // 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 result in the textbox
                    ResultView.Text = myStringBuilder.ToString();
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString(), "Error");
            }

            // 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)
                    MessageBox.Show("Executing geoprocessing failed. " + listVersionsJob.Error.Message, "Geoprocessing error");
                else
                    MessageBox.Show("An error occurred. " + ex.ToString(), "Sample error");
            }
            finally
            {
                // Set the UI to indicate that the geoprocessing is not running
                SetBusy(false);
            }

            return results;
        }

        private void SetBusy(bool isBusy = true)
        {
            if (isBusy)
            {
                // Change UI to indicate that the geoprocessing is running
                BusyOverlay.Visibility = Visibility.Visible;
                Progress.IsIndeterminate = true;
            }
            else
            {
                // Change UI to indicate that the geoprocessing is not running
                BusyOverlay.Visibility = Visibility.Collapsed;
                Progress.IsIndeterminate = false;
            }
        }
    }
}
XAML
<UserControl x:Class="ArcGISRuntime.WPF.Samples.ListGeodatabaseVersions.ListGeodatabaseVersions"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:esri="http://schemas.esri.com/arcgis/runtime/2013" 
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    <Grid>
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            <TextBlock Text="Current versions" Grid.Row="0" HorizontalAlignment="Center"/>
            <TextBox x:Name="ResultView" Grid.Row="1" TextWrapping="Wrap" ScrollViewer.VerticalScrollBarVisibility="Visible" />
        </Grid>
        <Grid x:Name="BusyOverlay" Visibility="Collapsed" Background="#8C000000" Grid.RowSpan="4">
            <Border HorizontalAlignment="Center" VerticalAlignment="Center" Padding="10" Background="#FFC6C4C4">
                <Grid>
                    <ProgressBar IsIndeterminate="True" x:Name="Progress" Height="20" />
                    <TextBlock Text="Getting versions from the geoprocessing task..." HorizontalAlignment="Left" Margin="5" Height="Auto" />
                </Grid>
            </Border>
        </Grid>
    </Grid>
</UserControl>
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.
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.
LocalServerGeoprocessingCreate contour lines from local raster data using a local geoprocessing package `.gpk` and the contour geoprocessing tool.