fixed load and overlay flow, missing sync
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Michele Scandura 2021-09-17 11:42:36 +01:00
parent 9abe30904f
commit db41143312
10 changed files with 51 additions and 19 deletions

View File

@ -8,13 +8,13 @@ namespace Sledgemapper.Api.Commands
public class GetCampaignMapsCommand : IRequest<List<Session>>
{
public double Timestamp { get; private set; }
public string CampaignName { get; private set; }
public Guid CampaignId { get; private set; }
public string UserId { get; private set; }
public GetCampaignMapsCommand(string campaingName, string userId)
public GetCampaignMapsCommand(Guid campaignId, string userId)
{
Timestamp = DateTimeOffset.Now.ToUnixTimeMilliseconds();
CampaignName = campaingName;
CampaignId = campaignId;
UserId = userId;
}
}

View File

@ -1,14 +1,18 @@
using MediatR;
using Sledgemapper.Shared.Entities;
using System;
namespace Sledgemapper.Api.Commands
{
public class GetMapSnapshotCommand : IRequest<Session>
{
public string SessionName { get; private set; }
public GetMapSnapshotCommand(string sessionName)
public Guid MapId { get; private set; }
public Guid CampaignId { get; private set;
}
public GetMapSnapshotCommand(Guid campaignId, Guid mapId)
{
SessionName = sessionName;
MapId = mapId;
CampaignId = campaignId;
}
}
}

View File

@ -4,6 +4,7 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Sledgemapper.Api.Commands;
using Sledgemapper.Shared.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
@ -65,7 +66,7 @@ namespace Sledgemapper.Api.Controllers
[HttpGet]
[Route("{campaignName}/maps")]
public async Task<List<Session>> GetMaps(string campaignName)
public async Task<List<Session>> GetMaps(Guid campaignName)
{
var result = await _mediator.Send(new GetCampaignMapsCommand(campaignName, UserId.ToString()));
return result;

View File

@ -26,9 +26,9 @@ namespace Sledgemapper.Api.Controllers
}
[HttpGet]
public async Task<Session> Get(string campaign, string mapName)
public async Task<Session> Get(Guid campaign, Guid mapName)
{
var result = await _mediator.Send(new GetMapSnapshotCommand(mapName));
var result = await _mediator.Send(new GetMapSnapshotCommand(campaign, mapName));
return result;
}

View File

@ -1,4 +1,4 @@
using MediatR;
using MediatR;
using Microsoft.EntityFrameworkCore;
using Sledgemapper.Api.Commands;
using Sledgemapper.Api.Infrastructure.Data;
@ -29,7 +29,20 @@ namespace Sledgemapper.Api.Handlers
var user = await _dbcontext.Users.FindAsync(command.UserId);
_dbcontext.Attach(user);
var campaign = await _dbcontext.Campaigns.Where(campaign => campaign.CampaignName == command.CampaignName && campaign.OwnerId == command.UserId).Include(campaign => campaign.Maps).FirstAsync();
var campaign = await _dbcontext
.Campaigns
.Where(campaign => campaign.CampaignId == command.CampaignId)
.Include(c => c.InvitedUsers)
.Include(c => c.Maps)
.Include(c => c.Owner)
.Where(campaign => campaign.OwnerId == command.UserId || campaign.InvitedUsers.Contains(user)).FirstAsync();
//var campaign = await _dbcontext.Campaigns.Where(campaign => campaign.CampaignId == command.CampaignId && campaign.OwnerId == command.UserId).Include(campaign => campaign.Maps).FirstAsync();
var maps = campaign.Maps.Select(session => new Session { SessionName = session.SessionName, SessionId = session.SessionId }).ToList();
return maps;

View File

@ -20,7 +20,7 @@ namespace Sledgemapper.Api.Commands
Snapshot snapshot;
double timestamp;
Shared.Entities.Session mapSession;
var session = _dbcontext.Sessions.First(m => m.SessionName == notification.SessionName);
var session = _dbcontext.Sessions.First(m => m.SessionId == notification.MapId);
snapshot = _dbcontext.Snapshots.OrderByDescending(s => s.Timestamp).FirstOrDefault(m => m.SessionId == session.SessionId);
if (snapshot is null)
{

View File

@ -25,7 +25,14 @@ namespace Sledgemapper.Api.Handlers
var user = await _dbcontext.Users.FindAsync(command.UserId);
_dbcontext.Attach(user);
var campaign = await _dbcontext.Campaigns.Where(campaign => campaign.CampaignId == command.Campaign && campaign.OwnerId == command.UserId).Include(campaign => campaign.Maps).FirstAsync();
var campaign = await _dbcontext
.Campaigns
.Where(campaign => campaign.CampaignId == command.Campaign)
.Include(c => c.InvitedUsers)
.Include(c => c.Maps)
.Include(c => c.Owner)
.Where(campaign => campaign.OwnerId == command.UserId || campaign.InvitedUsers.Contains(user)).FirstAsync();
var maps = campaign.Maps.Any(s => s.SessionId == command.SessionId);

View File

@ -75,10 +75,10 @@ namespace Sledgemapper
[Get("/campaign/{campaignName}/maps")]
Task<List<Session>> GetMaps(string campaignName);
Task<List<Session>> GetMaps(Guid campaignName);
[Get("/map/{campaignName}/{mapName}")]
Task<Session> GetMap(string campaignName, string mapName);
Task<Session> GetMap(Guid campaignName, Guid mapName);
[Post("/campaign/{campaignName}/players/{email}")]

View File

@ -84,7 +84,7 @@ namespace Sledgemapper.UI
CenterOnTile(obj.X, obj.Y);
}
private void OnMapOpenedMessage(MapOpenedMessage obj)
private async void OnMapOpenedMessage(MapOpenedMessage obj)
{
lblMap.Text = obj.MapName;
MenuConnectSync.Enabled = true;
@ -93,6 +93,13 @@ namespace Sledgemapper.UI
CommunicationManager.SessionData.MapEntityDeleted -= OnMapEntityDeleted;
CommunicationManager.SessionData.MapEntityAdded += OnMapEntityAdded;
CommunicationManager.SessionData.MapEntityDeleted += OnMapEntityDeleted;
var serverMap = await CommunicationManager.Api.GetMap(State.Instance.CampaignId, State.Instance.MapId);
CommunicationManager.SessionData.Overlays = serverMap.Overlays;
CommunicationManager.SessionData.Map = serverMap.Map;
CommunicationManager.SessionData.Walls = serverMap.Walls;
CommunicationManager.SessionData.Notes = serverMap.Notes;
CommunicationManager.SessionData.Lines = serverMap.Lines;
CommunicationManager.SessionData.Rooms = serverMap.Rooms;
}
private async void OnSignalrConnectionUpdateMessage(SignalrConnectionUpdateMessage obj)
@ -204,7 +211,7 @@ namespace Sledgemapper.UI
return;
}
var serverMap = await CommunicationManager.Api.Session(CommunicationManager.SessionData.SessionName);
var serverMap = await CommunicationManager.Api.GetMap(State.Instance.CampaignId, State.Instance.MapId);
CommunicationManager.SessionData.Overlays = serverMap.Overlays;
CommunicationManager.SessionData.Map = serverMap.Map;
CommunicationManager.SessionData.Walls = serverMap.Walls;

View File

@ -35,14 +35,14 @@ namespace Sledgemapper.UI
{
State.Instance.MapName = _selectedMap;
State.Instance.MapId = _selectedMapId;
var map = CommunicationManager.Api.GetMap(State.Instance.CampaignName, State.Instance.MapName);
// var map = CommunicationManager.Api.GetMap(State.Instance.CampaignId, State.Instance.MapId);
Messenger.Publish(new MapOpenedMessage(this) { MapName = State.Instance.MapName });
this.GetContainingWindow().Close();
}
public async Task LoadMaps()
{
var campaigns = await CommunicationManager.Api.GetMaps(State.Instance.CampaignName);
var campaigns = await CommunicationManager.Api.GetMaps(State.Instance.CampaignId);
foreach (var campaign in campaigns)
{
var item = new ListItem();