Imports NLog
Imports DigitalData.Modules.Logging
Imports DigitalData.Modules.Windream
Imports DigitalData.Modules.Language
Imports DigitalData.Modules.Base
Public Class ConnectionBuilder
Implements IConnectionBuilder
Private ReadOnly LogConfig As LogConfig
Private SessionReconnect As Boolean = False
Private DriveLetter As String = "W"
Private BasePath As String = BASE_PATH
Private Support64Bit As Boolean = False
Private ServerName As String = Nothing
Private UserName As String = Nothing
Private Password As String = Nothing
Private Domain As String = Nothing
Private Const BASE_PATH As String = "\\windream\objects"
Public Sub New(LogConfig As LogConfig)
Me.LogConfig = LogConfig
End Sub
'''
''' Sets flag in Windream class to reconnect on lost connection
'''
''' A IConnectionBuilder instance to allow for chaining
Public Function WithSessionReconnect() As IConnectionBuilder Implements IConnectionBuilder.WithSessionReconnect
SessionReconnect = True
Return Me
End Function
'''
''' Sets the drive letter of windream drive, default is "W"
'''
''' The drive letter to use
''' A IConnectionBuilder instance to allow for chaining
Public Function WithDriveLetter(driveLetter As String) As IConnectionBuilder Implements IConnectionBuilder.WithDriveLetter
Me.DriveLetter = driveLetter
BasePath = String.Empty
Return Me
End Function
'''
''' Sets the drive letter to String.Empty, use \\windream\objects as Windream base path
'''
''' The windream base path, eg. \\windream\objects
''' A IConnectionBuilder instance to allow for chaining
Public Function WithWindreamObjects(BasePath As String) As IConnectionBuilder Implements IConnectionBuilder.WithWindreamObjects
BasePath = BasePath
DriveLetter = String.Empty
Return Me
End Function
'''
''' Sets the drive letter to String.Empty, use \\windream\objects as Windream base path
'''
''' A IConnectionBuilder instance to allow for chaining
Public Function WithWindreamObjects() As IConnectionBuilder Implements IConnectionBuilder.WithWindreamObjects
BasePath = BASE_PATH
DriveLetter = String.Empty
Return Me
End Function
Public Function WithWindreamObjectsOrDriveLetter(BasePath As String, DriveLetter As String) As IConnectionBuilder Implements IConnectionBuilder.WithWindreamObjectsOrDriveLetter
If ObjectEx.NotNull(BasePath, Nothing) IsNot Nothing Then
Return WithWindreamObjects(BasePath)
ElseIf ObjectEx.NotNull(DriveLetter, Nothing) IsNot Nothing Then
Return WithDriveLetter(DriveLetter)
Else
Return WithWindreamObjects()
End If
End Function
'''
''' Sets flag in Windream class to indicate 64-bit support
'''
''' A IConnectionBuilder instance to allow for chaining
Public Function With64BitSupport() As IConnectionBuilder Implements IConnectionBuilder.With64BitSupport
Support64Bit = True
Return Me
End Function
'''
''' Sets the servername in Windream class, overriding the client setting
'''
'''
''' A IConnectionBuilder instance to allow for chaining
Public Function WithServerName(serverName As String) As IConnectionBuilder Implements IConnectionBuilder.WithServerName
Me.ServerName = serverName
Return Me
End Function
'''
''' Sets the username, password and domain in Windream class, overriding the client settings
'''
''' The username used for the connection
''' The password used for the connection
''' The domain used for the connection
''' A IConnectionBuilder instance to allow for chaining
Public Function WithImpersonation(userName As String, password As String, domain As String) As IConnectionBuilder Implements IConnectionBuilder.WithImpersonation
Me.UserName = userName
Me.Password = password
Me.Domain = domain
Return Me
End Function
'''
''' Creates a connection.
'''
''' If there was an error while establishing the connection
''' A Windream Object
Public Function Connect() As Windream Implements IConnectionBuilder.Connect
Return New Windream(LogConfig, SessionReconnect, DriveLetter, BasePath, Support64Bit, ServerName, UserName, Password, Domain)
End Function
End Class