Skip to content

Commit 7889057

Browse files
authored
Merge pull request #933 from softworkz/submit_invocation_rename
Rename PropertyGet to more generic Invocator
2 parents 68c50f1 + 385dcfb commit 7889057

File tree

11 files changed

+140
-140
lines changed

11 files changed

+140
-140
lines changed

src/ElectronNET.API/API/ApiBase.cs

Lines changed: 54 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

src/ElectronNET.API/API/App.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ public Task<string> NameAsync
366366
{
367367
get
368368
{
369-
return this.GetPropertyAsync<string>();
369+
return this.InvokeAsync<string>();
370370
}
371371
}
372372

@@ -501,7 +501,7 @@ public void Show()
501501
public async Task<string> GetAppPathAsync(CancellationToken cancellationToken = default)
502502
{
503503
cancellationToken.ThrowIfCancellationRequested();
504-
return await this.GetPropertyAsync<string>().ConfigureAwait(false);
504+
return await this.InvokeAsync<string>().ConfigureAwait(false);
505505
}
506506

507507
/// <summary>
@@ -565,7 +565,7 @@ public void SetPath(PathName name, string path)
565565
public async Task<string> GetVersionAsync(CancellationToken cancellationToken = default)
566566
{
567567
cancellationToken.ThrowIfCancellationRequested();
568-
return await this.GetPropertyAsync<string>().ConfigureAwait(false);
568+
return await this.InvokeAsync<string>().ConfigureAwait(false);
569569
}
570570

571571
/// <summary>
@@ -579,7 +579,7 @@ public async Task<string> GetVersionAsync(CancellationToken cancellationToken =
579579
public async Task<string> GetLocaleAsync(CancellationToken cancellationToken = default)
580580
{
581581
cancellationToken.ThrowIfCancellationRequested();
582-
return await this.GetPropertyAsync<string>().ConfigureAwait(false);
582+
return await this.InvokeAsync<string>().ConfigureAwait(false);
583583
}
584584

585585
/// <summary>
@@ -850,7 +850,7 @@ public async Task<bool> SetUserTasksAsync(UserTask[] userTasks, CancellationToke
850850
public async Task<JumpListSettings> GetJumpListSettingsAsync(CancellationToken cancellationToken = default)
851851
{
852852
cancellationToken.ThrowIfCancellationRequested();
853-
return await this.GetPropertyAsync<JumpListSettings>().ConfigureAwait(false);
853+
return await this.InvokeAsync<JumpListSettings>().ConfigureAwait(false);
854854
}
855855

856856
/// <summary>
@@ -941,7 +941,7 @@ public void ReleaseSingleInstanceLock()
941941
public async Task<bool> HasSingleInstanceLockAsync(CancellationToken cancellationToken = default)
942942
{
943943
cancellationToken.ThrowIfCancellationRequested();
944-
return await this.GetPropertyAsync<bool>().ConfigureAwait(false);
944+
return await this.InvokeAsync<bool>().ConfigureAwait(false);
945945
}
946946

947947
/// <summary>
@@ -980,7 +980,7 @@ public void SetUserActivity(string type, object userInfo, string webpageUrl)
980980
public async Task<string> GetCurrentActivityTypeAsync(CancellationToken cancellationToken = default)
981981
{
982982
cancellationToken.ThrowIfCancellationRequested();
983-
return await this.GetPropertyAsync<string>().ConfigureAwait(false);
983+
return await this.InvokeAsync<string>().ConfigureAwait(false);
984984
}
985985

986986
/// <summary>
@@ -1043,7 +1043,7 @@ public async Task<int> ImportCertificateAsync(ImportCertificateOptions options,
10431043
public async Task<ProcessMetric[]> GetAppMetricsAsync(CancellationToken cancellationToken = default)
10441044
{
10451045
cancellationToken.ThrowIfCancellationRequested();
1046-
return await this.GetPropertyAsync<ProcessMetric[]>().ConfigureAwait(false);
1046+
return await this.InvokeAsync<ProcessMetric[]>().ConfigureAwait(false);
10471047
}
10481048

10491049
/// <summary>
@@ -1055,7 +1055,7 @@ public async Task<ProcessMetric[]> GetAppMetricsAsync(CancellationToken cancella
10551055
public async Task<GPUFeatureStatus> GetGpuFeatureStatusAsync(CancellationToken cancellationToken = default)
10561056
{
10571057
cancellationToken.ThrowIfCancellationRequested();
1058-
return await this.GetPropertyAsync<GPUFeatureStatus>().ConfigureAwait(false);
1058+
return await this.InvokeAsync<GPUFeatureStatus>().ConfigureAwait(false);
10591059
}
10601060

10611061
/// <summary>
@@ -1090,7 +1090,7 @@ public async Task<bool> SetBadgeCountAsync(int count, CancellationToken cancella
10901090
public async Task<int> GetBadgeCountAsync(CancellationToken cancellationToken = default)
10911091
{
10921092
cancellationToken.ThrowIfCancellationRequested();
1093-
return await this.GetPropertyAsync<int>().ConfigureAwait(false);
1093+
return await this.InvokeAsync<int>().ConfigureAwait(false);
10941094
}
10951095

10961096
/// <summary>
@@ -1105,7 +1105,7 @@ public async Task<int> GetBadgeCountAsync(CancellationToken cancellationToken =
11051105
public async Task<bool> IsUnityRunningAsync(CancellationToken cancellationToken = default)
11061106
{
11071107
cancellationToken.ThrowIfCancellationRequested();
1108-
return await this.GetPropertyAsync<bool>().ConfigureAwait(false);
1108+
return await this.InvokeAsync<bool>().ConfigureAwait(false);
11091109
}
11101110

11111111
/// <summary>
@@ -1166,7 +1166,7 @@ public void SetLoginItemSettings(LoginSettings loginSettings)
11661166
public async Task<bool> IsAccessibilitySupportEnabledAsync(CancellationToken cancellationToken = default)
11671167
{
11681168
cancellationToken.ThrowIfCancellationRequested();
1169-
return await this.GetPropertyAsync<bool>().ConfigureAwait(false);
1169+
return await this.InvokeAsync<bool>().ConfigureAwait(false);
11701170
}
11711171

11721172
/// <summary>

0 commit comments

Comments
 (0)