fix: Cleans up core code (#1187)

**Only one functional change**
* Fixes a bug in LogFactory where `Warning` is being logged as `Information`

Non-functional changes:
* Updates/Fixes copyright headers
* Removes namespace scopes for core files.

View with [whitespace off](https://github.com/modernuo/ModernUO/pull/1187/files?w=1).
This commit is contained in:
Kamron Batman 2022-10-10 21:47:08 -07:00 committed by GitHub
parent 0138d40bda
commit f268d5d4e2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
262 changed files with 28527 additions and 28646 deletions

View file

@ -1,6 +1,6 @@
/*************************************************************************
* ModernUO *
* Copyright 2019-2020 - ModernUO Development Team *
* Copyright 2019-2022 - ModernUO Development Team *
* Email: hi@modernuo.com *
* File: RegionLoader.cs *
* *
@ -21,65 +21,64 @@ using Server.Json;
using Server.Logging;
using Server.Utilities;
namespace Server
namespace Server;
internal static class RegionLoader
{
internal static class RegionLoader
private static readonly ILogger logger = LogFactory.GetLogger(typeof(RegionLoader));
internal static void LoadRegions()
{
private static readonly ILogger logger = LogFactory.GetLogger(typeof(RegionLoader));
var path = Path.Join(Core.BaseDirectory, "Data/regions.json");
internal static void LoadRegions()
var failures = new List<string>();
var count = 0;
logger.Information("Loading regions");
var stopwatch = Stopwatch.StartNew();
var regions = JsonConfig.Deserialize<List<DynamicJson>>(path);
if (regions == null)
{
var path = Path.Join(Core.BaseDirectory, "Data/regions.json");
throw new JsonException($"Failed to deserialize {path}.");
}
var failures = new List<string>();
var count = 0;
foreach (var json in regions)
{
var type = AssemblyHandler.FindTypeByName(json.Type);
logger.Information("Loading regions");
var stopwatch = Stopwatch.StartNew();
var regions = JsonConfig.Deserialize<List<DynamicJson>>(path);
if (regions == null)
if (type == null || !typeof(Region).IsAssignableFrom(type))
{
throw new JsonException($"Failed to deserialize {path}.");
failures.Add($"\tInvalid region type {json.Type}");
continue;
}
foreach (var json in regions)
{
var type = AssemblyHandler.FindTypeByName(json.Type);
var region = type.CreateInstance<Region>(json, JsonConfig.DefaultOptions);
region?.Register();
count++;
}
if (type == null || !typeof(Region).IsAssignableFrom(type))
{
failures.Add($"\tInvalid region type {json.Type}");
continue;
}
stopwatch.Stop();
var region = type.CreateInstance<Region>(json, JsonConfig.DefaultOptions);
region?.Register();
count++;
}
if (failures.Count == 0)
{
logger.Information(
"Regions loaded ({Count} regions, {FailureCount} failures) ({Duration:F2} seconds)",
count,
failures.Count,
stopwatch.Elapsed.TotalSeconds
);
}
else
{
logger.Warning(
"Failed loading regions ({Count} regions, {FailureCount} failures) ({Duration:F2} seconds)",
count,
failures.Count,
stopwatch.Elapsed.TotalSeconds
);
stopwatch.Stop();
if (failures.Count == 0)
{
logger.Information(
"Regions loaded ({Count} regions, {FailureCount} failures) ({Duration:F2} seconds)",
count,
failures.Count,
stopwatch.Elapsed.TotalSeconds
);
}
else
{
logger.Warning(
"Failed loading regions ({Count} regions, {FailureCount} failures) ({Duration:F2} seconds)",
count,
failures.Count,
stopwatch.Elapsed.TotalSeconds
);
logger.Warning("{Failures}", failures);
}
logger.Warning("{Failures}", failures);
}
}
}