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_ARRAY_LENGTH = 2147483647
Public Const SERVICE_MAX_STRING_LENGTH = 2147483647 Public Const SERVICE_MAX_STRING_LENGTH = 2147483647
Public Const SERVICE_MAX_CONNECTIONS = 10000 Public Const SERVICE_MAX_CONNECTIONS = 10000
Public Const SERVICE_OPEN_TIMEOUT = 3
Public Const FOLDER_NAME_LAYOUT = "Layout" Public Const FOLDER_NAME_LAYOUT = "Layout"
End Class End Class

View File

@ -1,11 +1,11 @@
Imports DigitalData.Modules.Logging Imports System.ServiceModel
Imports DigitalData.Modules.Config
Imports System.ServiceModel
Imports EDMI_ClientSuite.NetworkService_DDEDM
Imports System.ServiceModel.Channels Imports System.ServiceModel.Channels
Imports DigitalData.Modules.Logging
Imports EDMI_ClientSuite.NetworkService_DDEDM
Public Class ClassInit Public Class ClassService
Private Const OPEN_TIMEOUT_SECONDS = 3 Private ReadOnly _LogConfig As LogConfig
Private ReadOnly _Logger As Logger
Public Enum ConnectionTestResult Public Enum ConnectionTestResult
Successful Successful
@ -13,23 +13,17 @@ Public Class ClassInit
Unknown Unknown
End Enum End Enum
Private ReadOnly _Logger As Logger Public Sub New(LogConfig As LogConfig)
_LogConfig = LogConfig
Public Sub New() _Logger = _LogConfig.GetLogger()
_Logger = My.LogConfig.GetLogger()
End Sub 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) Public Async Function TestConnectionAsync(EndpointURL As String) As Task(Of ConnectionTestResult)
Return Await Task.Factory.StartNew(Function() Return Await Task.Factory.StartNew(Function()
Try Try
Dim oChannelFactory = GetChannelFactory(EndpointURL) Dim oChannelFactory = GetChannelFactory(EndpointURL)
Dim oChannel = oChannelFactory.CreateChannel() 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.Open()
oChannel.Close() oChannel.Close()
@ -45,24 +39,17 @@ Public Class ClassInit
End Function End Function
Public Function GetChannelFactory() As IChannelFactory(Of IEDMServiceChannel) Public Function GetChannelFactory() As IChannelFactory(Of IEDMServiceChannel)
'Return GetChannelFactory(My.Settings.ICMServiceAddress) Return GetChannelFactory(My.Config.ServiceConnection)
Return GetChannelFactory(My.ConfigManager.Config.ServiceConnection)
End Function End Function
Public Function GetChannelFactory(EndpointURL As String) As ChannelFactory(Of IEDMServiceChannel) Public Function GetChannelFactory(EndpointURL As String) As ChannelFactory(Of IEDMServiceChannel)
Dim oBinding = GetBinding() Dim oBinding = GetBinding()
Dim oEndpoint = GetEndpoint(EndpointURL) Dim oEndpoint = New EndpointAddress(EndpointURL)
Dim oFactory As New ChannelFactory(Of IEDMServiceChannel)(oBinding, oEndpoint) Dim oFactory As New ChannelFactory(Of IEDMServiceChannel)(oBinding, oEndpoint)
Return oFactory Return oFactory
End Function End Function
Private Function GetEndpoint(EndpointURL As String) As EndpointAddress
Dim oEndpoint = New EndpointAddress(EndpointURL)
Return oEndpoint
End Function
Private Function GetBinding() As NetTcpBinding Private Function GetBinding() As NetTcpBinding
Dim oBinding As New NetTcpBinding() Dim oBinding As New NetTcpBinding()
oBinding.Security.Mode = SecurityMode.Transport oBinding.Security.Mode = SecurityMode.Transport
@ -73,7 +60,7 @@ Public Class ClassInit
oBinding.MaxConnections = ClassConstants.SERVICE_MAX_CONNECTIONS oBinding.MaxConnections = ClassConstants.SERVICE_MAX_CONNECTIONS
oBinding.ReaderQuotas.MaxArrayLength = ClassConstants.SERVICE_MAX_ARRAY_LENGTH oBinding.ReaderQuotas.MaxArrayLength = ClassConstants.SERVICE_MAX_ARRAY_LENGTH
oBinding.ReaderQuotas.MaxStringContentLength = ClassConstants.SERVICE_MAX_STRING_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 Return oBinding
End Function End Function

View File

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

View File

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

View File

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