Zooflow: Implement Single file Search Results, Rework client wrt Address parsing

This commit is contained in:
Jonathan Jenne
2022-04-13 15:39:01 +02:00
parent 7716a04452
commit 160040535d
23 changed files with 346 additions and 234 deletions

View File

@@ -1,24 +1,21 @@
Imports System.ServiceModel
Imports System.Xml
Imports DigitalData.Modules.Base
Imports DigitalData.Modules.EDMI.API.EDMIServiceReference
Imports DigitalData.Modules.Logging
Public Class Channel
' Infos about MaxBufferSize and MaxBufferPoolSize
' https://social.msdn.microsoft.com/Forums/vstudio/en-US/d6e234d3-942f-4e9d-8470-32618d3f3212/maxbufferpoolsize-vs-maxbuffersize?forum=wcf
Inherits BaseClass
Public Const MAX_RECEIVED_MESSAGE_SIZE = 2147483647 ' 1GB
Public Const MAX_BUFFER_SIZE = 104857600 ' 100MB
Public Const MAX_BUFFER_POOL_SIZE = 1048576 ' 1MB
Private ReadOnly ChannelFactory As ChannelFactory(Of IEDMIServiceChannel)
Public Const MAX_CONNECTIONS = 500
Public Const MAX_ARRAY_LENGTH = 2147483647
Public Const MAX_STRING_CONTENT_LENGTH = 2147483647
Public Event Reconnect As EventHandler
Public Shared Function GetBinding(Optional AuthenticationMode As TcpClientCredentialType = TcpClientCredentialType.Windows) As NetTcpBinding
Return New NetTcpBinding() With {
.MaxReceivedMessageSize = MAX_RECEIVED_MESSAGE_SIZE,
.MaxBufferSize = MAX_BUFFER_SIZE,
.MaxBufferPoolSize = MAX_BUFFER_POOL_SIZE,
.MaxReceivedMessageSize = Constants.ChannelSettings.MAX_RECEIVED_MESSAGE_SIZE,
.MaxBufferSize = Constants.ChannelSettings.MAX_BUFFER_SIZE,
.MaxBufferPoolSize = Constants.ChannelSettings.MAX_BUFFER_POOL_SIZE,
.TransferMode = TransferMode.Streamed,
.Security = New NetTcpSecurity() With {
.Mode = SecurityMode.Transport,
@@ -27,11 +24,41 @@ Public Class Channel
}
},
.ReaderQuotas = New XmlDictionaryReaderQuotas() With {
.MaxArrayLength = MAX_ARRAY_LENGTH,
.MaxStringContentLength = MAX_STRING_CONTENT_LENGTH
.MaxArrayLength = Constants.ChannelSettings.MAX_ARRAY_LENGTH,
.MaxStringContentLength = Constants.ChannelSettings.MAX_STRING_CONTENT_LENGTH
}
}
End Function
Public Sub New(pLogConfig As LogConfig, pServerAddress As ServerAddressStruct)
MyBase.New(pLogConfig)
ChannelFactory = GetChannelFactory(pServerAddress)
End Sub
''' <summary>
''' Creates a channel and adds a Faulted-Handler
''' </summary>
''' <returns>A channel object</returns>
Public Function GetChannel() As IEDMIServiceChannel
Try
Logger.Debug("Creating channel.")
Dim oChannel = ChannelFactory.CreateChannel()
AddHandler oChannel.Faulted, Sub() RaiseEvent Reconnect(Me, Nothing)
Return oChannel
Catch ex As Exception
Logger.Error(ex)
Throw ex
End Try
End Function
Private Function GetChannelFactory(pServerAddress As ServerAddressStruct) As ChannelFactory(Of IEDMIServiceChannel)
Dim oBinding = GetBinding()
Dim oAddress = New EndpointAddress($"net.tcp://{pServerAddress.Host}:{pServerAddress.Port}/DigitalData/Services/Main")
Dim oFactory = New ChannelFactory(Of IEDMIServiceChannel)(oBinding, oAddress)
Return oFactory
End Function
End Class

View File

@@ -0,0 +1,31 @@
Imports DigitalData.Modules.Base
Imports DigitalData.Modules.Logging
Public Class Connection
Public Function ParseServiceAddress(pHost As String, pPort As Integer) As ServerAddressStruct
Dim oAddress As ServerAddressStruct
oAddress.Host = pHost
oAddress.Port = pPort
Return oAddress
End Function
Public Function ParseServiceAddress(pAddress As String) As ServerAddressStruct
Dim oAddressList As List(Of String)
Dim oAddress As ServerAddressStruct
If pAddress.Contains(";"c) Then
oAddressList = pAddress.Split(";"c).ToList
ElseIf pAddress.Contains(":"c) Then
oAddressList = pAddress.Split(":"c).ToList
Else
oAddressList = New List(Of String) From {pAddress, Constants.DEFAULT_SERVICE_PORT}
End If
oAddress.Host = oAddressList.First()
oAddress.Port = oAddressList.Item(1)
Return oAddress
End Function
End Class

View File

@@ -0,0 +1,4 @@
Public Structure ServerAddressStruct
Public Host As String
Public Port As Integer
End Structure