From a2f4c064921047995bb7ab2e0dc32b27125dfd51 Mon Sep 17 00:00:00 2001 From: Jonathan Jenne Date: Thu, 14 Feb 2019 15:54:02 +0100 Subject: [PATCH] rename class init to class service --- EDMI_ClientSuite/ClassConstants.vb | 1 + .../{ClassInit.vb => ClassService.vb} | 39 +++++++------------ EDMI_ClientSuite/EDMI_ClientSuite.vbproj | 2 +- EDMI_ClientSuite/frmConfigService.vb | 18 ++++----- EDMI_ClientSuite/frmSplash.vb | 15 +++---- 5 files changed, 30 insertions(+), 45 deletions(-) rename EDMI_ClientSuite/{ClassInit.vb => ClassService.vb} (75%) diff --git a/EDMI_ClientSuite/ClassConstants.vb b/EDMI_ClientSuite/ClassConstants.vb index 1f4d0d34..df542a90 100644 --- a/EDMI_ClientSuite/ClassConstants.vb +++ b/EDMI_ClientSuite/ClassConstants.vb @@ -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 diff --git a/EDMI_ClientSuite/ClassInit.vb b/EDMI_ClientSuite/ClassService.vb similarity index 75% rename from EDMI_ClientSuite/ClassInit.vb rename to EDMI_ClientSuite/ClassService.vb index bec7cdc4..a3c002c6 100644 --- a/EDMI_ClientSuite/ClassInit.vb +++ b/EDMI_ClientSuite/ClassService.vb @@ -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 diff --git a/EDMI_ClientSuite/EDMI_ClientSuite.vbproj b/EDMI_ClientSuite/EDMI_ClientSuite.vbproj index 342ea652..8f5b80da 100644 --- a/EDMI_ClientSuite/EDMI_ClientSuite.vbproj +++ b/EDMI_ClientSuite/EDMI_ClientSuite.vbproj @@ -117,8 +117,8 @@ - + True diff --git a/EDMI_ClientSuite/frmConfigService.vb b/EDMI_ClientSuite/frmConfigService.vb index 9e9ef5a2..d0a60491 100644 --- a/EDMI_ClientSuite/frmConfigService.vb +++ b/EDMI_ClientSuite/frmConfigService.vb @@ -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." diff --git a/EDMI_ClientSuite/frmSplash.vb b/EDMI_ClientSuite/frmSplash.vb index baeee23b..4a4a0e5b 100644 --- a/EDMI_ClientSuite/frmSplash.vb +++ b/EDMI_ClientSuite/frmSplash.vb @@ -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)