Merge branch 'main' into feature-whiteboards-recent-and-history
# Conflicts: # front/src/App.vue
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
using AipsCore.Application.Abstract.MessageBroking;
|
||||
using AipsCore.Application.Models.Shape.Command.CreateRectangle;
|
||||
|
||||
namespace AipsCore.Application.Common.Message.AddRectangle;
|
||||
|
||||
public record AddRectangleMessage(CreateRectangleCommand Command) : IMessage;
|
||||
@@ -0,0 +1,19 @@
|
||||
using AipsCore.Application.Abstract;
|
||||
using AipsCore.Application.Abstract.MessageBroking;
|
||||
|
||||
namespace AipsCore.Application.Common.Message.AddRectangle;
|
||||
|
||||
public class AddRectangleMessageHandler : IMessageHandler<AddRectangleMessage>
|
||||
{
|
||||
private readonly IDispatcher _dispatcher;
|
||||
|
||||
public AddRectangleMessageHandler(IDispatcher dispatcher)
|
||||
{
|
||||
_dispatcher = dispatcher;
|
||||
}
|
||||
|
||||
public async Task Handle(AddRectangleMessage message, CancellationToken cancellationToken)
|
||||
{
|
||||
await _dispatcher.Execute(message.Command, cancellationToken);
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ using AipsCore.Domain.Models.Shape.ValueObjects;
|
||||
namespace AipsCore.Application.Models.Shape.Command.CreateRectangle;
|
||||
|
||||
public record CreateRectangleCommand(
|
||||
string Id,
|
||||
string WhiteboardId,
|
||||
string AuthorId,
|
||||
int PositionX,
|
||||
@@ -11,4 +12,4 @@ public record CreateRectangleCommand(
|
||||
string Color,
|
||||
int EndPositionX,
|
||||
int EndPositionY,
|
||||
int BorderThickness) : ICommand<ShapeId>;
|
||||
int BorderThickness) : ICommand;
|
||||
@@ -13,7 +13,7 @@ using AipsCore.Domain.Models.Whiteboard.ValueObjects;
|
||||
|
||||
namespace AipsCore.Application.Models.Shape.Command.CreateRectangle;
|
||||
|
||||
public class CreateRectangleCommandHandler : ICommandHandler<CreateRectangleCommand, ShapeId>
|
||||
public class CreateRectangleCommandHandler : ICommandHandler<CreateRectangleCommand>
|
||||
{
|
||||
private readonly IShapeRepository _shapeRepository;
|
||||
private readonly IWhiteboardRepository _whiteboardRepository;
|
||||
@@ -28,11 +28,12 @@ public class CreateRectangleCommandHandler : ICommandHandler<CreateRectangleComm
|
||||
_unitOfWork = unitOfWork;
|
||||
}
|
||||
|
||||
public async Task<ShapeId> Handle(CreateRectangleCommand command, CancellationToken cancellationToken = default)
|
||||
public async Task Handle(CreateRectangleCommand command, CancellationToken cancellationToken = default)
|
||||
{
|
||||
Validate(command);
|
||||
|
||||
var rectangle = Rectangle.Create(
|
||||
command.Id,
|
||||
command.WhiteboardId,
|
||||
command.AuthorId,
|
||||
command.PositionX, command.PositionY,
|
||||
@@ -43,8 +44,6 @@ public class CreateRectangleCommandHandler : ICommandHandler<CreateRectangleComm
|
||||
|
||||
await _shapeRepository.SaveAsync(rectangle, cancellationToken);
|
||||
await _unitOfWork.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return rectangle.Id;
|
||||
}
|
||||
|
||||
private void Validate(CreateRectangleCommand command)
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
using AipsCore.Application.Abstract.Query;
|
||||
|
||||
namespace AipsCore.Application.Models.Whiteboard.Query.GetWhiteboardInfoRT;
|
||||
|
||||
public record GetWhiteboardInfoRTQuery(Guid WhiteboardId) : IQuery<Infrastructure.Persistence.Whiteboard.Whiteboard>;
|
||||
@@ -0,0 +1,40 @@
|
||||
using AipsCore.Application.Abstract.Query;
|
||||
using AipsCore.Domain.Common.Validation;
|
||||
using AipsCore.Domain.Models.Whiteboard.Validation;
|
||||
using AipsCore.Domain.Models.Whiteboard.ValueObjects;
|
||||
using AipsCore.Infrastructure.Persistence.Db;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace AipsCore.Application.Models.Whiteboard.Query.GetWhiteboardInfoRT;
|
||||
|
||||
public class GetWhiteboardInfoRTQueryHandler
|
||||
: IQueryHandler<GetWhiteboardInfoRTQuery, Infrastructure.Persistence.Whiteboard.Whiteboard>
|
||||
{
|
||||
private readonly AipsDbContext _context;
|
||||
|
||||
public GetWhiteboardInfoRTQueryHandler(AipsDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<Infrastructure.Persistence.Whiteboard.Whiteboard> Handle(GetWhiteboardInfoRTQuery query, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var whiteboard = await GetQuery(query.WhiteboardId).FirstOrDefaultAsync(cancellationToken);
|
||||
|
||||
if (whiteboard is null)
|
||||
{
|
||||
throw new ValidationException(WhiteboardErrors.NotFound(new WhiteboardId(query.WhiteboardId.ToString())));
|
||||
}
|
||||
|
||||
return whiteboard;
|
||||
}
|
||||
|
||||
private IQueryable<Infrastructure.Persistence.Whiteboard.Whiteboard> GetQuery(Guid whiteboardId)
|
||||
{
|
||||
return _context.Whiteboards
|
||||
.Where(w => w.Id == whiteboardId)
|
||||
.Include(w => w.Memberships)
|
||||
.Include(w => w.Owner)
|
||||
.Include(w => w.Shapes);
|
||||
}
|
||||
}
|
||||
@@ -30,6 +30,7 @@ public class RabbitMqSubscriber : IMessageSubscriber
|
||||
|
||||
await channel.QueueDeclareAsync(
|
||||
queue: GetQueueName<T>(),
|
||||
autoDelete: false,
|
||||
durable: true);
|
||||
|
||||
await channel.QueueBindAsync(
|
||||
|
||||
@@ -6,4 +6,16 @@
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\AipsCore\AipsCore.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="DotNetEnv" Version="3.1.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Hubs\Dtos\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -1,9 +1,19 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
|
||||
namespace AipsRT.Hubs;
|
||||
|
||||
[Authorize]
|
||||
public class TestHub : Hub
|
||||
{
|
||||
public override async Task OnConnectedAsync()
|
||||
{
|
||||
Console.WriteLine($"LOOOOOOOOOG: [{Context.UserIdentifier}] User identifier connected");
|
||||
Console.WriteLine($"LOOOOOG222: [{Context.User?.Identity?.Name}] User identity name connected");
|
||||
|
||||
await base.OnConnectedAsync();
|
||||
}
|
||||
|
||||
public async Task SendText(string text)
|
||||
{
|
||||
await Clients.All.SendAsync("ReceiveText", text);
|
||||
|
||||
57
dotnet/AipsRT/Hubs/WhiteboardHub.cs
Normal file
57
dotnet/AipsRT/Hubs/WhiteboardHub.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
using AipsCore.Application.Abstract.MessageBroking;
|
||||
using AipsRT.Model.Whiteboard;
|
||||
using AipsRT.Model.Whiteboard.Shapes;
|
||||
using AipsRT.Services.Interfaces;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
|
||||
namespace AipsRT.Hubs;
|
||||
|
||||
[Authorize]
|
||||
public class WhiteboardHub : Hub
|
||||
{
|
||||
private readonly WhiteboardManager _whiteboardManager;
|
||||
private readonly IMessagingService _messagingService;
|
||||
|
||||
public WhiteboardHub(WhiteboardManager whiteboardManager, IMessagingService messagingService)
|
||||
{
|
||||
_whiteboardManager = whiteboardManager;
|
||||
_messagingService = messagingService;
|
||||
}
|
||||
|
||||
public async Task JoinWhiteboard(Guid whiteboardId)
|
||||
{
|
||||
if (!_whiteboardManager.WhiteboardExists(whiteboardId))
|
||||
await _whiteboardManager.AddWhiteboard(whiteboardId);
|
||||
|
||||
await Groups.AddToGroupAsync(Context.ConnectionId, whiteboardId.ToString());
|
||||
|
||||
var state = _whiteboardManager.GetWhiteboard(whiteboardId)!;
|
||||
|
||||
_whiteboardManager.AddUserToWhiteboard(Guid.Parse(Context.UserIdentifier!), whiteboardId);
|
||||
|
||||
await Clients.Caller.SendAsync("InitWhiteboard", state);
|
||||
await Clients.GroupExcept(whiteboardId.ToString(), Context.ConnectionId)
|
||||
.SendAsync("Joined", Context.UserIdentifier!);
|
||||
}
|
||||
|
||||
public async Task LeaveWhiteboard(Guid whiteboardId)
|
||||
{
|
||||
await Clients.GroupExcept(whiteboardId.ToString(), Context.ConnectionId)
|
||||
.SendAsync("Leaved", Context.UserIdentifier!);
|
||||
}
|
||||
|
||||
public async Task AddRectangle(Rectangle rectangle)
|
||||
{
|
||||
var whiteboard = _whiteboardManager.GetWhiteboardForUser(Guid.Parse(Context.UserIdentifier!))!;
|
||||
|
||||
rectangle.OwnerId = Guid.Parse(Context.UserIdentifier!);
|
||||
|
||||
await _messagingService.CreatedRectangle(whiteboard.WhiteboardId, rectangle);
|
||||
|
||||
whiteboard.AddRectangle(rectangle);
|
||||
|
||||
await Clients.GroupExcept(whiteboard.WhiteboardId.ToString(), Context.ConnectionId)
|
||||
.SendAsync("AddedRectangle", rectangle);
|
||||
}
|
||||
}
|
||||
52
dotnet/AipsRT/Model/Whiteboard/GetWhiteboardService.cs
Normal file
52
dotnet/AipsRT/Model/Whiteboard/GetWhiteboardService.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using AipsCore.Application.Abstract;
|
||||
using AipsCore.Application.Models.Whiteboard.Query.GetWhiteboardInfoRT;
|
||||
using AipsCore.Domain.Models.Shape.Enums;
|
||||
using AipsRT.Model.Whiteboard.Shapes.Map;
|
||||
|
||||
namespace AipsRT.Model.Whiteboard;
|
||||
|
||||
public class GetWhiteboardService
|
||||
{
|
||||
private readonly IDispatcher _dispatcher;
|
||||
|
||||
public GetWhiteboardService(IDispatcher dispatcher)
|
||||
{
|
||||
_dispatcher = dispatcher;
|
||||
}
|
||||
|
||||
public async Task<Whiteboard> GetWhiteboard(Guid whiteboardId)
|
||||
{
|
||||
var query = new GetWhiteboardInfoRTQuery(whiteboardId);
|
||||
return Map(await _dispatcher.Execute(query));
|
||||
}
|
||||
|
||||
private static Whiteboard Map(AipsCore.Infrastructure.Persistence.Whiteboard.Whiteboard entity)
|
||||
{
|
||||
var whiteboard = new Whiteboard()
|
||||
{
|
||||
WhiteboardId = entity.Id,
|
||||
OwnerId = entity.OwnerId,
|
||||
};
|
||||
|
||||
foreach (var shape in entity.Shapes)
|
||||
{
|
||||
switch (shape.Type)
|
||||
{
|
||||
case ShapeType.Rectangle:
|
||||
whiteboard.AddRectangle(shape.ToRectangle());
|
||||
break;
|
||||
case ShapeType.Arrow:
|
||||
whiteboard.AddArrow(shape.ToArrow());
|
||||
break;
|
||||
case ShapeType.Line:
|
||||
whiteboard.AddLine(shape.ToLine());
|
||||
break;
|
||||
case ShapeType.Text:
|
||||
whiteboard.AddTextShape(shape.ToTextShape());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return whiteboard;
|
||||
}
|
||||
}
|
||||
10
dotnet/AipsRT/Model/Whiteboard/Shapes/Arrow.cs
Normal file
10
dotnet/AipsRT/Model/Whiteboard/Shapes/Arrow.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using AipsRT.Model.Whiteboard.Structs;
|
||||
|
||||
namespace AipsRT.Model.Whiteboard.Shapes;
|
||||
|
||||
public class Arrow : Shape
|
||||
{
|
||||
public Position EndPosition { get; set; }
|
||||
|
||||
public int Thickness { get; set; }
|
||||
}
|
||||
10
dotnet/AipsRT/Model/Whiteboard/Shapes/Line.cs
Normal file
10
dotnet/AipsRT/Model/Whiteboard/Shapes/Line.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using AipsRT.Model.Whiteboard.Structs;
|
||||
|
||||
namespace AipsRT.Model.Whiteboard.Shapes;
|
||||
|
||||
public class Line : Shape
|
||||
{
|
||||
public Position EndPosition { get; set; }
|
||||
|
||||
public int Thickness { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
using AipsRT.Model.Whiteboard.Structs;
|
||||
|
||||
namespace AipsRT.Model.Whiteboard.Shapes.Map;
|
||||
|
||||
public static class ShapeMappingExtensions
|
||||
{
|
||||
extension(AipsCore.Infrastructure.Persistence.Shape.Shape shape)
|
||||
{
|
||||
public Rectangle ToRectangle()
|
||||
{
|
||||
return new Rectangle()
|
||||
{
|
||||
Id = shape.Id,
|
||||
Position = new Position(shape.PositionX, shape.PositionY),
|
||||
Color = shape.Color,
|
||||
EndPosition = new Position(shape.EndPositionX!.Value, shape.EndPositionY!.Value),
|
||||
BorderThickness = shape.Thickness!.Value,
|
||||
};
|
||||
}
|
||||
|
||||
public Arrow ToArrow()
|
||||
{
|
||||
return new Arrow()
|
||||
{
|
||||
Id = shape.Id,
|
||||
Position = new Position(shape.PositionX, shape.PositionY),
|
||||
Color = shape.Color,
|
||||
EndPosition = new Position(shape.EndPositionX!.Value, shape.EndPositionY!.Value),
|
||||
Thickness = shape.Thickness!.Value,
|
||||
};
|
||||
}
|
||||
|
||||
public Line ToLine()
|
||||
{
|
||||
return new Line()
|
||||
{
|
||||
Id = shape.Id,
|
||||
Position = new Position(shape.PositionX, shape.PositionY),
|
||||
Color = shape.Color,
|
||||
EndPosition = new Position(shape.EndPositionX!.Value, shape.EndPositionY!.Value),
|
||||
Thickness = shape.Thickness!.Value,
|
||||
};
|
||||
}
|
||||
|
||||
public TextShape ToTextShape()
|
||||
{
|
||||
return new TextShape()
|
||||
{
|
||||
Id = shape.Id,
|
||||
Position = new Position(shape.PositionX, shape.PositionY),
|
||||
Color = shape.Color,
|
||||
TextValue = shape.TextValue!,
|
||||
TextSize = shape.TextSize!.Value
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
10
dotnet/AipsRT/Model/Whiteboard/Shapes/Rectangle.cs
Normal file
10
dotnet/AipsRT/Model/Whiteboard/Shapes/Rectangle.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using AipsRT.Model.Whiteboard.Structs;
|
||||
|
||||
namespace AipsRT.Model.Whiteboard.Shapes;
|
||||
|
||||
public class Rectangle : Shape
|
||||
{
|
||||
public Position EndPosition { get; set; }
|
||||
|
||||
public int BorderThickness { get; set; }
|
||||
}
|
||||
14
dotnet/AipsRT/Model/Whiteboard/Shapes/Shape.cs
Normal file
14
dotnet/AipsRT/Model/Whiteboard/Shapes/Shape.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using AipsRT.Model.Whiteboard.Structs;
|
||||
|
||||
namespace AipsRT.Model.Whiteboard.Shapes;
|
||||
|
||||
public abstract class Shape
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
|
||||
public Guid OwnerId { get; set; }
|
||||
|
||||
public Position Position { get; set; }
|
||||
|
||||
public string Color { get; set; }
|
||||
}
|
||||
10
dotnet/AipsRT/Model/Whiteboard/Shapes/TextShape.cs
Normal file
10
dotnet/AipsRT/Model/Whiteboard/Shapes/TextShape.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using AipsRT.Model.Whiteboard.Shapes;
|
||||
|
||||
namespace AipsRT.Model.Whiteboard.Shapes;
|
||||
|
||||
public class TextShape : Shape
|
||||
{
|
||||
public string TextValue { get; set; }
|
||||
|
||||
public int TextSize { get; set; }
|
||||
}
|
||||
13
dotnet/AipsRT/Model/Whiteboard/Structs/Position.cs
Normal file
13
dotnet/AipsRT/Model/Whiteboard/Structs/Position.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
namespace AipsRT.Model.Whiteboard.Structs;
|
||||
|
||||
public struct Position
|
||||
{
|
||||
public int X { get; set; }
|
||||
public int Y { get; set; }
|
||||
|
||||
public Position(int x, int y)
|
||||
{
|
||||
X = x;
|
||||
Y = y;
|
||||
}
|
||||
}
|
||||
41
dotnet/AipsRT/Model/Whiteboard/Whiteboard.cs
Normal file
41
dotnet/AipsRT/Model/Whiteboard/Whiteboard.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using AipsRT.Model.Whiteboard.Shapes;
|
||||
|
||||
namespace AipsRT.Model.Whiteboard;
|
||||
|
||||
public class Whiteboard
|
||||
{
|
||||
public Guid WhiteboardId { get; set; }
|
||||
|
||||
public Guid OwnerId { get; set; }
|
||||
|
||||
public List<Shape> Shapes { get; } = [];
|
||||
|
||||
public List<Rectangle> Rectangles { get; } = [];
|
||||
public List<Arrow> Arrows { get; } = [];
|
||||
public List<Line> Lines { get; } = [];
|
||||
public List<TextShape> TextShapes { get; } = [];
|
||||
|
||||
public void AddRectangle(Rectangle shape)
|
||||
{
|
||||
Shapes.Add(shape);
|
||||
Rectangles.Add(shape);
|
||||
}
|
||||
|
||||
public void AddArrow(Arrow shape)
|
||||
{
|
||||
Shapes.Add(shape);
|
||||
Arrows.Add(shape);
|
||||
}
|
||||
|
||||
public void AddLine(Line shape)
|
||||
{
|
||||
Shapes.Add(shape);
|
||||
Lines.Add(shape);
|
||||
}
|
||||
|
||||
public void AddTextShape(TextShape shape)
|
||||
{
|
||||
Shapes.Add(shape);
|
||||
TextShapes.Add(shape);
|
||||
}
|
||||
}
|
||||
59
dotnet/AipsRT/Model/Whiteboard/WhiteboardManager.cs
Normal file
59
dotnet/AipsRT/Model/Whiteboard/WhiteboardManager.cs
Normal file
@@ -0,0 +1,59 @@
|
||||
using System.Collections.Concurrent;
|
||||
using AipsCore.Application.Abstract;
|
||||
|
||||
namespace AipsRT.Model.Whiteboard;
|
||||
|
||||
public class WhiteboardManager
|
||||
{
|
||||
private readonly IServiceScopeFactory _scopeFactory;
|
||||
private readonly ConcurrentDictionary<Guid, Whiteboard> _whiteboards = new();
|
||||
private readonly ConcurrentDictionary<Guid, Guid> _userInWhiteboards = new();
|
||||
|
||||
public WhiteboardManager(IServiceScopeFactory scopeFactory)
|
||||
{
|
||||
_scopeFactory = scopeFactory;
|
||||
}
|
||||
|
||||
public async Task AddWhiteboard(Guid whiteboardId)
|
||||
{
|
||||
var getWhiteboardService = _scopeFactory.CreateScope().ServiceProvider.GetRequiredService<GetWhiteboardService>();
|
||||
var whiteboard = await getWhiteboardService.GetWhiteboard(whiteboardId);
|
||||
|
||||
_whiteboards[whiteboardId] = whiteboard;
|
||||
}
|
||||
|
||||
public bool WhiteboardExists(Guid whiteboardId)
|
||||
{
|
||||
return _whiteboards.ContainsKey(whiteboardId);
|
||||
}
|
||||
|
||||
public void RemoveWhiteboard(Guid whiteboardId)
|
||||
{
|
||||
_whiteboards.TryRemove(whiteboardId, out _);
|
||||
}
|
||||
|
||||
public Whiteboard? GetWhiteboard(Guid whiteboardId)
|
||||
{
|
||||
return _whiteboards.GetValueOrDefault(whiteboardId);
|
||||
}
|
||||
|
||||
public void AddUserToWhiteboard(Guid userId, Guid whiteboardId)
|
||||
{
|
||||
_userInWhiteboards[userId] = whiteboardId;
|
||||
}
|
||||
|
||||
public Guid GetUserWhiteboard(Guid userId)
|
||||
{
|
||||
return _userInWhiteboards[userId];
|
||||
}
|
||||
|
||||
public void RemoveUserFromWhiteboard(Guid userId, Guid whiteboardId)
|
||||
{
|
||||
_userInWhiteboards.TryRemove(whiteboardId, out _);
|
||||
}
|
||||
|
||||
public Whiteboard? GetWhiteboardForUser(Guid userId)
|
||||
{
|
||||
return GetWhiteboard(GetUserWhiteboard(userId));
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,25 @@
|
||||
using AipsCore.Infrastructure.DI;
|
||||
using AipsRT.Hubs;
|
||||
using AipsRT.Model.Whiteboard;
|
||||
using AipsRT.Services;
|
||||
using AipsRT.Services.Interfaces;
|
||||
using DotNetEnv;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
|
||||
Env.Load("../../.env");
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
builder.Configuration.AddEnvironmentVariables();
|
||||
|
||||
builder.Services.AddSignalR();
|
||||
|
||||
builder.Services.AddAips(builder.Configuration);
|
||||
|
||||
builder.Services.AddScoped<GetWhiteboardService>();
|
||||
builder.Services.AddSingleton<WhiteboardManager>();
|
||||
builder.Services.AddSingleton<IMessagingService, MessagingService>();
|
||||
|
||||
builder.Services.AddCors(options =>
|
||||
{
|
||||
options.AddPolicy("frontend",
|
||||
@@ -26,6 +41,11 @@ app.MapGet("/test", (IHubContext<TestHub> hubContext) =>
|
||||
});
|
||||
|
||||
app.UseCors("frontend");
|
||||
app.MapHub<TestHub>("/testhub");
|
||||
|
||||
app.UseAuthentication();
|
||||
app.UseAuthorization();
|
||||
|
||||
app.MapHub<TestHub>("/hubs/test");
|
||||
app.MapHub<WhiteboardHub>("/hubs/whiteboard");
|
||||
|
||||
app.Run();
|
||||
8
dotnet/AipsRT/Services/Interfaces/IMessagingService.cs
Normal file
8
dotnet/AipsRT/Services/Interfaces/IMessagingService.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
using AipsRT.Model.Whiteboard.Shapes;
|
||||
|
||||
namespace AipsRT.Services.Interfaces;
|
||||
|
||||
public interface IMessagingService
|
||||
{
|
||||
Task CreatedRectangle(Guid whiteboardId, Rectangle rectangle);
|
||||
}
|
||||
36
dotnet/AipsRT/Services/MessagingService.cs
Normal file
36
dotnet/AipsRT/Services/MessagingService.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using AipsCore.Application.Abstract.MessageBroking;
|
||||
using AipsCore.Application.Common.Message.AddRectangle;
|
||||
using AipsCore.Application.Models.Shape.Command.CreateRectangle;
|
||||
using AipsRT.Model.Whiteboard.Shapes;
|
||||
using AipsRT.Services.Interfaces;
|
||||
|
||||
namespace AipsRT.Services;
|
||||
|
||||
public class MessagingService : IMessagingService
|
||||
{
|
||||
private readonly IMessagePublisher _messagePublisher;
|
||||
|
||||
public MessagingService(IMessagePublisher messagePublisher)
|
||||
{
|
||||
_messagePublisher = messagePublisher;
|
||||
}
|
||||
|
||||
public async Task CreatedRectangle(Guid whiteboardId, Rectangle rectangle)
|
||||
{
|
||||
var command = new CreateRectangleCommand(
|
||||
rectangle.Id.ToString(),
|
||||
whiteboardId.ToString(),
|
||||
rectangle.OwnerId.ToString(),
|
||||
rectangle.Position.X,
|
||||
rectangle.Position.Y,
|
||||
rectangle.Color,
|
||||
rectangle.EndPosition.X,
|
||||
rectangle.EndPosition.Y,
|
||||
rectangle.BorderThickness
|
||||
);
|
||||
|
||||
var message = new AddRectangleMessage(command);
|
||||
|
||||
await _messagePublisher.PublishAsync(message);
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ using System.Reflection;
|
||||
using AipsCore.Application.Abstract;
|
||||
using AipsCore.Application.Abstract.MessageBroking;
|
||||
using AipsCore.Application.Common.Message.TestMessage;
|
||||
using AipsCore.Domain.Common.Validation;
|
||||
using AipsWorker.Utilities;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
|
||||
@@ -48,7 +49,26 @@ public class WorkerService : BackgroundService
|
||||
|
||||
private async Task HandleMessage<T>(T message, CancellationToken ct) where T : IMessage
|
||||
{
|
||||
await _dispatcher.Execute(message, ct);
|
||||
try
|
||||
{
|
||||
await _dispatcher.Execute(message, ct);
|
||||
|
||||
Console.WriteLine($"OK: {message.GetType().Name}");
|
||||
}
|
||||
catch (ValidationException validationException)
|
||||
{
|
||||
Console.WriteLine("===Validation Exception: ");
|
||||
foreach (var error in validationException.ValidationErrors)
|
||||
{
|
||||
Console.WriteLine(" * Code: " + error.Code);
|
||||
Console.WriteLine(" * Message: " + error.Message);
|
||||
Console.WriteLine("===================");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("Unhandled Exception: " + ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
private MethodInfo GetMessageHandleMethod(Type messageType)
|
||||
|
||||
Reference in New Issue
Block a user