rename class init to class service

This commit is contained in:
Jonathan Jenne 2019-02-14 15:54:02 +01:00
parent 191b3010bb
commit a2f4c06492
5 changed files with 30 additions and 45 deletions

View File

@ -4,6 +4,7 @@
Public Const SERVICE_MAX_ARRAY_LENGTH = 2147483647
Public Const SERVICE_MAX_STRING_LENGTH = 2147483647
Public Const SERVICE_MAX_CONNECTIONS = 10000
Public Const SERVICE_OPEN_TIMEOUT = 3
Public Const FOLDER_NAME_LAYOUT = "Layout"
End Class

View File

@ -1,11 +1,11 @@
Imports DigitalData.Modules.Logging
Imports DigitalData.Modules.Config
Imports System.ServiceModel
Imports EDMI_ClientSuite.NetworkService_DDEDM
Imports System.ServiceModel
Imports System.ServiceModel.Channels
Imports DigitalData.Modules.Logging
Imports EDMI_ClientSuite.NetworkService_DDEDM
Public Class ClassInit
Private Const OPEN_TIMEOUT_SECONDS = 3
Public Class ClassService
Private ReadOnly _LogConfig As LogConfig
Private ReadOnly _Logger As Logger
Public Enum ConnectionTestResult
Successful
@ -13,23 +13,17 @@ Public Class ClassInit
Unknown
End Enum
Private ReadOnly _Logger As Logger
Public Sub New()
_Logger = My.LogConfig.GetLogger()
Public Sub New(LogConfig As LogConfig)
_LogConfig = LogConfig
_Logger = _LogConfig.GetLogger()
End Sub
Public Function TestConnectionURLExists() As Boolean
Return My.ConfigManager.Config.ServiceConnection <> String.Empty
'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.OperationTimeout = New TimeSpan(0, 0, ClassConstants.SERVICE_OPEN_TIMEOUT)
oChannel.Open()
oChannel.Close()
@ -45,24 +39,17 @@ Public Class ClassInit
End Function
Public Function GetChannelFactory() As IChannelFactory(Of IEDMServiceChannel)
'Return GetChannelFactory(My.Settings.ICMServiceAddress)
Return GetChannelFactory(My.ConfigManager.Config.ServiceConnection)
Return GetChannelFactory(My.Config.ServiceConnection)
End Function
Public Function GetChannelFactory(EndpointURL As String) As ChannelFactory(Of IEDMServiceChannel)
Dim oBinding = GetBinding()
Dim oEndpoint = GetEndpoint(EndpointURL)
Dim oEndpoint = New EndpointAddress(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
@ -73,7 +60,7 @@ Public Class ClassInit
oBinding.MaxConnections = ClassConstants.SERVICE_MAX_CONNECTIONS
oBinding.ReaderQuotas.MaxArrayLength = ClassConstants.SERVICE_MAX_ARRAY_LENGTH
oBinding.ReaderQuotas.MaxStringContentLength = ClassConstants.SERVICE_MAX_STRING_LENGTH
oBinding.OpenTimeout = New TimeSpan(0, 0, OPEN_TIMEOUT_SECONDS)
oBinding.OpenTimeout = New TimeSpan(0, 0, ClassConstants.SERVICE_OPEN_TIMEOUT)
Return oBinding
End Function

View File

@ -117,8 +117,8 @@
<Compile Include="ApplicationEvents.vb" />
<Compile Include="ClassConfig.vb" />
<Compile Include="ClassConstants.vb" />
<Compile Include="ClassInit.vb" />
<Compile Include="ClassLayout.vb" />
<Compile Include="ClassService.vb" />
<Compile Include="ClassUtils.vb" />
<Compile Include="Connected Services\NetworkService_DDEDM\Reference.vb">
<AutoGen>True</AutoGen>

View File

@ -1,10 +1,8 @@
Imports EDMI_ClientSuite.ClassInit
Public Class frmConfigService
Private _Init As ClassInit
Public Class frmConfigService
Private _Service As ClassService
Private Sub frmServiceConfig_Load(sender As Object, e As EventArgs) Handles Me.Load
_Init = New ClassInit()
_Service = New ClassService(My.LogConfig)
If My.ConfigManager.Config.ServiceConnection <> String.Empty Then
txtIPAddress.Text = My.ConfigManager.Config.ServiceIP
@ -18,22 +16,20 @@ Public Class frmConfigService
Dim oIPAddress = txtIPAddress.Text
Dim oPort = txtPort.Text
Dim oEndpointURL = $"net.tcp://{oIPAddress}:{oPort}/DigitalData/Services/Main"
Dim oResult As ConnectionTestResult
Dim oResult As ClassService.ConnectionTestResult
My.Config.ServiceIP = oIPAddress
My.Config.ServicePort = Integer.Parse(oPort)
lblStatus.Text = "Verbindung wird hergestellt..."
oResult = Await _Init.TestConnectionAsync(My.ConfigManager.Config.ServiceConnection)
oResult = Await _Service.TestConnectionAsync(My.ConfigManager.Config.ServiceConnection)
If oResult = ConnectionTestResult.Successful Then
' Save Endpoint URL
If oResult = ClassService.ConnectionTestResult.Successful Then
My.ConfigManager.Save()
'My.Settings.ICMServiceAddress = oEndpointURL
lblStatus.Text = "Verbindung hergestellt."
Else
Select Case oResult
Case ConnectionTestResult.NotFound
Case ClassService.ConnectionTestResult.NotFound
lblStatus.Text = "Dienst konnte nicht gefunden werden. Bitte überprüfen sie Addresse und Port."
Case Else
lblStatus.Text = "Unbekannter Fehler."

View File

@ -25,14 +25,17 @@ Public NotInheritable Class frmSplash
BringToFront()
Dim oInit As New ClassInit()
Dim oConnectionURLExists = oInit.TestConnectionURLExists()
Dim oService As New ClassService(My.LogConfig)
Dim oConnectionURLExists As Boolean = My.Config.ServiceConnection <> String.Empty
'Dim oInit As New ClassInit()
'Dim oConnectionURLExists = oInit.TestConnectionURLExists()
If Not oConnectionURLExists Then
Dim oResult = frmConfigService.ShowDialog()
If oResult = DialogResult.Cancel Then
MsgBox("Es wurde keine Dienst Verbindungsurl hinterlegt. Die Anwendung wird beendet.")
MsgBox("Es wurde keine Dienst-Verbindungsurl hinterlegt. Die Anwendung wird beendet.")
Application.Exit()
Else
StartWorker()
@ -57,17 +60,15 @@ Public NotInheritable Class frmSplash
End Sub
Private Sub bw_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs)
Dim oInit As New ClassInit()
Dim oService As New ClassService(My.LogConfig)
'------------------
_Worker.ReportProgress(SetProgress(1), "Connecting to service..")
Dim oChannelFactory As ChannelFactory(Of IEDMServiceChannel)
Dim oChannel As IEDMServiceChannel
Dim oConnectionSuccessful = False
oChannelFactory = oInit.GetChannelFactory()
oChannelFactory = oService.GetChannelFactory()
oChannel = oChannelFactory.CreateChannel()
Thread.Sleep(SLEEP_TIME)