implement

This commit is contained in:
2026-02-17 00:48:28 +01:00
parent 0119c7a737
commit 5c7909034f
57 changed files with 1676 additions and 114 deletions

View File

@@ -1,6 +1,9 @@
using AipsCore.Application.Abstract.MessageBroking;
using AipsCore.Application.Common.Message.MoveShape;
using AipsCore.Application.Models.Shape.Command.MoveShape;
using AipsRT.Model.Whiteboard;
using AipsRT.Model.Whiteboard.Shapes;
using AipsRT.Model.Whiteboard.Structs;
using AipsRT.Services.Interfaces;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.SignalR;
@@ -41,17 +44,89 @@ public class WhiteboardHub : Hub
.SendAsync("Leaved", Context.UserIdentifier!);
}
private Guid CurrentUserId => Guid.Parse(Context.UserIdentifier!);
private Whiteboard CurrentWhiteboard => _whiteboardManager.GetWhiteboardForUser(CurrentUserId)!;
private async Task ResetCurrentUser()
{
await Clients.Caller.SendAsync("InitWhiteboard", CurrentWhiteboard);
}
private async Task SendToOthers(string methodName, object? arg)
{
await Clients.GroupExcept(CurrentWhiteboard.WhiteboardId.ToString(), Context.ConnectionId)
.SendAsync(methodName, arg);
}
public async Task AddRectangle(Rectangle rectangle)
{
var whiteboard = _whiteboardManager.GetWhiteboardForUser(Guid.Parse(Context.UserIdentifier!))!;
rectangle.OwnerId = Guid.Parse(Context.UserIdentifier!);
rectangle.OwnerId = CurrentUserId;
var whiteboard = CurrentWhiteboard;
await _messagingService.CreatedRectangle(whiteboard.WhiteboardId, rectangle);
whiteboard.AddRectangle(rectangle);
await Clients.GroupExcept(whiteboard.WhiteboardId.ToString(), Context.ConnectionId)
.SendAsync("AddedRectangle", rectangle);
await SendToOthers("AddedRectangle", rectangle);
}
public async Task AddArrow(Arrow arrow)
{
arrow.OwnerId = CurrentUserId;
var whiteboard = CurrentWhiteboard;
await _messagingService.CreatedArrow(whiteboard.WhiteboardId, arrow);
whiteboard.AddArrow(arrow);
await SendToOthers("AddedArrow", arrow);
}
public async Task AddLine(Line line)
{
line.OwnerId = CurrentUserId;
var whiteboard = CurrentWhiteboard;
await _messagingService.CreateLine(whiteboard.WhiteboardId, line);
whiteboard.AddLine(line);
await SendToOthers("AddedLine", line);
}
public async Task AddTextShape(TextShape textShape)
{
textShape.OwnerId = CurrentUserId;
var whiteboard = CurrentWhiteboard;
await _messagingService.CreateTextShape(whiteboard.WhiteboardId, textShape);
whiteboard.AddTextShape(textShape);
await SendToOthers("AddedTextShape", textShape);
}
public async Task MoveShape(MoveShapeCommand moveShape)
{
var whiteboard = CurrentWhiteboard;
var shape = whiteboard.Shapes.Find(s => s.Id.ToString() == moveShape.ShapeId);
if (shape is null || shape.OwnerId != CurrentUserId)
{
await ResetCurrentUser();
return;
}
shape.Move(new Position(moveShape.NewPositionX, moveShape.NewPositionY));
await SendToOthers("MovedShape", moveShape);
}
public async Task PlaceShape(MoveShapeCommand moveShape)
{
await MoveShape(moveShape);
await _messagingService.MoveShape(moveShape);
}
}