mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2025-04-28 19:19:47 +00:00
Implemented SendMessageUseFirstResult for message bus
This commit is contained in:
parent
82cda5ee66
commit
562276ed3f
@ -51,6 +51,11 @@ public partial class InnerScrolling : MSGComponentBase
|
|||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override Task<TResult?> ProcessMessageWithResult<TPayload, TResult>(ComponentBase? sendingComponent, Event triggeredEvent, TPayload? data) where TResult : default where TPayload : default
|
||||||
|
{
|
||||||
|
return Task.FromResult(default(TResult));
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private string Height => $"height: calc(100vh - {this.HeaderHeight} - {this.MainLayout.AdditionalHeight});";
|
private string Height => $"height: calc(100vh - {this.HeaderHeight} - {this.MainLayout.AdditionalHeight});";
|
||||||
|
@ -92,6 +92,11 @@ public partial class MainLayout : LayoutComponentBase, IMessageBusReceiver
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Task<TResult?> ProcessMessageWithResult<TPayload, TResult>(ComponentBase? sendingComponent, Event triggeredEvent, TPayload? data)
|
||||||
|
{
|
||||||
|
return Task.FromResult<TResult?>(default);
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private async Task DismissUpdate()
|
private async Task DismissUpdate()
|
||||||
|
@ -10,4 +10,7 @@ public enum Event
|
|||||||
// Update events:
|
// Update events:
|
||||||
USER_SEARCH_FOR_UPDATE,
|
USER_SEARCH_FOR_UPDATE,
|
||||||
UPDATE_AVAILABLE,
|
UPDATE_AVAILABLE,
|
||||||
|
|
||||||
|
// Chat events:
|
||||||
|
HAS_CHAT_UNSAVED_CHANGES,
|
||||||
}
|
}
|
@ -5,4 +5,6 @@ namespace AIStudio.Tools;
|
|||||||
public interface IMessageBusReceiver
|
public interface IMessageBusReceiver
|
||||||
{
|
{
|
||||||
public Task ProcessMessage<T>(ComponentBase? sendingComponent, Event triggeredEvent, T? data);
|
public Task ProcessMessage<T>(ComponentBase? sendingComponent, Event triggeredEvent, T? data);
|
||||||
|
|
||||||
|
public Task<TResult?> ProcessMessageWithResult<TPayload, TResult>(ComponentBase? sendingComponent, Event triggeredEvent, TPayload? data);
|
||||||
}
|
}
|
@ -21,6 +21,8 @@ public abstract class MSGComponentBase : ComponentBase, IDisposable, IMessageBus
|
|||||||
|
|
||||||
public abstract Task ProcessMessage<T>(ComponentBase? sendingComponent, Event triggeredEvent, T? data);
|
public abstract Task ProcessMessage<T>(ComponentBase? sendingComponent, Event triggeredEvent, T? data);
|
||||||
|
|
||||||
|
public abstract Task<TResult?> ProcessMessageWithResult<TPayload, TResult>(ComponentBase? sendingComponent, Event triggeredEvent, TPayload? data);
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Implementation of IDisposable
|
#region Implementation of IDisposable
|
||||||
@ -37,6 +39,11 @@ public abstract class MSGComponentBase : ComponentBase, IDisposable, IMessageBus
|
|||||||
await this.MessageBus.SendMessage(this, triggeredEvent, data);
|
await this.MessageBus.SendMessage(this, triggeredEvent, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected async Task<TResult?> SendMessageWithResult<TPayload, TResult>(Event triggeredEvent, TPayload? data)
|
||||||
|
{
|
||||||
|
return await this.MessageBus.SendMessageUseFirstResult<TPayload, TResult>(this, triggeredEvent, data);
|
||||||
|
}
|
||||||
|
|
||||||
protected void ApplyFilters(ComponentBase[] components, Event[] events)
|
protected void ApplyFilters(ComponentBase[] components, Event[] events)
|
||||||
{
|
{
|
||||||
this.MessageBus.ApplyFilters(this, components, events);
|
this.MessageBus.ApplyFilters(this, components, events);
|
||||||
|
@ -64,4 +64,23 @@ public sealed class MessageBus
|
|||||||
this.sendingSemaphore.Release();
|
this.sendingSemaphore.Release();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<TResult?> SendMessageUseFirstResult<TPayload, TResult>(ComponentBase? sendingComponent, Event triggeredEvent, TPayload? data = default)
|
||||||
|
{
|
||||||
|
foreach (var (receiver, componentFilter) in this.componentFilters)
|
||||||
|
{
|
||||||
|
if (componentFilter.Length > 0 && sendingComponent is not null && !componentFilter.Contains(sendingComponent))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
var eventFilter = this.componentEvents[receiver];
|
||||||
|
if (eventFilter.Length == 0 || eventFilter.Contains(triggeredEvent))
|
||||||
|
{
|
||||||
|
var result = await receiver.ProcessMessageWithResult<TPayload, TResult>(sendingComponent, triggeredEvent, data);
|
||||||
|
if (result is not null)
|
||||||
|
return (TResult) result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return default;
|
||||||
|
}
|
||||||
}
|
}
|
@ -73,6 +73,11 @@ public sealed class UpdateService : BackgroundService, IMessageBusReceiver
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Task<TResult?> ProcessMessageWithResult<TPayload, TResult>(ComponentBase? sendingComponent, Event triggeredEvent, TPayload? data)
|
||||||
|
{
|
||||||
|
return Task.FromResult<TResult?>(default);
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Overrides of BackgroundService
|
#region Overrides of BackgroundService
|
||||||
|
Loading…
Reference in New Issue
Block a user