@@ -37,21 +37,120 @@ public HubConnection(HttpConnectionOptions options)
37
37
public Task StartAsync ( ) => JSRuntime . Current . InvokeAsync < object > ( START_CONNECTION_METHOD , this . InternalConnectionId ) ;
38
38
public Task StopAsync ( ) => JSRuntime . Current . InvokeAsync < object > ( STOP_CONNECTION_METHOD , this . InternalConnectionId ) ;
39
39
40
- public IDisposable On < TResult > ( string methodName , Func < TResult , Task > handler )
40
+ public IDisposable On < TResult1 > ( string methodName , Func < TResult1 , Task > handler )
41
+ => On < TResult1 , object , object , object , object , object , object , object , object , object > ( methodName ,
42
+ ( t1 , t2 , t3 , t4 , t5 , t6 , t7 , t8 , t9 , t10 ) => handler ( t1 ) ) ;
43
+
44
+ public IDisposable On < TResult1 , TResult2 > ( string methodName , Func < TResult1 , TResult2 , Task > handler )
45
+ => On < TResult1 , TResult2 , object , object , object , object , object , object , object , object > ( methodName ,
46
+ ( t1 , t2 , t3 , t4 , t5 , t6 , t7 , t8 , t9 , t10 ) => handler ( t1 , t2 ) ) ;
47
+
48
+ public IDisposable On < TResult1 , TResult2 , TResult3 > ( string methodName , Func < TResult1 , TResult2 , TResult3 , Task > handler )
49
+ => On < TResult1 , TResult2 , TResult3 , object , object , object , object , object , object , object > ( methodName ,
50
+ ( t1 , t2 , t3 , t4 , t5 , t6 , t7 , t8 , t9 , t10 ) => handler ( t1 , t2 , t3 ) ) ;
51
+
52
+ public IDisposable On < TResult1 , TResult2 , TResult3 , TResult4 > ( string methodName , Func < TResult1 , TResult2 , TResult3 , TResult4 , Task > handler )
53
+ => On < TResult1 , TResult2 , TResult3 , TResult4 , object , object , object , object , object , object > ( methodName ,
54
+ ( t1 , t2 , t3 , t4 , t5 , t6 , t7 , t8 , t9 , t10 ) => handler ( t1 , t2 , t3 , t4 ) ) ;
55
+
56
+ public IDisposable On < TResult1 , TResult2 , TResult3 , TResult4 , TResult5 > ( string methodName , Func < TResult1 , TResult2 , TResult3 , TResult4 , TResult5 , Task > handler )
57
+ => On < TResult1 , TResult2 , TResult3 , TResult4 , TResult5 , object , object , object , object , object > ( methodName ,
58
+ ( t1 , t2 , t3 , t4 , t5 , t6 , t7 , t8 , t9 , t10 ) => handler ( t1 , t2 , t3 , t4 , t5 ) ) ;
59
+
60
+ public IDisposable On < TResult1 , TResult2 , TResult3 , TResult4 , TResult5 , TResult6 > ( string methodName ,
61
+ Func < TResult1 , TResult2 , TResult3 , TResult4 , TResult5 , TResult6 , Task > handler )
62
+ => On < TResult1 , TResult2 , TResult3 , TResult4 , TResult5 , TResult6 , object , object , object , object > ( methodName ,
63
+ ( t1 , t2 , t3 , t4 , t5 , t6 , t7 , t8 , t9 , t10 ) => handler ( t1 , t2 , t3 , t4 , t5 , t6 ) ) ;
64
+
65
+ public IDisposable On < TResult1 , TResult2 , TResult3 , TResult4 , TResult5 , TResult6 , TResult7 > ( string methodName ,
66
+ Func < TResult1 , TResult2 , TResult3 , TResult4 , TResult5 , TResult6 , TResult7 , Task > handler )
67
+ => On < TResult1 , TResult2 , TResult3 , TResult4 , TResult5 , TResult6 , TResult7 , object , object , object > ( methodName ,
68
+ ( t1 , t2 , t3 , t4 , t5 , t6 , t7 , t8 , t9 , t10 ) => handler ( t1 , t2 , t3 , t4 , t5 , t6 , t7 ) ) ;
69
+
70
+ public IDisposable On < TResult1 , TResult2 , TResult3 , TResult4 , TResult5 , TResult6 , TResult7 , TResult8 > ( string methodName ,
71
+ Func < TResult1 , TResult2 , TResult3 , TResult4 , TResult5 , TResult6 , TResult7 , TResult8 , Task > handler )
72
+ => On < TResult1 , TResult2 , TResult3 , TResult4 , TResult5 , TResult6 , TResult7 , TResult8 , object , object > ( methodName ,
73
+ ( t1 , t2 , t3 , t4 , t5 , t6 , t7 , t8 , t9 , t10 ) => handler ( t1 , t2 , t3 , t4 , t5 , t6 , t7 , t8 ) ) ;
74
+
75
+ public IDisposable On < TResult1 , TResult2 , TResult3 , TResult4 , TResult5 , TResult6 , TResult7 , TResult8 , TResult9 > ( string methodName ,
76
+ Func < TResult1 , TResult2 , TResult3 , TResult4 , TResult5 , TResult6 , TResult7 , TResult8 , TResult9 , Task > handler )
77
+ => On < TResult1 , TResult2 , TResult3 , TResult4 , TResult5 , TResult6 , TResult7 , TResult8 , TResult9 , object > ( methodName ,
78
+ ( t1 , t2 , t3 , t4 , t5 , t6 , t7 , t8 , t9 , t10 ) => handler ( t1 , t2 , t3 , t4 , t5 , t6 , t7 , t8 , t9 ) ) ;
79
+
80
+ public IDisposable On < TResult1 , TResult2 , TResult3 , TResult4 , TResult5 , TResult6 , TResult7 , TResult8 , TResult9 , TResult10 > ( string methodName ,
81
+ Func < TResult1 , TResult2 , TResult3 , TResult4 , TResult5 , TResult6 , TResult7 , TResult8 , TResult9 , TResult10 , Task > handler )
41
82
{
42
83
if ( string . IsNullOrEmpty ( methodName ) ) throw new ArgumentNullException ( nameof ( methodName ) ) ;
43
84
if ( handler == null ) throw new ArgumentNullException ( nameof ( handler ) ) ;
44
85
45
86
var callbackId = Guid . NewGuid ( ) . ToString ( ) ;
46
87
47
88
var callback = new HubMethodCallback ( callbackId , methodName , this ,
48
- ( json ) =>
89
+ ( payloads ) =>
49
90
{
50
- var payload = Json . Deserialize < TResult > ( json ) ;
51
- return handler ( payload ) ;
91
+ TResult1 t1 = default ;
92
+ TResult2 t2 = default ;
93
+ TResult3 t3 = default ;
94
+ TResult4 t4 = default ;
95
+ TResult5 t5 = default ;
96
+ TResult6 t6 = default ;
97
+ TResult7 t7 = default ;
98
+ TResult8 t8 = default ;
99
+ TResult9 t9 = default ;
100
+ TResult10 t10 = default ;
101
+
102
+ if ( payloads . Length > 0 )
103
+ {
104
+ t1 = Json . Deserialize < TResult1 > ( payloads [ 0 ] ) ;
105
+ }
106
+ if ( payloads . Length > 1 )
107
+ {
108
+ t2 = Json . Deserialize < TResult2 > ( payloads [ 1 ] ) ;
109
+ }
110
+ if ( payloads . Length > 2 )
111
+ {
112
+ t3 = Json . Deserialize < TResult3 > ( payloads [ 2 ] ) ;
113
+ }
114
+ if ( payloads . Length > 3 )
115
+ {
116
+ t4 = Json . Deserialize < TResult4 > ( payloads [ 3 ] ) ;
117
+ }
118
+ if ( payloads . Length > 4 )
119
+ {
120
+ t5 = Json . Deserialize < TResult5 > ( payloads [ 4 ] ) ;
121
+ }
122
+ if ( payloads . Length > 5 )
123
+ {
124
+ t6 = Json . Deserialize < TResult6 > ( payloads [ 5 ] ) ;
125
+ }
126
+ if ( payloads . Length > 6 )
127
+ {
128
+ t7 = Json . Deserialize < TResult7 > ( payloads [ 6 ] ) ;
129
+ }
130
+ if ( payloads . Length > 7 )
131
+ {
132
+ t8 = Json . Deserialize < TResult8 > ( payloads [ 7 ] ) ;
133
+ }
134
+ if ( payloads . Length > 8 )
135
+ {
136
+ t9 = Json . Deserialize < TResult9 > ( payloads [ 8 ] ) ;
137
+ }
138
+ if ( payloads . Length > 9 )
139
+ {
140
+ t10 = Json . Deserialize < TResult10 > ( payloads [ 9 ] ) ;
141
+ }
142
+
143
+ return handler ( t1 , t2 , t3 , t4 , t5 , t6 , t7 , t8 , t9 , t10 ) ;
52
144
}
53
145
) ;
54
146
147
+ RegisterHandle ( methodName , callback ) ;
148
+
149
+ return callback ;
150
+ }
151
+
152
+ internal void RegisterHandle ( string methodName , HubMethodCallback callback )
153
+ {
55
154
if ( this . _callbacks . TryGetValue ( methodName , out var methodHandlers ) )
56
155
{
57
156
methodHandlers [ callback . Id ] = callback ;
@@ -65,9 +164,6 @@ public IDisposable On<TResult>(string methodName, Func<TResult, Task> handler)
65
164
}
66
165
67
166
( ( IJSInProcessRuntime ) JSRuntime . Current ) . Invoke < object > ( ON_METHOD , this . InternalConnectionId , new DotNetObjectRef ( callback ) ) ;
68
-
69
- //HubConnectionManager.On(this.InternalConnectionId, callback);
70
- return callback ;
71
167
}
72
168
73
169
internal void RemoveHandle ( string methodName , string callbackId )
@@ -76,7 +172,7 @@ internal void RemoveHandle(string methodName, string callbackId)
76
172
{
77
173
if ( callbacks . TryGetValue ( callbackId , out var callback ) )
78
174
{
79
- ( ( IJSInProcessRuntime ) JSRuntime . Current ) . Invoke < object > ( OFF_METHOD , this . InternalConnectionId , new DotNetObjectRef ( callback ) ) ;
175
+ ( ( IJSInProcessRuntime ) JSRuntime . Current ) . Invoke < object > ( OFF_METHOD , this . InternalConnectionId , methodName , callbackId ) ;
80
176
//HubConnectionManager.Off(this.InternalConnectionId, handle.Item1);
81
177
callbacks . Remove ( callbackId ) ;
82
178
@@ -88,12 +184,13 @@ internal void RemoveHandle(string methodName, string callbackId)
88
184
}
89
185
}
90
186
91
- public void OnClose ( Func < Exception , Task > callback ) {
187
+ public void OnClose ( Func < Exception , Task > callback )
188
+ {
92
189
this . _closeCallback = new HubCloseCallback ( callback ) ;
93
190
( ( IJSInProcessRuntime ) JSRuntime . Current ) . Invoke < object > ( ON_CLOSE_METHOD ,
94
191
this . InternalConnectionId ,
95
192
new DotNetObjectRef ( this . _closeCallback ) ) ;
96
- }
193
+ }
97
194
98
195
public Task InvokeAsync ( string methodName , params object [ ] args ) =>
99
196
JSRuntime . Current . InvokeAsync < object > ( INVOKE_ASYNC_METHOD , this . InternalConnectionId , methodName , args ) ;
0 commit comments