Click or drag to resize
Code Example: Geoprocessor_GetTaskInfoAsync

Demonstrates getting the GPTaskInfo metadata for a Geoprocessing task (aka. a GPServer Task on ArcGIS Server).

Code Example
Geoprocessor Get Task Info Async

This section contains selected code files from a Visual Studio project that emphasize specific ArcGIS Runtime SDK (Windows Desktop) features. For example: some code examples may accomplish the bulk of the work as a configuration property in the .xaml file and hence only the .xaml file will be shown in detail below. In other code examples, the .xaml is used to define the configuration of graphical elements for the application but the application logic is performed in the code behind, hence you may see both the .xaml and .cs/.vb files shown in detail below.

XAML
<Window x:Class="Geoprocessor_GetTaskInfoAsync.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:esri="http://schemas.esri.com/arcgis/runtime/2013"
    Title="MainWindow" Height="600" Width="800">
    <Grid x:Name="LayoutRoot">
        <StackPanel Orientation="Vertical">
            <ComboBox x:Name="ComboBox1" SelectedIndex="0"/>
            <Button x:Name="Button1" Content="Select an item in the ComboBox and click this button to get metadata about the GPServer task." 
                        Height="30" Click="Button1_Click" Width="782"/>
            <TextBox x:Name="TextBlock1" TextWrapping="Wrap"  Height="534" />
        </StackPanel>
    </Grid>
</Window>

SPECIAL NOTE: The XAML displayed above comes from a C# project. If you are a VB.NET developer, you will need to modify the text for the x:Class namespace from "Geoprocessor_GetTaskInfoAsync.MainWindow" to be just "MainWindow".

namespace Geoprocessor_GetTaskInfoAsync
{
    public partial class MainWindow : System.Windows.Window
    {
        public MainWindow()
        {
            InitializeComponent();

            // Add some Url's to various ArcGIS Server GPServer tasks that can interrogated by the Geoprocessor.GetTaskInfoAsync() Method.
            ComboBox1.Items.Add("http://serverapps10.esri.com/ArcGIS/rest/services/SamplesNET/USA_Data_ClipTools/GPServer/ClipCounties");
            ComboBox1.Items.Add("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Network/ESRI_DriveTime_US/GPServer/CreateDriveTimePolygonsDisks");
            ComboBox1.Items.Add("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Population_World/GPServer/PopulationSummary");
            ComboBox1.Items.Add("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Elevation/ESRI_Elevation_World/GPServer/Viewshed");
            ComboBox1.Items.Add("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_Currents_World/GPServer/MessageInABottle");
            ComboBox1.Items.Add("http://sampleserver5.arcgisonline.com/arcgis/rest/services/NetworkAnalysis/SanDiego/GPServer/Generate%20Service%20Areas");
            ComboBox1.Items.Add("http://sampleserver5.arcgisonline.com/arcgis/rest/services/NetworkAnalysis/SanDiego/GPServer/Solve%20Vehicle%20Routing%20Problem");
            ComboBox1.Items.Add("http://sampleserver5.arcgisonline.com/arcgis/rest/services/NetworkAnalysis/SanDiegoSync/GPServer/Edit%20Vehicle%20Routing%20Problem");
            ComboBox1.Items.Add("http://sampleserver5.arcgisonline.com/arcgis/rest/services/Utilities/PrintingTools/GPServer/Export%20Web%20Map%20Task");
            ComboBox1.Items.Add("http://sampleserver6.arcgisonline.com/arcgis/rest/services/911CallsHotspot/GPServer/911%20Calls%20Hotspot");
        }

        private async void Button1_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            // Get the Url chosen by the user in the ComboBox.
            string myGPUrl = ComboBox1.SelectedItem.ToString();

            // Create a Uri from the string version of the Url.
            System.Uri myGPUri = new System.Uri(myGPUrl);

            // Create a new Geoprocessor Task from the Uri.
            Esri.ArcGISRuntime.Tasks.Geoprocessing.Geoprocessor myGeoprocessor = new Esri.ArcGISRuntime.Tasks.Geoprocessing.Geoprocessor(myGPUri);

            // Get the GPTaskInfo object which holds metadata about the ArcGIS Server Geoprocessing Task. 
            Esri.ArcGISRuntime.ArcGISServices.GPTaskInfo myGPTaskInfo = await myGeoprocessor.GetTaskInfoAsync();

            // Get the GPTaskInfo.Category string published by the web service. The category is a user defined string that can be useful for 
            // grouping like Geoprocessing tasks. 
            string myCategory = myGPTaskInfo.Category;
            if (myCategory == null)
            {
                myCategory = "[Nothing/Null]";
            }

            // Get the GPTaskInfo.Description string published by the web service. The description is a user defined string that tells what types of
            // Geoprocessing Task can be performed.
            string myDescription = myGPTaskInfo.Description;
            if (myDescription == null)
            {
                myDescription = "[Nothing/Null]";
            }

            // Get the GPTaskInfo.DisplayName string published by the web service. The display name is a user defined string that the published web 
            // service is known as. It can contain human readable characters like spaces, hyphens, dashes, slashes, etc.
            string myDisplayName = myGPTaskInfo.DisplayName;
            if (myDisplayName == null)
            {
                myDisplayName = "[Nothing/Null]";
            }

            // Get the GPTaskInfo.ExecutionType Enumeration published by the web service. Typically the web service can run either 'Synchronous'
            // or 'Asynchronous'.
            Esri.ArcGISRuntime.ArcGISServices.ExecutionType myExecutionType = myGPTaskInfo.ExecutionType;

            // Get the GPTaskInfo.HelpUrl Uri published by the web service. This can be extremely useful for understanding how the Geoprocessing
            // service was created. This should be reviewed as well as the ArcGIS Server REST Services Directory page for the Uri defined for the 
            // Geoprocessing Task to fully understand what is needed to execute the Task successfully.
            System.Uri myHelpUrl = myGPTaskInfo.HelpUrl;

            // Get the GPTaskInfo.Name published by the web service. The name is the internal name of the published web service and should follow the
            // naming convention of: letters, numbers, and the underscore.
            string myName = myGPTaskInfo.Name;

            // Get the GPTaskInfo.Parameters objects published by the web service. This property contains a read only collection of GPParameterInfo 
            // objects. These parameters define the input and output expectations of the web service. 
            System.Collections.Generic.IReadOnlyCollection<Esri.ArcGISRuntime.ArcGISServices.GPParameterInfo> myParameters = myGPTaskInfo.Parameters;

            // Create a StringBuilder to hold information to display back to the user about the various GPTaskInfo Properties.
            System.Text.StringBuilder myStringBuilder_MapServiceInfo = new System.Text.StringBuilder();

            // Add all of the GPTaskInfo Properties into the StringBuilder.
            myStringBuilder_MapServiceInfo.AppendLine("Category: " + myCategory.ToString());
            myStringBuilder_MapServiceInfo.AppendLine("Description: " + myDescription.ToString());
            myStringBuilder_MapServiceInfo.AppendLine("DisplayName: " + myDisplayName.ToString());
            myStringBuilder_MapServiceInfo.AppendLine("ExecutionType: " + myExecutionType.ToString());
            myStringBuilder_MapServiceInfo.AppendLine("HelpUrl: " + myHelpUrl.ToString());
            myStringBuilder_MapServiceInfo.AppendLine("Name: " + myName.ToString());
            myStringBuilder_MapServiceInfo.AppendLine("GPParameterInfo: " + myParameters.Count.ToString());

            // Loop through the read only collection of the GPParamenterInfo objects.
            foreach (Esri.ArcGISRuntime.ArcGISServices.GPParameterInfo oneGPParameterInfo in myParameters)
            {
                // Get the GPParamenterInfo.Category string published for the GP parameter. The category is a user defined string that can be useful for 
                // grouping like Geoprocessing tasks.
                string myCatageoryGPParamenterInfo = oneGPParameterInfo.Category;

                // Get the GPParamenterInfo.DataType string published for the GP parameter. The data type is the string name of whatever type of data (ex: 
                // GPLinearUnit, GPFeatureRecordSetLayer, GPDataFile, GPString, etc.) that will serve as either and input or output for the Geoprocessing task. 
                string myDataTypeGPParamenterInfo = oneGPParameterInfo.DataType;

                // Get the GPParamenterInfo.GPParameterDirection Enumeration published for the GP parameter. The GP parameter direction tells
                // whether the particular GPParameterInfo object is an input or output to the GPTask.
                Esri.ArcGISRuntime.ArcGISServices.GPParameterDirection myDirectionGPParamenterInfo = oneGPParameterInfo.Direction;

                // Get the GPParamenterInfo .DisplayName string published for the GP parameter. The display name is a user defined string that the 
                // published Web service is known as. It can contain human readable characters like spaces, hyphens, dashes, slashes, etc.
                string myDisplayNameGPParamenterInfo = oneGPParameterInfo.DisplayName;

                // Get the GPParamenterInfo.Name published for the GP parameter. The name is the internal name of the GPParamenterInfo and should 
                // follow the naming convention of: letters, numbers, and the underscore.
                string myNameGPParamenterInfo = oneGPParameterInfo.Name;

                // Get the GPParamenterInfo.ParameterType published for the GP parameter. The parameter type tells the necessity of of the particular
                // GP Parameter (ex: required, optional, derived, etc.).
                Esri.ArcGISRuntime.ArcGISServices.GPParameterType myParameterTypeGPParamenterInfo = oneGPParameterInfo.ParameterType;

                // Add all of the GPParamenterInfo Properties into the StringBuilder.
                myStringBuilder_MapServiceInfo.AppendLine("GPParameterInfo.Category: " + myCatageoryGPParamenterInfo.ToString());
                myStringBuilder_MapServiceInfo.AppendLine("GPParameterInfo.DataType: " + myDataTypeGPParamenterInfo.ToString());
                myStringBuilder_MapServiceInfo.AppendLine("GPParameterInfo.Direction: " + myDirectionGPParamenterInfo.ToString());
                myStringBuilder_MapServiceInfo.AppendLine("GPParameterInfo.DisplayName: " + myDisplayNameGPParamenterInfo.ToString());
                myStringBuilder_MapServiceInfo.AppendLine("GPParameterInfo.NameGP: " + myNameGPParamenterInfo.ToString());
                myStringBuilder_MapServiceInfo.AppendLine("GPParameterInfo.ParameterType: " + myParameterTypeGPParamenterInfo.ToString());

                // Get the GPParamenterInfo.DefaultValue object published for the GP parameter. The default value is an object meaning it could be simple
                // (like a GPString, GPDouble, GPBoolean, etc.) or complex (meaning an conglomeration of multiple other objects). 
                object myDefaultValueGPParamenterInfo = oneGPParameterInfo.DefaultValue;
                if (myDefaultValueGPParamenterInfo == null)
                {
                    myDefaultValueGPParamenterInfo = "[Nothing/Null]";
                }
                else
                {
                    myStringBuilder_MapServiceInfo.AppendLine("GPParameterInfo.DefaultValue: " + myDefaultValueGPParamenterInfo.ToString());
                    if (myDataTypeGPParamenterInfo == "GPString")
                    {
                        myStringBuilder_MapServiceInfo.AppendLine("GPParameterInfo.DefaultValue.GPString: " + myDefaultValueGPParamenterInfo.ToString());
                    }
                    else if (myDataTypeGPParamenterInfo == "GPDouble")
                    {
                        myStringBuilder_MapServiceInfo.AppendLine("GPParameterInfo.DefaultValue.GPDouble: " + myDefaultValueGPParamenterInfo.ToString());
                    }
                    else if (myDataTypeGPParamenterInfo == "GPBoolean")
                    {
                        myStringBuilder_MapServiceInfo.AppendLine("GPParameterInfo.DefaultValue.GPBoolean: " + myDefaultValueGPParamenterInfo.ToString());
                    }
                    else
                    {
                        // ISSUE:  When the default value is a complex object (i.e. not a simple type like a GPString, GPBoolean, GPDouble, etc.) you will 
                        // need to review the ArcGIS Server REST Services Directory page for the Uri defined for the Geoprocessing Task to fully understand 
                        // what the default value object is comprised of. As of the ArcGIS Runtime SDK 10.2.6, it is not possible to convert the System.Object 
                        // to the actual ArcGIS Runtime SDK object (ex: GPFeatureRecordSetLayer, GPRasterDataLayer, GPDate, GPLinearUnit, GPDataFile, etc.) directly.
                        object myObject = myDefaultValueGPParamenterInfo;
                    }
                }

                // Get the GPParamenterInfo.ChoiceList objects published for the GP parameter. This property contains a read only collection of 
                // static choices that one could choose from as an option in the GP parameter. The list of choices vary from one GP parameter to
                // another depending on how the GPTask was created. The choices in the choice list match the GPParameterInfo.DataType and the 
                // GPParameterInfo.DefaultValue will match one of those choices.
                System.Collections.Generic.IReadOnlyList<object> myChoiceListGPParamenterInfo = oneGPParameterInfo.ChoiceList;

                // Loop through each option in the choice list for the GP parameter and display them in he StringBuilder.
                if (myChoiceListGPParamenterInfo != null)
                {
                    myStringBuilder_MapServiceInfo.AppendLine("GPParameterInfo.ChoiceList: " + myChoiceListGPParamenterInfo.Count.ToString());
                    foreach (object oneChoice in myChoiceListGPParamenterInfo)
                    {
                        myStringBuilder_MapServiceInfo.AppendLine("GPParameterInfo.ChoiceList: " + oneChoice.ToString());
                    }
                    myStringBuilder_MapServiceInfo.AppendLine("---------------------------");
                }

            }

            // Display all of the metadata information back to the user.
            TextBlock1.Text = myStringBuilder_MapServiceInfo.ToString();
        }    
    }
}