T type logging
This commit is contained in:
+3
-3
@@ -2,9 +2,9 @@ using Core.Annotations;
|
||||
using Core.DI;
|
||||
using Core.Models.Enums;
|
||||
using Core.Models.Spt.Config;
|
||||
using Core.Models.Utils;
|
||||
using Core.Servers;
|
||||
using Core.Services;
|
||||
using ILogger = Core.Models.Utils.ILogger;
|
||||
|
||||
namespace Core.Utils;
|
||||
|
||||
@@ -14,7 +14,7 @@ public class App
|
||||
protected Dictionary<string, long> _onUpdateLastRun;
|
||||
protected CoreConfig _coreConfig;
|
||||
|
||||
private ILogger _logger;
|
||||
private ISptLogger<App> _logger;
|
||||
private TimeUtil _timeUtil;
|
||||
private LocalisationService _localisationService;
|
||||
private ConfigServer _configServer;
|
||||
@@ -25,7 +25,7 @@ public class App
|
||||
private IEnumerable<OnUpdate> _onUpdate;
|
||||
|
||||
public App(
|
||||
ILogger logger,
|
||||
ISptLogger<App> logger,
|
||||
TimeUtil timeUtil,
|
||||
LocalisationService localisationService,
|
||||
ConfigServer configServer,
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
using Core.Annotations;
|
||||
using Core.DI;
|
||||
using Core.Models.Eft.Common.Tables;
|
||||
using Core.Models.Enums;
|
||||
using Core.Models.Spt.Config;
|
||||
using Core.Models.Spt.Server;
|
||||
using Core.Models.Utils;
|
||||
using Core.Routers;
|
||||
using Core.Servers;
|
||||
using Core.Services;
|
||||
using ILogger = Core.Models.Utils.ILogger;
|
||||
using Path = System.IO.Path;
|
||||
|
||||
namespace Core.Utils;
|
||||
|
||||
@@ -20,20 +18,20 @@ public class DatabaseImporter : OnLoad
|
||||
private string filepath;
|
||||
private HttpConfig httpConfig;
|
||||
|
||||
private readonly ILogger _logger;
|
||||
private readonly LocalisationService _localisationService;
|
||||
protected ISptLogger<DatabaseImporter> _logger;
|
||||
protected LocalisationService _localisationService;
|
||||
|
||||
private readonly DatabaseServer _databaseServer;
|
||||
protected DatabaseServer _databaseServer;
|
||||
|
||||
private readonly ImageRouter _imageRouter;
|
||||
private readonly EncodingUtil _encodingUtil;
|
||||
private readonly HashUtil _hashUtil;
|
||||
private readonly ImporterUtil _importerUtil;
|
||||
private readonly ConfigServer _configServer;
|
||||
private readonly FileUtil _fileUtil;
|
||||
protected ImageRouter _imageRouter;
|
||||
protected EncodingUtil _encodingUtil;
|
||||
protected HashUtil _hashUtil;
|
||||
protected ImporterUtil _importerUtil;
|
||||
protected ConfigServer _configServer;
|
||||
protected FileUtil _fileUtil;
|
||||
|
||||
public DatabaseImporter(
|
||||
ILogger logger,
|
||||
ISptLogger<DatabaseImporter> logger,
|
||||
// TODO: are we gonna use this? @inject("JsonUtil") protected jsonUtil: JsonUtil,
|
||||
FileUtil fileUtil,
|
||||
LocalisationService localisationService,
|
||||
|
||||
@@ -8,9 +8,9 @@ namespace Core.Utils;
|
||||
[Injectable(InjectionType.Singleton)]
|
||||
public class HashUtil
|
||||
{
|
||||
private readonly Regex MongoIdRegex = new("^[a-fA-F0-9]{24}$");
|
||||
protected Regex MongoIdRegex = new("^[a-fA-F0-9]{24}$");
|
||||
|
||||
private readonly RandomUtil _randomUtil;
|
||||
protected RandomUtil _randomUtil;
|
||||
|
||||
public HashUtil(RandomUtil randomUtil)
|
||||
{
|
||||
@@ -114,4 +114,4 @@ public enum HashingAlgorithm
|
||||
{
|
||||
MD5,
|
||||
SHA1
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ public class HttpResponseUtil
|
||||
_jsonUtil = jsonUtil;
|
||||
}
|
||||
|
||||
private readonly ImmutableList<Regex> _cleanupRegexList =
|
||||
protected ImmutableList<Regex> _cleanupRegexList =
|
||||
[
|
||||
new("[\\b]"),
|
||||
new("[\\f]"),
|
||||
|
||||
+87
-59
@@ -1,22 +1,19 @@
|
||||
using System.Reflection;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using Core.Annotations;
|
||||
using Core.Utils.Json.Converters;
|
||||
using ILogger = Core.Models.Utils.ILogger;
|
||||
using Core.Models.Utils;
|
||||
|
||||
namespace Core.Utils;
|
||||
|
||||
[Injectable(InjectionType.Singleton)]
|
||||
public class ImporterUtil
|
||||
{
|
||||
private readonly FileUtil _fileUtil;
|
||||
private readonly JsonUtil _jsonUtil;
|
||||
private readonly Models.Utils.ILogger _logger;
|
||||
protected FileUtil _fileUtil;
|
||||
protected JsonUtil _jsonUtil;
|
||||
protected ISptLogger<ImporterUtil> _logger;
|
||||
|
||||
private readonly HashSet<string> filesToIgnore = ["bearsuits.json", "usecsuits.json", "archivedquests.json"];
|
||||
|
||||
public ImporterUtil(ILogger logger, FileUtil fileUtil, JsonUtil jsonUtil)
|
||||
protected HashSet<string> filesToIgnore = ["bearsuits.json", "usecsuits.json", "archivedquests.json"];
|
||||
|
||||
public ImporterUtil(ISptLogger<ImporterUtil> logger, FileUtil fileUtil, JsonUtil jsonUtil)
|
||||
{
|
||||
_logger = logger;
|
||||
_fileUtil = fileUtil;
|
||||
@@ -49,35 +46,41 @@ public class ImporterUtil
|
||||
if (_fileUtil.GetFileExtension(file) != "json") continue;
|
||||
if (filesToIgnore.Contains(_fileUtil.GetFileName(file).ToLower())) continue;
|
||||
tasks.Add(
|
||||
Task.Factory.StartNew(() =>
|
||||
{
|
||||
var fileData = _fileUtil.ReadFile(file);
|
||||
if (onReadCallback != null)
|
||||
onReadCallback(file, fileData);
|
||||
|
||||
var setMethod = GetSetMethod(
|
||||
_fileUtil.StripExtension(file).ToLower(),
|
||||
loadedType,
|
||||
out var propertyType,
|
||||
out var isDictionary
|
||||
);
|
||||
try
|
||||
Task.Factory.StartNew(
|
||||
() =>
|
||||
{
|
||||
var fileDeserialized = _jsonUtil.Deserialize(fileData, propertyType);
|
||||
if (onObjectDeserialized != null)
|
||||
onObjectDeserialized(file, fileDeserialized);
|
||||
var fileData = _fileUtil.ReadFile(file);
|
||||
if (onReadCallback != null)
|
||||
onReadCallback(file, fileData);
|
||||
|
||||
lock (dictionaryLock)
|
||||
var setMethod = GetSetMethod(
|
||||
_fileUtil.StripExtension(file).ToLower(),
|
||||
loadedType,
|
||||
out var propertyType,
|
||||
out var isDictionary
|
||||
);
|
||||
try
|
||||
{
|
||||
setMethod.Invoke(result,
|
||||
isDictionary ? [_fileUtil.StripExtension(file), fileDeserialized] : [fileDeserialized]);
|
||||
var fileDeserialized = _jsonUtil.Deserialize(fileData, propertyType);
|
||||
if (onObjectDeserialized != null)
|
||||
onObjectDeserialized(file, fileDeserialized);
|
||||
|
||||
lock (dictionaryLock)
|
||||
{
|
||||
setMethod.Invoke(
|
||||
result,
|
||||
isDictionary
|
||||
? [_fileUtil.StripExtension(file), fileDeserialized]
|
||||
: [fileDeserialized]
|
||||
);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new Exception($"Unable to deserialize or set properties for file '{file}'", e);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new Exception($"Unable to deserialize or set properties for file '{file}'", e);
|
||||
}
|
||||
})
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -85,33 +88,51 @@ public class ImporterUtil
|
||||
foreach (var directory in directories)
|
||||
{
|
||||
tasks.Add(
|
||||
Task.Factory.StartNew(() =>
|
||||
{
|
||||
var setMethod = GetSetMethod(directory.Split("/").Last().Replace("_", ""), loadedType, out var matchedProperty, out var isDictionary);
|
||||
var loadTask = LoadRecursiveAsync($"{directory}/", matchedProperty);
|
||||
loadTask.Wait();
|
||||
lock (dictionaryLock)
|
||||
Task.Factory.StartNew(
|
||||
() =>
|
||||
{
|
||||
setMethod.Invoke(result, isDictionary ? [directory, loadTask.Result] : [loadTask.Result]);
|
||||
var setMethod = GetSetMethod(
|
||||
directory.Split("/").Last().Replace("_", ""),
|
||||
loadedType,
|
||||
out var matchedProperty,
|
||||
out var isDictionary
|
||||
);
|
||||
var loadTask = LoadRecursiveAsync($"{directory}/", matchedProperty);
|
||||
loadTask.Wait();
|
||||
lock (dictionaryLock)
|
||||
{
|
||||
setMethod.Invoke(result, isDictionary ? [directory, loadTask.Result] : [loadTask.Result]);
|
||||
}
|
||||
}
|
||||
})
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// return the result of all async fetch
|
||||
return Task.WhenAll(tasks).ContinueWith((t) =>
|
||||
{
|
||||
if (t.IsCanceled || t.IsFaulted)
|
||||
{
|
||||
var exceptionList = tasks.Where(t => t.IsFaulted || t.IsCanceled).Select(t => t.Exception!).ToList();
|
||||
throw new Exception("Error processing one or more DatabaseFiles", new AggregateException(exceptionList));
|
||||
}
|
||||
}).ContinueWith(t =>
|
||||
{
|
||||
if (t.IsFaulted || t.IsCanceled)
|
||||
throw t.Exception!;
|
||||
return result;
|
||||
});
|
||||
return Task.WhenAll(tasks)
|
||||
.ContinueWith(
|
||||
(t) =>
|
||||
{
|
||||
if (t.IsCanceled || t.IsFaulted)
|
||||
{
|
||||
var exceptionList = tasks.Where(t => t.IsFaulted || t.IsCanceled)
|
||||
.Select(t => t.Exception!)
|
||||
.ToList();
|
||||
throw new Exception(
|
||||
"Error processing one or more DatabaseFiles",
|
||||
new AggregateException(exceptionList)
|
||||
);
|
||||
}
|
||||
}
|
||||
)
|
||||
.ContinueWith(
|
||||
t =>
|
||||
{
|
||||
if (t.IsFaulted || t.IsCanceled)
|
||||
throw t.Exception!;
|
||||
return result;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public MethodInfo GetSetMethod(string propertyName, Type type, out Type propertyType, out bool isDictionary)
|
||||
@@ -127,15 +148,22 @@ public class ImporterUtil
|
||||
else
|
||||
{
|
||||
var matchedProperty = type.GetProperties()
|
||||
.FirstOrDefault(prop =>
|
||||
string.Equals(prop.Name.ToLower(), _fileUtil.StripExtension(propertyName).ToLower(),
|
||||
StringComparison.Ordinal));
|
||||
.FirstOrDefault(
|
||||
prop =>
|
||||
string.Equals(
|
||||
prop.Name.ToLower(),
|
||||
_fileUtil.StripExtension(propertyName).ToLower(),
|
||||
StringComparison.Ordinal
|
||||
)
|
||||
);
|
||||
if (matchedProperty == null)
|
||||
throw new Exception(
|
||||
$"Unable to find property '{_fileUtil.StripExtension(propertyName)}' for type '{type.Name}'");
|
||||
$"Unable to find property '{_fileUtil.StripExtension(propertyName)}' for type '{type.Name}'"
|
||||
);
|
||||
propertyType = matchedProperty.PropertyType;
|
||||
setMethod = matchedProperty.GetSetMethod();
|
||||
}
|
||||
|
||||
return setMethod;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Text.Unicode;
|
||||
using Core.Annotations;
|
||||
using Core.Models.Eft.Ws;
|
||||
using Core.Models.Enums;
|
||||
using Core.Models.Spt.Dialog;
|
||||
using Core.Utils.Json.Converters;
|
||||
@@ -29,7 +30,8 @@ public class JsonUtil
|
||||
new EftEnumConverter<QuestStatusEnum>(),
|
||||
new EftEnumConverter<QuestRewardType>(),
|
||||
new EftEnumConverter<SideType>(),
|
||||
new EftEnumConverter<BonusSkillType>()
|
||||
new EftEnumConverter<BonusSkillType>(),
|
||||
new EftEnumConverter<NotificationEventType>()
|
||||
}
|
||||
};
|
||||
private static readonly JsonSerializerOptions jsonSerializerOptionsIndented = new(jsonSerializerOptionsNoIndent)
|
||||
|
||||
@@ -2,10 +2,10 @@ namespace Core.Utils
|
||||
{
|
||||
public class ProgressWriter
|
||||
{
|
||||
private readonly int _total;
|
||||
private readonly int? _maxBarLength;
|
||||
private readonly string? _barFillChar;
|
||||
private readonly string? _barEmptyChar;
|
||||
protected int _total;
|
||||
protected int? _maxBarLength;
|
||||
protected string? _barFillChar;
|
||||
protected string? _barEmptyChar;
|
||||
|
||||
public ProgressWriter(int total, int maxBarLength, string barFillChar, string barEmptyChar)
|
||||
{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using System.Security.Cryptography;
|
||||
using Core.Annotations;
|
||||
using ILogger = Core.Models.Utils.ILogger;
|
||||
using Core.Models.Utils;
|
||||
|
||||
namespace Core.Utils;
|
||||
|
||||
@@ -8,11 +8,11 @@ namespace Core.Utils;
|
||||
[Injectable(InjectionType.Singleton)]
|
||||
public class RandomUtil
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
protected ISptLogger<RandomUtil> _logger;
|
||||
|
||||
public RandomUtil
|
||||
(
|
||||
ILogger logger
|
||||
ISptLogger<RandomUtil> logger
|
||||
)
|
||||
{
|
||||
_logger = logger;
|
||||
|
||||
@@ -6,7 +6,7 @@ namespace Core.Utils
|
||||
[Injectable]
|
||||
public class TimerUtil
|
||||
{
|
||||
private readonly Stopwatch _stopwatch;
|
||||
protected Stopwatch _stopwatch;
|
||||
|
||||
public TimerUtil()
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using Core.Annotations;
|
||||
using Core.Models.Enums;
|
||||
using Core.Models.Logging;
|
||||
using Core.Models.Spt.Config;
|
||||
using Core.Models.Utils;
|
||||
using Core.Servers;
|
||||
using Core.Services;
|
||||
|
||||
@@ -51,12 +51,12 @@ public class Watermark {
|
||||
protected List<string> text = [];
|
||||
protected string versionLabel = "";
|
||||
|
||||
protected Models.Utils.ILogger _logger;
|
||||
protected ISptLogger<Watermark> _logger;
|
||||
protected ConfigServer _configServer;
|
||||
protected LocalisationService _localisationService;
|
||||
protected WatermarkLocale _watermarkLocale;
|
||||
public Watermark(
|
||||
Models.Utils.ILogger logger,
|
||||
ISptLogger<Watermark> logger,
|
||||
ConfigServer configServer,
|
||||
LocalisationService localisationService,
|
||||
WatermarkLocale watermarkLocale
|
||||
@@ -182,7 +182,7 @@ public class Watermark {
|
||||
|
||||
// Log watermark to screen
|
||||
foreach (var text in result) {
|
||||
_logger.LogWithColor(text, LogTextColor.Yellow);
|
||||
_logger.LogWithColor(text, textColor: LogTextColor.Yellow);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user