cleanup
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Michele Scandura 2021-09-30 11:19:38 +01:00
parent 94f71fc00f
commit 73400b5c9f
16 changed files with 104 additions and 46 deletions

View File

@ -10,8 +10,9 @@ using System.Linq;
using System.Security.Claims; using System.Security.Claims;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Sledgemapper.Api.Core.Entities; using Sentry;
using Sledgemapper.Api.Models; using Sledgemapper.Api.Models;
using User = Sledgemapper.Api.Core.Entities.User;
namespace Sledgemapper.Api.Controllers namespace Sledgemapper.Api.Controllers
{ {

View File

@ -2,12 +2,13 @@ using MediatR;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Sledgemapper.Api.Commands; using Sledgemapper.Api.Commands;
using Sledgemapper.Api.Infrastructure.Data; using Sledgemapper.Api.Infrastructure.Data;
using Sledgemapper.Shared.Entities;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Sentry;
using Session = Sledgemapper.Shared.Entities.Session;
namespace Sledgemapper.Api.Handlers namespace Sledgemapper.Api.Handlers
{ {
@ -26,18 +27,18 @@ namespace Sledgemapper.Api.Handlers
{ {
try try
{ {
var user = await _dbcontext.Users.FindAsync(command.UserId); var user = await _dbcontext.Users.FindAsync(new[] { command.UserId }, cancellationToken: cancellationToken);
_dbcontext.Attach(user); _dbcontext.Attach(user);
var campaign = await _dbcontext var campaign = await _dbcontext
.Campaigns .Campaigns
.Where(campaign => campaign.CampaignId == command.CampaignId) .Where(campaign => campaign.CampaignId == command.CampaignId)
.Include(c => c.InvitedUsers) .Include(c => c.InvitedUsers)
.Include(c => c.Maps) .Include(c => c.Maps)
.Include(c => c.Owner) .Include(c => c.Owner)
.Where(campaign => campaign.OwnerId == command.UserId || campaign.InvitedUsers.Contains(user)).FirstAsync(); .Where(campaign => campaign.OwnerId == command.UserId || campaign.InvitedUsers.Contains(user)).FirstAsync(cancellationToken);
@ -49,6 +50,7 @@ namespace Sledgemapper.Api.Handlers
} }
catch (Exception ex) catch (Exception ex)
{ {
SentrySdk.CaptureException(ex);
} }
return null; return null;
} }

View File

@ -8,6 +8,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Sentry;
namespace Sledgemapper.Api.Handlers namespace Sledgemapper.Api.Handlers
{ {
@ -26,27 +27,25 @@ namespace Sledgemapper.Api.Handlers
{ {
try try
{ {
var user = await _dbcontext.Users.FindAsync(command.UserId); var user = await _dbcontext.Users.FindAsync(new[] { command.UserId }, cancellationToken: cancellationToken);
_dbcontext.Attach(user); _dbcontext.Attach(user);
var campaign = await _dbcontext var campaign = await _dbcontext
.Campaigns .Campaigns
.Where(campaign => campaign.CampaignId == command.CampaignId) .Where(campaign => campaign.CampaignId == command.CampaignId)
.Include(c => c.InvitedUsers) .Include(c => c.InvitedUsers)
.Include(c => c.Owner) .Include(c => c.Owner)
.Where(campaign => campaign.OwnerId == command.UserId || campaign.InvitedUsers.Contains(user)).FirstAsync(); .Where(campaign => campaign.OwnerId == command.UserId || campaign.InvitedUsers.Contains(user)).FirstAsync(cancellationToken);
//var campaign = await _dbcontext.Campaigns.Where(campaign => campaign.CampaignId == command.CampaignId && campaign.OwnerId == command.UserId).Include(campaign => campaign.InvitedUsers).FirstAsync(); //var campaign = await _dbcontext.Campaigns.Where(campaign => campaign.CampaignId == command.CampaignId && campaign.OwnerId == command.UserId).Include(campaign => campaign.InvitedUsers).FirstAsync();
var players = campaign.InvitedUsers.Select(user => new Player { Initials = user.Initials, UserName = user.UserName , UserId = new Guid(user.Id)}).ToList(); var players = campaign.InvitedUsers.Select(user => new Player { Initials = user.Initials, UserName = user.UserName, UserId = new Guid(user.Id) }).ToList();
return players; return players;
} }
catch (Exception ex) catch (Exception ex)
{ {
SentrySdk.CaptureException(ex);
} }
return null; return null;
} }

View File

@ -8,6 +8,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Sentry;
namespace Sledgemapper.Api.Handlers namespace Sledgemapper.Api.Handlers
{ {
@ -38,6 +39,7 @@ namespace Sledgemapper.Api.Handlers
} }
catch (Exception ex) catch (Exception ex)
{ {
SentrySdk.CaptureException(ex);
} }
return new List<Campaign>(); return new List<Campaign>();
} }

View File

@ -4,6 +4,7 @@ using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using MediatR; using MediatR;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Sentry;
using Sledgemapper.Api.Commands; using Sledgemapper.Api.Commands;
using Sledgemapper.Api.Infrastructure.Data; using Sledgemapper.Api.Infrastructure.Data;
@ -24,7 +25,7 @@ namespace Sledgemapper.Api.Handlers
{ {
try try
{ {
var user = await _dbContext.Users.FindAsync(command.UserId); var user = await _dbContext.Users.FindAsync(new[] { command.UserId }, cancellationToken: cancellationToken);
var campaign = await _dbContext var campaign = await _dbContext
.Campaigns .Campaigns
@ -46,6 +47,7 @@ namespace Sledgemapper.Api.Handlers
} }
catch (Exception ex) catch (Exception ex)
{ {
SentrySdk.CaptureException(ex);
} }
return false; return false;

View File

@ -4,7 +4,8 @@ using Sledgemapper.Api.Infrastructure.Data;
using System; using System;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Sledgemapper.Api.Core.Entities; using Sentry;
using User = Sledgemapper.Api.Core.Entities.User;
namespace Sledgemapper.Api.Handlers namespace Sledgemapper.Api.Handlers
{ {
@ -39,8 +40,7 @@ namespace Sledgemapper.Api.Handlers
} }
catch (Exception ex) catch (Exception ex)
{ {
SentrySdk.CaptureException(ex);
} }
return false; return false;
} }

View File

@ -3,6 +3,9 @@ using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Sentry;
using Sentry.AspNetCore;
using Sentry.Extensibility;
using Sledgemapper.Api.Infrastructure.Data; using Sledgemapper.Api.Infrastructure.Data;
namespace Sledgemapper.Api namespace Sledgemapper.Api
@ -11,18 +14,64 @@ namespace Sledgemapper.Api
{ {
public static void Main(string[] args) public static void Main(string[] args)
{ {
var host= CreateHostBuilder(args).Build(); var host = CreateHostBuilder(args).Build();
CreateDbIfNotExists(host); CreateDbIfNotExists(host);
host.Run(); using (Sentry.SentrySdk.Init(o =>
{
o.Dsn = "https://dbd98432b84b445696dc2996e4e01c90@glitchtip.michelescandura.com/2";
o.MaxBreadcrumbs = 50;
o.Debug = true;
o.StackTraceMode = StackTraceMode.Enhanced;
o.AttachStacktrace = true;
o.Release = "1.0.0-alpha.3";
#if DEBUG
o.Environment = "dev";
#else
o.Environment = "production";
#endif
}))
// {
host.Run();
SentrySdk.CaptureMessage("Backend starting");
//}
} }
public static IHostBuilder CreateHostBuilder(string[] args) => public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args) Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder => .ConfigureWebHostDefaults(webBuilder =>
{ {
webBuilder.UseSentry(o =>
{
o.Dsn = "https://dbd98432b84b445696dc2996e4e01c90@glitchtip.michelescandura.com/2";
o.MaxRequestBodySize = RequestSize.Always;
o.MaxBreadcrumbs = 50;
o.Debug = true;
o.StackTraceMode = StackTraceMode.Enhanced;
o.AttachStacktrace = true;
o.Release = "1.0.0-alpha.3";
//o.TracesSampler = ctx =>
//{
// if (string.Equals(ctx.TryGetHttpRoute(), "/Home/Privacy", StringComparison.Ordinal))
// {
// // Collect fewer traces for this page
// return 0.3;
// }
// return 1;
//};
#if DEBUG
o.Environment = "dev";
#else
o.Environment = "production";
#endif
});
webBuilder.UseStartup<Startup>(); webBuilder.UseStartup<Startup>();
}); });
// public static IHostBuilder CreateHostBuilder(string[] args) => // public static IHostBuilder CreateHostBuilder(string[] args) =>
// Host.CreateDefaultBuilder(args) // Host.CreateDefaultBuilder(args)
// .ConfigureWebHostDefaults(webBuilder => // .ConfigureWebHostDefaults(webBuilder =>
@ -30,21 +79,19 @@ namespace Sledgemapper.Api
// webBuilder.UseStartup<Startup>(); // webBuilder.UseStartup<Startup>();
// }); // });
private static void CreateDbIfNotExists(IHost host) private static void CreateDbIfNotExists(IHost host)
{ {
using (var scope = host.Services.CreateScope()) using var scope = host.Services.CreateScope();
var services = scope.ServiceProvider;
try
{ {
var services = scope.ServiceProvider; var context = services.GetRequiredService<SledgemapperDbContext>();
try // DbInitializer.Initialize(context);
{ }
var context = services.GetRequiredService<SledgemapperDbContext>(); catch (Exception ex)
// DbInitializer.Initialize(context); {
} var logger = services.GetRequiredService<ILogger<Program>>();
catch (Exception ex) logger.LogError(ex, "An error occurred creating the DB.");
{
var logger = services.GetRequiredService<ILogger<Program>>();
logger.LogError(ex, "An error occurred creating the DB.");
}
} }
} }
} }

View File

@ -19,6 +19,8 @@
</PackageReference> </PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="5.0.10" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="5.0.10" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="5.0.2" /> <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="5.0.2" />
<PackageReference Include="Sentry" Version="3.9.3" />
<PackageReference Include="Sentry.AspNetCore" Version="3.9.3" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.2" /> <PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.2" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.12.2" /> <PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.12.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.10" /> <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.10" />

View File

@ -11,10 +11,12 @@ using Microsoft.AspNetCore.SignalR.Client;
using Polly; using Polly;
using Polly.Retry; using Polly.Retry;
using Refit; using Refit;
using Sentry;
using SharpFontInternal; using SharpFontInternal;
using Sledgemapper.Messages; using Sledgemapper.Messages;
using Sledgemapper.Shared.Entities; using Sledgemapper.Shared.Entities;
using TinyMessenger; using TinyMessenger;
using Session = Sledgemapper.Shared.Entities.Session;
namespace Sledgemapper namespace Sledgemapper
{ {
@ -141,7 +143,7 @@ namespace Sledgemapper
Connection.On<Player>("NewPlayer", player => Connection.On<Player>("NewPlayer", player =>
{ {
var p = SessionData.Players.FirstOrDefault(m => m.UserId == player.UserId); var p = SessionData.Players.FirstOrDefault(m => m.UserId == player.UserId);
if (p is null) if (p is not null)
{ {
SessionData.Players.Add(player); SessionData.Players.Add(player);
} }
@ -299,7 +301,7 @@ namespace Sledgemapper
//_authenticateResponse = await Api.Authenticate(authenticateModel).ConfigureAwait(false); //_authenticateResponse = await Api.Authenticate(authenticateModel).ConfigureAwait(false);
var data = Encoding.UTF8.GetBytes(JsonSerializer.Serialize(_authenticateResponse)); var data = Encoding.UTF8.GetBytes(JsonSerializer.Serialize(_authenticateResponse));
Program.helper.SaveUnencryptedTokenCache(JsonSerializer.SerializeToUtf8Bytes(_authenticateResponse)); Program.Helper.SaveUnencryptedTokenCache(JsonSerializer.SerializeToUtf8Bytes(_authenticateResponse));
await Connection.StopAsync(); await Connection.StopAsync();
@ -335,7 +337,7 @@ namespace Sledgemapper
} }
catch (Exception ex) catch (Exception ex)
{ {
SentrySdk.CaptureException(ex);
} }
await Connection.StartAsync(); await Connection.StartAsync();
@ -343,7 +345,7 @@ namespace Sledgemapper
public void CheckLogin() public void CheckLogin()
{ {
var data = Program.helper.LoadUnencryptedTokenCache(); var data = Program.Helper.LoadUnencryptedTokenCache();
if (data != null && data.Any()) if (data != null && data.Any())
{ {

View File

@ -9,8 +9,8 @@ namespace Sledgemapper
{ {
public static class Program public static class Program
{ {
private static IConfiguration configuration; private static IConfiguration _configuration;
public static MsalCacheHelper helper; public static MsalCacheHelper Helper { get; private set; }
[STAThread] [STAThread]
static void Main() static void Main()
@ -19,7 +19,7 @@ namespace Sledgemapper
.SetBasePath(System.IO.Directory.GetCurrentDirectory()) .SetBasePath(System.IO.Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json"); .AddJsonFile("appsettings.json");
configuration = builder.Build(); _configuration = builder.Build();
// Loading PublicClientApplicationOptions from the values set on appsettings.json // Loading PublicClientApplicationOptions from the values set on appsettings.json
@ -40,17 +40,18 @@ namespace Sledgemapper
.Build(); .Build();
// storage = Storage.Create(storageProperties); // storage = Storage.Create(storageProperties);
helper = MsalCacheHelper.CreateAsync(storageProperties).Result; Helper = MsalCacheHelper.CreateAsync(storageProperties).Result;
using (Sentry.SentrySdk.Init(o => using (Sentry.SentrySdk.Init(o =>
{ {
o.Dsn = "https://973ac1606651454ba7a19f642d0a9bc1@glitchtip.michelescandura.com/1"; o.Dsn = "https://973ac1606651454ba7a19f642d0a9bc1@glitchtip.michelescandura.com/1";
//o.Dsn = "https://3a58b39d3d38447a83b647fdb1c68160@o1020733.ingest.sentry.io/5986244";
o.MaxBreadcrumbs = 50; o.MaxBreadcrumbs = 50;
o.Debug = true; o.Debug = true;
o.StackTraceMode = StackTraceMode.Enhanced; o.StackTraceMode = StackTraceMode.Enhanced;
o.AttachStacktrace = true; o.AttachStacktrace = true;
o.Release = "1.0.0-alpha.3"; o.Release = "1.0.0-alpha.3";
o.TracesSampleRate = 1.0;
#if DEBUG #if DEBUG
o.Environment = "dev"; o.Environment = "dev";
#else #else

View File

@ -879,7 +879,7 @@ namespace Sledgemapper
var items = _sessionData.Lines.Values.Union<BaseMapEntity>(_sessionData.Rooms.Values) var items = _sessionData.Lines.Values.Union<BaseMapEntity>(_sessionData.Rooms.Values)
.OrderBy(t => t.Timestamp).ToArray(); .OrderBy(t => t.Timestamp).ToArray();
for (var i = 0; i < items.Count(); i++) for (var i = 0; i < items.Length; i++)
{ {
var item = items.ElementAt(i); var item = items.ElementAt(i);
if (IsMapElementOffscreen(item)) continue; if (IsMapElementOffscreen(item)) continue;

View File

@ -140,7 +140,7 @@ namespace Sledgemapper.UI
{ {
var button = ((TextButton)sender); var button = ((TextButton)sender);
Container container = button.Parent; Container container = button.Parent;
while (!(container is Window)) while (container is not Window)
{ {
container = container.Parent; container = container.Parent;
} }

View File

@ -222,7 +222,7 @@ namespace Sledgemapper.UI
_windowEditor.ShowModal(Desktop); _windowEditor.ShowModal(Desktop);
} }
private async void OnLoginSuccesfulMessage(LoginSuccesfulMessage obj) private void OnLoginSuccesfulMessage(LoginSuccesfulMessage obj)
{ {
//MenuConnectNew.Enabled = true; //MenuConnectNew.Enabled = true;
//MenuConnectJoin.Enabled = true; //MenuConnectJoin.Enabled = true;

View File

@ -64,7 +64,6 @@ namespace Sledgemapper.UI
private void OnMapSelected(object sender, EventArgs e) private void OnMapSelected(object sender, EventArgs e)
{ {
var item = sender as ListItem; var item = sender as ListItem;
var localContent = item.GetParentContentInWindow<Widget>();
var list = item.Parent as Grid; var list = item.Parent as Grid;
for (var i = 0; i < list.ChildrenCount; i++) for (var i = 0; i < list.ChildrenCount; i++)

File diff suppressed because one or more lines are too long

0
legacyDb/test Normal file
View File