jj: client suite
This commit is contained in:
@@ -1,61 +1,68 @@
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports DigitalData.Modules.Logging.LogConfig
|
||||
Imports System.ServiceModel
|
||||
Imports EDMI_ClientSuite.NetworkService_DDEDM
|
||||
Imports System.IO
|
||||
|
||||
|
||||
Public Class ClassInit
|
||||
Private _ChannelFactory As ChannelFactory(Of IEDMServiceChannel)
|
||||
Private _Channel As IEDMServiceChannel
|
||||
Private _Logger As Logger
|
||||
Private _MyLogger As LogConfig
|
||||
Private _LogConfig As LogConfig
|
||||
|
||||
Private CurrentRetry As Integer = 0
|
||||
|
||||
Private Const MAX_RETRIES = 10
|
||||
Private Const OPEN_TIMEOUT = 10
|
||||
|
||||
Public Sub New()
|
||||
Dim oUserAppdata = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Digital Data\EDMI_Client_Suite\Log")
|
||||
|
||||
_MyLogger = New LogConfig(LogConfig.PathType.CustomPath, oUserAppdata)
|
||||
_Logger = _MyLogger.GetLogger()
|
||||
_LogConfig = New LogConfig(PathType.AppData)
|
||||
_Logger = _LogConfig.GetLogger()
|
||||
MyLogger = _Logger
|
||||
MyLogConfig = _MyLogger
|
||||
|
||||
Try
|
||||
Dim binding As New NetTcpBinding()
|
||||
binding.Security.Mode = SecurityMode.Transport
|
||||
binding.Security.Transport.ClientCredentialType = TcpClientCredentialType.Windows
|
||||
binding.MaxReceivedMessageSize = 2147483647
|
||||
binding.MaxBufferSize = 2147483647
|
||||
binding.MaxBufferPoolSize = 2147483647
|
||||
binding.MaxConnections = 10000
|
||||
binding.ReaderQuotas.MaxArrayLength = 2147483647
|
||||
binding.ReaderQuotas.MaxStringContentLength = 2147483647
|
||||
'binding.TransferMode = TransferMode.Streamed
|
||||
|
||||
Dim endpointAddress = New EndpointAddress(My.Settings.EDM_NetworkService_Adress)
|
||||
_ChannelFactory = New ChannelFactory(Of IEDMServiceChannel)(binding, endpointAddress)
|
||||
Connect2NetService()
|
||||
Catch ex As Exception
|
||||
_Logger.Error(ex)
|
||||
End Try
|
||||
MyLogConfig = _LogConfig
|
||||
|
||||
|
||||
_ChannelFactory = ConfigureChannelFactory()
|
||||
_Logger.Debug("Service channelfactory created")
|
||||
|
||||
Connect()
|
||||
End Sub
|
||||
Private Sub Connect2NetService()
|
||||
|
||||
Public Function ConfigureChannelFactory()
|
||||
Dim oBinding As New NetTcpBinding()
|
||||
oBinding.Security.Mode = SecurityMode.Transport
|
||||
oBinding.Security.Transport.ClientCredentialType = TcpClientCredentialType.Windows
|
||||
oBinding.MaxReceivedMessageSize = 2147483647
|
||||
oBinding.MaxBufferSize = 2147483647
|
||||
oBinding.MaxBufferPoolSize = 2147483647
|
||||
oBinding.MaxConnections = 10000
|
||||
oBinding.ReaderQuotas.MaxArrayLength = 2147483647
|
||||
oBinding.ReaderQuotas.MaxStringContentLength = 2147483647
|
||||
'oBinding.OpenTimeout = New TimeSpan(0, 0, OPEN_TIMEOUT)
|
||||
Dim oEndpointAddress = New EndpointAddress(My.Settings.EDM_NetworkService_Adress)
|
||||
|
||||
Return New ChannelFactory(Of IEDMServiceChannel)(oBinding, oEndpointAddress)
|
||||
End Function
|
||||
|
||||
Private Sub Connect()
|
||||
Try
|
||||
_Channel = Nothing
|
||||
_Channel = _ChannelFactory.CreateChannel()
|
||||
_Logger.Info("Successfully connected to EDM_Network Service")
|
||||
_Logger.Debug("Service channel created")
|
||||
_Logger.Debug("Opening service channel")
|
||||
AddHandler _Channel.Faulted, AddressOf Reconnect
|
||||
|
||||
_Channel.Open()
|
||||
_Logger.Debug("Service channel opened")
|
||||
_Logger.Info("Connection to service established!")
|
||||
Catch ex As Exception
|
||||
_Logger.Error(ex)
|
||||
Throw ex
|
||||
End Try
|
||||
|
||||
|
||||
End Sub
|
||||
Private Sub Reconnect()
|
||||
Private Sub Reconnect(sender As Object, e As EventArgs)
|
||||
_Logger.Warn("Could not connect to service. Retrying.")
|
||||
_Channel.Abort()
|
||||
|
||||
Connect2NetService()
|
||||
Connect()
|
||||
End Sub
|
||||
|
||||
End Class
|
||||
|
||||
Reference in New Issue
Block a user