Common Simple Server task
Common_SimpleServerTask_VBNet\SimpleServerTask_VBNet.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
Imports System.Collections.Generic
'using System.Linq;
Imports System.Text
Imports System.Web.UI
Imports ESRI.ArcGIS.ADF.Web.UI.WebControls
Imports System.ComponentModel


Namespace Commom_SimpleServerTask_VBNet

    ' Specifies the class used to configure the task in ArcGIS Manager
    ' Specifies the image used to represent the task in a container (e.g. the Visual Studio toolbox)
    <System.Web.UI.ToolboxData("<{0}:SimpleServerTask_VBNet runat=""server"" Width=""100px"" BorderWidth=""1px""><TaskResultsContainers><esri:BuddyControl Name=""TaskResults1"" /></TaskResultsContainers> </{0}:SimpleServerTask_VBNet>"), _
     Designer(GetType(SimpleServerTaskDesigner_VBNet)), _
     ESRI.ArcGIS.ADF.Web.UI.WebControls.WebConfigurator(GetType(SimpleServerTaskWebConfigurator_VBNet)), System.Drawing.ToolboxBitmap(GetType(SimpleServerTask_VBNet))> _
        Public Class SimpleServerTask_VBNet
        Inherits FloatingPanelTask

#Region "Instance Variable Declarations"

        Private m_textBox As System.Web.UI.HtmlControls.HtmlInputText = Nothing
        Private m_executeButton As System.Web.UI.HtmlControls.HtmlInputButton = Nothing

        Private m_taskTextKey As String = "textValue"
#End Region

#Region "Instance Properties"

        ' Specifies that the property will appear in Visual Studio's properties pane
        ' Specifies the category within which the property will be grouped
        ' Specifies the property's default value
        ' Specifies that the property be persisted as an attribute
        <System.ComponentModel.Browsable(True), System.ComponentModel.Category("Appearance"), System.ComponentModel.DefaultValue("Execute"), System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.Attribute)> _
        Public Property ButtonText() As String
            Get
                ' Attempt to retrieve the button text from state
                Dim buttonTextObject As Object = StateManager.GetProperty("buttonText")
                ' If no button text was stored in state, return the default value.  Otherwise,
                ' return the text as a string.
                Return If((buttonTextObject Is Nothing), "Execute", TryCast(buttonTextObject, String))
            End Get
            Set(ByVal value As String)
                ' Store the passed-in value in state
                StateManager.SetProperty("buttonText", value)
            End Set
        End Property

#End Region

        ' Configures the task's interface
        Protected Overrides Sub CreateChildControls()
            Controls.Clear()
            MyBase.CreateChildControls()

            ' Initialize the task's textbox
            m_textBox = New System.Web.UI.HtmlControls.HtmlInputText()
            m_textBox.ID = "txtTaskText"

            ' Add textbox to the task's controls collection
            Controls.Add(m_textBox)

            ' Initialize the task's execute button
            m_executeButton = New System.Web.UI.HtmlControls.HtmlInputButton()
            m_executeButton.ID = "btnExecute"
            m_executeButton.Value = ButtonText

            ' Format JavaScript string that will construct the task's callback argument when OK is clicked.
            ' For instance, if "523" was typed in the task's textbox, this expression would evaluate to 
            ' 'textValue=523'
            Dim jsGetTaskCallbackArgument As String = String.Format("'{0}=' + document.getElementById('{1}').value", m_taskTextKey, m_textBox.ClientID)

            ' Format JavaScript to invoke the ADF's executeTask method when OK is clicked.  Pass the
            ' task's argument and callback invocation to the method.

            Dim jsOnClick As String = String.Format("executeTask({0},""{1}"");", jsGetTaskCallbackArgument, CallbackFunctionString)

            ' Wire the task execution javascript to the OK button's onclick event and the text box's
            ' onkeydown event.
            m_executeButton.Attributes.Add("onclick", jsOnClick)

            ' Add the button to the task's controls collection
            Controls.Add(m_executeButton)
        End Sub

        Public Overrides Function GetCallbackResult() As String
            ' Set the task's Input member to the value of the task's textbox 
            Dim keyValColl As System.Collections.Specialized.NameValueCollection = ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackUtility.ParseStringIntoNameValueCollection(CallbackEventArgument)
            Input = keyValColl(m_taskTextKey)
            Return MyBase.GetCallbackResult()
        End Function

        Public Overrides Sub ExecuteTask()
            ' Clear any left-over task results and make sure task input exists
            Results = Nothing
            If Input() Is Nothing Then
                Return
            End If

            ' Get the task's textbox value from the Input property
            Dim textBoxValue As String = TryCast(Input(), String)

            ' Format the heading of the task result to display the current time on the server
            Dim taskResultHeading As String = String.Format("The time on the server is {0}", System.DateTime.Now.ToShortTimeString())

            ' Format the detail of the task result to display the value of the task's textbox when
            ' the task was executed
            Dim taskResultDetail As String = String.Format("The value in the textbox is: {0}", textBoxValue)

            ' Create a simple task result with the heading and detail
            Dim simpleTaskResult As New ESRI.ArcGIS.ADF.Web.UI.WebControls.SimpleTaskResult(taskResultHeading, taskResultDetail)

            ' Set the task's Results property to the simple task result.  The contents of this property
            ' will be passed to the task's results container.
            Results = simpleTaskResult
        End Sub
        Public Overrides Sub Refresh()
            Dim tmp As String = TryCast(Input(), String)
            If (Not String.IsNullOrEmpty(tmp)) Then
                m_textBox.Value = tmp
            End If
            MyBase.Refresh()
        End Sub

        Public Overrides Function GetGISResourceItemDependencies() As List(Of GISResourceItemDependency)
            Dim list As New System.Collections.Generic.List(Of ESRI.ArcGIS.ADF.Web.UI.WebControls.GISResourceItemDependency)()
            Return list
        End Function
    End Class

End Namespace