Tuesday, December 23, 2008

Workflow for adding DataTable, DataSet to ADF TaskResults WebControl

I've found out the hard way on several occassions that the ArcGIS Server 9.3 .NET ADF has issues if things are not done the way they are explicitly outlined in the samples. Now any good API will contain necessary information to inform the developer if there is any particular patterns to follow, e.g. when addings results to a TaskResults webControl, if we set gl.renderOnClient = true after adding to the GraphicsDataSet, it won't render on client. Does this seem reasonable? There's lots and lots of peculiarities with the ArcGIS Server ADF API, and the API docs contains virtually no info other than input & return types, which is no more info than what Visual Studio's Object Browser offers. In fact, you'll probably get more info from using dotNetReflector than looking at the ADF API docs. 
How can it be made better?
  • Very simple, hire a skilled developer to write the docs who has some programming experience and exposure to other APIs as well. They should write the docs by looking at the code and samples, the docs are not inert. 
  • Take a look at other good API's out there, e.g. Sun Java API, Ext JS API. 
  • Add PreConditions, PostConditions to methods, constructors etc. for each input, return parameters
  • Add links to the return, input types (this is the least that could be expected)
  • Add diagrams to explain complex design patterns (object models, class diagrams etc)
  • Avoid the use of Utility classes for each namespace
Anyways, this is the workflow that I found I had to follow in order to add datatables to the TaskResults WebControl and render them on the client (any deviation and it won't work): 
  1. Convert the DataTable dt to a GraphicsLayer, GraphicsLayer gl = ESRI.ArcGIS.ADF.Web.Converter.ConvertToGraphicsLayer(dt)
  2. Get the appropriate LayerFormat, lf, from web.config or MapResourceManager or create your own one
  3. lf.apply(gl)
  4. gl.renderOnClient = true
  5. for each DataRow in GraphicsLayer (which is a subclass of DataTable), set the IsSelectedRow to true,  dataRow.IsSelectedColumn = true
  6. Create a new GraphicsDataSet, gds (which is a subclass of DataSet)
  7. Add that GraphicsLayer, gl to the gds gds.Tables.Add(gl)
  8. If you're inside the ExecuteTask() method of a Custom ADF Task, then you can Me.Results = gds
  9. Or you can create a TaskResultNode,  TaskResultNode resultTRN = adfTaskResultsInstance.CreateTaskResultNode(null, null, null, gds, false, true); Me.Results = resultTRN

No comments:

Post a Comment