version 0.0.0.2 of EDMIAPI
This commit is contained in:
parent
0c7933fb8a
commit
bdb47ad6de
@ -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
|
||||
}
|
||||
|
||||
@ -8,6 +8,12 @@ Public Class Document
|
||||
Private _logConfig As LogConfig
|
||||
Private _channelFactory As ChannelFactory(Of 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)
|
||||
_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()
|
||||
''' <summary>
|
||||
''' Connect to the service
|
||||
''' </summary>
|
||||
''' <returns>True if connection was successful, false otherwise</returns>
|
||||
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
|
||||
|
||||
''' <summary>
|
||||
''' 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
|
||||
''' <summary>
|
||||
''' Aborts the channel and creates a new connection
|
||||
''' </summary>
|
||||
Private Sub Reconnect()
|
||||
_logger.Warn("Connection faulted. Trying to reconnect..")
|
||||
|
||||
'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)
|
||||
Try
|
||||
_channel.Abort()
|
||||
_channel = GetChannel()
|
||||
_channel.Open()
|
||||
Catch ex As Exception
|
||||
_logger.Error(ex)
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
' oTimeTotal = oStopwatch.Elapsed
|
||||
' oStopwatch.Reset()
|
||||
''' <summary>
|
||||
''' 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
|
||||
' _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
|
||||
Return oChannel
|
||||
Catch ex As Exception
|
||||
_logger.Error(ex)
|
||||
Throw ex
|
||||
End Try
|
||||
End Function
|
||||
End Class
|
||||
|
||||
@ -8,10 +8,10 @@ Imports System.Runtime.InteropServices
|
||||
|
||||
' Werte der Assemblyattribute überprüfen
|
||||
|
||||
<Assembly: AssemblyTitle("EDMI_FILE_OPs")>
|
||||
<Assembly: AssemblyTitle("EDMIAPI")>
|
||||
<Assembly: AssemblyDescription("")>
|
||||
<Assembly: AssemblyCompany("")>
|
||||
<Assembly: AssemblyProduct("EDMI_FILE_OPs")>
|
||||
<Assembly: AssemblyCompany("Digital Data")>
|
||||
<Assembly: AssemblyProduct("EDMIAPI")>
|
||||
<Assembly: AssemblyCopyright("Copyright © 2018")>
|
||||
<Assembly: AssemblyTrademark("")>
|
||||
|
||||
@ -31,5 +31,5 @@ Imports System.Runtime.InteropServices
|
||||
' übernehmen, indem Sie "*" eingeben:
|
||||
' <Assembly: AssemblyVersion("1.0.*")>
|
||||
|
||||
<Assembly: AssemblyVersion("1.0.0.0")>
|
||||
<Assembly: AssemblyVersion("0.0.0.2")>
|
||||
<Assembly: AssemblyFileVersion("1.0.0.0")>
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user