@@ -29,15 +29,15 @@ protected enum SocketEventNameTypes
2929 CamelCase ,
3030 }
3131
32- private const int PropertyTimeout = 1000 ;
32+ private const int InvocationTimeout = 1000 ;
3333
3434 private readonly string objectName ;
35- private readonly ConcurrentDictionary < string , PropertyGetter > propertyGetters ;
36- private readonly ConcurrentDictionary < string , string > propertyEventNames = new ( ) ;
37- private readonly ConcurrentDictionary < string , string > propertyMessageNames = new ( ) ;
35+ private readonly ConcurrentDictionary < string , Invocator > invocators ;
36+ private readonly ConcurrentDictionary < string , string > invocationEventNames = new ( ) ;
37+ private readonly ConcurrentDictionary < string , string > invocationMessageNames = new ( ) ;
3838 private readonly ConcurrentDictionary < string , string > methodMessageNames = new ( ) ;
3939 private static readonly ConcurrentDictionary < string , EventContainer > eventContainers = new ( ) ;
40- private static readonly ConcurrentDictionary < string , ConcurrentDictionary < string , PropertyGetter > > AllPropertyGetters = new ( ) ;
40+ private static readonly ConcurrentDictionary < string , ConcurrentDictionary < string , Invocator > > AllInvocators = new ( ) ;
4141
4242 private readonly object objLock = new object ( ) ;
4343
@@ -58,7 +58,7 @@ protected set
5858 protected ApiBase ( )
5959 {
6060 this . objectName = this . GetType ( ) . Name . LowerFirst ( ) ;
61- propertyGetters = AllPropertyGetters . GetOrAdd ( objectName , _ => new ConcurrentDictionary < string , PropertyGetter > ( ) ) ;
61+ this . invocators = AllInvocators . GetOrAdd ( this . objectName , _ => new ConcurrentDictionary < string , Invocator > ( ) ) ;
6262 }
6363
6464 protected void CallMethod0 ( [ CallerMemberName ] string callerName = null )
@@ -113,37 +113,37 @@ protected void CallMethod3(object val1, object val2, object val3, [CallerMemberN
113113 }
114114 }
115115
116- protected Task < T > GetPropertyAsync < T > ( object arg = null , [ CallerMemberName ] string callerName = null )
116+ protected Task < T > InvokeAsync < T > ( object arg = null , [ CallerMemberName ] string callerName = null )
117117 {
118118 Debug . Assert ( callerName != null , nameof ( callerName ) + " != null" ) ;
119119
120120 lock ( this . objLock )
121121 {
122- return this . propertyGetters . GetOrAdd ( callerName , _ =>
122+ return this . invocators . GetOrAdd ( callerName , _ =>
123123 {
124- var getter = new PropertyGetter < T > ( this , callerName , PropertyTimeout , arg ) ;
124+ var getter = new Invocator < T > ( this , callerName , InvocationTimeout , arg ) ;
125125
126126 getter . Task < T > ( ) . ContinueWith ( _ =>
127127 {
128128 lock ( this . objLock )
129129 {
130- return this . propertyGetters . TryRemove ( callerName , out var _ ) ;
130+ return this . invocators . TryRemove ( callerName , out var _ ) ;
131131 }
132132 } ) ;
133133
134134 return getter ;
135135 } ) . Task < T > ( ) ;
136136 }
137137 }
138-
138+
139139 protected void AddEvent ( Action value , int ? id = null , [ CallerMemberName ] string callerName = null )
140140 {
141141 Debug . Assert ( callerName != null , nameof ( callerName ) + " != null" ) ;
142- var eventName = EventName ( callerName ) ;
143-
144- var eventKey = EventKey ( eventName , id ) ;
142+ var eventName = this . EventName ( callerName ) ;
143+
144+ var eventKey = this . EventKey ( eventName , id ) ;
145145
146- lock ( objLock )
146+ lock ( this . objLock )
147147 {
148148 var container = eventContainers . GetOrAdd ( eventKey , _ =>
149149 {
@@ -156,14 +156,14 @@ protected void AddEvent(Action value, int? id = null, [CallerMemberName] string
156156 container . Register ( value ) ;
157157 }
158158 }
159-
159+
160160 protected void RemoveEvent ( Action value , int ? id = null , [ CallerMemberName ] string callerName = null )
161161 {
162162 Debug . Assert ( callerName != null , nameof ( callerName ) + " != null" ) ;
163- var eventName = EventName ( callerName ) ;
164- var eventKey = EventKey ( eventName , id ) ;
163+ var eventName = this . EventName ( callerName ) ;
164+ var eventKey = this . EventKey ( eventName , id ) ;
165165
166- lock ( objLock )
166+ lock ( this . objLock )
167167 {
168168 if ( eventContainers . TryGetValue ( eventKey , out var container ) && ! container . Unregister ( value ) )
169169 {
@@ -172,15 +172,15 @@ protected void RemoveEvent(Action value, int? id = null, [CallerMemberName] stri
172172 }
173173 }
174174 }
175-
175+
176176 protected void AddEvent < T > ( Action < T > value , int ? id = null , [ CallerMemberName ] string callerName = null )
177177 {
178178 Debug . Assert ( callerName != null , nameof ( callerName ) + " != null" ) ;
179-
180- var eventName = EventName ( callerName ) ;
181- var eventKey = EventKey ( eventName , id ) ;
182179
183- lock ( objLock )
180+ var eventName = this . EventName ( callerName ) ;
181+ var eventKey = this . EventKey ( eventName , id ) ;
182+
183+ lock ( this . objLock )
184184 {
185185 var container = eventContainers . GetOrAdd ( eventKey , _ =>
186186 {
@@ -197,10 +197,10 @@ protected void AddEvent<T>(Action<T> value, int? id = null, [CallerMemberName] s
197197 protected void RemoveEvent < T > ( Action < T > value , int ? id = null , [ CallerMemberName ] string callerName = null )
198198 {
199199 Debug . Assert ( callerName != null , nameof ( callerName ) + " != null" ) ;
200- var eventName = EventName ( callerName ) ;
201- var eventKey = EventKey ( eventName , id ) ;
200+ var eventName = this . EventName ( callerName ) ;
201+ var eventKey = this . EventKey ( eventName , id ) ;
202202
203- lock ( objLock )
203+ lock ( this . objLock )
204204 {
205205 if ( eventContainers . TryGetValue ( eventKey , out var container ) && ! container . Unregister ( value ) )
206206 {
@@ -212,33 +212,33 @@ protected void RemoveEvent<T>(Action<T> value, int? id = null, [CallerMemberName
212212
213213 private string EventName ( string callerName )
214214 {
215- switch ( SocketEventNameType )
215+ switch ( this . SocketEventNameType )
216216 {
217217 case SocketEventNameTypes . DashedLower :
218- return $ "{ objectName } -{ callerName . ToDashedEventName ( ) } ";
218+ return $ "{ this . objectName } -{ callerName . ToDashedEventName ( ) } ";
219219 case SocketEventNameTypes . CamelCase :
220- return $ "{ objectName } -{ callerName . ToCamelCaseEventName ( ) } ";
220+ return $ "{ this . objectName } -{ callerName . ToCamelCaseEventName ( ) } ";
221221 default :
222222 throw new ArgumentOutOfRangeException ( ) ;
223223 }
224224 }
225-
225+
226226 private string EventKey ( string eventName , int ? id )
227227 {
228228 return string . Format ( CultureInfo . InvariantCulture , "{0}{1:D}" , eventName , id ) ;
229229 }
230230
231- internal abstract class PropertyGetter
231+ internal abstract class Invocator
232232 {
233233 public abstract Task < T > Task < T > ( ) ;
234234 }
235235
236- internal class PropertyGetter < T > : PropertyGetter
236+ internal class Invocator < T > : Invocator
237237 {
238238 private readonly Task < T > tcsTask ;
239239 private TaskCompletionSource < T > tcs ;
240240
241- public PropertyGetter ( ApiBase apiBase , string callerName , int timeoutMs , object arg = null )
241+ public Invocator ( ApiBase apiBase , string callerName , int timeoutMs , object arg = null )
242242 {
243243 this . tcs = new TaskCompletionSource < T > ( TaskCreationOptions . RunContinuationsAsynchronously ) ;
244244 this . tcsTask = this . tcs . Task ;
@@ -249,22 +249,22 @@ public PropertyGetter(ApiBase apiBase, string callerName, int timeoutMs, object
249249 switch ( apiBase . SocketTaskEventNameType )
250250 {
251251 case SocketTaskEventNameTypes . DashesLowerFirst :
252- eventName = apiBase . propertyEventNames . GetOrAdd ( callerName , s => $ "{ apiBase . objectName } -{ s . StripAsync ( ) . LowerFirst ( ) } -completed") ;
252+ eventName = apiBase . invocationEventNames . GetOrAdd ( callerName , s => $ "{ apiBase . objectName } -{ s . StripAsync ( ) . LowerFirst ( ) } -completed") ;
253253 break ;
254254 case SocketTaskEventNameTypes . NoDashUpperFirst :
255- eventName = apiBase . propertyEventNames . GetOrAdd ( callerName , s => $ "{ apiBase . objectName } { s . StripAsync ( ) } Completed") ;
255+ eventName = apiBase . invocationEventNames . GetOrAdd ( callerName , s => $ "{ apiBase . objectName } { s . StripAsync ( ) } Completed") ;
256256 break ;
257257 default :
258258 throw new ArgumentOutOfRangeException ( ) ;
259259 }
260-
260+
261261 switch ( apiBase . SocketTaskMessageNameType )
262262 {
263263 case SocketTaskMessageNameTypes . DashesLowerFirst :
264- messageName = apiBase . propertyMessageNames . GetOrAdd ( callerName , s => $ "{ apiBase . objectName } -{ s . StripAsync ( ) . LowerFirst ( ) } ") ;
264+ messageName = apiBase . invocationMessageNames . GetOrAdd ( callerName , s => $ "{ apiBase . objectName } -{ s . StripAsync ( ) . LowerFirst ( ) } ") ;
265265 break ;
266266 case SocketTaskMessageNameTypes . NoDashUpperFirst :
267- messageName = apiBase . propertyMessageNames . GetOrAdd ( callerName , s => apiBase . objectName + s . StripAsync ( ) ) ;
267+ messageName = apiBase . invocationMessageNames . GetOrAdd ( callerName , s => apiBase . objectName + s . StripAsync ( ) ) ;
268268 break ;
269269 default :
270270 throw new ArgumentOutOfRangeException ( ) ;
@@ -289,17 +289,17 @@ public PropertyGetter(ApiBase apiBase, string callerName, int timeoutMs, object
289289 }
290290 }
291291 } ) ;
292-
292+
293293 if ( arg != null )
294294 {
295- _ = apiBase . Id >= 0 ? BridgeConnector . Socket . Emit ( messageName , apiBase . Id , arg ) : BridgeConnector . Socket . Emit ( messageName , arg ) ;
295+ _ = apiBase . Id >= 0 ? BridgeConnector . Socket . Emit ( messageName , apiBase . Id , arg ) : BridgeConnector . Socket . Emit ( messageName , arg ) ;
296296 }
297297 else
298298 {
299- _ = apiBase . Id >= 0 ? BridgeConnector . Socket . Emit ( messageName , apiBase . Id ) : BridgeConnector . Socket . Emit ( messageName ) ;
299+ _ = apiBase . Id >= 0 ? BridgeConnector . Socket . Emit ( messageName , apiBase . Id ) : BridgeConnector . Socket . Emit ( messageName ) ;
300300 }
301301
302- System . Threading . Tasks . Task . Delay ( PropertyTimeout ) . ContinueWith ( _ =>
302+ System . Threading . Tasks . Task . Delay ( InvocationTimeout ) . ContinueWith ( _ =>
303303 {
304304 if ( this . tcs != null )
305305 {
@@ -321,7 +321,7 @@ public override Task<T1> Task<T1>()
321321 return this . tcsTask as Task < T1 > ;
322322 }
323323 }
324-
324+
325325 [ SuppressMessage ( "ReSharper" , "InconsistentlySynchronizedField" ) ]
326326 private class EventContainer
327327 {
@@ -330,41 +330,41 @@ private class EventContainer
330330
331331 private Action < T > GetEventActionT < T > ( )
332332 {
333- return ( Action < T > ) eventActionT ;
333+ return ( Action < T > ) this . eventActionT ;
334334 }
335335
336336 private void SetEventActionT < T > ( Action < T > actionT )
337337 {
338- eventActionT = actionT ;
338+ this . eventActionT = actionT ;
339339 }
340340
341- public void OnEventAction ( ) => eventAction ? . Invoke ( ) ;
341+ public void OnEventAction ( ) => this . eventAction ? . Invoke ( ) ;
342342
343- public void OnEventActionT < T > ( T p ) => GetEventActionT < T > ( ) ? . Invoke ( p ) ;
343+ public void OnEventActionT < T > ( T p ) => this . GetEventActionT < T > ( ) ? . Invoke ( p ) ;
344344
345345 public void Register ( Action receiver )
346346 {
347- eventAction += receiver ;
347+ this . eventAction += receiver ;
348348 }
349349
350350 public void Register < T > ( Action < T > receiver )
351351 {
352- var actionT = GetEventActionT < T > ( ) ;
352+ var actionT = this . GetEventActionT < T > ( ) ;
353353 actionT += receiver ;
354- SetEventActionT ( actionT ) ;
354+ this . SetEventActionT ( actionT ) ;
355355 }
356356
357357 public bool Unregister ( Action receiver )
358358 {
359- eventAction -= receiver ;
359+ this . eventAction -= receiver ;
360360 return this . eventAction != null ;
361361 }
362362
363363 public bool Unregister < T > ( Action < T > receiver )
364364 {
365- var actionT = GetEventActionT < T > ( ) ;
365+ var actionT = this . GetEventActionT < T > ( ) ;
366366 actionT -= receiver ;
367- SetEventActionT ( actionT ) ;
367+ this . SetEventActionT ( actionT ) ;
368368
369369 return actionT != null ;
370370 }
0 commit comments