microsoft-visualbasic-runtime/Net/Protocol/Reflection/ProtocolInvoker.vb

98 lines
3.2 KiB
VB.net
Raw Normal View History

2019-05-22 19:02:42 +08:00
#Region "Microsoft.VisualBasic::aa6e139f0db4826a5ae49e31cb42da81, Microsoft.VisualBasic.Core\Net\Protocol\Reflection\ProtocolInvoker.vb"
2018-08-02 20:14:48 +08:00
2018-10-06 16:50:20 +08:00
' Author:
'
' asuka (amethyst.asuka@gcmodeller.org)
' xie (genetics@smrucc.org)
' xieguigang (xie.guigang@live.com)
'
' Copyright (c) 2018 GPL3 Licensed
'
'
' GNU GENERAL PUBLIC LICENSE (GPL3)
'
'
' This program is free software: you can redistribute it and/or modify
' it under the terms of the GNU General Public License as published by
' the Free Software Foundation, either version 3 of the License, or
' (at your option) any later version.
'
' This program is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
' GNU General Public License for more details.
'
' You should have received a copy of the GNU General Public License
' along with this program. If not, see <http://www.gnu.org/licenses/>.
2018-10-06 16:50:20 +08:00
' /********************************************************************************/
2018-10-06 16:50:20 +08:00
' Summaries:
2018-10-06 16:50:20 +08:00
' Class ProtocolInvoker
'
' Constructor: (+1 Overloads) Sub New
' Function: InvokeProtocol0, InvokeProtocol1, InvokeProtocol2, ToString
'
'
' /********************************************************************************/
2018-08-02 20:14:48 +08:00
#End Region
Imports System.Reflection
Imports Microsoft.VisualBasic.Net.Http
Imports Microsoft.VisualBasic.Win32
Namespace Net.Protocols.Reflection
2018-10-06 03:14:37 +08:00
''' <summary>
''' Working in server side
''' </summary>
Friend Class ProtocolInvoker
2018-08-02 20:14:48 +08:00
ReadOnly obj As Object
ReadOnly method As MethodInfo
2018-08-02 20:14:48 +08:00
Sub New(obj As Object, method As MethodInfo)
2018-08-02 20:14:48 +08:00
Me.obj = obj
Me.method = method
2018-08-02 20:14:48 +08:00
End Sub
2018-10-05 03:16:38 +08:00
Public Function InvokeProtocol0(request As RequestStream, remoteDevice As System.Net.IPEndPoint) As RequestStream
Dim value = method.Invoke(obj, Nothing)
2018-08-02 20:14:48 +08:00
Dim data = DirectCast(value, RequestStream)
Return data
End Function
2018-10-05 03:16:38 +08:00
Public Function InvokeProtocol1(request As RequestStream, remoteDevice As System.Net.IPEndPoint) As RequestStream
Dim value = method.Invoke(obj, {request})
2018-08-02 20:14:48 +08:00
Dim data = DirectCast(value, RequestStream)
Return data
End Function
Public Function InvokeProtocol2(request As RequestStream, remoteDevice As System.Net.IPEndPoint) As RequestStream
2018-08-02 20:14:48 +08:00
Try
Dim value = method.Invoke(obj, {request, remoteDevice})
2018-08-02 20:14:48 +08:00
Dim data = DirectCast(value, RequestStream)
2018-08-02 20:14:48 +08:00
Return data
Catch ex As Exception
ex = New Exception(method.FullName, ex)
2018-08-02 20:14:48 +08:00
If WindowsServices.Initialized Then
Call ServicesLogs.LogException(ex)
Else
Call App.LogException(ex)
End If
Return NetResponse.RFC_UNKNOWN_ERROR
End Try
End Function
Public Overrides Function ToString() As String
Return $"{obj.ToString} -> {method.Name}"
2018-08-02 20:14:48 +08:00
End Function
End Class
End Namespace