Common CustomDataSource
Common_CustomDataSource_VBNet\CustomDataSource_VBNet\TiledMapDataSource_VBNet\MapResource.vb
' Copyright 2007 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
Imports System.Text
Imports System.Web.UI
Imports System.Collections
Imports ESRI.ArcGIS.ADF.Web.DataSources
Imports ESRI.ArcGIS.ADF.Web.Display.Graphics

Namespace TiledMapDataSource_VBNet
  Public Class MapResource
    Implements IMapResource
    Public Sub New()
    End Sub
    Public Sub New(ByVal name_Renamed As String, ByVal dataSource_Renamed As GISDataSource)
      Me.name_Renamed = name_Renamed
      Me.dataSource_Renamed = dataSource_Renamed
    End Sub

    #Region "IMapResource implementation"

    Private mapInformation_Renamed As IMapInformation = Nothing
    Private displaySettings_Renamed As ESRI.ArcGIS.ADF.Web.DisplaySettings = Nothing

        Public ReadOnly Property MapInformation() As IMapInformation Implements IMapResource.MapInformation
            Get
                Return mapInformation_Renamed
            End Get
        End Property

    Public Property DisplaySettings() As ESRI.ArcGIS.ADF.Web.DisplaySettings Implements IMapResource.DisplaySettings
      Get
        Return displaySettings_Renamed
      End Get
      Set
        displaySettings_Renamed = Value
      End Set
    End Property

    #End Region

    #Region "IGISResource implementation"

    Private initialized_Renamed As Boolean = False
    Private name_Renamed As String = String.Empty
    Private resourceDefinition_Renamed As String = String.Empty
    Private dataSource_Renamed As IGISDataSource = Nothing
    Private functionalities_Renamed As GISFunctionalityCollection = New GISFunctionalityCollection()
    Friend layerVisibility As Dictionary(Of String, Boolean) = Nothing
    Private validationtimeout_Renamed As Integer = 0

    Public Property Name() As String Implements IMapResource.Name
      Get
        Return name_Renamed
      End Get
      Set
        name_Renamed = Value
      End Set
    End Property

    Public Property ValidationTimeout() As Integer Implements IMapResource.ValidationTimeout
      Get
        Return validationtimeout_Renamed
      End Get
      Set
        validationtimeout_Renamed = Value
      End Set
    End Property

    Public Property ResourceDefinition() As String Implements IMapResource.ResourceDefinition
      Get
        Return resourceDefinition_Renamed
      End Get
      Set
        resourceDefinition_Renamed = Value
      End Set
    End Property

    Public Property DataSource() As IGISDataSource Implements IMapResource.DataSource
      Get
        Return dataSource_Renamed
      End Get
      Set
        dataSource_Renamed = Value
      End Set
    End Property

    Public Property Functionalities() As GISFunctionalityCollection Implements IMapResource.Functionalities
      Get
        Return functionalities_Renamed
      End Get
      Set
        functionalities_Renamed = Value
      End Set
    End Property

    Public Function SupportsFunctionality(ByVal functionalityType As System.Type) As Boolean Implements IMapResource.SupportsFunctionality
      If functionalityType Is GetType(ESRI.ArcGIS.ADF.Web.DataSources.IMapFunctionality) Then
      Return True
      ElseIf functionalityType Is GetType(ESRI.ArcGIS.ADF.Web.DataSources.ITileFunctionality) Then
      Return True
      ElseIf functionalityType Is GetType(ESRI.ArcGIS.ADF.Web.DataSources.IMapTocFunctionality) Then
      Return True
      Else
        Return False
      End If
    End Function

    Public Function CreateFunctionality(ByVal functionalityType As System.Type, ByVal functionalityName As String) As IGISFunctionality Implements IMapResource.CreateFunctionality
      Dim func As IGISFunctionality = Nothing
      If functionalityType Is GetType(ESRI.ArcGIS.ADF.Web.DataSources.IMapFunctionality) Then
        func = New MapFunctionality(functionalityName, Me)
      ElseIf functionalityType Is GetType(ESRI.ArcGIS.ADF.Web.DataSources.ITileFunctionality) Then
        Dim tileCacheInfo As TileCacheInfo = TryCast(mapInformation_Renamed.TileCacheInfo, TileCacheInfo)
        func = New TileFunctionality(functionalityName, Me, tileCacheInfo)
      ElseIf functionalityType Is GetType(ESRI.ArcGIS.ADF.Web.DataSources.IMapTocFunctionality) Then
        Dim tileCacheInfo As TileCacheInfo = TryCast(mapInformation_Renamed.TileCacheInfo, TileCacheInfo)
        func = New MapTocFunctionality(functionalityName, Me, tileCacheInfo)
      Else
        Throw New ArgumentException("functionalityType")
      End If
      Return func
    End Function

    Public ReadOnly Property Initialized() As Boolean Implements IMapResource.Initialized
      Get
        Return initialized_Renamed
      End Get
    End Property

    Public Sub LoadState() Implements IMapResource.LoadState
      If dataSource_Renamed Is Nothing Then
      Return
      End If
      If dataSource_Renamed.State Is Nothing Then
      Return
      End If

      Dim o As Object = dataSource_Renamed.State(key)
      If Not o Is Nothing Then
        Dim mr As MapResource = TryCast(o, MapResource)
        mapInformation_Renamed = mr.mapInformation
        layerVisibility = mr.layerVisibility
      End If
    End Sub

    Public Sub Initialize() Implements IMapResource.Initialize
      If mapInformation_Renamed Is Nothing Then
        mapInformation_Renamed = New MapInformation(DataSource.DataSourceDefinition, ResourceDefinition)
      End If

      If layerVisibility Is Nothing Then
        Dim tileCacheInfo As TileCacheInfo = CType(mapInformation_Renamed.TileCacheInfo, TileCacheInfo)
        layerVisibility = New Dictionary(Of String, Boolean)()
        If Not tileCacheInfo.Layers Is Nothing Then
          For Each kvp As KeyValuePair(Of String, String) In tileCacheInfo.Layers
            layerVisibility.Add(kvp.Key, True)
          Next kvp
        End If
      End If
      initialized_Renamed = True
    End Sub

    Public Sub SaveState() Implements IMapResource.SaveState
      If dataSource_Renamed Is Nothing Then
      Return
      End If
      If dataSource_Renamed.State Is Nothing Then
      Return
      End If
      dataSource_Renamed.State(key) = Me
    End Sub

    Public Sub Dispose() Implements IMapResource.Dispose
      initialized_Renamed = False
    End Sub

    Public Sub ClearState() Implements IMapResource.ClearState
      If DataSource Is Nothing OrElse DataSource.State Is Nothing Then
      Return
      End If
      DataSource.State(key) = Nothing
    End Sub

    #End Region

    #Region "private Key Properties"
    Private ReadOnly Property key() As String
      Get
        Dim tmp As String = Me.GetType().ToString() & ":" & name_Renamed
        Return (tmp)
      End Get
    End Property
    #End Region

  End Class
End Namespace