Modules/EDMI_ClientSuite/ClassInit.vb
Jonathan Jenne 1ae788f52e jj
2019-01-30 14:40:05 +01:00

84 lines
3.4 KiB
VB.net

Imports DigitalData.Modules.Logging
Imports DigitalData.Modules.Logging.LogConfig
Imports System.ServiceModel
Imports EDMI_ClientSuite.NetworkService_DDEDM
Public Class ClassInit
Private Const OPEN_TIMEOUT_SECONDS = 3
Private Const MAX_MESSAGE_SIZE = 2147483647
Private Const MAX_BUFFER_SIZE = 2147483647
Private Const MAX_ARRAY_LENGTH = 2147483647
Private Const MAX_STRING_LENGTH = 2147483647
Private Const MAX_CONNECTIONS = 10000
Public Enum ConnectionTestResult
Successful
NotFound
Unknown
End Enum
Private ReadOnly _Logger As Logger
Public Sub New()
_Logger = My.LogConfig.GetLogger()
End Sub
Public Function TestConnectionURLExists()
Return My.Settings.ICMServiceAddress <> String.Empty
End Function
Public Async Function TestConnectionAsync(EndpointURL As String) As Task(Of ConnectionTestResult)
Return Await Task.Factory.StartNew(Function()
Try
Dim oChannelFactory = GetChannelFactory(EndpointURL)
Dim oChannel = oChannelFactory.CreateChannel()
oChannel.OperationTimeout = New TimeSpan(0, 0, OPEN_TIMEOUT_SECONDS)
oChannel.Open()
oChannel.Close()
Return ConnectionTestResult.Successful
Catch ex As EndpointNotFoundException
_Logger.Error(ex)
Return ConnectionTestResult.NotFound
Catch ex As Exception
_Logger.Error(ex)
Return ConnectionTestResult.Unknown
End Try
End Function)
End Function
Public Function GetChannelFactory() As ChannelFactory(Of IEDMServiceChannel)
Return GetChannelFactory(My.Settings.ICMServiceAddress)
End Function
Public Function GetChannelFactory(EndpointURL As String) As ChannelFactory(Of IEDMServiceChannel)
Dim oBinding = GetBinding()
Dim oEndpoint = GetEndpoint(EndpointURL)
Dim oFactory As New ChannelFactory(Of IEDMServiceChannel)(oBinding, oEndpoint)
Return oFactory
End Function
Private Function GetEndpoint(EndpointURL As String) As EndpointAddress
Dim oEndpoint = New EndpointAddress(EndpointURL)
Return oEndpoint
End Function
Private Function GetBinding() As NetTcpBinding
Dim oBinding As New NetTcpBinding()
oBinding.Security.Mode = SecurityMode.Transport
oBinding.Security.Transport.ClientCredentialType = TcpClientCredentialType.Windows
oBinding.MaxReceivedMessageSize = MAX_MESSAGE_SIZE
oBinding.MaxBufferSize = MAX_BUFFER_SIZE
oBinding.MaxBufferPoolSize = MAX_BUFFER_SIZE
oBinding.MaxConnections = MAX_CONNECTIONS
oBinding.ReaderQuotas.MaxArrayLength = MAX_ARRAY_LENGTH
oBinding.ReaderQuotas.MaxStringContentLength = MAX_STRING_LENGTH
oBinding.OpenTimeout = New TimeSpan(0, 0, OPEN_TIMEOUT_SECONDS)
Return oBinding
End Function
End Class