'------------------------------------------------------------------------------
' <autogenerated>
'	 This code was generated by a tool.
'	 Runtime Version: 1.1.4322.573
'
'	 Changes to this file may cause incorrect behavior and will be lost if 
'	 the code is regenerated.
' </autogenerated>
'------------------------------------------------------------------------------


Imports Microsoft.VisualBasic
   Imports System
   Imports System.Configuration
   Imports System.Xml
Namespace ConfigBuilderExample


   ''' <summary>
   ''' Handles the 'DatabaseSettings' custom configuration section.
   ''' </summary>
   Public NotInheritable Class DatabaseSettingsSectionHandler : Inherits Object : Implements IConfigurationSectionHandler

	  ''' <summary>
	  ''' The name of the configuration section handled by this class.
	  ''' </summary>
	  Public Const SectionName As String = "DatabaseSettings"

	  ''' <summary>
	  ''' Gets the object containing configuration values for the 'DatabaseSettings' configuration section.
	  ''' </summary>
	  Public Shared ReadOnly Property Config() As DatabaseSettingsConfig
		 Get
			Dim oConfig As Object = ConfigurationSettings.GetConfig(DatabaseSettingsSectionHandler.SectionName)
			If (oConfig Is Nothing) Then
			   Throw New ConfigurationException("The application configuration file must have the 'DatabaseSettings' configuration" & " section defined.")
			End If
			Return (CType(oConfig, DatabaseSettingsConfig))
		 End Get
	  End Property

	  ''' <summary>
	  ''' See <see cref="System.Configuration.IConfigurationSectionHandler.Create"/>.
	  ''' </summary>
	  Private Function Create(ByVal parentConfig As Object, ByVal webContext As Object, ByVal sectionNode As XmlNode) As Object Implements IConfigurationSectionHandler.Create
		 Dim sectionElement As XmlElement = (CType(sectionNode, XmlElement))
		 Return DatabaseSettingsConfig.Create(sectionElement)
	  End Function

	  ''' <summary>
	  ''' Returns a typed value that represents the value of the specified attribute, or the default value if no attribute is present.
	  ''' </summary>
	  Friend Shared Function GetValue(ByVal element As XmlElement, ByVal attributeName As String, ByVal attributeType As Type, ByVal defaultVal As String) As Object
		 Try
			Dim attrVal As String = element.GetAttribute(attributeName)
			If (attrVal.Length = 0) Then
			   If (defaultVal Is Nothing) Then
				  Throw New ConfigurationException(String.Format("Missing value for required attribute '{0}' of element '{1}'.", attributeName, element.Name))
			   End If
			   attrVal = defaultVal
			End If
			If attributeType.IsEnum Then
			   Return System.Enum.Parse(attributeType, attrVal)
			End If
			Return Convert.ChangeType(attrVal, attributeType, System.Threading.Thread.CurrentThread.CurrentCulture)
		 Catch e1 As ConfigurationException
			Throw
		 Catch ex As Exception
			Throw New ConfigurationException(String.Format("Failed to extract value for attribute '{0}' from element '{1}'.", attributeName, element.Name), ex)
		 End Try
	  End Function
   End Class

   ''' <summary>
   ''' Represents data from a 'DatabaseSettings' element in the 'DatabaseSettings' configuration section.
   ''' </summary>
   Public Class DatabaseSettingsConfig

	  Private _server As String

	  Private _username As String

	  Private _timeout As Integer

	  ''' <summary>
	  ''' Initializes a new DatabaseSettingsConfig instance.
	  ''' </summary>
'INSTANT VB NOTE: The parameter server was renamed since Visual Basic will not uniquely identify class members when parameters have the same name:
'INSTANT VB NOTE: The parameter username was renamed since Visual Basic will not uniquely identify class members when parameters have the same name:
'INSTANT VB NOTE: The parameter timeout was renamed since Visual Basic will not uniquely identify class members when parameters have the same name:
	  Public Sub New(ByVal server_Renamed As String, ByVal username_Renamed As String, ByVal timeout_Renamed As Integer)
		 Me._server = server_Renamed
		 Me._username = username_Renamed
		 Me._timeout = timeout_Renamed
	  End Sub

	  ''' <summary/>
	  Public ReadOnly Property Server() As String
		 Get
			Return Me._server
		 End Get
	  End Property

	  ''' <summary/>
	  Public ReadOnly Property Username() As String
		 Get
			Return Me._username
		 End Get
	  End Property

	  ''' <summary/>
	  Public ReadOnly Property Timeout() As Integer
		 Get
			Return Me._timeout
		 End Get
	  End Property

	  ''' <summary>
	  ''' Creates a new DatabaseSettingsConfig instance based on the specified element from the application configuration file.
	  ''' </summary>
	  Friend Shared Function Create(ByVal configElement As XmlElement) As DatabaseSettingsConfig
'INSTANT VB NOTE: The local variable server was renamed since Visual Basic will not uniquely identify class members when local variables have the same name:
		 Dim server_Renamed As String = (CType(DatabaseSettingsSectionHandler.GetValue(configElement, "server", GetType(String), Nothing), String))
'INSTANT VB NOTE: The local variable username was renamed since Visual Basic will not uniquely identify class members when local variables have the same name:
		 Dim username_Renamed As String = (CType(DatabaseSettingsSectionHandler.GetValue(configElement, "username", GetType(String), Nothing), String))
'INSTANT VB NOTE: The local variable timeout was renamed since Visual Basic will not uniquely identify class members when local variables have the same name:
		 Dim timeout_Renamed As Integer = (CInt(DatabaseSettingsSectionHandler.GetValue(configElement, "timeout", GetType(Integer), " 60")))
		 Return New DatabaseSettingsConfig(server_Renamed, username_Renamed, timeout_Renamed)
	  End Function
   End Class
End Namespace
