From d3f8fd23f41c543f103262611c77b9a05a8582da Mon Sep 17 00:00:00 2001 From: Michele Date: Thu, 14 Jan 2021 23:34:24 +0000 Subject: [PATCH] backend --- Sledgemapper.Api/Commands/NewLineCommand.cs | 14 +++++++ Sledgemapper.Api/Commands/NewRoomCommand.cs | 14 +++++++ .../Controllers/SessionController.cs | 12 ++++++ .../Handlers/NewLineCommandHandler.cs | 39 ++++++++++++++++++ .../Handlers/NewNoteCommandHandler.cs | 39 ++++++++++++++++++ .../Handlers/NewRoomCommandHandler.cs | 39 ++++++++++++++++++ .../Handlers/NewWallCommandHandler.cs | 27 ------------ .../Handlers/SendNewLineMessage.cs | 22 ++++++++++ .../Handlers/SendNewNoteMessage.cs | 22 ++++++++++ .../Handlers/SendNewRoomMessage.cs | 22 ++++++++++ .../Handlers/SendNewWallMessage.cs | 12 ------ Sledgemapper.Api/Hubs/SledgemapperHub.cs | 18 ++++++-- .../Notifications/NewLineNotification.cs | 14 +++++++ .../Notifications/NewRoomNotification.cs | 14 +++++++ Sledgemapper.Api/db/LocalDatabase.db | Bin 0 -> 20480 bytes Sledgemapper.Api/db/sledgemapper.db | Bin 0 -> 40960 bytes .../Clients/ISledgemapperClient.cs | 2 + Sledgemapper.Shared/Entities/Session.cs | 4 +- Sledgemapper/CommunicationManager.cs | 20 ++++++++- Sledgemapper/IMapApi.cs | 6 +++ Sledgemapper/Sledgemapper.cs | 6 +-- 21 files changed, 297 insertions(+), 49 deletions(-) create mode 100644 Sledgemapper.Api/Commands/NewLineCommand.cs create mode 100644 Sledgemapper.Api/Commands/NewRoomCommand.cs create mode 100644 Sledgemapper.Api/Handlers/NewLineCommandHandler.cs create mode 100644 Sledgemapper.Api/Handlers/NewNoteCommandHandler.cs create mode 100644 Sledgemapper.Api/Handlers/NewRoomCommandHandler.cs create mode 100644 Sledgemapper.Api/Handlers/SendNewLineMessage.cs create mode 100644 Sledgemapper.Api/Handlers/SendNewNoteMessage.cs create mode 100644 Sledgemapper.Api/Handlers/SendNewRoomMessage.cs create mode 100644 Sledgemapper.Api/Notifications/NewLineNotification.cs create mode 100644 Sledgemapper.Api/Notifications/NewRoomNotification.cs create mode 100644 Sledgemapper.Api/db/LocalDatabase.db create mode 100644 Sledgemapper.Api/db/sledgemapper.db diff --git a/Sledgemapper.Api/Commands/NewLineCommand.cs b/Sledgemapper.Api/Commands/NewLineCommand.cs new file mode 100644 index 0000000..3bfe3cf --- /dev/null +++ b/Sledgemapper.Api/Commands/NewLineCommand.cs @@ -0,0 +1,14 @@ +using Sledgemapper.Shared.Entities; + +namespace Sledgemapper.Api.Commands +{ + public class NewLineCommand : BaseCommand + { + public Line Line { get; private set; } + + public NewLineCommand(string sessionName, Line line, int userId) : base(sessionName, userId) + { + Line = line; + } + } +} diff --git a/Sledgemapper.Api/Commands/NewRoomCommand.cs b/Sledgemapper.Api/Commands/NewRoomCommand.cs new file mode 100644 index 0000000..5b7619e --- /dev/null +++ b/Sledgemapper.Api/Commands/NewRoomCommand.cs @@ -0,0 +1,14 @@ +using Sledgemapper.Shared.Entities; + +namespace Sledgemapper.Api.Commands +{ + public class NewRoomCommand : BaseCommand + { + public Room Room { get; private set; } + + public NewRoomCommand(string sessionName, Room room, int userId) : base(sessionName, userId) + { + Room = room; + } + } +} diff --git a/Sledgemapper.Api/Controllers/SessionController.cs b/Sledgemapper.Api/Controllers/SessionController.cs index 0ab3e32..2638ac5 100644 --- a/Sledgemapper.Api/Controllers/SessionController.cs +++ b/Sledgemapper.Api/Controllers/SessionController.cs @@ -60,6 +60,18 @@ namespace Sledgemapper.Api.Controllers await _mediator.Send(new NewNoteCommand(sessionName, note, UserId)); } + [HttpPost("room")] + public async Task Post(string sessionName, [FromBody] Room room) + { + await _mediator.Send(new NewRoomCommand(sessionName, room, UserId)); + } + + [HttpPost("line")] + public async Task Post(string sessionName, [FromBody] Line line) + { + await _mediator.Send(new NewLineCommand(sessionName, line, UserId)); + } + [HttpDelete("tile")] public async Task Delete(string sessionName, [FromBody] Tile tile) { diff --git a/Sledgemapper.Api/Handlers/NewLineCommandHandler.cs b/Sledgemapper.Api/Handlers/NewLineCommandHandler.cs new file mode 100644 index 0000000..4901dae --- /dev/null +++ b/Sledgemapper.Api/Handlers/NewLineCommandHandler.cs @@ -0,0 +1,39 @@ +using MediatR; +using Sledgemapper.Api.Data; +using Sledgemapper.Shared.Entities; +using Sledgemapper.Api.Commands; +using System.Linq; +using System.Text.Json; +using System.Threading; +using System.Threading.Tasks; +using Sledgemapper.Api.Notifications; + +namespace Sledgemapper.Api.Handlers +{ + public class NewLineCommandHandler : IRequestHandler + { + private readonly MyDbContext _dbcontext; + + private readonly IMediator _mediator; + + public NewLineCommandHandler(IMediator mediator, MyDbContext dbcontext) { _dbcontext = dbcontext; _mediator = mediator; } + + public async Task Handle(NewLineCommand notification, CancellationToken cancellationToken) + { + var jsonString = JsonSerializer.Serialize(notification.Line); + var session = _dbcontext.Sessions.First(m => m.SessionName == notification.SessionName); + _dbcontext.MapLogs.Add(new Sledgemapper.Api.Models.MapLog + { + Operation = "N", + SessionId = session.SessionId, + Type = "L", + Timestamp = notification.Timestamp, + Object = jsonString, + UserId = notification.UserId, + }); + await _dbcontext.SaveChangesAsync(); + await _mediator.Publish(new NewLineNotification(session, notification.Line, notification.UserId)); + return true; + } + } +} diff --git a/Sledgemapper.Api/Handlers/NewNoteCommandHandler.cs b/Sledgemapper.Api/Handlers/NewNoteCommandHandler.cs new file mode 100644 index 0000000..5a50e45 --- /dev/null +++ b/Sledgemapper.Api/Handlers/NewNoteCommandHandler.cs @@ -0,0 +1,39 @@ +using MediatR; +using Sledgemapper.Api.Data; +using Sledgemapper.Shared.Entities; +using Sledgemapper.Api.Commands; +using Sledgemapper.Api.Notifications; +using System.Linq; +using System.Text.Json; +using System.Threading; +using System.Threading.Tasks; + +namespace Sledgemapper.Api.Handlers +{ + public class NewNoteCommandHandler : IRequestHandler + { + private readonly MyDbContext _dbcontext; + + private readonly IMediator _mediator; + + public NewNoteCommandHandler(IMediator mediator, MyDbContext dbcontext) { _dbcontext = dbcontext; _mediator = mediator; } + + public async Task Handle(NewNoteCommand notification, CancellationToken cancellationToken) + { + var jsonString = JsonSerializer.Serialize(notification.Note); + var session = _dbcontext.Sessions.First(m => m.SessionName == notification.SessionName); + _dbcontext.MapLogs.Add(new Sledgemapper.Api.Models.MapLog + { + Operation = "N", + SessionId = session.SessionId, + Type = "N", + Timestamp = notification.Timestamp, + Object = jsonString, + UserId = notification.UserId, + }); + await _dbcontext.SaveChangesAsync(); + await _mediator.Publish(new NewNoteNotification(session, notification.Note, notification.UserId)); + return true; + } + } +} diff --git a/Sledgemapper.Api/Handlers/NewRoomCommandHandler.cs b/Sledgemapper.Api/Handlers/NewRoomCommandHandler.cs new file mode 100644 index 0000000..73561a1 --- /dev/null +++ b/Sledgemapper.Api/Handlers/NewRoomCommandHandler.cs @@ -0,0 +1,39 @@ +using MediatR; +using Sledgemapper.Api.Data; +using Sledgemapper.Shared.Entities; +using Sledgemapper.Api.Commands; +using System.Linq; +using System.Text.Json; +using System.Threading; +using System.Threading.Tasks; +using Sledgemapper.Api.Notifications; + +namespace Sledgemapper.Api.Handlers +{ + public class NewRoomCommandHandler : IRequestHandler + { + private readonly MyDbContext _dbcontext; + + private readonly IMediator _mediator; + + public NewRoomCommandHandler(IMediator mediator, MyDbContext dbcontext) { _dbcontext = dbcontext; _mediator = mediator; } + + public async Task Handle(NewRoomCommand notification, CancellationToken cancellationToken) + { + var jsonString = JsonSerializer.Serialize(notification.Room); + var session = _dbcontext.Sessions.First(m => m.SessionName == notification.SessionName); + _dbcontext.MapLogs.Add(new Sledgemapper.Api.Models.MapLog + { + Operation = "N", + SessionId = session.SessionId, + Type = "R", + Timestamp = notification.Timestamp, + Object = jsonString, + UserId = notification.UserId, + }); + await _dbcontext.SaveChangesAsync(); + await _mediator.Publish(new NewRoomNotification(session, notification.Room, notification.UserId)); + return true; + } + } +} diff --git a/Sledgemapper.Api/Handlers/NewWallCommandHandler.cs b/Sledgemapper.Api/Handlers/NewWallCommandHandler.cs index a1a34ea..af69b69 100644 --- a/Sledgemapper.Api/Handlers/NewWallCommandHandler.cs +++ b/Sledgemapper.Api/Handlers/NewWallCommandHandler.cs @@ -36,31 +36,4 @@ namespace Sledgemapper.Api.Handlers return true; } } - - public class NewNoteCommandHandler : IRequestHandler - { - private readonly MyDbContext _dbcontext; - - private readonly IMediator _mediator; - - public NewNoteCommandHandler(IMediator mediator, MyDbContext dbcontext) { _dbcontext = dbcontext; _mediator = mediator; } - - public async Task Handle(NewNoteCommand notification, CancellationToken cancellationToken) - { - var jsonString = JsonSerializer.Serialize(notification.Note); - var session = _dbcontext.Sessions.First(m => m.SessionName == notification.SessionName); - _dbcontext.MapLogs.Add(new Sledgemapper.Api.Models.MapLog - { - Operation = "N", - SessionId = session.SessionId, - Type = "N", - Timestamp = notification.Timestamp, - Object = jsonString, - UserId = notification.UserId, - }); - await _dbcontext.SaveChangesAsync(); - await _mediator.Publish(new NewNoteNotification(session, notification.Note, notification.UserId)); - return true; - } - } } diff --git a/Sledgemapper.Api/Handlers/SendNewLineMessage.cs b/Sledgemapper.Api/Handlers/SendNewLineMessage.cs new file mode 100644 index 0000000..e0e9c86 --- /dev/null +++ b/Sledgemapper.Api/Handlers/SendNewLineMessage.cs @@ -0,0 +1,22 @@ +using MediatR; +using Microsoft.AspNetCore.SignalR; +using Sledgemapper.Api.Notifications; +using Sledgemapper.Clients; +using System.Threading; +using System.Threading.Tasks; +using Sledgemapper.Api.Hubs; + +namespace Sledgemapper.Api.Handlers +{ + public class SendNewLineMessage : INotificationHandler + { + private readonly IHubContext _hub; + + public SendNewLineMessage(IHubContext hub) => _hub = hub; + + public async Task Handle(NewLineNotification notification, CancellationToken cancellationToken) + { + await _hub.Clients.Groups(notification.Session.SessionName).NewLine(notification.Line); + } + } +} diff --git a/Sledgemapper.Api/Handlers/SendNewNoteMessage.cs b/Sledgemapper.Api/Handlers/SendNewNoteMessage.cs new file mode 100644 index 0000000..37e9f5a --- /dev/null +++ b/Sledgemapper.Api/Handlers/SendNewNoteMessage.cs @@ -0,0 +1,22 @@ +using MediatR; +using Microsoft.AspNetCore.SignalR; +using Sledgemapper.Api.Notifications; +using Sledgemapper.Clients; +using System.Threading; +using System.Threading.Tasks; +using Sledgemapper.Api.Hubs; + +namespace Sledgemapper.Api.Handlers +{ + public class SendNewNoteMessage : INotificationHandler + { + private readonly IHubContext _hub; + + public SendNewNoteMessage(IHubContext hub) => _hub = hub; + + public async Task Handle(NewNoteNotification notification, CancellationToken cancellationToken) + { + await _hub.Clients.Groups(notification.Session.SessionName).NewNote(notification.Note); + } + } +} diff --git a/Sledgemapper.Api/Handlers/SendNewRoomMessage.cs b/Sledgemapper.Api/Handlers/SendNewRoomMessage.cs new file mode 100644 index 0000000..adbf4ec --- /dev/null +++ b/Sledgemapper.Api/Handlers/SendNewRoomMessage.cs @@ -0,0 +1,22 @@ +using MediatR; +using Microsoft.AspNetCore.SignalR; +using Sledgemapper.Api.Notifications; +using Sledgemapper.Clients; +using System.Threading; +using System.Threading.Tasks; +using Sledgemapper.Api.Hubs; + +namespace Sledgemapper.Api.Handlers +{ + public class SendNewRoomMessage : INotificationHandler + { + private readonly IHubContext _hub; + + public SendNewRoomMessage(IHubContext hub) => _hub = hub; + + public async Task Handle(NewRoomNotification notification, CancellationToken cancellationToken) + { + await _hub.Clients.Groups(notification.Session.SessionName).NewRoom(notification.Room); + } + } +} diff --git a/Sledgemapper.Api/Handlers/SendNewWallMessage.cs b/Sledgemapper.Api/Handlers/SendNewWallMessage.cs index 699ff55..34d5567 100644 --- a/Sledgemapper.Api/Handlers/SendNewWallMessage.cs +++ b/Sledgemapper.Api/Handlers/SendNewWallMessage.cs @@ -19,16 +19,4 @@ namespace Sledgemapper.Api.Handlers await _hub.Clients.Groups(notification.Session.SessionName).NewWall(notification.Wall); } } - - public class SendNewNoteMessage : INotificationHandler - { - private readonly IHubContext _hub; - - public SendNewNoteMessage(IHubContext hub) => _hub = hub; - - public async Task Handle(NewNoteNotification notification, CancellationToken cancellationToken) - { - await _hub.Clients.Groups(notification.Session.SessionName).NewNote(notification.Note); - } - } } diff --git a/Sledgemapper.Api/Hubs/SledgemapperHub.cs b/Sledgemapper.Api/Hubs/SledgemapperHub.cs index 5cb91cd..c356461 100644 --- a/Sledgemapper.Api/Hubs/SledgemapperHub.cs +++ b/Sledgemapper.Api/Hubs/SledgemapperHub.cs @@ -46,6 +46,16 @@ namespace Sledgemapper.Api.Hubs await Clients.Group(sessionName).NewTile(tile); } + public async Task NewRoom(string sessionName, Room room) + { + await Clients.Group(sessionName).NewRoom(room); + } + + public async Task NewLine(string sessionName, Line line) + { + await Clients.Group(sessionName).NewLine(line); + } + public async Task NewWall(string sessionName, Wall tile) { await Clients.Group(sessionName).NewWall(tile); @@ -113,7 +123,7 @@ namespace Sledgemapper.Api.Hubs var userId = int.Parse(Context.User.Identity.Name); var SessionUsers = _dbContext.SessionUsers.Where(m => m.SessionId == sessionId).OrderBy(m => m.UserId).ToList(); var user = _datacontext.Users.First(u => u.Id == userId); - var player = new Player { UserId = userId, Initials = user.Initials, Position = tile, Color = UserColors[userId]}; + var player = new Player { UserId = userId, Initials = user.Initials, Position = tile, Color = UserColors[userId] }; await Clients.Group(sessionName).PlayerUpdate(player); } @@ -131,7 +141,7 @@ namespace Sledgemapper.Api.Hubs public override async Task OnDisconnectedAsync(Exception exception) { var userConnection = _dbContext.UserConnections.FirstOrDefault(m => m.ConnectionId == Context.ConnectionId); - var userId=userConnection.UserId; + var userId = userConnection.UserId; if (userConnection != null) { _dbContext.UserConnections.Remove(userConnection); @@ -142,8 +152,8 @@ namespace Sledgemapper.Api.Hubs foreach (var userSession in userSessions) { var session = _dbContext.Sessions.FirstOrDefault(m => m.SessionId == userSession.SessionId); - - await Clients.Group(session.SessionName).RemovePlayer(new Player{UserId=userId}); //send remove player + + await Clients.Group(session.SessionName).RemovePlayer(new Player { UserId = userId }); //send remove player _dbContext.SessionUsers.Remove(userSession); } } diff --git a/Sledgemapper.Api/Notifications/NewLineNotification.cs b/Sledgemapper.Api/Notifications/NewLineNotification.cs new file mode 100644 index 0000000..25c3005 --- /dev/null +++ b/Sledgemapper.Api/Notifications/NewLineNotification.cs @@ -0,0 +1,14 @@ +using Sledgemapper.Shared.Entities; + +namespace Sledgemapper.Api.Notifications +{ + public class NewLineNotification : BaseNotification + { + public Line Line { get; private set; } + + public NewLineNotification(Models.Session session, Line line, int userId) : base(session, userId) + { + Line = line; + } + } +} diff --git a/Sledgemapper.Api/Notifications/NewRoomNotification.cs b/Sledgemapper.Api/Notifications/NewRoomNotification.cs new file mode 100644 index 0000000..d83e27d --- /dev/null +++ b/Sledgemapper.Api/Notifications/NewRoomNotification.cs @@ -0,0 +1,14 @@ +using Sledgemapper.Shared.Entities; + +namespace Sledgemapper.Api.Notifications +{ + public class NewRoomNotification : BaseNotification + { + public Room Room { get; private set; } + + public NewRoomNotification(Models.Session session, Room room, int userId) : base(session, userId) + { + Room = room; + } + } +} diff --git a/Sledgemapper.Api/db/LocalDatabase.db b/Sledgemapper.Api/db/LocalDatabase.db new file mode 100644 index 0000000000000000000000000000000000000000..22b8623b6d6a4c96d001c3bfc7c6179d7a5b57f0 GIT binary patch literal 20480 zcmeI)e@qis902gUwpbw6G88Xcw(@8Maj>qS{8%i^(i~9f4{Wd4u4s4AZmX15?v4pM zw-lK%OBPLF8`;J-9a(U=urLxM3E7x4n}S(1Dsd_qb90FXl|N*zD(tm@A}RaBzvlA& z=H2z(d-uL~?{n=RcWr9jVDJha^h$uMWd*dFNFYQaVjV&RL5T4ZgO}M5;fiE-1HY1U z>I+rHgsP-dCcjNcWE+Vkr{!PC4&n*~2!H?xfB*=900@8p2!H?x{C@<>C5xzx4ALR6 zRXz`2=fn3{F5XjD@9|g9-;B{&Xe~n{Mq6Z{(Y$@r{cNo#6OUZglqQx^6h$^?L~`1A z564GVl844CBW+5QE{jJvlzO)k=}in>LR*l@%pjA^U_d&v$;w!?xE(3W%Um-<$}M`M z*5W{Av;%2vj9G8OnT@oG$(+em?B#gDgilC`7}`FaYqrn8F4z@LAD%{(QF^~u@UlKW zN>@3{^Vg9z1*BG@?^e|-9eICHx&lwh;=2(Dtfkbn-?@x*gxa+Hh3Vdnt$<9lQr=}Mz zqBiA`gxBx(G|aqH*m@xl*>*)ejw>r_bNJpqHvDmu;f0j{Lf`@c0w4eaAOHd&00JNY z0w4eaAOHd&@Yo5gAjLG5t> znJW9z%HH?3JngS(sp(fJa<{noi5scs4FD9m*zOsz9#jPKHr?%zNuyJEw@apbdbJFkr$9HNdQZZn z^mTpFXziK){r@dOe(RAgFbo0#5C8!X009sH0T2KI5C8!X009vAuL{JGVv3CX>x1YY D*?GHv literal 0 HcmV?d00001 diff --git a/Sledgemapper.Api/db/sledgemapper.db b/Sledgemapper.Api/db/sledgemapper.db new file mode 100644 index 0000000000000000000000000000000000000000..3991092d72fb7e356729169aaf303d3ec6fc53b3 GIT binary patch literal 40960 zcmeI*%}?8A90zdQ2?VDN-dh(ThGsn+)`+Mg2}ww%N#!L%5y5%a!gfHWF)b`OAu*+> z+JVr+{(wpQ2X@$f(k>H+oqF3eP5T3S+Hr?UZKYlI_>DL(RHRg@6uwpn_T%{Xdww53 z56HwoF`wDh6mh5C+?O>m!o0_D9CKF`8HVBLhnIfX%LH9<+Z*&V>sY^Nm1FL#{p6#2 zd47kPJe&N+_ruMfZ~W%{-Mh&@qfJ;K009U<00Izzz=#SQ^B(^f0rq5SSFI|K(v_`p zOKGmuRaLpC?bcOeGhOX&^sW?AOQn>UmR3_0kz8~T5wns=x(_AdZKEY!C4q+%H1(__ zbx~=xXioizEo(hpbu{vQc^x}DN0@mXyY!^z@kpTM@%R(d?8&Eg$<{tQf+X)NR?~!) zu`H$YWoN+y4(UqkNU4V-fs@9##~%o=r_-9eT~oSMy0<)5($dm$CN%)i=N0MF14}{a z`6#8 zk1@}>2cdn+vPY`Yd`(R`ZrndN$8H)GwGL|Zx^t_g92_d@J*8*U)m357&f6-T>p^;C zpnaG1_@}1WCtn*eH{?d9e&2lNx*`y>u|s5TUq;A2^2*crGBcu~G-dr8!bOwfxS?FI z>rE$QmAX@NwSTP};`)<70YL0Kpc%|)Mw$`zUqC1UY`EFmMT$r8Ov*tf)Dbk#hAy2~%G+V69g zi*HQI^bZ%a0P`HsGKO)9heM%6c;PiJCijrT#RwaTSz*82t!fWQ(%H=+hYF1so{vV) z$IADgv_EDo6aT=mVkUc|&c_z!6Z2s+S??4w!yx$u0%N<=vjfB*y_009U<00Izz00bZafom?{ z<9RCJ;o0-+|7#9{@*w~L2tWV=5P$##AOHafKmY;K@775-!B0}BKo009U<00Izz00bZa0SG_<0;4D3b_u+!U;i8L z|GyMoj$VnV2m%m*00bZa0SG_<0uX=z1R!wT1$gsc1?UX=-~W4oI{>cxh(P@ifB*y_ Y009U<00Izz00bZ~f&yOs@_&r`AANmh#{d8T literal 0 HcmV?d00001 diff --git a/Sledgemapper.Shared/Clients/ISledgemapperClient.cs b/Sledgemapper.Shared/Clients/ISledgemapperClient.cs index 2b51308..a1ec349 100644 --- a/Sledgemapper.Shared/Clients/ISledgemapperClient.cs +++ b/Sledgemapper.Shared/Clients/ISledgemapperClient.cs @@ -9,6 +9,7 @@ namespace Sledgemapper.Clients Task NewWall(Wall wall); Task NewOverlay(Overlay overlay); Task NewNote(Note note); + Task NewRoom(Room room); Task DeleteTile(Tile tile); Task DeleteNote(Note note); Task DeleteWall(Wall wall); @@ -18,5 +19,6 @@ namespace Sledgemapper.Clients Task RemovePlayer(Player player); Task UpdateMap(Session player); Task RefreshPlayers(); + Task NewLine(Line line); } } diff --git a/Sledgemapper.Shared/Entities/Session.cs b/Sledgemapper.Shared/Entities/Session.cs index 00b6a0a..f9db985 100644 --- a/Sledgemapper.Shared/Entities/Session.cs +++ b/Sledgemapper.Shared/Entities/Session.cs @@ -201,7 +201,7 @@ namespace Sledgemapper.Shared.Entities Lines.TryAdd(newLine.ToString(), newLine); //TODO fix this - //OnRaiseMapEntityAddedEvent(new MapEntityAddedEventArgs(newTile)); + OnRaiseMapEntityAddedEvent(new MapEntityAddedEventArgs(newLine)); } public void NewRoom(Room line) @@ -221,7 +221,7 @@ namespace Sledgemapper.Shared.Entities Rooms.TryAdd(newLine.ToString(), newLine); //TODO fix this - //OnRaiseMapEntityAddedEvent(new MapEntityAddedEventArgs(newTile)); + OnRaiseMapEntityAddedEvent(new MapEntityAddedEventArgs(newLine)); } } } diff --git a/Sledgemapper/CommunicationManager.cs b/Sledgemapper/CommunicationManager.cs index a48e326..0fc37b6 100644 --- a/Sledgemapper/CommunicationManager.cs +++ b/Sledgemapper/CommunicationManager.cs @@ -95,6 +95,18 @@ namespace Sledgemapper SessionData.Map.TryAdd(tile.ToString(), tile); }); + Connection.On("NewRoom", (room) => + { + SessionData.Rooms.Remove(room.ToString(), out var _); + SessionData.Rooms.TryAdd(room.ToString(), room); + }); + + Connection.On("NewLine", (line) => + { + SessionData.Lines.Remove(line.ToString(), out var _); + SessionData.Lines.TryAdd(line.ToString(), line); + }); + Connection.On("RefreshPlayers", () => { if (!string.IsNullOrWhiteSpace(SessionData.SessionName)) @@ -166,7 +178,7 @@ namespace Sledgemapper { await Policy .Handle(ex => ex.StatusCode == HttpStatusCode.RequestTimeout) - + .RetryForeverAsync() //.RetryAsync(Polly.RetrySyntax., async (exception, retryCount) => await Task.Delay(500)) .ExecuteAsync(async () => await call().ConfigureAwait(false)) @@ -192,6 +204,12 @@ namespace Sledgemapper case Note note: Queue.Enqueue(async () => await Execute(async () => await Api.NewNote(note, SessionData.SessionName).ConfigureAwait(false))); break; + case Room room: + Queue.Enqueue(async () => await Execute(async () => await Api.NewRoom(room, SessionData.SessionName).ConfigureAwait(false))); + break; + case Line line: + Queue.Enqueue(async () => await Execute(async () => await Api.NewLine(line, SessionData.SessionName).ConfigureAwait(false))); + break; } break; diff --git a/Sledgemapper/IMapApi.cs b/Sledgemapper/IMapApi.cs index 5b0ebc5..a68b3cd 100644 --- a/Sledgemapper/IMapApi.cs +++ b/Sledgemapper/IMapApi.cs @@ -49,5 +49,11 @@ namespace Sledgemapper [Headers("Authorization")] [Post("/users/authenticate")] Task Authenticate([Body] AuthenticateModel registerModel); + + [Post("/session/{sessionName}/room")] + Task NewRoom(Room room, string sessionName); + + [Post("/session/{sessionName}/line")] + Task NewLine(Line line, string sessionName); } } \ No newline at end of file diff --git a/Sledgemapper/Sledgemapper.cs b/Sledgemapper/Sledgemapper.cs index de1f0d0..6d47a63 100644 --- a/Sledgemapper/Sledgemapper.cs +++ b/Sledgemapper/Sledgemapper.cs @@ -607,9 +607,9 @@ namespace Sledgemapper GraphicsDevice.SetRenderTarget(null); - Vector2 texelSize = new Vector2((float)(1 / (double)rendertarget.Width), (float)(1 / (double)rendertarget.Height)); - outlineShader.Parameters["TexelSize"].SetValue(texelSize); - outlineShader.Parameters["BorderSize"].SetValue((int)(_state.TileSize / 100f *20f)); + Vector2 texelSize = new Vector2((float)rendertarget.Width, (float)rendertarget.Height); + outlineShader.Parameters["ImageSize"].SetValue(texelSize); + //outlineShader.Parameters["BorderSize"].SetValue((int)(_state.TileSize / 100f *10f)); outlineShader.Parameters["R"].SetValue(_settings.OverlayTintColor.R / 255.0f); outlineShader.Parameters["G"].SetValue(_settings.OverlayTintColor.G / 255.0f);