version 0.0.0.2 of EDMIAPI

This commit is contained in:
Jonathan Jenne 2019-04-25 14:09:24 +02:00
parent 0c7933fb8a
commit bdb47ad6de
4 changed files with 56 additions and 70 deletions

View File

@ -1,4 +1,5 @@
Imports System.ServiceModel Imports System.ServiceModel
Imports System.Xml
Public Class Channel Public Class Channel
Public Shared Function GetBinding() As NetTcpBinding Public Shared Function GetBinding() As NetTcpBinding
@ -13,7 +14,7 @@ Public Class Channel
.ClientCredentialType = TcpClientCredentialType.Windows .ClientCredentialType = TcpClientCredentialType.Windows
} }
}, },
.ReaderQuotas = New Xml.XmlDictionaryReaderQuotas() With { .ReaderQuotas = New XmlDictionaryReaderQuotas() With {
.MaxArrayLength = Constants.MAX_ARRAY_LENGTH, .MaxArrayLength = Constants.MAX_ARRAY_LENGTH,
.MaxStringContentLength = Constants.MAX_STRING_CONTENT_LENGTH .MaxStringContentLength = Constants.MAX_STRING_CONTENT_LENGTH
} }

View File

@ -8,6 +8,12 @@ Public Class Document
Private _logConfig As LogConfig Private _logConfig As LogConfig
Private _channelFactory As ChannelFactory(Of IEDMServiceChannel) Private _channelFactory As ChannelFactory(Of IEDMServiceChannel)
Private _channel As IEDMServiceChannel Private _channel As IEDMServiceChannel
''' <summary>
''' Creates a new EDMIAPI object
''' </summary>
''' <param name="LogConfig">LogConfig object</param>
''' <param name="ServiceAdress">The full service url to connect to</param>
Public Sub New(LogConfig As LogConfig, ServiceAdress As String) Public Sub New(LogConfig As LogConfig, ServiceAdress As String)
_logger = LogConfig.GetLogger() _logger = LogConfig.GetLogger()
_logConfig = LogConfig _logConfig = LogConfig
@ -15,30 +21,32 @@ Public Class Document
Try Try
Dim oBinding = Channel.GetBinding() Dim oBinding = Channel.GetBinding()
Dim oAddress = New EndpointAddress(ServiceAdress) Dim oAddress = New EndpointAddress(ServiceAdress)
_channelFactory = New ChannelFactory(Of IEDMServiceChannel)(oBinding, oAddress) Dim oFactory = New ChannelFactory(Of IEDMServiceChannel)(oBinding, oAddress)
Connect2NetService()
_channelFactory = oFactory
Catch ex As Exception Catch ex As Exception
_logger.Error(ex) _logger.Error(ex)
End Try End Try
End Sub End Sub
Private Function Connect2NetService() ''' <summary>
''' Connect to the service
''' </summary>
''' <returns>True if connection was successful, false otherwise</returns>
Public Function Connect()
Try Try
_channel = Nothing _channel = GetChannel()
_channel = _channelFactory.CreateChannel()
_logger.Info("Successfully connected to EDM_Network Service") _logger.Debug("Opening channel..")
AddHandler _channel.Faulted, AddressOf Reconnect
_channel.Open() _channel.Open()
_logger.Info("Connection to Service established!")
Return True Return True
Catch ex As Exception Catch ex As Exception
_logger.Error(ex) _logger.Error(ex)
Return True Return False
End Try End Try
End Function End Function
Private Sub Reconnect()
_channel.Abort()
Connect2NetService()
End Sub
''' <summary> ''' <summary>
''' Imports a file by filename ''' Imports a file by filename
@ -120,59 +128,36 @@ Public Class Document
End Try End Try
End Function End Function
'Public Async Function New_EDMI_File(oFILENAME As String, oUserName As String) As Task(Of String) ''' <summary>
' Try ''' Aborts the channel and creates a new connection
' Dim oFileGUID As DocumentResult = Await CreateDocument(oFILENAME) ''' </summary>
' Dim oFileRecordID = Nothing Private Sub Reconnect()
' If Not IsNothing(oFileGUID) Then _logger.Warn("Connection faulted. Trying to reconnect..")
' 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
' Try _channel.Abort()
' Dim oTimeTotal As TimeSpan _channel = GetChannel()
' Dim oStopwatch As New Stopwatch() _channel.Open()
' oStopwatch.Start() Catch ex As Exception
' Dim oRecord_ID As String _logger.Error(ex)
' Dim oRequestName = Await _channel.CreateDatabaseRequestAsync("CreateEDMFileRecord", True) End Try
' Dim oResult = Await _channel.ReturnScalarAsync(FBCommand) End Sub
' oTimeTotal = oStopwatch.Elapsed ''' <summary>
' oStopwatch.Reset() ''' Creates a channel and adds a Faulted-Handler
''' </summary>
''' <returns>A channel object</returns>
Private Function GetChannel() As IEDMServiceChannel
Try
_logger.Debug("Creating channel..")
Dim oChannel = _channelFactory.CreateChannel()
' Await _channel.CloseDatabaseRequestAsync() AddHandler oChannel.Faulted, AddressOf Reconnect
' If Not oResult.OK Then Return oChannel
' _logger.Warn($"Unexpected error while executing command: {oResult.ErrorMessage}") Catch ex As Exception
' Else _logger.Error(ex)
' oRecord_ID = oResult.Scalar Throw ex
' _logger.Debug($"SCALAR (SERVICE) {FBCommand} - TIME: {(oTimeTotal.ToString)}") End Try
' End If End Function
' 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
End Class End Class

View File

@ -8,10 +8,10 @@ Imports System.Runtime.InteropServices
' Werte der Assemblyattribute überprüfen ' Werte der Assemblyattribute überprüfen
<Assembly: AssemblyTitle("EDMI_FILE_OPs")> <Assembly: AssemblyTitle("EDMIAPI")>
<Assembly: AssemblyDescription("")> <Assembly: AssemblyDescription("")>
<Assembly: AssemblyCompany("")> <Assembly: AssemblyCompany("Digital Data")>
<Assembly: AssemblyProduct("EDMI_FILE_OPs")> <Assembly: AssemblyProduct("EDMIAPI")>
<Assembly: AssemblyCopyright("Copyright © 2018")> <Assembly: AssemblyCopyright("Copyright © 2018")>
<Assembly: AssemblyTrademark("")> <Assembly: AssemblyTrademark("")>
@ -31,5 +31,5 @@ Imports System.Runtime.InteropServices
' übernehmen, indem Sie "*" eingeben: ' übernehmen, indem Sie "*" eingeben:
' <Assembly: AssemblyVersion("1.0.*")> ' <Assembly: AssemblyVersion("1.0.*")>
<Assembly: AssemblyVersion("1.0.0.0")> <Assembly: AssemblyVersion("0.0.0.2")>
<Assembly: AssemblyFileVersion("1.0.0.0")> <Assembly: AssemblyFileVersion("1.0.0.0")>

View File

@ -9,7 +9,7 @@ Public Class frmFileTest
Private Sub frmFileTest_Load(sender As Object, e As EventArgs) Handles Me.Load Private Sub frmFileTest_Load(sender As Object, e As EventArgs) Handles Me.Load
Try Try
_fileOp = New Document(My.LogConfig, My.Settings.EDM_NetworkService_Adress) _fileOp = New Document(My.LogConfig, My.Settings.EDM_NetworkService_Adress)
_fileOp.Connect()
Catch ex As Exception Catch ex As Exception
Logger.Warn($"Unexpected error in frmFileTest_Load: {ex.Message}") Logger.Warn($"Unexpected error in frmFileTest_Load: {ex.Message}")
End Try End Try
@ -37,7 +37,7 @@ Public Class frmFileTest
listboxLog.Items.Add($"Filename: {oResult.Document.FileName}") listboxLog.Items.Add($"Filename: {oResult.Document.FileName}")
listboxLog.Items.Add($"----------------------------------------------------------") listboxLog.Items.Add($"----------------------------------------------------------")
Catch ex As Exception Catch ex As Exception
MsgBox(ex.Message) ShowErrorMessage(ex)
Logger.Error(ex) Logger.Error(ex)
End Try End Try
End Sub End Sub