1 | #Region "Microsoft.VisualBasic::aa6e139f0db4826a5ae49e31cb42da81, Microsoft.VisualBasic.Core\Net\Protocol\Reflection\ProtocolInvoker.vb" |
2 | |
3 | ' Author: |
4 | ' |
5 | ' asuka (amethyst.asuka@gcmodeller.org) |
6 | ' xie (genetics@smrucc.org) |
7 | ' xieguigang (xie.guigang@live.com) |
8 | ' |
9 | ' Copyright (c) 2018 GPL3 Licensed |
10 | ' |
11 | ' |
12 | ' GNU GENERAL PUBLIC LICENSE (GPL3) |
13 | ' |
14 | ' |
15 | ' This program is free software: you can redistribute it and/or modify |
16 | ' it under the terms of the GNU General Public License as published by |
17 | ' the Free Software Foundation, either version 3 of the License, or |
18 | ' (at your option) any later version. |
19 | ' |
20 | ' This program is distributed in the hope that it will be useful, |
21 | ' but WITHOUT ANY WARRANTY; without even the implied warranty of |
22 | ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
23 | ' GNU General Public License for more details. |
24 | ' |
25 | ' You should have received a copy of the GNU General Public License |
26 | ' along with this program. If not, see <http://www.gnu.org/licenses/>. |
27 | |
28 | |
29 | |
30 | ' /********************************************************************************/ |
31 | |
32 | ' Summaries: |
33 | |
34 | ' Class ProtocolInvoker |
35 | ' |
36 | ' Constructor: (+1 Overloads) Sub New |
37 | ' Function: InvokeProtocol0, InvokeProtocol1, InvokeProtocol2, ToString |
38 | ' |
39 | ' |
40 | ' /********************************************************************************/ |
41 | |
42 | #End Region |
43 | |
44 | Imports System.Reflection |
45 | Imports Microsoft.VisualBasic.Net.Http |
46 | Imports Microsoft.VisualBasic.Win32 |
47 | |
48 | Namespace Net.Protocols.Reflection |
49 | |
50 | ''' <summary> |
51 | ''' Working in server side |
52 | ''' </summary> |
53 | Friend Class ProtocolInvoker |
54 | |
55 | ReadOnly obj As Object |
56 | ReadOnly method As MethodInfo |
57 | |
58 | Sub New(obj As Object, method As MethodInfo) |
59 | Me.obj = obj |
60 | Me.method = method |
61 | End Sub |
62 | |
63 | Public Function InvokeProtocol0(request As RequestStream, remoteDevice As System.Net.IPEndPoint) As RequestStream |
64 | Dim value = method.Invoke(obj, Nothing) |
65 | Dim data = DirectCast(value, RequestStream) |
66 | Return data |
67 | End Function |
68 | |
69 | Public Function InvokeProtocol1(request As RequestStream, remoteDevice As System.Net.IPEndPoint) As RequestStream |
70 | Dim value = method.Invoke(obj, {request}) |
71 | Dim data = DirectCast(value, RequestStream) |
72 | Return data |
73 | End Function |
74 | |
75 | Public Function InvokeProtocol2(request As RequestStream, remoteDevice As System.Net.IPEndPoint) As RequestStream |
76 | Try |
77 | Dim value = method.Invoke(obj, {request, remoteDevice}) |
78 | Dim data = DirectCast(value, RequestStream) |
79 | |
80 | Return data |
81 | Catch ex As Exception |
82 | ex = New Exception(method.FullName, ex) |
83 | |
84 | If WindowsServices.Initialized Then |
85 | Call ServicesLogs.LogException(ex) |
86 | Else |
87 | Call App.LogException(ex) |
88 | End If |
89 | Return NetResponse.RFC_UNKNOWN_ERROR |
90 | End Try |
91 | End Function |
92 | |
93 | Public Overrides Function ToString() As String |
94 | Return $"{obj.ToString} -> {method.Name}" |
95 | End Function |
96 | End Class |
97 | End Namespace |