Wrap message processing logic in InvokeAsync calls

This commit is contained in:
Thorsten Sommer 2025-06-02 19:11:47 +02:00
parent ea41e84cf3
commit bc80f93047
No known key found for this signature in database
GPG Key ID: B0B7E2FC074BF1F5
2 changed files with 98 additions and 92 deletions

View File

@ -44,6 +44,8 @@ public abstract class MSGComponentBase : ComponentBase, IDisposable, IMessageBus
#region Implementation of IMessageBusReceiver #region Implementation of IMessageBusReceiver
public async Task ProcessMessage<T>(ComponentBase? sendingComponent, Event triggeredEvent, T? data) public async Task ProcessMessage<T>(ComponentBase? sendingComponent, Event triggeredEvent, T? data)
{
await this.InvokeAsync(async () =>
{ {
switch (triggeredEvent) switch (triggeredEvent)
{ {
@ -58,6 +60,7 @@ public abstract class MSGComponentBase : ComponentBase, IDisposable, IMessageBus
} }
await this.ProcessIncomingMessage(sendingComponent, triggeredEvent, data); await this.ProcessIncomingMessage(sendingComponent, triggeredEvent, data);
});
} }
public async Task<TResult?> ProcessMessageWithResult<TPayload, TResult>(ComponentBase? sendingComponent, Event triggeredEvent, TPayload? data) public async Task<TResult?> ProcessMessageWithResult<TPayload, TResult>(ComponentBase? sendingComponent, Event triggeredEvent, TPayload? data)

View File

@ -138,6 +138,8 @@ public partial class MainLayout : LayoutComponentBase, IMessageBusReceiver, ILan
public string ComponentName => nameof(MainLayout); public string ComponentName => nameof(MainLayout);
public async Task ProcessMessage<TMessage>(ComponentBase? sendingComponent, Event triggeredEvent, TMessage? data) public async Task ProcessMessage<TMessage>(ComponentBase? sendingComponent, Event triggeredEvent, TMessage? data)
{
await this.InvokeAsync(async () =>
{ {
switch (triggeredEvent) switch (triggeredEvent)
{ {
@ -164,7 +166,7 @@ public partial class MainLayout : LayoutComponentBase, IMessageBusReceiver, ILan
break; break;
case Event.CONFIGURATION_CHANGED: case Event.CONFIGURATION_CHANGED:
if(this.SettingsManager.ConfigurationData.App.NavigationBehavior is NavBehavior.ALWAYS_EXPAND) if (this.SettingsManager.ConfigurationData.App.NavigationBehavior is NavBehavior.ALWAYS_EXPAND)
this.navBarOpen = true; this.navBarOpen = true;
else else
this.navBarOpen = false; this.navBarOpen = false;
@ -209,7 +211,7 @@ public partial class MainLayout : LayoutComponentBase, IMessageBusReceiver, ILan
// Check if there is an enterprise configuration plugin to download: // Check if there is an enterprise configuration plugin to download:
// //
var enterpriseEnvironment = this.MessageBus.CheckDeferredMessages<EnterpriseEnvironment>(Event.STARTUP_ENTERPRISE_ENVIRONMENT).FirstOrDefault(); var enterpriseEnvironment = this.MessageBus.CheckDeferredMessages<EnterpriseEnvironment>(Event.STARTUP_ENTERPRISE_ENVIRONMENT).FirstOrDefault();
if(enterpriseEnvironment != default) if (enterpriseEnvironment != default)
await PluginFactory.TryDownloadingConfigPluginAsync(enterpriseEnvironment.ConfigurationId, enterpriseEnvironment.ConfigurationServerUrl); await PluginFactory.TryDownloadingConfigPluginAsync(enterpriseEnvironment.ConfigurationId, enterpriseEnvironment.ConfigurationServerUrl);
// Load (but not start) all plugins without waiting for them: // Load (but not start) all plugins without waiting for them:
@ -230,6 +232,7 @@ public partial class MainLayout : LayoutComponentBase, IMessageBusReceiver, ILan
await this.InvokeAsync(this.StateHasChanged); await this.InvokeAsync(this.StateHasChanged);
break; break;
} }
});
} }
public Task<TResult?> ProcessMessageWithResult<TPayload, TResult>(ComponentBase? sendingComponent, Event triggeredEvent, TPayload? data) public Task<TResult?> ProcessMessageWithResult<TPayload, TResult>(ComponentBase? sendingComponent, Event triggeredEvent, TPayload? data)