Common Custom EditorTask
Common_CustomEditorTask_VBNet\CustomEditorTask_VBNet\CustomEditorTask.vb
' Copyright 2011 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
Namespace CustomEditorTask_VBNet
    <System.ComponentModel.DefaultProperty("Text"), System.Web.UI.ToolboxData("<{0}:CustomEditorTask runat=server></{0}:CustomEditorTask>")> _
    Public Class CustomEditorTask
        Inherits ESRI.ArcGIS.ADF.ArcGISServer.Editor.EditorTask

#Region "WebControl Life Cycle Event Overrides"

        Protected Overrides Sub OnLoad(ByVal eventArgs As System.EventArgs)
            MyBase.OnLoad(eventArgs)
            'Uncomment the following if you want to Set attribute filtering parameters for the EditorTask during the 
            ' Page Load event of the initial request.            
            'if (!this.Page.IsPostBack)
            '{
            '    FilterAttributes();
            '}
        End Sub

#End Region

#Region "EditorTask Overrides"

        ' Override to create and return a custom settings panel
        Protected Overrides Function CreateSettingsPanel() As ESRI.ArcGIS.ADF.ArcGISServer.Editor.EditorSettingsPanel
            Return New CustomEditorSettingsPanel(Me)
            'return base.CreateSettingsPanel();
        End Function

        ' Override to create and return a custom Editor
        Protected Overrides Function CreateEditor() As ESRI.ArcGIS.ADF.ArcGISServer.Editor.Editor
            Return New CustomEditor(Me)
            'return base.CreateEditor();
        End Function

        ' Override to execute logic after an editor tool has completed execution
        Protected Overrides Sub OnPostToolExecute(ByVal editorToolEventArgs As ESRI.ArcGIS.ADF.ArcGISServer.Editor.Tools.EditorToolEventArgs, ByVal returnMessages As ESRI.ArcGIS.ADF.ArcGISServer.Editor.StringList)
            MyBase.OnPostToolExecute(editorToolEventArgs, returnMessages)

            ' After a tool that modifies features has executed, add creation and modified time to edited feature.
            ' The "Tentative Assessed Parcel" layer contains two Date fields: CreationTime and LastModified.
            ' If a new feature was created, update the CreationTime field with the current Date.  
            ' If an existing feature was modified (via the tools listed), update the LastModified field with the current Date.
            'if (editorToolEventArgs.ServerAction.Editor.SelectedLayerName == "Tentative Assessed Parcels")
            If editorToolEventArgs.ServerAction.Editor.SelectedLayerName = "Blocks" Then
                ' Get the feature class underlying the layer containing the edited feature
                Dim featureClass As ESRI.ArcGIS.Geodatabase.IFeatureClass = editorToolEventArgs.ServerAction.Editor.FeatureLayer.FeatureClass

                ' If statements check the ServerAction type to determine which tool executed
                If TypeOf editorToolEventArgs.ServerAction Is ESRI.ArcGIS.ADF.ArcGISServer.Editor.Tools.CreateFeature Then
                    ' Get a reference to the feature that was modified via the tool that executed
                    Dim createFeature As ESRI.ArcGIS.ADF.ArcGISServer.Editor.Tools.CreateFeature = CType(editorToolEventArgs.ServerAction, ESRI.ArcGIS.ADF.ArcGISServer.Editor.Tools.CreateFeature)
                    Dim feature As ESRI.ArcGIS.Geodatabase.IFeature = featureClass.GetFeature(createFeature.Feature)

                    ' Populate the CreationTime field with the current time on the server
                    Dim index As Integer = feature.Fields.FindField("CreationTime")
                    If index > -1 Then
                        feature.Value(index) = System.DateTime.Now
                        feature.Store()
                    End If
                    ' For simplicity only a few tools that modify features have been included
                ElseIf TypeOf editorToolEventArgs.ServerAction Is ESRI.ArcGIS.ADF.ArcGISServer.Editor.Tools.AddVertex Then
                    ' Get the tool that executed and update the last modified time attribute via utility method
                    Dim addVertex As ESRI.ArcGIS.ADF.ArcGISServer.Editor.Tools.AddVertex = CType(editorToolEventArgs.ServerAction, ESRI.ArcGIS.ADF.ArcGISServer.Editor.Tools.AddVertex)
                    UpdateLastModifiedTime(addVertex.Features, featureClass)
                ElseIf TypeOf editorToolEventArgs.ServerAction Is ESRI.ArcGIS.ADF.ArcGISServer.Editor.Tools.MoveVertex Then
                    ' Get the tool that executed and update the last modified time attribute via utility method
                    Dim moveVertex As ESRI.ArcGIS.ADF.ArcGISServer.Editor.Tools.MoveVertex = CType(editorToolEventArgs.ServerAction, ESRI.ArcGIS.ADF.ArcGISServer.Editor.Tools.MoveVertex)
                    UpdateLastModifiedTime(moveVertex.Features, featureClass)
                ElseIf TypeOf editorToolEventArgs.ServerAction Is ESRI.ArcGIS.ADF.ArcGISServer.Editor.Tools.MoveFeature Then
                    ' Get the tool that executed and update the last modified time attribute via utility method
                    Dim moveFeature As ESRI.ArcGIS.ADF.ArcGISServer.Editor.Tools.MoveFeature = CType(editorToolEventArgs.ServerAction, ESRI.ArcGIS.ADF.ArcGISServer.Editor.Tools.MoveFeature)
                    UpdateLastModifiedTime(moveFeature.Features, featureClass)
                End If

                ' Refreshes the EditAttributesPanel (returned from call to Editor.AttributesEditor property)
                ' and adds callbacks to the Map control associated with the Editor.
                ESRI.ArcGIS.ADF.ArcGISServer.Editor.EditorUtilities.RefreshAttributes(editorToolEventArgs.ServerAction.Editor, Nothing)
            End If
        End Sub

#End Region

#Region "Instance Properties"

        ' Custom property to set limit on number of records returned from query.
        <System.ComponentModel.Browsable(True), System.ComponentModel.Category("Select by Attributes"), System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.Attribute), System.ComponentModel.DefaultValue(100), System.ComponentModel.Description("Maximum number of sample values to return on select by attributes panel.")> _
        Public Property SampleValueLimit() As Integer
            Get
                If StateManager.GetProperty("sampleValueLimit") Is Nothing Then
                    Me.SampleValueLimit = 100
                End If
                Return CInt(Fix(StateManager.GetProperty("sampleValueLimit")))
            End Get
            Set(ByVal value As Integer)
                StateManager.SetProperty("sampleValueLimit", value)
            End Set
        End Property

        ' Custom property to define snapping in map units
        <System.ComponentModel.Browsable(True), System.ComponentModel.Category("Snapping"), System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.Attribute), System.ComponentModel.DefaultValue(CustomSnappingPanel.DEFAULT_SNAP_TOL_MAPUNITS), System.ComponentModel.Description("The maximum distance in map units for which " & "snapping rules will be effective.")> _
        Public Property SnapToleranceMapUnits() As Double
            Get
                Dim obj As Object = StateManager.GetProperty("snapTolMapUnits")
                If obj Is Nothing Then
                    Return CustomSnappingPanel.DEFAULT_SNAP_TOL_MAPUNITS
                End If

                Return CDbl(obj)
            End Get

            Set(ByVal value As Double)
                StateManager.SetProperty("snapTolMapUnits", value)
            End Set
        End Property

        ' Custom property to define if snapping should use pixels (default) or map units.
        <System.ComponentModel.Browsable(True), System.ComponentModel.Category("Snapping"), System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.Attribute), System.ComponentModel.DefaultValue(True), System.ComponentModel.Description("Indicates if snapping uses map units or pixels.")> _
        Public Property UseMapUnitsForSnapping() As Boolean
            Get
                Dim obj As Object = StateManager.GetProperty("useSnappingMapUnits")
                If obj IsNot Nothing Then
                    Return CBool(obj)
                End If
                Return True
            End Get
            Set(ByVal value As Boolean)
                StateManager.SetProperty("useSnappingMapUnits", value)
            End Set
        End Property

#End Region

#Region "Instance Methods"

        ' Used during post tool execute to update the LastModified field of edited features
        Private Sub UpdateLastModifiedTime(ByVal featureIDs As System.Collections.Generic.List(Of Integer), ByVal featureClass As ESRI.ArcGIS.Geodatabase.IFeatureClass)
            ' Iterate through the passed-in feature IDs and update the corresponding feature's
            ' LastModified field with the current server time
            Dim index As Integer = featureClass.Fields.FindField("LastModified")

            For Each featureID As Integer In featureIDs
                Dim feature As ESRI.ArcGIS.Geodatabase.IFeature = featureClass.GetFeature(featureID)
                feature.Value(index) = System.DateTime.Now
                feature.Store()
            Next featureID
        End Sub
        'This function is not used currently in the sample.
        Private Sub FilterAttributes()
            ' Get the ArcGIS Server Local MapFunctionality associated with the EditorTask
            Dim agsLocalMapFunctionality As ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapFunctionality = Me.Editor.MapFunctionality

            Dim layerIDs() As String = Nothing
            Dim layerNames() As String = Nothing
            agsLocalMapFunctionality.GetLayers(layerIDs, layerNames)

            ' Iterate through feature layers in the MapFunction (map resource) and set
            ' attribute display parameters when editing attributes in the EditAttributesPanel.
            For i As Integer = 0 To layerIDs.Length - 1
                Dim layerName As String = layerNames(i)
                Dim layerID As Integer = System.Int32.Parse(layerIDs(i))
                If layerName = "Parcels" Then
                    Dim attributeDisplayInfo As New ESRI.ArcGIS.ADF.ArcGISServer.Editor.AttributeDisplayInfo(layerID, ESRI.ArcGIS.ADF.ArcGISServer.Editor.AttributeDisplayMode.ReadOnly)
                    attributeDisplayInfo.Overrides.Add(New ESRI.ArcGIS.ADF.ArcGISServer.Editor.AttributeDisplayOverride("Parcel_ID", ESRI.ArcGIS.ADF.ArcGISServer.Editor.AttributeDisplayMode.Editable))
                    Me.AttributeDisplay.AttributeDisplayInfos.Add(attributeDisplayInfo)
                ElseIf layerName = "Road centerline" Then
                    Dim attributeDisplayInfo As New ESRI.ArcGIS.ADF.ArcGISServer.Editor.AttributeDisplayInfo(layerID, ESRI.ArcGIS.ADF.ArcGISServer.Editor.AttributeDisplayMode.Editable)
                    attributeDisplayInfo.Overrides.Add(New ESRI.ArcGIS.ADF.ArcGISServer.Editor.AttributeDisplayOverride("NAME", ESRI.ArcGIS.ADF.ArcGISServer.Editor.AttributeDisplayMode.ReadOnly))
                    Me.AttributeDisplay.AttributeDisplayInfos.Add(attributeDisplayInfo)
                ElseIf layerName = "Blocks" Then
                    Dim attributeDisplayInfo As New ESRI.ArcGIS.ADF.ArcGISServer.Editor.AttributeDisplayInfo(layerID, ESRI.ArcGIS.ADF.ArcGISServer.Editor.AttributeDisplayMode.Hidden)
                    attributeDisplayInfo.Overrides.Add(New ESRI.ArcGIS.ADF.ArcGISServer.Editor.AttributeDisplayOverride("Res", ESRI.ArcGIS.ADF.ArcGISServer.Editor.AttributeDisplayMode.Editable))
                    Me.AttributeDisplay.AttributeDisplayInfos.Add(attributeDisplayInfo)
                End If
            Next i
        End Sub

#End Region
    End Class
End Namespace