Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.NET 9 Upgrade & Overhaul #65

Merged
merged 3 commits into from
Feb 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
if: github.event_name == 'pull_request'
- uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.305
dotnet-version: 9.0.102
- uses: actions/checkout@v3
with:
fetch-depth: 0
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.305
dotnet-version: 9.0.102
- name: Checkout source
uses: actions/checkout@v3
- name: Prepare publish artifacts
Expand Down
16 changes: 8 additions & 8 deletions CentCom.API/CentCom.API.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@

<ItemGroup>
<PackageReference Include="BuildBundlerMinifier" Version="3.2.449" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="7.0.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.8" />
<PackageReference Include="MinVer" Version="4.3.0">
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="9.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.1" />
<PackageReference Include="MinVer" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Npgsql" Version="7.0.4" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.4" />
<PackageReference Include="Swashbuckle.AspNetCore.Swagger" Version="6.5.0" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="6.5.0" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUi" Version="6.5.0" />
<PackageReference Include="Npgsql" Version="9.0.2" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.3" />
<PackageReference Include="Swashbuckle.AspNetCore.Swagger" Version="7.2.0" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="7.2.0" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUi" Version="7.2.0" />
</ItemGroup>

<ItemGroup>
Expand Down
9 changes: 2 additions & 7 deletions CentCom.API/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,9 @@

namespace CentCom.API;

public class Startup
public class Startup(IConfiguration configuration)
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}

public IConfiguration Configuration { get; }
public IConfiguration Configuration { get; } = configuration;

// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
Expand Down
18 changes: 9 additions & 9 deletions CentCom.Common/CentCom.Common.csproj
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<ItemGroup>
<PackageReference Include="EFCore.NamingConventions" Version="7.0.2" />
<PackageReference Include="Enums.NET" Version="4.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.8" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
<PackageReference Include="MinVer" Version="4.3.0">
<PackageReference Include="EFCore.NamingConventions" Version="9.0.0" />
<PackageReference Include="Enums.NET" Version="5.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.1" />
<PackageReference Include="MinVer" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Npgsql" Version="7.0.4" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.4" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="7.0.0" />
<PackageReference Include="Remora.Rest" Version="3.2.0" />
<PackageReference Include="Npgsql" Version="9.0.2" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.3" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="9.0.0-preview.2.efcore.9.0.0" />
<PackageReference Include="Remora.Rest" Version="3.4.0" />
</ItemGroup>

</Project>
8 changes: 4 additions & 4 deletions CentCom.Exporter/CentCom.Exporter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Dapper" Version="2.0.143" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="7.0.4" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="7.0.0" />
<PackageReference Include="MinVer" Version="4.3.0">
<PackageReference Include="Dapper" Version="2.1.35" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="9.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="9.0.1" />
<PackageReference Include="MinVer" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
52 changes: 28 additions & 24 deletions CentCom.Server/BanSources/BanParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ private async Task<CheckHistory> ParseBans(IJobExecutionContext context)
};

// Get stored bans from the database
List<Ban> storedBans = null;
List<Ban> storedBans;
try
{
storedBans = await DbContext.Bans
Expand All @@ -143,7 +143,7 @@ private async Task<CheckHistory> ParseBans(IJobExecutionContext context)
// Get bans from the source
var isCompleteRefresh = context.MergedJobDataMap.GetBoolean("completeRefresh") || !storedBans.Any();
history.CompleteRefresh = isCompleteRefresh;
IEnumerable<Ban> bans = null;
List<Ban> bans;
try
{
bans = await (isCompleteRefresh ? FetchAllBansAsync() : FetchNewBansAsync());
Expand Down Expand Up @@ -178,24 +178,25 @@ private async Task<CheckHistory> ParseBans(IJobExecutionContext context)
}

// Remove and report any invalid data from the parsed data
var dirtyBans = bans.Where(x => x.CKey == null || (SourceSupportsBanIDs && x.BanID == null));
if (dirtyBans.Any())
var dirtyBans = bans.Where(x => x.CKey == null || (SourceSupportsBanIDs && x.BanID == null)).ToList();
if (dirtyBans.Count != 0)
{
bans = bans.Except(dirtyBans);
history.Erroneous = dirtyBans.Count();
bans = bans.Except(dirtyBans).ToList();
history.Erroneous = dirtyBans.Count;
Logger.LogWarning(
$"Removed {history.Erroneous} erroneous bans from parsed data. This shouldn't happen!");
"Removed {Erroneous} erroneous bans from parsed data. This shouldn't happen!", history.Erroneous);
}

// Remove erronenous duplicates from source
var sourceDupes = bans.GroupBy(x => x, BanEqualityComparer.Instance)
.Where(x => x.Count() > 1)
.SelectMany(x => x.OrderBy(y => y.Id).Skip(1));
if (sourceDupes.Any())
.SelectMany(x => x.OrderBy(y => y.Id).Skip(1))
.ToList();
if (sourceDupes.Count != 0)
{
Logger.LogWarning(
$"Removing {sourceDupes.Count()} duplicated bans from source, this indicates an issue with the source data!");
bans = bans.Except(sourceDupes);
"Removing {SourceDupes} duplicated bans from source, this indicates an issue with the source data!", sourceDupes.Count);
bans = bans.Except(sourceDupes).ToList();
}

// Check for ban updates
Expand All @@ -207,7 +208,7 @@ private async Task<CheckHistory> ParseBans(IJobExecutionContext context)
b.MakeKeysCanonical();

// Attempt to find matching bans in the database
Ban matchedBan = null;
Ban matchedBan;
if (SourceSupportsBanIDs)
{
matchedBan = storedBans.FirstOrDefault(x =>
Expand Down Expand Up @@ -274,15 +275,15 @@ private async Task<CheckHistory> ParseBans(IJobExecutionContext context)
storedBans.AddRange(toInsert);
}

Logger.LogInformation($"Inserting {toInsert.Count} new bans, updating {updated} modified bans...");
Logger.LogInformation("Inserting {NewBans} new bans, updating {Updated} modified bans...", toInsert.Count, updated);
history.Added = toInsert.Count;
history.Updated = updated;
await DbContext.SaveChangesAsync();

// No need to continue unless this is a complete refresh
if (!isCompleteRefresh)
{
Logger.LogInformation("Completed ban parsing. Partial refresh complete.");
Logger.LogInformation("Completed ban parsing. Partial refresh complete");
history.CompletedUpload = DateTimeOffset.UtcNow;
return history;
}
Expand All @@ -298,9 +299,11 @@ private async Task<CheckHistory> ParseBans(IJobExecutionContext context)
}

// Apply deletions
Logger.LogInformation(missingBans.Count > 0
? $"Removing {missingBans.Count} deleted bans..."
: "Found no deleted bans to remove");
if (missingBans.Count > 0)
Logger.LogInformation("Removing {MissingBans} deleted bans...", missingBans.Count);
else
Logger.LogInformation("Found no deleted bans to remove");

history.Deleted = missingBans.Count;
if (missingBans.Count > 0)
{
Expand All @@ -316,16 +319,17 @@ private async Task<CheckHistory> ParseBans(IJobExecutionContext context)
// Delete any accidental duplications
var duplicates = storedBans.GroupBy(x => x, BanEqualityComparer.Instance)
.Where(x => x.Count() > 1)
.SelectMany(x => x.OrderBy(x => x.Id).Skip(1));
if (duplicates.Any())
.SelectMany(x => x.OrderBy(y => y.Id).Skip(1))
.ToList();
if (duplicates.Count != 0)
{
Logger.LogWarning($"Removing {duplicates.Count()} duplicated bans from the database");
Logger.LogWarning("Removing {Duplicates} duplicated bans from the database", duplicates.Count);
DbContext.RemoveRange(duplicates);
await DbContext.SaveChangesAsync();
}

history.CompletedUpload = DateTimeOffset.UtcNow;
Logger.LogInformation("Completed ban parsing. Complete refresh complete.");
Logger.LogInformation("Completed ban parsing. Complete refresh complete");
return history;
}

Expand Down Expand Up @@ -367,7 +371,7 @@ public async Task<Dictionary<string, BanSource>> GetSourcesAsync()
/// </remarks>
/// <param name="bans">A collection of bans to have their source objects assigned</param>
/// <returns>A collection of bans which have correct database-backed BanSource objects assigned</returns>
public async Task<IEnumerable<Ban>> AssignBanSources(IEnumerable<Ban> bans)
public async Task<List<Ban>> AssignBanSources(List<Ban> bans)
{
var sources = await GetSourcesAsync();
foreach (var b in bans)
Expand All @@ -387,11 +391,11 @@ public async Task<IEnumerable<Ban>> AssignBanSources(IEnumerable<Ban> bans)
/// just to limit the response size
/// </remarks>
/// <returns>A collection of bans found from the source</returns>
public abstract Task<IEnumerable<Ban>> FetchNewBansAsync();
public abstract Task<List<Ban>> FetchNewBansAsync();

/// <summary>
/// Attempts to fetch all bans from the ban source
/// </summary>
/// <returns>A collection of bans found from the source</returns>
public abstract Task<IEnumerable<Ban>> FetchAllBansAsync();
public abstract Task<List<Ban>> FetchAllBansAsync();
}
6 changes: 3 additions & 3 deletions CentCom.Server/BanSources/BeeBanParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public BeeBanParser(DatabaseContext dbContext, BeeBanService banService, ILogger
_banService = banService;
}

protected override Dictionary<string, BanSource> Sources => new Dictionary<string, BanSource>
protected override Dictionary<string, BanSource> Sources => new()
{
{ "bee-lrp", new BanSource
{
Expand All @@ -38,7 +38,7 @@ public BeeBanParser(DatabaseContext dbContext, BeeBanService banService, ILogger
protected override bool SourceSupportsBanIDs => true;
protected override string Name => "Beestation";

public override async Task<IEnumerable<Ban>> FetchNewBansAsync()
public override async Task<List<Ban>> FetchNewBansAsync()
{
Logger.LogInformation("Getting new bans for Beestation...");
var recent = await DbContext.Bans
Expand All @@ -65,7 +65,7 @@ public override async Task<IEnumerable<Ban>> FetchNewBansAsync()
return foundBans;
}

public override async Task<IEnumerable<Ban>> FetchAllBansAsync()
public override async Task<List<Ban>> FetchAllBansAsync()
{
Logger.LogInformation("Getting all bans for Beestation...");
return await _banService.GetBansBatchedAsync();
Expand Down
14 changes: 7 additions & 7 deletions CentCom.Server/BanSources/FulpBanParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace CentCom.Server.BanSources;

public class FulpBanParser : BanParser
{
private const int PAGES_PER_BATCH = 12;
private const int PagesPerBatch = 12;
private readonly FulpBanService _banService;

public FulpBanParser(DatabaseContext dbContext, FulpBanService banService, ILogger<FulpBanParser> logger) : base(dbContext, logger)
Expand All @@ -20,7 +20,7 @@ public FulpBanParser(DatabaseContext dbContext, FulpBanService banService, ILogg
Logger = logger;
}

protected override Dictionary<string, BanSource> Sources => new Dictionary<string, BanSource>
protected override Dictionary<string, BanSource> Sources => new()
{
{ "fulp", new BanSource
{
Expand All @@ -33,13 +33,13 @@ public FulpBanParser(DatabaseContext dbContext, FulpBanService banService, ILogg
protected override bool SourceSupportsBanIDs => false;
protected override string Name => "Fulpstation";

public override async Task<IEnumerable<Ban>> FetchAllBansAsync()
public override async Task<List<Ban>> FetchAllBansAsync()
{
Logger.LogInformation("Getting all bans for Fulpstation...");
return await _banService.GetBansBatchedAsync();
}

public override async Task<IEnumerable<Ban>> FetchNewBansAsync()
public override async Task<List<Ban>> FetchNewBansAsync()
{
Logger.LogInformation("Getting new bans for Fulpstation...");
var recent = await DbContext.Bans
Expand All @@ -54,13 +54,13 @@ public override async Task<IEnumerable<Ban>> FetchNewBansAsync()

while (true)
{
var batch = await _banService.GetBansBatchedAsync(page, PAGES_PER_BATCH);
var batch = await _banService.GetBansBatchedAsync(page, PagesPerBatch);
foundBans.AddRange(batch);
if (!batch.Any() || batch.Any(x => recent.Any(y => y.BannedOn == x.BannedOn && y.CKey == y.CKey)))
if (batch.Count == 0 || batch.Any(x => recent.Any(y => y.BannedOn == x.BannedOn && y.CKey == x.CKey)))
{
break;
}
page += PAGES_PER_BATCH;
page += PagesPerBatch;
}

return foundBans;
Expand Down
31 changes: 13 additions & 18 deletions CentCom.Server/BanSources/StandardBanParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,18 @@

namespace CentCom.Server.BanSources;

public class StandardBanParser : BanParser
public class StandardBanParser(
DatabaseContext dbContext,
ILogger<StandardBanParser> logger,
StandardProviderService banService,
IConfiguration config)
: BanParser(dbContext, logger)
{
private readonly StandardProviderService _banService;
private readonly List<StandardProviderConfiguration> _providerConfigs;
private readonly List<StandardProviderConfiguration> _providerConfigs = config.GetSection("standardSources").Get<List<StandardProviderConfiguration>>();
private string _name;

private Dictionary<string, BanSource> _sources;

public StandardBanParser(DatabaseContext dbContext, ILogger<StandardBanParser> logger,
StandardProviderService banService,
IConfiguration config) :
base(dbContext, logger)
{
_banService = banService;
_providerConfigs = config.GetSection("standardSources").Get<List<StandardProviderConfiguration>>();
}

protected override Dictionary<string, BanSource> Sources => _sources;

protected override bool SourceSupportsBanIDs => true;
Expand All @@ -45,18 +40,18 @@ protected override Task Configure(IJobExecutionContext context)

// Configure the ban service for this source
_name = source.Display;
_banService.Configure(source);
banService.Configure(source);

// Ensure source is set
_sources = new Dictionary<string, BanSource>
{
{ _banService.Source.Name, _banService.Source }
{ banService.Source.Name, banService.Source }
};

return Task.CompletedTask;
}

public override async Task<IEnumerable<Ban>> FetchNewBansAsync()
public override async Task<List<Ban>> FetchNewBansAsync()
{
Logger.LogInformation("Fetching new bans for {Name}...", Name);
var recent = await DbContext.Bans
Expand All @@ -66,12 +61,12 @@ public override async Task<IEnumerable<Ban>> FetchNewBansAsync()
.Include(x => x.JobBans)
.Include(x => x.SourceNavigation)
.ToListAsync();
return await _banService.GetBansBatchedAsync(searchFor: recent.Select(x => int.Parse(x.BanID)));
return await banService.GetBansBatchedAsync(searchFor: recent.Select(x => int.Parse(x.BanID)).ToList());
}

public override async Task<IEnumerable<Ban>> FetchAllBansAsync()
public override async Task<List<Ban>> FetchAllBansAsync()
{
Logger.LogInformation("Fetching all bans for {Name}...", Name);
return await _banService.GetBansBatchedAsync();
return await banService.GetBansBatchedAsync();
}
}
Loading
Loading