implement feedback loop
This commit is contained in:
25
dotnet/AipsRT/Services/ErrorSubscriberBackgroundService.cs
Normal file
25
dotnet/AipsRT/Services/ErrorSubscriberBackgroundService.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using AipsCore.Application.Abstract;
|
||||
using AipsCore.Application.Abstract.MessageBroking;
|
||||
using AipsCore.Application.Common.Message.ErrorMessage;
|
||||
|
||||
namespace AipsRT.Services;
|
||||
|
||||
public class ErrorSubscriberBackgroundService : BackgroundService
|
||||
{
|
||||
private readonly IMessageSubscriber _subscriber;
|
||||
private readonly IDispatcher _dispatcher;
|
||||
|
||||
public ErrorSubscriberBackgroundService(IMessageSubscriber subscriber, IDispatcher dispatcher)
|
||||
{
|
||||
_subscriber = subscriber;
|
||||
_dispatcher = dispatcher;
|
||||
}
|
||||
|
||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
{
|
||||
await _subscriber.SubscribeAsync<ErrorMessage>(async (errorMessage, ct) =>
|
||||
{
|
||||
await _dispatcher.Execute(errorMessage, ct);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -11,5 +11,5 @@ public interface IMessagingService
|
||||
Task CreateLine(Guid whiteboardId, Line line);
|
||||
Task CreateTextShape(Guid whiteboardId, TextShape textShape);
|
||||
|
||||
Task MoveShape(MoveShapeCommand moveShape);
|
||||
Task MoveShape(Guid whiteboardId, MoveShapeCommand moveShape);
|
||||
}
|
||||
@@ -95,9 +95,9 @@ public class MessagingService : IMessagingService
|
||||
await _messagePublisher.PublishAsync(message);
|
||||
}
|
||||
|
||||
public async Task MoveShape(MoveShapeCommand moveShape)
|
||||
public async Task MoveShape(Guid whiteboardId, MoveShapeCommand moveShape)
|
||||
{
|
||||
var message = new MoveShapeMessage(moveShape);
|
||||
var message = new MoveShapeMessage(whiteboardId, moveShape);
|
||||
await _messagePublisher.PublishAsync(message);
|
||||
}
|
||||
}
|
||||
29
dotnet/AipsRT/Services/RtErrorHandleStrategy.cs
Normal file
29
dotnet/AipsRT/Services/RtErrorHandleStrategy.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using AipsCore.Application.Common.Message.ErrorMessage;
|
||||
using AipsRT.Hubs;
|
||||
using AipsRT.Model.Whiteboard;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
|
||||
namespace AipsRT.Services;
|
||||
|
||||
public class RtErrorHandleStrategy : IErrorMessageHandleStrategy
|
||||
{
|
||||
private readonly IHubContext<WhiteboardHub> _hubContext;
|
||||
private readonly WhiteboardManager _whiteboardManager;
|
||||
|
||||
public RtErrorHandleStrategy(IHubContext<WhiteboardHub> hubContext, WhiteboardManager whiteboardManager)
|
||||
{
|
||||
_hubContext = hubContext;
|
||||
_whiteboardManager = whiteboardManager;
|
||||
}
|
||||
|
||||
public async Task Handle(ErrorMessage message, CancellationToken cancellationToken)
|
||||
{
|
||||
await _whiteboardManager.RefreshWhiteboard(message.WhiteboardId);
|
||||
|
||||
var whiteboard = _whiteboardManager.GetWhiteboard(message.WhiteboardId)!;
|
||||
|
||||
await _hubContext.Clients
|
||||
.Group(whiteboard.WhiteboardId.ToString())
|
||||
.SendAsync("InitWhiteboard", whiteboard, cancellationToken);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user