Experience with custom tasks

Source: Internet
Author: User
Experience on custom tasks 1. Class Introduction
The TaskManager and taskresults controls are provided in the ADF ). The task manager control can accommodate a series of task controls provided in the ADF (for example, searchattributestask/queryattributestask/findplacetask/findaddresstask/geoprocessingtask/editortask). Our custom task control can also be placed in it.
The custom task control is generally inherited from the task abstract class (task or floatingpaneltask. The similarities between floatingpaneltask and task are as follows. web. UI. webcontrols. compositecontrol inherits, while system. web. UI. webcontrols. compositecontrol implements the icallbackeventhandler interface, so they all have Ajax capabilities.
The difference between floatingpaneltask and task is whether it is included in floatingpanel. So the following focuses on the task abstract class. In addition to implementing icallbackeventhandler, the task class also implements two interfaces: ibuddycontrolsupport and itask.
(1) The ibuddycontrolsupport interface defines the getsupportedbuddycontroltypes method to describe the space type bound to the task. For example, the overviewmap control is bound to map, and the Toolbar Control is bound to map and pagelayout controls. If we operate on map, we can use the following Code :
Public type [] getsupportedbuddycontroltypes () {return New Type [] {typeof (MAP )};}
(2) itask Interface
Main attributes and Methods
Object input {Get; set ;}
Parameters before and after submission. Because the task inherits from compositecontrol, the variable parameter content is stored in Variable _ callbackarg. Therefore, in getcallbackresult (), _ callbackarg is used to generate input content. The generated input content is generally used in executetask.
Object results {Get; set ;}
The result generated by the task. Generally generated in executetask. Displayresults (taskjobid, input, results) is called in the method getcallbackresult () of floatingpaneltask, while displayresults traverses the result control to display resultscontainer. displayresults (this, jobid, taskinput, taskresults );
Callbackresultcollection callbackresults {Get ;}
Set of callback results. After displayresults (taskjobid, input, results) calls the task result control to traverse and display the result, callbackresults. copyfrom (resultscontainer. callbackresults) is executed for callback registration. In the floatingpaneltask class, callbackresults. tostring () is executed in the getcallbackresult () method to generate the next Callback content.
In addition to implementing the preceding two interfaces, the createchildcontrols () method is an important method for customizing tasks. To add a child control to the control set, you must override the protected createchildcontrols () method. In this method, we use the controls. Add () method to add each sub-control to the Control tree. To avoid naming conflicts between child controls and other controls on the page, we use the inamingcontainer interface.

2. Example: common_customtask_csharp
(1) code about the task execution button in createchildcontrols ():
string argument = string. format ("'bufferdistance = '+ document. getelementbyid ('{0 }'). value ", distanceinput. clientid);
string onclick = string. format ("executetask ({0}, \" {1} \ ");", argument, callbackfunctionstring);
button. attributes. add ("onclick", onclick);
here, the Click Event of the button inspires the executetask method. The generated parameters are as follows:
webform_docallback ('taskmanager1 $ simpletask_csharp1 ', argument, processcallbackresult, context, postbackerror, true) ");"
the executetask method exists in display_task.js. The following code is used:
var taskjobidcounter = 0;

function executetask (callbackarguments, callbackfunctionstring, taskjobid)
{< br> If (taskjobid = NULL)
{< br> taskjobidcounter ++;
taskjobid = taskjobidcounter;
}< br>
startactivityindicator (callbackarguments, callbackfunctionstring, taskjobid );
var TMP = "startjob (\" "+ callbackarguments. replace ('\ "', '\"') + "\", \ "" + callbackfunctionstring + "\" "+", "+ taskjobid + ")";
window. setTimeout (TMP, 1000);
}

Function startactivityindicator (callbackarguments, callbackfunctionstring, taskjobid)
{
VaR argument = "eventarg = starttaskactivityindicator & taskjobid =" + taskjobid;
If (callbackarguments. length> 0) argument + = "&" + callbackarguments;
VaR context = NULL;
// Call webform_docallback,
// Argument is "eventarg = starttaskactivityindicator & taskjobid =" + taskjobid; + callbackarguments
Eval (callbackfunctionstring );
}

Function startjob (callbackarguments, callbackfunctionstring, taskjobid)
{
VaR argument = "eventarg = executetask & taskjobid =" + taskjobid;
If (callbackarguments. length> 0) argument + = "&" + callbackarguments;
VaR context = NULL;
// Call webform_docallback,
// Argument is "eventarg = executetask & taskjobid =" + taskjobid; "+ callbackarguments
Eval (callbackfunctionstring );
}
Obviously, the executetask () method in display_task.js causes Ajax callback. The generated string is "eventarg = executetask & taskjobid = 2 & bufferdistance = 10"
(2) because the task inherits from compositecontrol, the variable parameter content is stored in Variable _ callbackarg. Generally, in getcallbackresult (), _ callbackarg is used to generate input content.
Namevaluecollection keyvalcoll = callbackutility. parsestringintonamevaluecollection (_ callbackarg );
If (keyvalcoll ["eventarg"] = "executetask ")
{
String sdistance = keyvalcoll ["bufferdistance"];
Float fdistance;
Float. tryparse (sdistance, out fdistance );
Object [] inputs = new object [2];
Inputs [0] = fdistance;
Elementgraphicslayer clonedlayer = graphicslayer. Clone () as elementgraphicslayer;
Foreach (datarow row in graphicslayer. Rows) clonedlayer. importrow (ROW );
Inputs [1] = clonedlayer;
Graphicslayer. Clear ();
Input = inputs;
}
(3) The generated input content is generally used in executetask.
Object [] inputs = input as object [];
// Buffer distance
Float bufferdistance = (float) Inputs [0];
If (float. isnan (bufferdistance) bufferdistance = 0.0f;
ESRI. ArcGIS. ADF. Web. display. Graphics. elementgraphicslayer inputlayer = inputs [1] As elementgraphicslayer;
If (inputlayer = NULL) return;
......

3. Other examples recommended for reference:
(1) http://blogs.esri.com/Dev/blogs/arcgisserver/archive/2007/10/24/Displaying-task-results-in-a-table.aspx
(2) http://arcscripts.esri.com/details.asp? Dbid = 15133
(3) http://blogs.esri.com/Dev/blogs/arcgisserver/archive/2007/05/16/Print-Task-Sample.aspx

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.