Common Custom tasks


Purpose
This sample illustrates a range of techniques for developing custom tasks using the task framework included with the Web Application Developer Framework (ADF). The task framework is unique to the Web ADF and is not inherently dependent on a specific data source. Each task in this sample is placed in its own assembly (Visual Studio project) and has a companion Web page to demonstrate the task's functionality.
 
This sample includes the following task examples:
  • AsyncTask—Illustrates how to submit a job for asynchronous processing, return control to the client, check the job status, and return the job's results once it is complete.
  • EmbeddedResourcesTask—Demonstrates how to register and use Web resources, such as images and JavaScript files.
  • PostBackTask—Shows several techniques for invoking and handling asynchronous requests using callbacks and partial postbacks.
  • ScriptTask—Includes a "super class" task implementation that enables subclasses to easily make server-side functionality scriptable. Allows server-side properties and methods to be invoked from the client with minimal code and is compatible with callbacks and partial postbacks. Especially useful for tasks that have several functions requiring requests to the server.
  • QueryBuilderTask—Illustrates a fully fleshed out implementation of a ScriptTask that has several interdependent controls for input specification. Enables construction and execution of queries at run time.
  • FindNearTask—Demonstrates a FloatingPanelTask implementation with a number of advanced features. Includes a toolbar that enables run time specification of a search area through interactions with buddied Map and TaskResults controls and allows cumulative merging of search areas as new areas are specified. Shows how task results can be displayed in a table embedded in a floating panel.
  • OptimizeTask—Demonstrates how to minimize the amount of overhead required to create a task and its child controls. By default, each Web request to a page reconstructs the page and its contents, including a task control and its child controls. If the Web request does not require the construction of a task (for example, the task or a subcomponent is not involved in processing the request), you can skip its construction. This saves valuable request processing time, especially if your task is notably complex. An optimizer class (AsyncOptimizer) is utilized in the task's CreateChildControls method to determine if child control creation is necessary.

How to use

Data has been provided for your use with this sample. It can be found at <Your ArcGIS Developer Kit Install directory>/Samples/data/USA/USA.mxd and <Your ArcGIS Developer Kit Install directory>/Samples/data/NorthAmerica (hosted online).
If the sample has associated data, you will find that the sample's zip file includes a "data" folder alongside the language folders. However, you will need to update the sample to point to the location of the data once you have extracted all the files.

At design time
  1. Verify that the Web ADF for the .NET Framework is installed and functioning properly. For information on installing and configuring the Web ADF, consult the installation guide.
  2. In Windows Explorer, navigate to <ArcGIS install location>\DeveloperKit10.0\Samples\ServerNET. This folder contains the Common_CustomTasks_CSharp and Common_CustomTasks_VBNet folders.
  3. Open the folder of the language you're going to use—CSharp or VBNet—and copy the Common_CustomTasks_<language> folder to c:\inetpub\wwwroot. The <language> variable can be either CSharp or VBNet.
  4. Open the IIS Manager from Control Panel > Administrative Tools > Internet Information Services (IIS) Manager or Internet Information Services.
  5. In the console tree view on the left, navigate to Local Computer > Web Sites > Default Web Site, expand Default Web Site, open the Common_CustomTasks_<language> folder, right-click the CustomTasksWebSite folder, and click Properties. The Properties dialog box opens.
  6. Click the Directory tab, click the Create button in the Application Settings section, then click OK to close the Properties dialog box.
  7. Open the solution for the version of Visual Studio you're using (2008 or 2010). The Visual Studio version is appended to the solution file name. For example, the Visual Studio 2008 solution file for the Common_CustomTasks_CSharp sample is Common_CustomTasks_CSharp2008.sln and is located in the c:\inetpub\wwwroot\Common_CustomTasks_CSharp folder.
  8. In Solution Explorer, right-click the CustomTasksWebSite project, and select Set as StartUp Project.
  9. Right-click the page you want to view and select Set As Start Page.
  10. The pages in this sample are configured to use the USA and NorthAmerica map services, and it is assumed that USA service is running on the local machine (localhost) while NorthAmerica is accessed online. You can create these services by publishing the map documents located at <ArcGIS install location>\DeveloperKit10.0\Samples\data. Usa.mxd is in the USA folder. For instructions on how to publish a map document to ArcGIS Server, refer to the Publishing a GIS resource to the server topic in the ArcGIS Server Help. The sample also uses following URL for geometry tasks like buffer. http://tasks.arcgisonline.com/arcgis/services/Geometry/GeometryServer
  11. If these services are running on a remote machine, you must specify the proper location. To do this, open the page you want to view in Design view, open the properties window for the MapResourceManager control, and click the ellipsis next to the ResourceItems property. The ResourceItem Collection Editor dialog box opens.
  12. Click the ellipsis next to the Definition property. The Map Resource Definition Editor dialog box opens.
  13. In the Data Source field, replace localhost with the name of the machine hosting the service.
  14. If necessary, set the run time identity of the Web application by following one of the next two steps. If not necessary, proceed to step 17.
  15. At design time, the identity of the user running Visual Studio is used to connect to an ArcGIS Server local data source. At run time, that identity is established by the Web application. Only one identity can be used to define access to the ArcGIS Server local data sources in a single Web application. This identity can be explicitly defined when building the Web ADF application in Visual Studio by right-clicking the Web project in Solution Explorer and selecting the Add ArcGIS Identity option. Enter the identity credentials that will be used to access ArcGIS Server local resources at run time. This information is added to the web.config file in a standard ASP.NET identity tag. If the Encrypt identity in web.config check box is checked, the identity tag will be encrypted; otherwise, the username and password are stored as clear text.
  16. Open the web.config file and add an <identity> element in <system.web>, set the impersonate attribute to true, and add a username and password attribute and set them to a valid user account. If you're working with ArcGIS Server local data sources, ensure the account has access to the geographic information system (GIS) server resources referenced in the Map control.
  17. Save the solution. This sample includes pre-built custom task assemblies and the appropriate statements in each corresponding .aspx file to load and utilize these custom tasks. To rebuild a custom task control, see the following section.

Rebuild a custom task control
  1. Each task's source code is in the <task name>_<language> class library project—for example, EmbeddedResourcesTask_CSharp. Build the custom task control by right-clicking the project, and selecting Build from the context menu.
  2. Open the corresponding Web page in Design view. The name of the corresponding Web page is in the form <task name>WebPage—for example, EmbeddedResourcesTaskWebPage.
  3. Right-click the General tab on the Visual Studio toolbox, select Choose Items, and navigate to the location of the assembly (<task name>_<language>.dll) generated in the previous step (for example, c:\inetpub\wwwroot\Common_CustomTasks_<language>\CustomTasksWebSite\bin\Debug.) A new control reference with the name <task name>_<language> is available in the Visual Studio toolbox.
  4. If a custom task control has already been added to the TaskManager control in the page, delete it, drag the new task control into the TaskManager, and set its TaskResults container property to the TaskResults1 control on the page.
  5. Click the Debug drop-down menu and click Start Debugging.

At run time
  1. Open a browser and enter the URL of the page you wish to view. For example, http://localhost/Common_CustomTasks_CSharp/CustomTasksWebSite would take you to the root of the sample web site.
  2. Use the custom task Web pages as outlined below.

Async task Web page
  1. Go to AsyncTaskWebPage.aspx.
  2. Click the Execute button several times. The task result nodes change from an executing message to a submitted message to a succeeded message.

Embedded resources task Web page
  1. Go to EmbeddedResourcesTaskWebPage.aspx.
  2. Click the Change Image button. The image changes. The images and the JavaScript that changes them were included in the task as embedded resources.

Postback task Web page
  1. Go to PostBackTaskWebPage.aspx.
  2. The PostBackTask has three buttons that all have similar effects. The instructive part of this example is the different ways those effects are achieved. To see this, place breakpoints and step through the code for each button.
  3. Add a ScriptManager to the page (enabling partial postbacks) and step through the code again.

Script task Web page
  1. Go to ScriptTaskWebPage.aspx.
  2. Type the name of a map service running locally into the text box and click Get Layers. The task result appears on the bottom of the task interface. The task execution and interface update are both done through server-side members that have been made scriptable.
  3. Type something that is not the name of a map service and click Get Layers. An error message appears on the task interface.

Query builder task Web page
  1. Go to QueryBuilderTaskWebPage.aspx.
  2. Change the layer. Note the cascading changes to the Fields and Sample Values. This behavior is initiated via scriptable server-side members.
  3. Change the field. The Sample Values are updated.
  4. Click the Add to Query button. The selected values in the drop-down lists have been turned into a query expression and placed in the Query text box.
  5. Click the Execute Query button. The results are displayed.
  6. Click Switch Maps in the upper right corner of the page. The task's drop-down lists are updated with information pertaining to the California service.

Find near task Web page
  1. Go to FindNearTaskWebPage.aspx.
  2. Click the Define search area by point tool, and click a point on the map.
  3. Change the units to miles. The search area is updated.
  4. Change the search distance to 300. The search area is updated.
  5. Click the Define search area by polyline tool, click several points on the map to draw a polyline, and double-click when finished. The search area is updated to include a buffer around the polyline.
  6. Click the Define search area by polygon tool, draw the polygon on the map, and double-click when finished. The search area is updated to include a buffer around the polygon.
  7. Click Find on the Query Counties task. The task executes and finds six counties.
  8. In the TaskResults control, click the Query Counties node, then click the Counties child node. The feature nodes for the six counties that were found appear.
  9. On FindNearTask, select the tool to specify the search area by task result.
  10. Click one of the county task result nodes. The search area updates to include a buffer around the county corresponding to the node that was clicked.
  11. Click the tool to define a search area by selecting features from the map.
  12. In the drop-down list that appears, choose States as the selection layer.
  13. On the map, click and drag a small box over a few states. The search area is updated with a buffer around the selected states.
  14. From the Search Layer drop-down list, select States.
  15. Click the Find button. The states intersecting the buffer are selected and the task results appear in a floating panel.
  16. On FindNearTask, click the command to clear input features from the map. Input features and buffers are removed, but the task results remain.

FindNearUserControltask Web Page
  1. Go to FindNearUserControlTaskWebPage.aspx.
  2. All the functionality is same as provided by Find Near task web page, only difference being that the Find Near task on this page is a usercontrol task which is plugged into out-of-the box UserControlTask control.

Optimize task Web page
  1. Go to OptimizerTaskWebPage.aspx.
  2. Enter a value in the text box in the task and click the button to execute the task. The task iterates through the CreateChildControls method and generates output for the TaskResults control.
  3. Click a tool in the toolbar to zoom in or out on the map.
  4. Apply the tool in the map. The child controls for the task are not created (you need to step through the code in debug to see this).
  5. Click the callback or partial postback button in the task. The task iterates through the CreateChildControls method and processes the async request. The map zooms in by a factor of 2. Even though the task did not process the async request, one of its child controls did, so iterating through CreateChildControls was necessary.

Common_CustomTasks_CSharp\AsyncTask_CSharp\AsyncTask_CSharp.csproj Class library project file for the AsyncTask control.
Common_CustomTasks_CSharp\AsyncTask_CSharp\BasicAsyncTask.cs AsyncTask implementation code.
Common_CustomTasks_CSharp\CustomTasksWebSite\AsyncTaskWebPage.aspx User interface for the Web application.
Common_CustomTasks_CSharp\CustomTasksWebSite\AsyncTaskWebPage.aspx.cs Code behind the user interface.
Common_CustomTasks_CSharp\EmbeddedResourcesTask_CSharp\EmbeddedResourcesTask_CSharp.csproj Class library project file for the EmbeddedResourcesTask control.
Common_CustomTasks_CSharp\EmbeddedResourcesTask_CSharp\EmbeddedResourcesTask.cs EmbeddedResourcesTask implementation code.
Common_CustomTasks_CSharp\EmbeddedResourcesTask_CSharp\Resources\JavaScript\CustomJavaScript.js Embedded JavaScript for switching images.
Common_CustomTasks_CSharp\CustomTasksWebSite\EmbeddedResourcesTaskWebPage.aspx User interface for the Web application.
Common_CustomTasks_CSharp\CustomTasksWebSite\EmbeddedResourcesTaskWebPage.aspx.cs Code behind the user interface.
Common_CustomTasks_CSharp\PostBackTask_CSharp\PostBackTask_CSharp.csproj Class library project file for the PostBackTask control.
Common_CustomTasks_CSharp\PostBackTask_CSharp\PostBackTask.cs PostBackTask implementation code.
Common_CustomTasks_CSharp\PostBackTask_CSharp\Resources\JavaScript\CustomSendRequest.js JavaScript for sending a custom request to the server.
Common_CustomTasks_CSharp\CustomTasksWebSite\PostBackTaskWebPage.aspx User interface for the Web application.
Common_CustomTasks_CSharp\CustomTasksWebSite\PostBackTaskWebPage.aspx.cs Code behind the user interface.
Common_CustomTasks_CSharp\ScriptTask_CSharp\ScriptTask_CSharp.csproj Class library project file for the ScriptTask control.
Common_CustomTasks_CSharp\ScriptTask_CSharp\ScriptTask.cs ScriptTask implementation code. Super class for scriptable tasks.
Common_CustomTasks_CSharp\ScriptTask_CSharp\SimpleScriptTask.cs SimpleScriptTask implementation code. Sub-classes ScriptTask.
Common_CustomTasks_CSharp\CustomTasksWebSite\ScriptTaskWebPage.aspx User interface for the Web application.
Common_CustomTasks_CSharp\CustomTasksWebSite\ScriptTaskWebPage.aspx.cs Code behind the user interface.
Common_CustomTasks_CSharp\QueryBuilderTask_CSharp\QueryBuilderTask_CSharp.csproj Class library project file for the QueryBuilderTask control.
Common_CustomTasks_CSharp\QueryBuilderTask_CSharp\QueryBuilderTask.cs QueryBuilderTask implementation code.
Common_CustomTasks_CSharp\QueryBuilderTask_CSharp\QueryBuilderTask.js Client functions for QueryBuilderTask.
Common_CustomTasks_CSharp\CustomTasksWebSite\QueryBuilderTaskWebPage.aspx User interface for the Web application.
Common_CustomTasks_CSharp\CustomTasksWebSite\QueryBuilderTaskWebPage.aspx.cs Code behind the user interface.
Common_CustomTasks_CSharp\FindNearTask_CSharp\FindNearTask_CSharp.csproj Class library project file for the FindNearTask control.
Common_CustomTasks_CSharp\FindNearTask_CSharp\FindNearTask.cs FindNearTask implementation code.
Common_CustomTasks_CSharp\FindNearTask_CSharp\Tools.cs Implementation of input specification tools.
Common_CustomTasks_CSharp\FindNearTask_CSharp\TaskResultsPanel.cs FloatingPanel implementation for displaying task results in a table.
Common_CustomTasks_CSharp\FindNearTask_CSharp\InputParameters.cs Manages input parameters for Find Near operations.
Common_CustomTasks_CSharp\FindNearTask_CSharp\GraphicsResource.cs Manages the graphics resource used to display task input geometries.
Common_CustomTasks_CSharp\FindNearTask_CSharp\TabularResultOptions.cs Options for displaying task results.
Common_CustomTasks_CSharp\FindNearTask_CSharp\Resources\javascript\FindNearTask.js Client functions for FindNearTask.
Common_CustomTasks_CSharp\FindNearTask_CSharp\Resources\javascript\TaskResultsPanel.js Client functions for TaskResultsPanel.
Common_CustomTasks_CSharp\CustomTasksWebSite\FindNearTaskWebPage.aspx User interface for the Web application.
Common_CustomTasks_CSharp\CustomTasksWebSite\FindNearTaskWebPage.aspx.cs Code behind the user interface.
Common_CustomTasks_CSharp\OptimizeTask_CSharp\OptimizeTask_CSharp.csproj Class library project file for the OptimizeTask control.
Common_CustomTasks_CSharp\OptimizeTask_CSharp\OptimizeTask.cs OptimizeTask implementation code. Notable entries are present in the CreateChildControls method.
Common_CustomTasks_CSharp\OptimizeTask_CSharp\AsyncOptimizer.cs Optimizer utility class.
Common_CustomTasks_CSharp\CustomTasksWebSite\OptimizeTaskWebPage.aspx User interface for the Web application.
Common_CustomTasks_CSharp\CustomTasksWebSite\OptimizeTaskWebPage.aspx.cs Code behind the user interface.
Download the C# files
Common_CustomTasks_VBNet\AsyncTask_VBNet\AsyncTask_VBNet.vbproj Class library project file for the AsyncTask control.
Common_CustomTasks_VBNet\AsyncTask_VBNet\BasicAsyncTask.vb AsyncTask implementation code.
Common_CustomTasks_VBNet\CustomTasksWebSite\AsyncTaskWebPage.aspx User interface for the Web application.
Common_CustomTasks_VBNet\CustomTasksWebSite\AsyncTaskWebPage.aspx.vb Code behind the user interface.
Common_CustomTasks_VBNet\EmbeddedResourcesTask_VBNet\EmbeddedResourcesTask_VBNet.vbproj Class library project file for the EmbeddedResourcesTask control.
Common_CustomTasks_VBNet\EmbeddedResourcesTask_VBNet\EmbeddedResourcesTask.vb EmbeddedResourcesTask implementation code.
Common_CustomTasks_VBNet\EmbeddedResourcesTask_VBNet\Resources\JavaScript\CustomJavaScript.js Embedded JavaScript for switching images.
Common_CustomTasks_VBNet\CustomTasksWebSite\EmbeddedResourcesTaskWebPage.aspx User interface for the Web application.
Common_CustomTasks_VBNet\CustomTasksWebSite\EmbeddedResourcesTaskWebPage.aspx.vb Code behind the user interface.
Common_CustomTasks_VBNet\PostBackTask_VBNet\PostBackTask_VBNet.vbproj Class library project file for the PostBackTask control.
Common_CustomTasks_VBNet\PostBackTask_VBNet\PostBackTask.vb PostBackTask implementation code.
Common_CustomTasks_VBNet\PostBackTask_VBNet\Resources\JavaScript\CustomSendRequest.js JavaScript for sending a custom request to the server.
Common_CustomTasks_VBNet\CustomTasksWebSite\PostBackTaskWebPage.aspx User interface for the Web application.
Common_CustomTasks_VBNet\CustomTasksWebSite\PostBackTaskWebPage.aspx.vb Code behind the user interface.
Common_CustomTasks_VBNet\ScriptTask_VBNet\ScriptTask_VBNet.vbproj Class library project file for the ScriptTask control.
Common_CustomTasks_VBNet\ScriptTask_VBNet\ScriptTask.vb ScriptTask implementation code. Super class for scriptable tasks.
Common_CustomTasks_VBNet\ScriptTask_VBNet\SimpleScriptTask.vb SimpleScriptTask implementation code. Sub-classes ScriptTask.
Common_CustomTasks_VBNet\CustomTasksWebSite\ScriptTaskWebPage.aspx User interface for the Web application.
Common_CustomTasks_VBNet\CustomTasksWebSite\ScriptTaskWebPage.aspx.vb Code behind the user interface.
Common_CustomTasks_VBNet\QueryBuilderTask_VBNet\QueryBuilderTask_VBNet.vbproj Class library project file for the QueryBuilderTask control.
Common_CustomTasks_VBNet\QueryBuilderTask_VBNet\QueryBuilderTask.vb QueryBuilderTask implementation code.
Common_CustomTasks_VBNet\QueryBuilderTask_VBNet\QueryBuilderTask.js Client functions for QueryBuilderTask.
Common_CustomTasks_VBNet\CustomTasksWebSite\QueryBuilderTaskWebPage.aspx User interface for the Web application.
Common_CustomTasks_VBNet\CustomTasksWebSite\QueryBuilderTaskWebPage.aspx.vb Code behind the user interface.
Common_CustomTasks_VBNet\FindNearTask_VBNet\FindNearTask_VBNet.vbproj Class library project file for the FindNearTask control.
Common_CustomTasks_VBNet\FindNearTask_VBNet\FindNearTask.vb FindNearTask implementation code.
Common_CustomTasks_VBNet\FindNearTask_VBNet\Tools.vb Implementation of input specification tools.
Common_CustomTasks_VBNet\FindNearTask_VBNet\TaskResultsPanel.vb FloatingPanel implementation for displaying task results in a table.
Common_CustomTasks_VBNet\FindNearTask_VBNet\InputParameters.vb Manages input parameters for Find Near operations.
Common_CustomTasks_VBNet\FindNearTask_VBNet\GraphicsResource.vb Manages the graphics resource used to display task input geometries.
Common_CustomTasks_VBNet\FindNearTask_VBNet\TabularResultOptions.vb Options for displaying task results.
Common_CustomTasks_VBNet\FindNearTask_VBNet\Resources\javascript\FindNearTask.js Client functions for FindNearTask.
Common_CustomTasks_VBNet\FindNearTask_VBNet\Resources\javascript\TaskResultsPanel.js Client functions for TaskResultsPanel.
Common_CustomTasks_VBNet\CustomTasksWebSite\FindNearTaskWebPage.aspx User interface for the Web application.
Common_CustomTasks_VBNet\CustomTasksWebSite\FindNearTaskWebPage.aspx.vb Code behind the user interface.
Common_CustomTasks_VBNet\OptimizeTask_VBNet\OptimizeTask_VBNet.vbproj Class library project file for the OptimizeTask control.
Common_CustomTasks_VBNet\OptimizeTask_VBNet\OptimizeTask.vb OptimizeTask implementation code. Notable entries are present in the CreateChildControls method.
Common_CustomTasks_VBNet\OptimizeTask_VBNet\AsyncOptimizer.vb Optimizer utility class.
Common_CustomTasks_VBNet\CustomTasksWebSite\OptimizeTaskWebPage.aspx User interface for the Web application.
Common_CustomTasks_VBNet\CustomTasksWebSite\OptimizeTaskWebPage.aspx.vb Code behind the user interface.
Download the VB.NET files

Download the files for all languages