Skip to content

Commit 515430f

Browse files
committed
ApiBase: Rename PropertyGet to more generic Invocator
1 parent 10bf461 commit 515430f

File tree

11 files changed

+104
-104
lines changed

11 files changed

+104
-104
lines changed

src/ElectronNET.API/API/ApiBase.cs

Lines changed: 18 additions & 18 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(objectName, _ => new ConcurrentDictionary<string, Invocator>());
6262
}
6363

6464
protected void CallMethod0([CallerMemberName] string callerName = null)
@@ -113,21 +113,21 @@ 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

@@ -228,17 +228,17 @@ private string EventKey(string eventName, int? id)
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,10 +249,10 @@ 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();
@@ -261,10 +261,10 @@ public PropertyGetter(ApiBase apiBase, string callerName, int timeoutMs, object
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();
@@ -299,7 +299,7 @@ public PropertyGetter(ApiBase apiBase, string callerName, int timeoutMs, object
299299
_ = 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
{

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>

src/ElectronNET.API/API/AutoUpdater.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public bool AutoDownload
2323
{
2424
get
2525
{
26-
return Task.Run(() => GetPropertyAsync<bool>()).Result;
26+
return Task.Run(() => this.InvokeAsync<bool>()).Result;
2727
}
2828
set
2929
{
@@ -40,7 +40,7 @@ public bool AutoInstallOnAppQuit
4040
{
4141
get
4242
{
43-
return Task.Run(() => GetPropertyAsync<bool>()).Result;
43+
return Task.Run(() => this.InvokeAsync<bool>()).Result;
4444
}
4545
set
4646
{
@@ -58,7 +58,7 @@ public bool AllowPrerelease
5858
{
5959
get
6060
{
61-
return Task.Run(() => GetPropertyAsync<bool>()).Result;
61+
return Task.Run(() => this.InvokeAsync<bool>()).Result;
6262
}
6363
set
6464
{
@@ -74,7 +74,7 @@ public bool FullChangelog
7474
{
7575
get
7676
{
77-
return Task.Run(() => GetPropertyAsync<bool>()).Result;
77+
return Task.Run(() => this.InvokeAsync<bool>()).Result;
7878
}
7979
set
8080
{
@@ -91,7 +91,7 @@ public bool AllowDowngrade
9191
{
9292
get
9393
{
94-
return Task.Run(() => GetPropertyAsync<bool>()).Result;
94+
return Task.Run(() => this.InvokeAsync<bool>()).Result;
9595
}
9696
set
9797
{
@@ -106,7 +106,7 @@ public string UpdateConfigPath
106106
{
107107
get
108108
{
109-
return Task.Run(() => GetPropertyAsync<string>()).Result;
109+
return Task.Run(() => this.InvokeAsync<string>()).Result;
110110
}
111111
}
112112

@@ -117,7 +117,7 @@ public Task<SemVer> CurrentVersionAsync
117117
{
118118
get
119119
{
120-
return Task.Run(() => GetPropertyAsync<SemVer>());
120+
return Task.Run(() => this.InvokeAsync<SemVer>());
121121
}
122122
}
123123

@@ -142,7 +142,7 @@ public Task<string> ChannelAsync
142142
{
143143
get
144144
{
145-
return Task.Run(() => GetPropertyAsync<string>());
145+
return Task.Run(() => this.InvokeAsync<string>());
146146
}
147147
}
148148

@@ -165,7 +165,7 @@ public Task<Dictionary<string, string>> RequestHeadersAsync
165165
{
166166
get
167167
{
168-
return Task.Run(() => GetPropertyAsync<Dictionary<string, string>>());
168+
return Task.Run(() => this.InvokeAsync<Dictionary<string, string>>());
169169
}
170170
}
171171

src/ElectronNET.API/API/BrowserView.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public Rectangle Bounds
3030
{
3131
get
3232
{
33-
return Task.Run(() => GetPropertyAsync<Rectangle>()).Result;
33+
return Task.Run(() => this.InvokeAsync<Rectangle>()).Result;
3434
}
3535
set
3636
{

0 commit comments

Comments
 (0)