GPPointFileInfo\GPFunctionFactory.vb
Creating a non-trival custom GP tool - inputs, outputs, and responding to environment settings
GPPointFileInfo\GPFunctionFactory.vb
' Copyright 2008 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 use restrictions at <your ArcGIS install location>/developerkit/userestrictions.txt.
' 

Imports Microsoft.VisualBasic
Imports System
Imports System.Runtime.InteropServices
Imports ESRI.ArcGIS.esriSystem
Imports ESRI.ArcGIS.ADF.CATIDs
Imports ESRI.ArcGIS.Geoprocessing
Imports ESRI.ArcGIS.Geodatabase

Namespace GPPointFileInfo
    <Guid("1EFD53C7-2A24-4207-8AEA-D23B4C2D4B21"), ComVisible(True)> _
    Public Class GPFunctionFactory
        Implements IGPFunctionFactory
        Private _name As String = "Developer Samples"
        Private _alias As String = "Developer Samples"

#Region "Component Category Registration"
        <ComRegisterFunction()> _
        Private Shared Sub Reg(ByVal regKey As String)
            GPFunctionFactories.Register(regKey)
        End Sub

        <ComUnregisterFunction()> _
        Private Shared Sub Unreg(ByVal regKey As String)
            GPFunctionFactories.Unregister(regKey)
        End Sub
#End Region

#Region "IGPFunctionFactory Members"

        Public ReadOnly Property Name() As String Implements IGPFunctionFactory.Name
            Get
                Return _name
            End Get
        End Property

        Public ReadOnly Property [Alias]() As String Implements IGPFunctionFactory.Alias
            Get
                Return _alias
            End Get
        End Property

        Public ReadOnly Property CLSID() As UID Implements IGPFunctionFactory.CLSID
            Get
                Dim uidCLSID As UID = TryCast(New UIDClass(), UID)

                uidCLSID.Value = Me.GetType().GUID.ToString("B")

                Return uidCLSID
            End Get
        End Property

        Public Function GetFunction(ByVal name As String) As IGPFunction Implements IGPFunctionFactory.GetFunction
            Dim gpFunction As IGPFunction

            Select Case name
                Case ("PointFileInfo")

                    gpFunction = New GPPointFileInfoFunction()


                Case Else

                    Throw New GPException(GPExceptionSeverity.Fatal, "Invalid Point File Info Function Factory. Unable To Get Function. Unhandled Case." & ObjectToString.GetNewline() & "name: " & ObjectToString.GetToString(name))
            End Select

            Return gpFunction
        End Function

        Public Function GetFunctionName(ByVal name As String) As IGPName Implements IGPFunctionFactory.GetFunctionName
            Dim gpName As IGPName

            Select Case name
                Case ("PointFileInfo")

                    gpName = TryCast(CreateGPFunctionNames(0), IGPName)


                Case Else

                    Throw New GPException(GPExceptionSeverity.Fatal, "Invalid Point File Info Function Factory. Unable To Get Function Name. Unhandled Case." & ObjectToString.GetNewline() & "name: " & ObjectToString.GetToString(name))
            End Select

            Return gpName
        End Function

        Public Function GetFunctionNames() As IEnumGPName Implements IGPFunctionFactory.GetFunctionNames
            Dim enumGPName As IEnumGPName = New EnumGPNameClass()

            Dim array As IArray = TryCast(enumGPName, IArray)

            array.Add(CreateGPFunctionNames(0))

            Return enumGPName
        End Function

        Private Function CreateGPFunctionNames(ByVal index As Long) As IGPFunctionName
            Dim gpFunctionName As IGPFunctionName

            Select Case index
                Case (0)

                    gpFunctionName = GetPointFileInfoGPFunctionName()


                Case Else

                    Throw New GPException(GPExceptionSeverity.Fatal, "Invalid Point File Info Function Factory. Unable To Create GP Function Names. Unhandled Case." & ObjectToString.GetNewline() & "index: " & ObjectToString.GetToString(index))
            End Select

            Return gpFunctionName
        End Function

        Private Function GetPointFileInfoGPFunctionName() As IGPFunctionName
            Dim gpFunctionName As IGPFunctionName = New GPFunctionNameClass()

            Dim gpName As IGPName = TryCast(gpFunctionName, IGPName)

            gpName.Category = "Terrain"
            gpName.Description = "This tool generates a 2D or 3D output feature class containing statistical information about input XYZ, LAS, or GENERATE data to be used in the Terrain build process."
            gpName.DisplayName = "Point File Information"
            gpName.Name = "PointFileInfo"
            gpName.Factory = TryCast(Me, IGPFunctionFactory)

            Return gpFunctionName
        End Function

        Public Function GetFunctionEnvironments() As IEnumGPEnvironment Implements IGPFunctionFactory.GetFunctionEnvironments
            Return Nothing
        End Function

#End Region
    End Class
End Namespace