From bdb47ad6de7ea100ec9a3f5ab7cb85c798da558b Mon Sep 17 00:00:00 2001 From: Jonathan Jenne Date: Thu, 25 Apr 2019 14:09:24 +0200 Subject: [PATCH] version 0.0.0.2 of EDMIAPI --- EDMI_FILE_OPs/Channel.vb | 3 +- EDMI_FILE_OPs/Document.vb | 119 ++++++++++------------- EDMI_FILE_OPs/My Project/AssemblyInfo.vb | 8 +- GUIs.ClientSuite/_TEST/frmFileTest.vb | 4 +- 4 files changed, 60 insertions(+), 74 deletions(-) diff --git a/EDMI_FILE_OPs/Channel.vb b/EDMI_FILE_OPs/Channel.vb index c18a7311..aa63c9ac 100644 --- a/EDMI_FILE_OPs/Channel.vb +++ b/EDMI_FILE_OPs/Channel.vb @@ -1,4 +1,5 @@ Imports System.ServiceModel +Imports System.Xml Public Class Channel Public Shared Function GetBinding() As NetTcpBinding @@ -13,7 +14,7 @@ Public Class Channel .ClientCredentialType = TcpClientCredentialType.Windows } }, - .ReaderQuotas = New Xml.XmlDictionaryReaderQuotas() With { + .ReaderQuotas = New XmlDictionaryReaderQuotas() With { .MaxArrayLength = Constants.MAX_ARRAY_LENGTH, .MaxStringContentLength = Constants.MAX_STRING_CONTENT_LENGTH } diff --git a/EDMI_FILE_OPs/Document.vb b/EDMI_FILE_OPs/Document.vb index bcb4fcab..c0bb55e4 100644 --- a/EDMI_FILE_OPs/Document.vb +++ b/EDMI_FILE_OPs/Document.vb @@ -8,6 +8,12 @@ Public Class Document Private _logConfig As LogConfig Private _channelFactory As ChannelFactory(Of IEDMServiceChannel) Private _channel As IEDMServiceChannel + + ''' + ''' Creates a new EDMIAPI object + ''' + ''' LogConfig object + ''' The full service url to connect to Public Sub New(LogConfig As LogConfig, ServiceAdress As String) _logger = LogConfig.GetLogger() _logConfig = LogConfig @@ -15,30 +21,32 @@ Public Class Document Try Dim oBinding = Channel.GetBinding() Dim oAddress = New EndpointAddress(ServiceAdress) - _channelFactory = New ChannelFactory(Of IEDMServiceChannel)(oBinding, oAddress) - Connect2NetService() + Dim oFactory = New ChannelFactory(Of IEDMServiceChannel)(oBinding, oAddress) + + _channelFactory = oFactory Catch ex As Exception _logger.Error(ex) End Try End Sub - Private Function Connect2NetService() + ''' + ''' Connect to the service + ''' + ''' True if connection was successful, false otherwise + Public Function Connect() Try - _channel = Nothing - _channel = _channelFactory.CreateChannel() - _logger.Info("Successfully connected to EDM_Network Service") - AddHandler _channel.Faulted, AddressOf Reconnect + _channel = GetChannel() + + _logger.Debug("Opening channel..") _channel.Open() + + _logger.Info("Connection to Service established!") Return True Catch ex As Exception _logger.Error(ex) - Return True + Return False End Try End Function - Private Sub Reconnect() - _channel.Abort() - Connect2NetService() - End Sub ''' ''' Imports a file by filename @@ -120,59 +128,36 @@ Public Class Document End Try End Function - 'Public Async Function New_EDMI_File(oFILENAME As String, oUserName As String) As Task(Of String) - ' Try - ' Dim oFileGUID As DocumentResult = Await CreateDocument(oFILENAME) - ' Dim oFileRecordID = Nothing - ' If Not IsNothing(oFileGUID) Then - ' Dim oSQL = $"SELECT FNEDMI_SET_RECORD(""TBEDMI_ADRESSE"",""{oUserName}"",FALSE,NULL,"""",'{oFileGUID._ContainerId}') FROM rdb$database;" - ' oFileRecordID = Await New_EDMIFile_CreateDB_Record(oSQL) - ' End If - ' Return oFileRecordID - ' Catch ex As Exception - ' _logger.Error(ex) - ' Return Nothing - ' End Try - 'End Function - - 'Private Async Function New_EDMIFile_CreateDB_Record(FBCommand As String) As Task(Of String) - ' Try - ' Dim oTimeTotal As TimeSpan - ' Dim oStopwatch As New Stopwatch() - ' oStopwatch.Start() - ' Dim oRecord_ID As String - ' Dim oRequestName = Await _channel.CreateDatabaseRequestAsync("CreateEDMFileRecord", True) - ' Dim oResult = Await _channel.ReturnScalarAsync(FBCommand) - - ' oTimeTotal = oStopwatch.Elapsed - ' oStopwatch.Reset() - - ' Await _channel.CloseDatabaseRequestAsync() - - ' If Not oResult.OK Then - ' _logger.Warn($"Unexpected error while executing command: {oResult.ErrorMessage}") - ' Else - ' oRecord_ID = oResult.Scalar - ' _logger.Debug($"SCALAR (SERVICE) {FBCommand} - TIME: {(oTimeTotal.ToString)}") - ' End If - ' Return oRecord_ID - ' Catch ex As Exception - ' _logger.Error(ex) - ' Return Nothing - ' End Try - 'End Function - 'Public Async Function Load_EDMIFile_2TempPath(oEDMIFile_GUID As String) As Task(Of String) - 'Try - ' Dim oResult As EDMIServiceReference.ContainerResult = Await _channel.GetFileAsync(oEDMIFile_GUID) - ' Dim oTempPath = Path.Combine(Path.GetTempPath(), "EDMI_FileContainer") - ' Directory.CreateDirectory(oTempPath) - ' Dim oFilePath = Path.Combine(oTempPath, $"{oResult.Container.FileId}.{oResult.Container.Extension}") - ' File.WriteAllBytes(oFilePath, oResult.Container.Contents) - ' ' Process.Start(oTempPath) - ' Return oTempPath - 'Catch ex As Exception - ' _logger.Error(ex) - ' Return Nothing - 'End Try - 'End Function + ''' + ''' Aborts the channel and creates a new connection + ''' + Private Sub Reconnect() + _logger.Warn("Connection faulted. Trying to reconnect..") + + Try + _channel.Abort() + _channel = GetChannel() + _channel.Open() + Catch ex As Exception + _logger.Error(ex) + End Try + End Sub + + ''' + ''' Creates a channel and adds a Faulted-Handler + ''' + ''' A channel object + Private Function GetChannel() As IEDMServiceChannel + Try + _logger.Debug("Creating channel..") + Dim oChannel = _channelFactory.CreateChannel() + + AddHandler oChannel.Faulted, AddressOf Reconnect + + Return oChannel + Catch ex As Exception + _logger.Error(ex) + Throw ex + End Try + End Function End Class diff --git a/EDMI_FILE_OPs/My Project/AssemblyInfo.vb b/EDMI_FILE_OPs/My Project/AssemblyInfo.vb index 24a1da3c..f7b314a3 100644 --- a/EDMI_FILE_OPs/My Project/AssemblyInfo.vb +++ b/EDMI_FILE_OPs/My Project/AssemblyInfo.vb @@ -8,10 +8,10 @@ Imports System.Runtime.InteropServices ' Werte der Assemblyattribute überprüfen - + - - + + @@ -31,5 +31,5 @@ Imports System.Runtime.InteropServices ' übernehmen, indem Sie "*" eingeben: ' - + diff --git a/GUIs.ClientSuite/_TEST/frmFileTest.vb b/GUIs.ClientSuite/_TEST/frmFileTest.vb index 13aaf27c..41c1a49c 100644 --- a/GUIs.ClientSuite/_TEST/frmFileTest.vb +++ b/GUIs.ClientSuite/_TEST/frmFileTest.vb @@ -9,7 +9,7 @@ Public Class frmFileTest Private Sub frmFileTest_Load(sender As Object, e As EventArgs) Handles Me.Load Try _fileOp = New Document(My.LogConfig, My.Settings.EDM_NetworkService_Adress) - + _fileOp.Connect() Catch ex As Exception Logger.Warn($"Unexpected error in frmFileTest_Load: {ex.Message}") End Try @@ -37,7 +37,7 @@ Public Class frmFileTest listboxLog.Items.Add($"Filename: {oResult.Document.FileName}") listboxLog.Items.Add($"----------------------------------------------------------") Catch ex As Exception - MsgBox(ex.Message) + ShowErrorMessage(ex) Logger.Error(ex) End Try End Sub