really good progress, need to fix tile upload

This commit is contained in:
Michele Scandura 2020-11-17 00:01:21 +00:00
parent 573e9ea7bf
commit 9ef43bb9f6
25 changed files with 280 additions and 112 deletions

View file

@ -0,0 +1,107 @@
using System.Transactions;
using System.Net.Mail;
using MediatR;
using Sledgemapper.Api.Data;
using Sledgemapper.Shared.Entities;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using Sledgemapper.Api.Handlers;
using System.Linq;
using Sledgemapper.Api.Models;
namespace Sledgemapper.Api.Commands
{
public class GetMapSnapshotCommand : IRequest<Sledgemapper.Shared.Entities.Session>
{
public string SessionName { get; private set; }
public GetMapSnapshotCommand(string sessionName)
{
SessionName = sessionName;
}
}
public class GetMapSnapshotCommandHandler : IRequestHandler<GetMapSnapshotCommand, Sledgemapper.Shared.Entities.Session>
{
private readonly MyDbContext _dbcontext;
private readonly IMediator _mediator;
public GetMapSnapshotCommandHandler(IMediator mediator, MyDbContext dbcontext) { _dbcontext = dbcontext; _mediator = mediator; }
public async Task<Sledgemapper.Shared.Entities.Session> Handle(GetMapSnapshotCommand notification, CancellationToken cancellationToken)
{
Snapshot snapshot;
double timestamp;
Sledgemapper.Shared.Entities.Session mapSession;
var session = _dbcontext.Sessions.First(m => m.SessionName == notification.SessionName);
snapshot = _dbcontext.Snapshots.FirstOrDefault(m => m.SessionId == session.SessionId);
if (snapshot is null)
{
timestamp = 0;
mapSession = new Shared.Entities.Session();
}
else
{
mapSession = JsonSerializer.Deserialize<Sledgemapper.Shared.Entities.Session>(snapshot.Object);
timestamp = snapshot.Timestamp;
}
var mapUpdates = _dbcontext.MapLogs.Where(m => m.SessionId == session.SessionId && m.Timestamp > timestamp).OrderBy(m => m.Timestamp).ToList();
foreach (var mapUpdate in mapUpdates)
{
if (mapUpdate.Operation == "N")
{
switch (mapUpdate.Type)
{
case "T":
var tile = JsonSerializer.Deserialize<Tile>(mapUpdate.Object);
mapSession.NewTile(tile, tile.ID);
break;
case "W":
var wall = JsonSerializer.Deserialize<Wall>(mapUpdate.Object);
mapSession.NewWall(wall, wall.ID);
break;
case "O":
var overlay = JsonSerializer.Deserialize<Overlay>(mapUpdate.Object);
mapSession.NewOverlay(overlay, overlay.ID);
break;
}
}
else if (mapUpdate.Operation == "D")
{
switch (mapUpdate.Type)
{
case "T":
var tile = JsonSerializer.Deserialize<Tile>(mapUpdate.Object);
mapSession.DeleteTile(tile);
break;
case "W":
var wall = JsonSerializer.Deserialize<Wall>(mapUpdate.Object);
mapSession.DeleteWall(wall);
break;
case "O":
var overlay = JsonSerializer.Deserialize<Overlay>(mapUpdate.Object);
mapSession.DeleteOverlay(overlay);
break;
}
}
}
var newSnapshot = new Snapshot{
SessionId=session.SessionId,
Timestamp=mapUpdates.Max(mapSession=>mapSession.Timestamp),
Object = JsonSerializer.Serialize<Sledgemapper.Shared.Entities.Session>(mapSession)
};
await _dbcontext.Snapshots.AddAsync(newSnapshot);
await _dbcontext.SaveChangesAsync();
return mapSession;
}
}
}

View file

@ -7,38 +7,42 @@ using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using Sledgemapper.Api.Handlers;
using System.Linq;
namespace Sledgemapper.Api.Commands
{
public class SaveNewTileCommand:BaseCommand<bool>
{
public Tile Tile {get;set;}
public SaveNewTileCommand(string sessionName, Tile tile, int userId):base(sessionName, userId){
Tile=tile;
public class SaveNewTileCommand : BaseCommand<bool>
{
public Tile Tile { get; set; }
public SaveNewTileCommand(string sessionName, Tile tile, int userId) : base(sessionName, userId)
{
Tile = tile;
}
}
}
public class SaveNewTileCommandHandler : IRequestHandler<SaveNewTileCommand, bool>
{
private readonly MyDbContext _dbcontext;
private readonly IMediator _mediator;
private readonly IMediator _mediator;
public SaveNewTileCommandHandler(IMediator mediator, MyDbContext dbcontext){ _dbcontext = dbcontext; _mediator= mediator;}
public SaveNewTileCommandHandler(IMediator mediator, MyDbContext dbcontext) { _dbcontext = dbcontext; _mediator = mediator; }
public async Task<bool> Handle(SaveNewTileCommand notification, CancellationToken cancellationToken)
{
var jsonString = JsonSerializer.Serialize<Tile>(notification.Tile);
var session = _dbcontext.Sessions.First(m => m.SessionName == notification.SessionName);
_dbcontext.MapLogs.Add(new Sledgemapper.Api.Models.MapLog
{
Operation = "N",
SessionName = notification.SessionName,
SessionId = session.SessionId,
Type = "T",
Timestamp = notification.Timestamp,
Object = jsonString
Object = jsonString,
UserId = notification.UserId
});
await _dbcontext.SaveChangesAsync();
await _mediator.Publish(new NewTileNotification(notification.SessionName, notification.Tile));
await _mediator.Publish(new NewTileNotification(notification.SessionName, notification.Tile, notification.UserId));
return true;
}

View file

@ -25,41 +25,53 @@ namespace Sledgemapper.Api.Controllers
return result;
}
[HttpGet]
public async Task<Session> Get(string sessionName)
{
var userId = int.Parse(HttpContext.User.Identity.Name);
var result = await _mediator.Send(new GetMapSnapshotCommand(sessionName));
return result;
}
[HttpPost("tile")]
public async Task Post(string sessionName, [FromBody] Tile tile)
{
var userId = int.Parse(HttpContext.User.Identity.Name);
await _mediator.Send(new SaveNewTileCommand(sessionName, tile, userId));
}
await _mediator.Send(new SaveNewTileCommand(sessionName, tile, userId)); }
[HttpPost("overlay")]
public async Task Post(string sessionName, [FromBody] Overlay overlay)
{
await _mediator.Publish(new NewOverlayNotification(sessionName, overlay));
var userId = int.Parse(HttpContext.User.Identity.Name);
await _mediator.Publish(new NewOverlayNotification(sessionName, overlay,userId));
}
[HttpPost("wall")]
public async Task Post(string sessionName, [FromBody] Wall wall)
{
await _mediator.Publish(new NewWallNotification(sessionName, wall));
var userId = int.Parse(HttpContext.User.Identity.Name);
await _mediator.Publish(new NewWallNotification(sessionName, wall,userId));
}
[HttpDelete("tile")]
public async Task Delete(string sessionName, [FromBody] Tile tile)
{
await _mediator.Publish(new DeleteTileNotification(sessionName, tile));
var userId = int.Parse(HttpContext.User.Identity.Name);
await _mediator.Publish(new DeleteTileNotification(sessionName, tile,userId));
}
[HttpDelete("overlay")]
public async Task Delete(string sessionName, [FromBody] Overlay overlay)
{
await _mediator.Publish(new DeleteOverlayNotification(sessionName, overlay));
var userId = int.Parse(HttpContext.User.Identity.Name);
await _mediator.Publish(new DeleteOverlayNotification(sessionName, overlay,userId));
}
[HttpDelete("wall")]
public async Task Delete(string sessionName, [FromBody] Wall wall)
{
await _mediator.Publish(new DeleteWallNotification(sessionName, wall));
var userId = int.Parse(HttpContext.User.Identity.Name);
await _mediator.Publish(new DeleteWallNotification(sessionName, wall,userId));
}

View file

@ -19,6 +19,7 @@ namespace Sledgemapper.Api.Data
public DbSet<Session> Sessions { get; set; }
public DbSet<UserConnection> UserConnections { get; set; }
public DbSet<SessionUser> SessionUsers { get; set; }
public DbSet<Snapshot> Snapshots { get; set; }
public MyDbContext(DbContextOptions options) : base(options)
{
@ -67,6 +68,12 @@ namespace Sledgemapper.Api.Data
entity.HasKey(e => e.SessionUserId);
});
modelBuilder.Entity<Snapshot>().ToTable("Snapshot", "dbo");
modelBuilder.Entity<Snapshot>(entity =>
{
entity.HasKey(e => e.SnapshotId);
});
base.OnModelCreating(modelBuilder);
}
}

View file

@ -1,6 +1,7 @@
using MediatR;
using Sledgemapper.Api.Data;
using Sledgemapper.Shared.Entities;
using System.Linq;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
@ -16,14 +17,16 @@ namespace Sledgemapper.Api.Handlers
public async Task Handle(DeleteOverlayNotification notification, CancellationToken cancellationToken)
{
var jsonString = JsonSerializer.Serialize<Overlay>(notification.Overlay);
var session = _dbcontext.Sessions.First(m=>m.SessionName== notification.SessionName);
_dbcontext.MapLogs.Add(new Sledgemapper.Api.Models.MapLog
{
Operation = "D",
SessionName = notification.SessionName,
SessionId = session.SessionId,
Type = "O",
Timestamp = notification.Timestamp,
Object = jsonString
Object = jsonString,
UserId=notification.UserId
});
await _dbcontext.SaveChangesAsync();

View file

@ -1,6 +1,7 @@
using MediatR;
using Sledgemapper.Api.Data;
using Sledgemapper.Shared.Entities;
using System.Linq;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
@ -16,14 +17,16 @@ namespace Sledgemapper.Api.Handlers
public async Task Handle(DeleteTileNotification notification, CancellationToken cancellationToken)
{
var jsonString = JsonSerializer.Serialize<Tile>(notification.Tile);
var session = _dbcontext.Sessions.First(m=>m.SessionName== notification.SessionName);
_dbcontext.MapLogs.Add(new Sledgemapper.Api.Models.MapLog
{
Operation = "D",
SessionName = notification.SessionName,
SessionId = session.SessionId,
Type = "T",
Timestamp = notification.Timestamp,
Object = jsonString
Object = jsonString,
UserId = notification.UserId
});
await _dbcontext.SaveChangesAsync();
}

View file

@ -20,14 +20,16 @@ namespace Sledgemapper.Api.Handlers
public async Task Handle(DeleteWallNotification notification, CancellationToken cancellationToken)
{
var jsonString = JsonSerializer.Serialize<Wall>(notification.Wall);
var session = _dbcontext.Sessions.First(m => m.SessionName == notification.SessionName);
_dbcontext.MapLogs.Add(new Sledgemapper.Api.Models.MapLog
{
Operation = "D",
SessionName = notification.SessionName,
SessionId = session.SessionId,
Type = "W",
Timestamp = notification.Timestamp,
Object = jsonString
Object = jsonString,
UserId = notification.UserId
});
await _dbcontext.SaveChangesAsync();
}

View file

@ -1,6 +1,7 @@
using MediatR;
using Sledgemapper.Api.Data;
using Sledgemapper.Shared.Entities;
using System.Linq;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
@ -16,14 +17,16 @@ namespace Sledgemapper.Api.Handlers
public async Task Handle(NewOverlayNotification notification, CancellationToken cancellationToken)
{
var jsonString = JsonSerializer.Serialize<Overlay>(notification.Overlay);
var session = _dbcontext.Sessions.First(m=>m.SessionName== notification.SessionName);
_dbcontext.MapLogs.Add(new Sledgemapper.Api.Models.MapLog
{
Operation = "N",
SessionName = notification.SessionName,
SessionId = session.SessionId,
Type = "O",
Timestamp = notification.Timestamp,
Object = jsonString
Object = jsonString,
UserId = notification.UserId
});
await _dbcontext.SaveChangesAsync();

View file

@ -1,31 +1,34 @@
using MediatR;
using Sledgemapper.Api.Data;
using Sledgemapper.Shared.Entities;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
// using MediatR;
// using Sledgemapper.Api.Data;
// using Sledgemapper.Shared.Entities;
// using System.Linq;
// using System.Text.Json;
// using System.Threading;
// using System.Threading.Tasks;
namespace Sledgemapper.Api.Handlers
{
public class SaveNewTile : INotificationHandler<NewTileNotification>
{
private readonly MyDbContext _dbcontext;
// namespace Sledgemapper.Api.Handlers
// {
// public class SaveNewTile : INotificationHandler<NewTileNotification>
// {
// private readonly MyDbContext _dbcontext;
public SaveNewTile(MyDbContext dbcontext) => _dbcontext = dbcontext;
// public SaveNewTile(MyDbContext dbcontext) => _dbcontext = dbcontext;
public async Task Handle(NewTileNotification notification, CancellationToken cancellationToken)
{
var jsonString = JsonSerializer.Serialize<Tile>(notification.Tile);
// public async Task Handle(NewTileNotification notification, CancellationToken cancellationToken)
// {
// var jsonString = JsonSerializer.Serialize<Tile>(notification.Tile);
// var session = _dbcontext.Sessions.First(m=>m.SessionName== notification.SessionName);
_dbcontext.MapLogs.Add(new Sledgemapper.Api.Models.MapLog
{
Operation = "N",
SessionName = notification.SessionName,
Type = "T",
Timestamp = notification.Timestamp,
Object = jsonString
});
await _dbcontext.SaveChangesAsync();
}
}
}
// _dbcontext.MapLogs.Add(new Sledgemapper.Api.Models.MapLog
// {
// Operation = "N",
// SessionId = session.SessionId,
// Type = "T",
// Timestamp = notification.Timestamp,
// Object = jsonString,
// UserId=notification.UserId
// });
// await _dbcontext.SaveChangesAsync();
// }
// }
// }

View file

@ -1,6 +1,7 @@
using MediatR;
using Sledgemapper.Api.Data;
using Sledgemapper.Shared.Entities;
using System.Linq;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
@ -16,14 +17,15 @@ namespace Sledgemapper.Api.Handlers
public async Task Handle(NewWallNotification notification, CancellationToken cancellationToken)
{
var jsonString = JsonSerializer.Serialize<Wall>(notification.Wall);
var session = _dbcontext.Sessions.First(m=>m.SessionName== notification.SessionName);
_dbcontext.MapLogs.Add(new Sledgemapper.Api.Models.MapLog
{
Operation = "N",
SessionName = notification.SessionName,
SessionId = session.SessionId,
Type = "W",
Timestamp = notification.Timestamp,
Object = jsonString
Object = jsonString,
UserId = notification.UserId,
});
await _dbcontext.SaveChangesAsync();
}

View file

@ -34,15 +34,15 @@ namespace SignalRChat.Hubs
// other colors
// #cca300, #20f200, #004011, #00e6d6, #005c73, #0057d9, #d900ca, #660029, #d9003a
// private static Dictionary<string, Session> _sessions = new Dictionary<string, Session>();
public List<string> Colors = new List<string>{"CC0000",
"CC3300",
"FFCC00",
"009900",
"006666",
"0066FF",
"0000CC",
"663399",
"CC0099"};
public List<string> Colors = new List<string>{
"#CC0000",
"#20f200",
"#FFCC00",
"#006666",
"#660029",
"#0000CC",
"#663399",
"#CC0099"};
public async Task NewTile(string sessionName, Tile tile)
{
@ -140,7 +140,7 @@ namespace SignalRChat.Hubs
// return session;
// }
public async Task<Sledgemapper.Shared.Entities.Session> JoinSession(string sessionName, string initials)
public async Task<Sledgemapper.Shared.Entities.Session> JoinSession(string sessionName)
{
var session = _dbContext.Sessions.FirstOrDefault(s => s.SessionName == sessionName);
var userId = int.Parse(Context.User.Identity.Name);
@ -151,25 +151,30 @@ namespace SignalRChat.Hubs
var userSession = new SessionUser { SessionId = session.SessionId, UserId = userId };
_dbContext.SessionUsers.Add(userSession);
await _dbContext.SaveChangesAsync();
var usersSession = _dbContext.SessionUsers.Where(m => m.SessionId == session.SessionId).Select(m => m.UserId).ToList();
var players = _datacontext.
Users.
Where(m => usersSession.Contains(m.Id)).ToList().
//Select((r, index) => new { Place = index, Name = r })
Select((p, index) => new Player
{
Initials = p.Initials,
UserId = userId,
Color = Colors[index],
Position = new Tile { X = 0, Y = 0 }
}).ToList();
// var players = _datacontext.
// Users.
// Where(m => usersSession.Contains(m.Id)).ToList().
// //Select((r, index) => new { Place = index, Name = r })
// Select((p, index) => new Player
// {
// Initials = p.Initials,
// UserId = userId,
// Color = Colors[index],
// Position = new Tile { X = 0, Y = 0 }
// }).ToList();
await _dbContext.SaveChangesAsync();
await Groups.AddToGroupAsync(Context.ConnectionId, sessionName);
var user = _datacontext.Users.First(u => u.Id == userId);
var SessionUsers = _dbContext.SessionUsers.Where(m => m.SessionId == session.SessionId).OrderBy(m => m.UserId).ToList();
var player = new Player { UserId = userId, Initials = user.Initials, Position = new Tile { X = 0, Y = 0 }, Color = Colors[SessionUsers.IndexOf(SessionUsers.FirstOrDefault(m => m.UserId == userId))] };
await Clients.Group(sessionName).NewPlayer(player);
var newSession = new Sledgemapper.Shared.Entities.Session
{
Players = players,
SessionName = sessionName
};
@ -196,12 +201,12 @@ namespace SignalRChat.Hubs
public async Task UpdatePosition(string sessionName, Tile tile)
{
// var userId = int.Parse(Context.User.Identity.Name);
// var session = _dbContext.Sessions.FirstOrDefault(m => m.SessionName == sessionName);
// var player = _sessions[sessionName].Players.First(m => m.ConnectionId == Context.ConnectionId);
// player.Position = tile;
// await Clients.Group(sessionName).PlayerUpdate(player);
var userId = int.Parse(Context.User.Identity.Name);
var session = _dbContext.Sessions.FirstOrDefault(m => m.SessionName == sessionName);
var SessionUsers = _dbContext.SessionUsers.Where(m => m.SessionId == session.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 = Colors[SessionUsers.IndexOf(SessionUsers.FirstOrDefault(m => m.UserId == userId))] };
await Clients.Group(sessionName).PlayerUpdate(player);
}
// public async Task<Session> Refresh(string sessionName)
@ -243,7 +248,7 @@ namespace SignalRChat.Hubs
{
var session = _dbContext.Sessions.FirstOrDefault(m => m.SessionId == userSession.SessionId);
await Clients.Group(session.SessionName).PlayerUpdate(null); //send remove player
_dbContext.Sessions.Remove(session);
_dbContext.SessionUsers.Remove(userSession);
}
}
@ -253,3 +258,4 @@ namespace SignalRChat.Hubs
}
}
}

View file

@ -10,10 +10,10 @@ namespace Sledgemapper.Api.Models
public int MapLogId { get; set; }
[Required]
public string User{get;set;}
public int UserId{get;set;}
[Required]
public string SessionName { get; set; }
public int SessionId { get; set; }
[Required]
[MaxLength(1)]

View file

@ -9,6 +9,10 @@ namespace Sledgemapper.Api.Models
[Key]
public int SnapshotId { get; set; }
[Required]
public int SessionId { get; set; }
[Required]
public string Object { get; set; }

View file

@ -7,11 +7,13 @@ namespace Sledgemapper.Api.Handlers
{
public double Timestamp { get; private set; }
public string SessionName { get; private set; }
public int UserId { get; private set; }
public BaseNotification(string sessionName)
public BaseNotification(string sessionName, int userId)
{
Timestamp = DateTimeOffset.Now.ToUnixTimeMilliseconds();
SessionName = sessionName;
UserId = userId;
}
}
}

View file

@ -6,7 +6,7 @@ namespace Sledgemapper.Api.Handlers
{
public Overlay Overlay { get; private set; }
public DeleteOverlayNotification(string sessionName, Overlay overlay) : base(sessionName)
public DeleteOverlayNotification(string sessionName, Overlay overlay, int userId) : base(sessionName, userId)
{
Overlay = overlay;
}

View file

@ -6,7 +6,7 @@ namespace Sledgemapper.Api.Handlers
{
public Tile Tile { get; private set; }
public DeleteTileNotification(string sessionName, Tile tile) : base(sessionName)
public DeleteTileNotification(string sessionName, Tile tile, int userId) : base(sessionName, userId)
{
Tile = tile;
}

View file

@ -6,7 +6,7 @@ namespace Sledgemapper.Api.Handlers
{
public Wall Wall { get; private set; }
public DeleteWallNotification(string sessionName, Wall wall) : base(sessionName)
public DeleteWallNotification(string sessionName, Wall wall, int userId) : base(sessionName, userId)
{
Wall = wall;
}

View file

@ -6,7 +6,7 @@ namespace Sledgemapper.Api.Handlers
{
public Overlay Overlay { get; private set; }
public NewOverlayNotification(string sessionName, Overlay overlay) : base(sessionName)
public NewOverlayNotification(string sessionName, Overlay overlay, int userId) : base(sessionName, userId)
{
Overlay = overlay;
}

View file

@ -2,7 +2,8 @@ namespace Sledgemapper.Api.Handlers
{
public class NewSessionNotification : BaseNotification
{
public int UserId { get; }
public NewSessionNotification(string sessionName, int userId) : base(sessionName) => UserId = userId;
public NewSessionNotification(string sessionName, int userId) : base(sessionName, userId)
{}
}
}

View file

@ -6,7 +6,7 @@ namespace Sledgemapper.Api.Handlers
{
public Tile Tile { get; private set; }
public NewTileNotification(string sessionName, Tile tile) : base(sessionName)
public NewTileNotification(string sessionName, Tile tile, int userId) : base(sessionName, userId)
{
Tile = tile;
}

View file

@ -6,7 +6,7 @@ namespace Sledgemapper.Api.Handlers
{
public Wall Wall { get; private set; }
public NewWallNotification(string sessionName, Wall wall) : base(sessionName)
public NewWallNotification(string sessionName, Wall wall, int userId) : base(sessionName, userId)
{
Wall = wall;
}

Binary file not shown.

View file

@ -58,6 +58,10 @@ namespace Sledgemapper
{
p.Position = player.Position;
}
else
{
SessionData.Players.Add(player);
}
});
Connection.On<Tile>("DeleteTile", (tile) =>
@ -115,13 +119,13 @@ namespace Sledgemapper
public async Task<bool> Register(RegisterModel registerModel)
{
var result = await Api.Register(registerModel);
var result = await Api.Register(registerModel).ConfigureAwait(false);
return result.IsSuccessStatusCode;
}
public async Task<AuthenticateResponse> Login(AuthenticateModel authenticateModel)
{
_authenticateResponse = await Api.Authenticate(authenticateModel);
_authenticateResponse = await Api.Authenticate(authenticateModel).ConfigureAwait(false);
return _authenticateResponse;
}
@ -143,13 +147,13 @@ namespace Sledgemapper
switch (entity)
{
case Tile tile:
Queue.Enqueue(async () => await Execute(async () => await Api.NewTile(tile, SessionData.SessionName)));
Queue.Enqueue(async () => await Execute(async () => await Api.NewTile(tile, SessionData.SessionName).ConfigureAwait(false)));
break;
case Overlay overlay:
Queue.Enqueue(async () => await Execute(async () => await Api.NewOverlay(overlay, SessionData.SessionName)));
Queue.Enqueue(async () => await Execute(async () => await Api.NewOverlay(overlay, SessionData.SessionName).ConfigureAwait(false)));
break;
case Wall wall:
Queue.Enqueue(async () => await Execute(async () => await Api.NewWall(wall, SessionData.SessionName)));
Queue.Enqueue(async () => await Execute(async () => await Api.NewWall(wall, SessionData.SessionName).ConfigureAwait(false)));
break;
}
break;
@ -158,13 +162,13 @@ namespace Sledgemapper
switch (entity)
{
case Tile tile:
Queue.Enqueue(async () => await Execute(async () => await Api.DeleteTile(tile, SessionData.SessionName)));
Queue.Enqueue(async () => await Execute(async () => await Api.DeleteTile(tile, SessionData.SessionName).ConfigureAwait(false)));
break;
case Overlay overlay:
Queue.Enqueue(async () => await Execute(async () => await Api.DeleteOverlay(overlay, SessionData.SessionName)));
Queue.Enqueue(async () => await Execute(async () => await Api.DeleteOverlay(overlay, SessionData.SessionName).ConfigureAwait(false)));
break;
case Wall wall:
Queue.Enqueue(async () => await Execute(async () => await Api.DeleteWall(wall, SessionData.SessionName)));
Queue.Enqueue(async () => await Execute(async () => await Api.DeleteWall(wall, SessionData.SessionName).ConfigureAwait(false)));
break;
}
break;

View file

@ -12,6 +12,9 @@ namespace Sledgemapper
[Headers("Authorization: Bearer")]
public interface IMapApi
{
[Get("/session/{sessionName}")]
Task<Session> Session(string sessionName);
[Post("/session/{sessionName}")]
Task<bool> NewSession(string sessionName);

View file

@ -347,7 +347,7 @@ namespace Sledgemapper
{
foreach (var player in _sessionData.Players.Copy())
{
var hexs = player.Color.Split(2).ToArray();
var hexs = player.Color.TrimStart('#').Split(2).ToArray();
var color = new Color(int.Parse(hexs[0], System.Globalization.NumberStyles.HexNumber),
int.Parse(hexs[1], System.Globalization.NumberStyles.HexNumber),
int.Parse(hexs[2], System.Globalization.NumberStyles.HexNumber));
@ -426,13 +426,13 @@ namespace Sledgemapper
var successful = false;
try
{
var result = await _communicationManager.Connection?.InvokeAsync<Session>("JoinSession", localContent.TxtSession.Text, _authResponse.Initials);
var result = await _communicationManager.Connection?.InvokeAsync<Session>("JoinSession", localContent.TxtSession.Text);
if (result != null)
{
_sessionData.Map = result.Map;
_sessionData.Walls = result.Walls;
_sessionData.Overlays = result.Overlays;
_sessionData.Players = result.Players;
_sessionData.MapEntityAdded += OnMapEntityAdded;
_sessionData.MapEntityDeleted += OnMapEntityDeleted;
}
@ -486,7 +486,7 @@ namespace Sledgemapper
}
successful = result;
var result2 = await _communicationManager.Connection?.InvokeAsync<Session>("JoinSession", localContent.TxtSession.Text, _authResponse.Initials);
var result2 = await _communicationManager.Connection?.InvokeAsync<Session>("JoinSession", localContent.TxtSession.Text);
}
catch (Exception ex)
@ -688,7 +688,9 @@ namespace Sledgemapper
private async void OnMenuConnectSyncSelected(object sender, EventArgs e)
{
await _communicationManager.Connection?.InvokeAsync("Sync", _sessionData.SessionName, _sessionData);
// await _communicationManager.Connection?.InvokeAsync("Sync", _sessionData.SessionName, _sessionData);
var serverMap = await _communicationManager.Api.Session(_sessionData.SessionName);
}
private void OnMenuConnectNewSelected(object sender, EventArgs e)