ArcGIS Simple Edit service
ArcGIS_SimpleEdit_VBNet\ArcGIS_SimpleEdit_WebAppVBNet\App_Code\AddPointTool.vb
' Copyright 2010 ESRI
' 
' All rights reserved under the copyright laws of the United States
' and applicable international laws, treaties, and conventions.
' 
' You may freely redistribute and use this sample code, with or
' without modification, provided you include the original copyright
' notice and use restrictions.
' 
' See the use restrictions.
' 

Imports Microsoft.VisualBasic
Imports System
Public Class AddPointTool
    Implements ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools.IMapServerToolAction
  #Region "IMapServerToolAction Members"

  Private Sub ServerAction(ByVal toolEventArgs As ESRI.ArcGIS.ADF.Web.UI.WebControls.ToolEventArgs) Implements ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools.IMapServerToolAction.ServerAction
    Dim adfMap As ESRI.ArcGIS.ADF.Web.UI.WebControls.Map = CType(toolEventArgs.Control, ESRI.ArcGIS.ADF.Web.UI.WebControls.Map)

    Try
      ' Retrieve the collection that will contain the tool parameters that were specified by the
      ' user on the page's interface.
      Dim toolArgsNameValueCollection As System.Collections.Specialized.NameValueCollection = Nothing
      If adfMap.Page.IsCallback Then
        ' Since the page is using the callback framework, the tool parameters have been packaged 
        ' along with the callback parameters.  This is done via custom javascript (see Default.aspx).
        Dim callbackArgs As String = adfMap.Page.Request.Params("__CALLBACKPARAM")
        toolArgsNameValueCollection = ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackUtility. ParseStringIntoNameValueCollection(callbackArgs)
      Else
        ' Since the page is not using the callback framework, that means the tool has executed via
        ' partial or full-page postback.  In the case of postbacks, the values of ASP.NET server 
        ' controls (which contain user-specified tool parameters in this case) are automatically
        ' passed in the page's request parameters.
        toolArgsNameValueCollection = adfMap.Page.Request.Params
      End If

      ' Get the tool input from the arguments collection
      Dim serviceNameString As String = toolArgsNameValueCollection("serviceNameTextBox")
      Dim serviceDetailsString As String = toolArgsNameValueCollection("serviceDetailsTextBox")
      Dim serviceTypeString As String = toolArgsNameValueCollection("serviceTypeDropDownList")

      ' Get the point on the map clicked by the user
      Dim mapPointEventArgs As ESRI.ArcGIS.ADF.Web.UI.WebControls.MapPointEventArgs = TryCast(toolEventArgs, ESRI.ArcGIS.ADF.Web.UI.WebControls.MapPointEventArgs)
      Dim adfPoint As ESRI.ArcGIS.ADF.Web.Geometry.Point = mapPointEventArgs.MapPoint

      ' Get a reference to the AddActionLocation web service
      Dim addActionLocationService As AddActionLocationService.AddActionLocationService = New AddActionLocationService.AddActionLocationService()

      ' Create a new action location and initialize it with the coordiantes of the point clicked
      Dim actionLocation As AddActionLocationService.ActionLocation = New AddActionLocationService.ActionLocation()
      actionLocation.X = adfPoint.X
      actionLocation.Y = adfPoint.Y

      ' Create a new action record and initialize it with the textbox and drop-down list values 
      ' specified by the user
      Dim actionRecord As AddActionLocationService.ActionRecord = New AddActionLocationService.ActionRecord()
      actionRecord.Name = serviceNameString
      actionRecord.Details = serviceDetailsString
      ' Convert the string representation of the selected service type to its counterpart in the
      ' AddActionLocationService.ServiceType enumeration
      Dim serviceType As AddActionLocationService.ServiceType = CType(System.Enum.Parse(GetType(AddActionLocationService.ServiceType), serviceTypeString, True), AddActionLocationService.ServiceType)
      actionRecord.ServiceType = serviceType

      ' Set the action record's location to the clicked point
      actionRecord.Location = actionLocation

      ' Add the new action record to the map service, which in turn creates a new feature with the
      ' specified attributes and adds it to the underlying feature class
      addActionLocationService.AddActionLocation(actionRecord)

      ' Refresh the map so the new feature is displayed
      adfMap.Refresh()
    Catch exception As System.Exception
      Dim errorAlertCallbackResult As ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResult = Utility.CreateErrorCallbackResult(exception)
      adfMap.CallbackResults.Add(errorAlertCallbackResult)
    End Try
  End Sub

  #End Region
End Class