diff --git a/Config/config.json b/Config/config.json index 7a4ce4f..d84759c 100644 --- a/Config/config.json +++ b/Config/config.json @@ -1,4 +1,4 @@ -{ +{ "serverLocation": "E:\\spt\\Server", "threads": 10, "threadPoolingTimeoutMs": 1000, @@ -47,6 +47,11 @@ "spawnPointToleranceForForced": 99.5, "looseLootCountTolerancePercentage": 75 }, + "collectorConfig": { + "collectorType": "Dump", + "maxEntitiesBeforeDumping": 1000, + "dumpLocation": "C:\\Users\\USER\\SPT\\tmp" + }, "writerConfig": { "outputLocation": "E:\\spt\\dumps\\output" }, diff --git a/GCHandler.cs b/GCHandler.cs index 87a3f35..9ac5393 100644 --- a/GCHandler.cs +++ b/GCHandler.cs @@ -1,6 +1,6 @@ -namespace LootDumpProcessor; +namespace LootDumpProcessor; -public class GCHandler +public static class GCHandler { public static void Collect() { diff --git a/Logger/ILogger.cs b/Logger/ILogger.cs index 3e410d1..e19a74b 100644 --- a/Logger/ILogger.cs +++ b/Logger/ILogger.cs @@ -1,8 +1,9 @@ -namespace LootDumpProcessor.Logger; +namespace LootDumpProcessor.Logger; public interface ILogger { void Setup(); void Log(string message, LogLevel level); + bool CanBeLogged(LogLevel level); void Stop(); } \ No newline at end of file diff --git a/Logger/LogLevel.cs b/Logger/LogLevel.cs index 12972cc..cb28877 100644 --- a/Logger/LogLevel.cs +++ b/Logger/LogLevel.cs @@ -1,4 +1,4 @@ -namespace LootDumpProcessor.Logger; +namespace LootDumpProcessor.Logger; public enum LogLevel { diff --git a/Logger/LoggerFactory.cs b/Logger/LoggerFactory.cs index 71ae33a..71b9650 100644 --- a/Logger/LoggerFactory.cs +++ b/Logger/LoggerFactory.cs @@ -1,4 +1,4 @@ -namespace LootDumpProcessor.Logger; +namespace LootDumpProcessor.Logger; public static class LoggerFactory { diff --git a/Logger/QueueLogger.cs b/Logger/QueueLogger.cs index 6511201..62fad18 100644 --- a/Logger/QueueLogger.cs +++ b/Logger/QueueLogger.cs @@ -1,15 +1,15 @@ -using System.Collections.Concurrent; +using System.Collections.Concurrent; namespace LootDumpProcessor.Logger; public class QueueLogger : ILogger { - private BlockingCollection queuedMessages = new BlockingCollection(); + private readonly BlockingCollection queuedMessages = new(); private Task? loggerThread; private bool isRunning; private int logLevel; - private static readonly int _logTerminationTimeoutMs = 1000; - private static readonly int _logTerminationRetryCount = 3; + private const int LogTerminationTimeoutMs = 1000; + private const int LogTerminationRetryCount = 3; public void Setup() { @@ -56,19 +56,14 @@ public class QueueLogger : ILogger private int GetLogLevel(LogLevel level) { - switch (level) + return level switch { - case LogLevel.Error: - return 1; - case LogLevel.Warning: - return 2; - case LogLevel.Info: - return 3; - case LogLevel.Debug: - return 4; - default: - throw new ArgumentOutOfRangeException(); - } + LogLevel.Error => 1, + LogLevel.Warning => 2, + LogLevel.Info => 3, + LogLevel.Debug => 4, + _ => throw new ArgumentOutOfRangeException() + }; } public void Log(string message, LogLevel level) @@ -77,6 +72,11 @@ public class QueueLogger : ILogger queuedMessages.Add(new LoggedMessage { Message = message, LogLevel = level }); } + public bool CanBeLogged(LogLevel level) + { + return GetLogLevel(level) <= logLevel; + } + // Wait for graceful termination of the logging thread public void Stop() { @@ -84,24 +84,24 @@ public class QueueLogger : ILogger if (loggerThread != null) { Console.ResetColor(); - int retryCount = 0; + var retryCount = 0; while (!loggerThread.IsCompleted) { - if (retryCount == _logTerminationRetryCount) + if (retryCount == LogTerminationRetryCount) { Console.WriteLine( $"Logger thread did not terminate by itself after {retryCount} retries. Some log messages may be lost."); break; } - Console.WriteLine($"Waiting {_logTerminationTimeoutMs}ms for logger termination"); - Thread.Sleep(_logTerminationTimeoutMs); + Console.WriteLine($"Waiting {LogTerminationTimeoutMs}ms for logger termination"); + Thread.Sleep(LogTerminationTimeoutMs); retryCount++; } } } - class LoggedMessage + private class LoggedMessage { public string Message { get; init; } public LogLevel LogLevel { get; init; } diff --git a/LootDumpProcessor.sln b/LootDumpProcessor.sln index 543a87e..0b2eb53 100644 --- a/LootDumpProcessor.sln +++ b/LootDumpProcessor.sln @@ -1,4 +1,4 @@ - + Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.4.33213.308 diff --git a/LootDumpProcessorContext.cs b/LootDumpProcessorContext.cs index 01e5538..ad4a98c 100644 --- a/LootDumpProcessorContext.cs +++ b/LootDumpProcessorContext.cs @@ -1,4 +1,4 @@ -using LootDumpProcessor.Model.Config; +using LootDumpProcessor.Model.Config; using LootDumpProcessor.Model.Output.StaticContainer; using LootDumpProcessor.Process; using LootDumpProcessor.Serializers.Json; @@ -6,22 +6,22 @@ using LootDumpProcessor.Serializers.Yaml; namespace LootDumpProcessor; -public class LootDumpProcessorContext +public static class LootDumpProcessorContext { private static Config? _config; - private static readonly object _configLock = new object(); + private static readonly object _configLock = new(); private static ForcedStatic? _forcedStatic; - private static readonly object _forcedStaticLock = new object(); + private static readonly object _forcedStaticLock = new(); private static Dictionary? _mapDirectoryMappings; - private static readonly object _mapDirectoryMappingsLock = new object(); + private static readonly object _mapDirectoryMappingsLock = new(); private static HashSet? _staticWeaponIds; - private static readonly object _staticWeaponIdsLock = new object(); + private static readonly object _staticWeaponIdsLock = new(); private static Dictionary>? _forcedItems; - private static readonly object _forcedItemsLock = new object(); + private static readonly object _forcedItemsLock = new(); private static Dictionary>? _forcedLoose; - private static readonly object _forcedLooseLock = new object(); + private static readonly object _forcedLooseLock = new(); private static TarkovItems? _tarkovItems; - private static readonly object _tarkovItemsLock = new object(); + private static readonly object _tarkovItemsLock = new(); public static Config GetConfig() { diff --git a/Model/ComposedKey.cs b/Model/ComposedKey.cs index 3ed052e..cbe1d5b 100644 --- a/Model/ComposedKey.cs +++ b/Model/ComposedKey.cs @@ -1,5 +1,6 @@ -using System.Text.Json.Serialization; +using System.Text.Json.Serialization; using LootDumpProcessor.Model.Processing; +using LootDumpProcessor.Utils; using Newtonsoft.Json; namespace LootDumpProcessor.Model; @@ -26,7 +27,7 @@ public class ComposedKey .Cast() .Select(i => (double)i.GetHashCode()) .Sum() - .ToString() ?? Guid.NewGuid().ToString(); + .ToString() ?? KeyGenerator.GetNextKey(); FirstItem = items?[0]; } @@ -34,7 +35,7 @@ public class ComposedKey { if (obj is not ComposedKey key) return false; - return this.Key == key.Key; + return Key == key.Key; } public override int GetHashCode() => Key.GetHashCode(); diff --git a/Model/Config/CollectorConfig.cs b/Model/Config/CollectorConfig.cs new file mode 100644 index 0000000..0e47aff --- /dev/null +++ b/Model/Config/CollectorConfig.cs @@ -0,0 +1,20 @@ +using System.Text.Json.Serialization; +using LootDumpProcessor.Process.Collector; +using Newtonsoft.Json; + +namespace LootDumpProcessor.Model.Config; + +public class CollectorConfig +{ + [JsonProperty("collectorType")] + [JsonPropertyName("collectorType")] + public CollectorType CollectorType { get; set; } + + [JsonProperty("maxEntitiesBeforeDumping")] + [JsonPropertyName("maxEntitiesBeforeDumping")] + public int MaxEntitiesBeforeDumping { get; set; } + + [JsonProperty("dumpLocation")] + [JsonPropertyName("dumpLocation")] + public string DumpLocation { get; set; } +} \ No newline at end of file diff --git a/Model/Config/Config.cs b/Model/Config/Config.cs index ef765fe..5448647 100644 --- a/Model/Config/Config.cs +++ b/Model/Config/Config.cs @@ -1,4 +1,4 @@ -using System.Text.Json.Serialization; +using System.Text.Json.Serialization; using LootDumpProcessor.Serializers.Json; using Newtonsoft.Json; @@ -49,6 +49,10 @@ public class Config [JsonProperty("writerConfig")] [JsonPropertyName("writerConfig")] public WriterConfig WriterConfig { get; set; } + + [JsonProperty("collectorConfig")] + [JsonPropertyName("collectorConfig")] + public CollectorConfig CollectorConfig { get; set; } [JsonProperty("containerIgnoreList")] [JsonPropertyName("containerIgnoreList")] diff --git a/Model/Config/DataStorageConfig.cs b/Model/Config/DataStorageConfig.cs index c8a7c23..5748458 100644 --- a/Model/Config/DataStorageConfig.cs +++ b/Model/Config/DataStorageConfig.cs @@ -1,4 +1,4 @@ -using System.Text.Json.Serialization; +using System.Text.Json.Serialization; using LootDumpProcessor.Storage; using Newtonsoft.Json; diff --git a/Model/Config/ForcedStatic.cs b/Model/Config/ForcedStatic.cs index bfe6928..5b30c9c 100644 --- a/Model/Config/ForcedStatic.cs +++ b/Model/Config/ForcedStatic.cs @@ -1,4 +1,4 @@ -using LootDumpProcessor.Model.Output.StaticContainer; +using LootDumpProcessor.Model.Output.StaticContainer; using YamlDotNet.Serialization; namespace LootDumpProcessor.Model.Config; diff --git a/Model/Config/IntakeReaderConfig.cs b/Model/Config/IntakeReaderConfig.cs index 9522bed..f0226f6 100644 --- a/Model/Config/IntakeReaderConfig.cs +++ b/Model/Config/IntakeReaderConfig.cs @@ -1,5 +1,6 @@ -using System.Text.Json.Serialization; +using System.Text.Json.Serialization; using LootDumpProcessor.Process.Reader; +using LootDumpProcessor.Process.Reader.Intake; using Newtonsoft.Json; namespace LootDumpProcessor.Model.Config; @@ -17,5 +18,5 @@ public class IntakeReaderConfig [JsonProperty("ignoredDumpLocations")] [JsonPropertyName("ignoredDumpLocations")] - public List IgnoredDumpLocations { get; set; } = new List(); + public List IgnoredDumpLocations { get; set; } = new(); } \ No newline at end of file diff --git a/Model/Config/LoggerConfig.cs b/Model/Config/LoggerConfig.cs index 40f22bf..01e1035 100644 --- a/Model/Config/LoggerConfig.cs +++ b/Model/Config/LoggerConfig.cs @@ -1,4 +1,4 @@ -using System.Text.Json.Serialization; +using System.Text.Json.Serialization; using LootDumpProcessor.Logger; using Newtonsoft.Json; diff --git a/Model/Config/MapDirectoryMapping.cs b/Model/Config/MapDirectoryMapping.cs index c2d1feb..9c9794d 100644 --- a/Model/Config/MapDirectoryMapping.cs +++ b/Model/Config/MapDirectoryMapping.cs @@ -1,4 +1,4 @@ -using YamlDotNet.Serialization; +using YamlDotNet.Serialization; namespace LootDumpProcessor.Model.Config; diff --git a/Model/Config/PreProcessorConfig.cs b/Model/Config/PreProcessorConfig.cs index 83cd608..1fd2bf3 100644 --- a/Model/Config/PreProcessorConfig.cs +++ b/Model/Config/PreProcessorConfig.cs @@ -1,4 +1,4 @@ -using System.Text.Json.Serialization; +using System.Text.Json.Serialization; using LootDumpProcessor.Process.Reader.PreProcess; using Newtonsoft.Json; diff --git a/Model/Config/ProcessorConfig.cs b/Model/Config/ProcessorConfig.cs index 51d1c31..92cd826 100644 --- a/Model/Config/ProcessorConfig.cs +++ b/Model/Config/ProcessorConfig.cs @@ -1,4 +1,4 @@ -using System.Text.Json.Serialization; +using System.Text.Json.Serialization; using Newtonsoft.Json; namespace LootDumpProcessor.Model.Config; diff --git a/Model/Config/ReaderConfig.cs b/Model/Config/ReaderConfig.cs index d37f157..87f0a9e 100644 --- a/Model/Config/ReaderConfig.cs +++ b/Model/Config/ReaderConfig.cs @@ -1,4 +1,4 @@ -using System.Text.Json.Serialization; +using System.Text.Json.Serialization; using LootDumpProcessor.Process.Reader.Filters; using Newtonsoft.Json; @@ -24,7 +24,7 @@ public class ReaderConfig [JsonProperty("acceptedFileExtensions")] [JsonPropertyName("acceptedFileExtensions")] - public List AcceptedFileExtensions { get; set; } = new List(); + public List AcceptedFileExtensions { get; set; } = new(); [JsonProperty("processSubFolders")] [JsonPropertyName("processSubFolders")] diff --git a/Model/Config/WriterConfig.cs b/Model/Config/WriterConfig.cs index fd6042b..3a4dc30 100644 --- a/Model/Config/WriterConfig.cs +++ b/Model/Config/WriterConfig.cs @@ -1,4 +1,4 @@ -using System.Text.Json.Serialization; +using System.Text.Json.Serialization; using Newtonsoft.Json; namespace LootDumpProcessor.Model.Config; diff --git a/Model/FireMode.cs b/Model/FireMode.cs index ba76a80..6a2e291 100644 --- a/Model/FireMode.cs +++ b/Model/FireMode.cs @@ -1,4 +1,4 @@ -using System.Text.Json.Serialization; +using System.Text.Json.Serialization; using Newtonsoft.Json; namespace LootDumpProcessor.Model @@ -13,7 +13,7 @@ namespace LootDumpProcessor.Model { return new FireMode { - FireModeType = this.FireModeType + FireModeType = FireModeType }; } } diff --git a/Model/Foldable.cs b/Model/Foldable.cs index 848faf2..71db1cc 100644 --- a/Model/Foldable.cs +++ b/Model/Foldable.cs @@ -1,4 +1,4 @@ -using System.Text.Json.Serialization; +using System.Text.Json.Serialization; using Newtonsoft.Json; namespace LootDumpProcessor.Model @@ -13,7 +13,7 @@ namespace LootDumpProcessor.Model { return new Foldable { - Folded = this.Folded + Folded = Folded }; } } diff --git a/Model/GroupPosition.cs b/Model/GroupPosition.cs index 07ef0f5..b45053a 100644 --- a/Model/GroupPosition.cs +++ b/Model/GroupPosition.cs @@ -1,5 +1,5 @@ -using System.Text.Json.Serialization; -using LootDumpProcessor.Process.Processor; +using System.Text.Json.Serialization; +using LootDumpProcessor.Utils; using Newtonsoft.Json; namespace LootDumpProcessor.Model @@ -26,10 +26,10 @@ namespace LootDumpProcessor.Model { return new GroupPosition { - Name = this.Name, - Weight = this.Weight, - Position = ProcessorUtil.Copy(this.Position), - Rotation = ProcessorUtil.Copy(this.Rotation) + Name = Name, + Weight = Weight, + Position = ProcessorUtil.Copy(Position), + Rotation = ProcessorUtil.Copy(Rotation) }; } } diff --git a/Model/Input/AirdropParameter.cs b/Model/Input/AirdropParameter.cs index 85648b3..5b5007f 100644 --- a/Model/Input/AirdropParameter.cs +++ b/Model/Input/AirdropParameter.cs @@ -1,4 +1,4 @@ -using System.Text.Json.Serialization; +using System.Text.Json.Serialization; using Newtonsoft.Json; namespace LootDumpProcessor.Model.Input diff --git a/Model/Input/Banner.cs b/Model/Input/Banner.cs index d003249..b8ce951 100644 --- a/Model/Input/Banner.cs +++ b/Model/Input/Banner.cs @@ -1,4 +1,4 @@ -using System.Text.Json.Serialization; +using System.Text.Json.Serialization; using Newtonsoft.Json; namespace LootDumpProcessor.Model.Input diff --git a/Model/Input/BotLocationModifier.cs b/Model/Input/BotLocationModifier.cs index d9415cb..2858246 100644 --- a/Model/Input/BotLocationModifier.cs +++ b/Model/Input/BotLocationModifier.cs @@ -1,4 +1,4 @@ -using System.Text.Json.Serialization; +using System.Text.Json.Serialization; using Newtonsoft.Json; namespace LootDumpProcessor.Model.Input diff --git a/Model/Input/ColliderParams.cs b/Model/Input/ColliderParams.cs index cb04740..918395d 100644 --- a/Model/Input/ColliderParams.cs +++ b/Model/Input/ColliderParams.cs @@ -1,4 +1,4 @@ -using System.Text.Json.Serialization; +using System.Text.Json.Serialization; using Newtonsoft.Json; namespace LootDumpProcessor.Model.Input diff --git a/Model/Input/Data.cs b/Model/Input/Data.cs index 051ffe0..22431f8 100644 --- a/Model/Input/Data.cs +++ b/Model/Input/Data.cs @@ -1,4 +1,4 @@ -using System.Text.Json.Serialization; +using System.Text.Json.Serialization; using Newtonsoft.Json; namespace LootDumpProcessor.Model.Input diff --git a/Model/Input/Exit.cs b/Model/Input/Exit.cs index 4a29820..a719027 100644 --- a/Model/Input/Exit.cs +++ b/Model/Input/Exit.cs @@ -1,4 +1,4 @@ -using System.Text.Json.Serialization; +using System.Text.Json.Serialization; using Newtonsoft.Json; namespace LootDumpProcessor.Model.Input diff --git a/Model/Input/ExitZones.cs b/Model/Input/ExitZones.cs index ce300a3..cec8856 100644 --- a/Model/Input/ExitZones.cs +++ b/Model/Input/ExitZones.cs @@ -1,4 +1,4 @@ -using System.Text.Json.Serialization; +using System.Text.Json.Serialization; using Newtonsoft.Json; namespace LootDumpProcessor.Model.Input diff --git a/Model/Input/Preview.cs b/Model/Input/Preview.cs index 0327bc4..eb79172 100644 --- a/Model/Input/Preview.cs +++ b/Model/Input/Preview.cs @@ -1,4 +1,4 @@ -using System.Text.Json.Serialization; +using System.Text.Json.Serialization; using Newtonsoft.Json; namespace LootDumpProcessor.Model.Input diff --git a/Model/Input/Props.cs b/Model/Input/Props.cs index d392cd2..01c4691 100644 --- a/Model/Input/Props.cs +++ b/Model/Input/Props.cs @@ -1,4 +1,4 @@ -using System.Text.Json.Serialization; +using System.Text.Json.Serialization; using Newtonsoft.Json; namespace LootDumpProcessor.Model.Input diff --git a/Model/Input/RootData.cs b/Model/Input/RootData.cs index 4611c6f..39d984b 100644 --- a/Model/Input/RootData.cs +++ b/Model/Input/RootData.cs @@ -1,4 +1,4 @@ -using System.Text.Json.Serialization; +using System.Text.Json.Serialization; using Newtonsoft.Json; namespace LootDumpProcessor.Model.Input diff --git a/Model/Input/SpawnPointParam.cs b/Model/Input/SpawnPointParam.cs index 43a5ffe..d34e1e5 100644 --- a/Model/Input/SpawnPointParam.cs +++ b/Model/Input/SpawnPointParam.cs @@ -1,4 +1,4 @@ -using System.Text.Json.Serialization; +using System.Text.Json.Serialization; using Newtonsoft.Json; namespace LootDumpProcessor.Model.Input diff --git a/Model/Input/Wave.cs b/Model/Input/Wave.cs index 9190422..1e7ebda 100644 --- a/Model/Input/Wave.cs +++ b/Model/Input/Wave.cs @@ -1,4 +1,4 @@ -using System.Text.Json.Serialization; +using System.Text.Json.Serialization; using Newtonsoft.Json; namespace LootDumpProcessor.Model.Input diff --git a/Model/Item.cs b/Model/Item.cs index 14c939d..f9e4d2d 100644 --- a/Model/Item.cs +++ b/Model/Item.cs @@ -1,5 +1,5 @@ -using System.Text.Json.Serialization; -using LootDumpProcessor.Process.Processor; +using System.Text.Json.Serialization; +using LootDumpProcessor.Utils; using Newtonsoft.Json; namespace LootDumpProcessor.Model @@ -34,24 +34,24 @@ namespace LootDumpProcessor.Model { if (obj is not Item parsed) return false; - return parsed.Tpl == this.Tpl && parsed.ParentId == this.ParentId; + return parsed.Tpl == Tpl && parsed.ParentId == ParentId; } public override int GetHashCode() { - return (this.Tpl?.GetHashCode() + this.ParentId?.GetHashCode()) ?? base.GetHashCode(); + return (Tpl?.GetHashCode() + ParentId?.GetHashCode()) ?? base.GetHashCode(); } public object Clone() { return new Item { - Id = this.Id, - Tpl = this.Tpl, - ParentId = this.ParentId, - SlotId = this.SlotId, - Location = this.Location, - Upd = ProcessorUtil.Copy(this.Upd) + Id = Id, + Tpl = Tpl, + ParentId = ParentId, + SlotId = SlotId, + Location = Location, + Upd = ProcessorUtil.Copy(Upd) }; } } diff --git a/Model/Output/AbstractDistribution.cs b/Model/Output/AbstractDistribution.cs index cc428d4..6499c85 100644 --- a/Model/Output/AbstractDistribution.cs +++ b/Model/Output/AbstractDistribution.cs @@ -1,4 +1,4 @@ -using System.Text.Json.Serialization; +using System.Text.Json.Serialization; using Newtonsoft.Json; namespace LootDumpProcessor.Model.Output; diff --git a/Model/Output/AmmoDistribution.cs b/Model/Output/AmmoDistribution.cs index 2250b48..f54387d 100644 --- a/Model/Output/AmmoDistribution.cs +++ b/Model/Output/AmmoDistribution.cs @@ -1,4 +1,4 @@ -using System.Text.Json.Serialization; +using System.Text.Json.Serialization; using Newtonsoft.Json; namespace LootDumpProcessor.Model.Output; diff --git a/Model/Output/ItemCountDistribution.cs b/Model/Output/ItemCountDistribution.cs index 31d0c02..3b8d8ec 100644 --- a/Model/Output/ItemCountDistribution.cs +++ b/Model/Output/ItemCountDistribution.cs @@ -1,4 +1,4 @@ -using System.Text.Json.Serialization; +using System.Text.Json.Serialization; using Newtonsoft.Json; namespace LootDumpProcessor.Model.Output diff --git a/Model/Output/ItemDistribution.cs b/Model/Output/ItemDistribution.cs index f534ecd..9f79cdd 100644 --- a/Model/Output/ItemDistribution.cs +++ b/Model/Output/ItemDistribution.cs @@ -1,4 +1,4 @@ -using System.Text.Json.Serialization; +using System.Text.Json.Serialization; using Newtonsoft.Json; namespace LootDumpProcessor.Model.Output diff --git a/Model/Output/LooseLoot/LooseLootRoot.cs b/Model/Output/LooseLoot/LooseLootRoot.cs index e67df3c..d4ef938 100644 --- a/Model/Output/LooseLoot/LooseLootRoot.cs +++ b/Model/Output/LooseLoot/LooseLootRoot.cs @@ -1,4 +1,4 @@ -using System.Text.Json.Serialization; +using System.Text.Json.Serialization; using Newtonsoft.Json; namespace LootDumpProcessor.Model.Output.LooseLoot diff --git a/Model/Output/LooseLoot/SpawnPoint.cs b/Model/Output/LooseLoot/SpawnPoint.cs index 63d942f..a804e8c 100644 --- a/Model/Output/LooseLoot/SpawnPoint.cs +++ b/Model/Output/LooseLoot/SpawnPoint.cs @@ -1,4 +1,4 @@ -using System.Text.Json.Serialization; +using System.Text.Json.Serialization; using Newtonsoft.Json; namespace LootDumpProcessor.Model.Output.LooseLoot diff --git a/Model/Output/LooseLoot/SpawnPointCount.cs b/Model/Output/LooseLoot/SpawnPointCount.cs index 632d61e..f18b5ed 100644 --- a/Model/Output/LooseLoot/SpawnPointCount.cs +++ b/Model/Output/LooseLoot/SpawnPointCount.cs @@ -1,4 +1,4 @@ -using System.Text.Json.Serialization; +using System.Text.Json.Serialization; using Newtonsoft.Json; namespace LootDumpProcessor.Model.Output.LooseLoot diff --git a/Model/Output/LooseLoot/SpawnPointsForced.cs b/Model/Output/LooseLoot/SpawnPointsForced.cs index bda9394..655bc2f 100644 --- a/Model/Output/LooseLoot/SpawnPointsForced.cs +++ b/Model/Output/LooseLoot/SpawnPointsForced.cs @@ -1,4 +1,4 @@ -using System.Text.Json.Serialization; +using System.Text.Json.Serialization; using Newtonsoft.Json; namespace LootDumpProcessor.Model.Output.LooseLoot diff --git a/Model/Output/StaticContainer/MapStaticLoot.cs b/Model/Output/StaticContainer/MapStaticLoot.cs index 80538ce..e15a887 100644 --- a/Model/Output/StaticContainer/MapStaticLoot.cs +++ b/Model/Output/StaticContainer/MapStaticLoot.cs @@ -1,4 +1,4 @@ -using System.Text.Json.Serialization; +using System.Text.Json.Serialization; using Newtonsoft.Json; namespace LootDumpProcessor.Model.Output.StaticContainer diff --git a/Model/Output/StaticContainer/StaticContainerRoot.cs b/Model/Output/StaticContainer/StaticContainerRoot.cs index da4d2c1..81ad89d 100644 --- a/Model/Output/StaticContainer/StaticContainerRoot.cs +++ b/Model/Output/StaticContainer/StaticContainerRoot.cs @@ -1,4 +1,4 @@ -using System.Text.Json.Serialization; +using System.Text.Json.Serialization; using Newtonsoft.Json; namespace LootDumpProcessor.Model.Output.StaticContainer diff --git a/Model/Output/StaticContainer/StaticDataPoint.cs b/Model/Output/StaticContainer/StaticDataPoint.cs index d9ddf0e..5a71188 100644 --- a/Model/Output/StaticContainer/StaticDataPoint.cs +++ b/Model/Output/StaticContainer/StaticDataPoint.cs @@ -1,4 +1,4 @@ -using System.Text.Json.Serialization; +using System.Text.Json.Serialization; using Newtonsoft.Json; namespace LootDumpProcessor.Model.Output.StaticContainer; diff --git a/Model/Output/StaticContainer/StaticForced.cs b/Model/Output/StaticContainer/StaticForced.cs index ea78a60..7b9bf24 100644 --- a/Model/Output/StaticContainer/StaticForced.cs +++ b/Model/Output/StaticContainer/StaticForced.cs @@ -1,4 +1,4 @@ -using System.Text.Json.Serialization; +using System.Text.Json.Serialization; using Newtonsoft.Json; using YamlDotNet.Serialization; diff --git a/Model/Output/StaticDistribution.cs b/Model/Output/StaticDistribution.cs index b1631c2..9686ee9 100644 --- a/Model/Output/StaticDistribution.cs +++ b/Model/Output/StaticDistribution.cs @@ -1,4 +1,4 @@ -using System.Text.Json.Serialization; +using System.Text.Json.Serialization; using Newtonsoft.Json; namespace LootDumpProcessor.Model.Output; diff --git a/Model/Output/StaticItemDistribution.cs b/Model/Output/StaticItemDistribution.cs index 377a9a5..b074afc 100644 --- a/Model/Output/StaticItemDistribution.cs +++ b/Model/Output/StaticItemDistribution.cs @@ -1,4 +1,4 @@ -using System.Text.Json.Serialization; +using System.Text.Json.Serialization; using Newtonsoft.Json; namespace LootDumpProcessor.Model.Output diff --git a/Model/Processing/BaseClasses.cs b/Model/Processing/BaseClasses.cs index 7494c37..4264ea5 100644 --- a/Model/Processing/BaseClasses.cs +++ b/Model/Processing/BaseClasses.cs @@ -1,4 +1,4 @@ -namespace LootDumpProcessor.Model.Processing; +namespace LootDumpProcessor.Model.Processing; public static class BaseClasses { diff --git a/Model/Processing/BasicInfo.cs b/Model/Processing/BasicInfo.cs index 0ae2c39..e5299c8 100644 --- a/Model/Processing/BasicInfo.cs +++ b/Model/Processing/BasicInfo.cs @@ -1,4 +1,4 @@ -using LootDumpProcessor.Model.Input; +using LootDumpProcessor.Model.Input; using Newtonsoft.Json; namespace LootDumpProcessor.Model.Processing; diff --git a/Model/Processing/CaliberTemplateCount.cs b/Model/Processing/CaliberTemplateCount.cs index 1749de9..bd60ba5 100644 --- a/Model/Processing/CaliberTemplateCount.cs +++ b/Model/Processing/CaliberTemplateCount.cs @@ -1,4 +1,4 @@ -namespace LootDumpProcessor.Model.Processing; +namespace LootDumpProcessor.Model.Processing; public class CaliberTemplateCount { diff --git a/Model/Processing/DumpProcessData.cs b/Model/Processing/DumpProcessData.cs index 7d50075..b091d18 100644 --- a/Model/Processing/DumpProcessData.cs +++ b/Model/Processing/DumpProcessData.cs @@ -1,4 +1,4 @@ -using LootDumpProcessor.Storage; +using LootDumpProcessor.Storage; namespace LootDumpProcessor.Model.Processing; diff --git a/Model/Processing/LooseLootCounts.cs b/Model/Processing/LooseLootCounts.cs index 99f604d..e631058 100644 --- a/Model/Processing/LooseLootCounts.cs +++ b/Model/Processing/LooseLootCounts.cs @@ -1,5 +1,6 @@ -using System.Text.Json.Serialization; +using System.Text.Json.Serialization; using LootDumpProcessor.Storage; +using LootDumpProcessor.Utils; using Newtonsoft.Json; namespace LootDumpProcessor.Model.Processing; @@ -8,7 +9,7 @@ public class LooseLootCounts : IKeyable { [JsonProperty("__id__")] [JsonPropertyName("__id__")] - public string __ID { get; set; } = Guid.NewGuid().ToString(); + public string __ID { get; set; } = KeyGenerator.GetNextKey(); public IKey Counts { get; set; } diff --git a/Model/Processing/ParsedDump.cs b/Model/Processing/ParsedDump.cs index d407bf0..7c62a3b 100644 --- a/Model/Processing/ParsedDump.cs +++ b/Model/Processing/ParsedDump.cs @@ -1,11 +1,11 @@ -using System.Text.RegularExpressions; +using System.Text.RegularExpressions; using LootDumpProcessor.Storage; namespace LootDumpProcessor.Model.Processing; public class ParsedDump : IKeyable { - private static readonly Regex _hashRegex = new Regex("([^a-zA-Z0-9])"); + private static readonly Regex _hashRegex = new("([^a-zA-Z0-9])"); public BasicInfo BasicInfo { get; set; } public PreProcessedLooseLoot LooseLoot { get; set; } public List Containers { get; set; } @@ -13,13 +13,13 @@ public class ParsedDump : IKeyable public override bool Equals(object? obj) { if (obj is ParsedDump dump) - return dump.BasicInfo.Equals(this.BasicInfo); + return dump.BasicInfo.Equals(BasicInfo); return false; } public override int GetHashCode() { - return this.BasicInfo.GetHashCode(); + return BasicInfo.GetHashCode(); } public IKey GetKey() diff --git a/Model/Processing/PartialData.cs b/Model/Processing/PartialData.cs index 7f4bd15..c5fca69 100644 --- a/Model/Processing/PartialData.cs +++ b/Model/Processing/PartialData.cs @@ -1,4 +1,4 @@ -using LootDumpProcessor.Storage; +using LootDumpProcessor.Storage; namespace LootDumpProcessor.Model.Processing; @@ -10,12 +10,12 @@ public class PartialData public override bool Equals(object? obj) { if (obj is ParsedDump dump) - return dump.BasicInfo.Equals(this.BasicInfo); + return dump.BasicInfo.Equals(BasicInfo); return false; } public override int GetHashCode() { - return this.BasicInfo.GetHashCode(); + return BasicInfo.GetHashCode(); } } \ No newline at end of file diff --git a/Model/Processing/PreProcessedLooseLoot.cs b/Model/Processing/PreProcessedLooseLoot.cs index 73ccc9a..0c3b6a2 100644 --- a/Model/Processing/PreProcessedLooseLoot.cs +++ b/Model/Processing/PreProcessedLooseLoot.cs @@ -1,4 +1,4 @@ -using LootDumpProcessor.Serializers.Json.Converters; +using LootDumpProcessor.Serializers.Json.Converters; using LootDumpProcessor.Storage; namespace LootDumpProcessor.Model.Processing; diff --git a/Model/Processing/PreProcessedStaticLoot.cs b/Model/Processing/PreProcessedStaticLoot.cs index b701ed2..4037803 100644 --- a/Model/Processing/PreProcessedStaticLoot.cs +++ b/Model/Processing/PreProcessedStaticLoot.cs @@ -1,4 +1,4 @@ -namespace LootDumpProcessor.Model.Processing; +namespace LootDumpProcessor.Model.Processing; public class PreProcessedStaticLoot { diff --git a/Model/Repairable.cs b/Model/Repairable.cs index b2d7b9c..7e0dcf7 100644 --- a/Model/Repairable.cs +++ b/Model/Repairable.cs @@ -1,4 +1,4 @@ -using System.Text.Json.Serialization; +using System.Text.Json.Serialization; using Newtonsoft.Json; namespace LootDumpProcessor.Model @@ -17,8 +17,8 @@ namespace LootDumpProcessor.Model { return new Repairable { - Durability = this.Durability, - MaxDurability = this.MaxDurability + Durability = Durability, + MaxDurability = MaxDurability }; } } diff --git a/Model/Tarkov/Handbook.cs b/Model/Tarkov/Handbook.cs index c78f848..05efb61 100644 --- a/Model/Tarkov/Handbook.cs +++ b/Model/Tarkov/Handbook.cs @@ -1,4 +1,4 @@ -namespace LootDumpProcessor.Model.Tarkov; +namespace LootDumpProcessor.Model.Tarkov; public class Category { diff --git a/Model/Tarkov/TemplateItems.cs b/Model/Tarkov/TemplateItems.cs index 450e576..92721a4 100644 --- a/Model/Tarkov/TemplateItems.cs +++ b/Model/Tarkov/TemplateItems.cs @@ -1,4 +1,4 @@ -using System.Text.Json.Serialization; +using System.Text.Json.Serialization; using Newtonsoft.Json; namespace LootDumpProcessor.Model.Tarkov; diff --git a/Model/Template.cs b/Model/Template.cs index 7047115..dbaee11 100644 --- a/Model/Template.cs +++ b/Model/Template.cs @@ -1,6 +1,6 @@ -using System.Text.Json.Serialization; -using LootDumpProcessor.Process.Processor; +using System.Text.Json.Serialization; using LootDumpProcessor.Storage; +using LootDumpProcessor.Utils; using Newtonsoft.Json; namespace LootDumpProcessor.Model @@ -9,7 +9,7 @@ namespace LootDumpProcessor.Model { [Newtonsoft.Json.JsonIgnore] [System.Text.Json.Serialization.JsonIgnore] - public string __ID { get; } = Guid.NewGuid().ToString(); + public string __ID { get; } = KeyGenerator.GetNextKey(); [JsonProperty("Id", NullValueHandling = NullValueHandling.Ignore)] [JsonPropertyName("Id")] @@ -82,17 +82,17 @@ namespace LootDumpProcessor.Model { return new Template { - Id = this.Id, - IsContainer = this.IsContainer, - UseGravity = this.UseGravity, - RandomRotation = this.RandomRotation, - Position = ProcessorUtil.Copy(this.Position), - Rotation = ProcessorUtil.Copy(this.Rotation), - IsGroupPosition = this.IsGroupPosition, - GroupPositions = ProcessorUtil.Copy(this.GroupPositions), - IsAlwaysSpawn = this.IsAlwaysSpawn, - Root = this.Root, - Items = ProcessorUtil.Copy(this.Items) + Id = Id, + IsContainer = IsContainer, + UseGravity = UseGravity, + RandomRotation = RandomRotation, + Position = ProcessorUtil.Copy(Position), + Rotation = ProcessorUtil.Copy(Rotation), + IsGroupPosition = IsGroupPosition, + GroupPositions = ProcessorUtil.Copy(GroupPositions), + IsAlwaysSpawn = IsAlwaysSpawn, + Root = Root, + Items = ProcessorUtil.Copy(Items) }; } } diff --git a/Model/Upd.cs b/Model/Upd.cs index 88a1cfe..9c02828 100644 --- a/Model/Upd.cs +++ b/Model/Upd.cs @@ -1,5 +1,6 @@ -using System.Text.Json.Serialization; +using System.Text.Json.Serialization; using LootDumpProcessor.Process.Processor; +using LootDumpProcessor.Utils; using Newtonsoft.Json; namespace LootDumpProcessor.Model @@ -26,10 +27,10 @@ namespace LootDumpProcessor.Model { return new Upd { - StackObjectsCount = this.StackObjectsCount, - FireMode = ProcessorUtil.Copy(this.FireMode), - Foldable = ProcessorUtil.Copy(this.Foldable), - Repairable = ProcessorUtil.Copy(this.Repairable) + StackObjectsCount = StackObjectsCount, + FireMode = ProcessorUtil.Copy(FireMode), + Foldable = ProcessorUtil.Copy(Foldable), + Repairable = ProcessorUtil.Copy(Repairable) }; } } diff --git a/Model/Vector3.cs b/Model/Vector3.cs index 71e075e..1be838a 100644 --- a/Model/Vector3.cs +++ b/Model/Vector3.cs @@ -1,4 +1,4 @@ -using System.Text.Json.Serialization; +using System.Text.Json.Serialization; using Newtonsoft.Json; namespace LootDumpProcessor.Model @@ -21,9 +21,9 @@ namespace LootDumpProcessor.Model { return new Vector3 { - X = this.X, - Y = this.Y, - Z = this.Z + X = X, + Y = Y, + Z = Z }; } } diff --git a/Process/Collector/CollectorFactory.cs b/Process/Collector/CollectorFactory.cs index 2aa20ae..66fa337 100644 --- a/Process/Collector/CollectorFactory.cs +++ b/Process/Collector/CollectorFactory.cs @@ -1,10 +1,17 @@ -namespace LootDumpProcessor.Process.Collector; +namespace LootDumpProcessor.Process.Collector; public static class CollectorFactory { + private static ICollector? _collector; public static ICollector GetInstance() { - // TODO: implement real factory - return new HashSetCollector(); + if (_collector == null) + _collector = LootDumpProcessorContext.GetConfig().CollectorConfig.CollectorType switch + { + CollectorType.Memory => new HashSetCollector(), + CollectorType.Dump => new DumpCollector(), + _ => throw new ArgumentOutOfRangeException() + }; + return _collector; } } \ No newline at end of file diff --git a/Process/Collector/CollectorType.cs b/Process/Collector/CollectorType.cs new file mode 100644 index 0000000..48e6e64 --- /dev/null +++ b/Process/Collector/CollectorType.cs @@ -0,0 +1,7 @@ +namespace LootDumpProcessor.Process.Collector; + +public enum CollectorType +{ + Memory, + Dump +} \ No newline at end of file diff --git a/Process/Collector/DumpCollector.cs b/Process/Collector/DumpCollector.cs new file mode 100644 index 0000000..7c825da --- /dev/null +++ b/Process/Collector/DumpCollector.cs @@ -0,0 +1,45 @@ +using LootDumpProcessor.Model.Processing; +using LootDumpProcessor.Serializers.Json; + +namespace LootDumpProcessor.Process.Collector; + +public class DumpCollector : ICollector +{ + private static readonly string DumpLocation = $"{LootDumpProcessorContext.GetConfig().CollectorConfig.DumpLocation}/collector/"; + private readonly List processedDumps = new(LootDumpProcessorContext.GetConfig().CollectorConfig.MaxEntitiesBeforeDumping + 50); + private readonly object lockObject = new(); + + public void Setup() + { + if (Directory.Exists(DumpLocation)) + { + Directory.Delete(DumpLocation, true); + } + + Directory.CreateDirectory(DumpLocation); + } + + public void Hold(PartialData parsedDump) + { + lock (lockObject) + { + processedDumps.Add(parsedDump); + if (processedDumps.Count > LootDumpProcessorContext.GetConfig().CollectorConfig.MaxEntitiesBeforeDumping) + { + var fileName = $"collector-{DateTime.Now.ToString("yyyyMMddHHmmssfffff")}.json"; + File.WriteAllText($"{DumpLocation}{fileName}", JsonSerializerFactory.GetInstance().Serialize(processedDumps)); + processedDumps.Clear(); + } + } + } + + public List Retrieve() + { + foreach (var file in Directory.GetFiles(DumpLocation)) + { + processedDumps.AddRange(JsonSerializerFactory.GetInstance().Deserialize>(File.ReadAllText(file))); + } + + return processedDumps; + } +} \ No newline at end of file diff --git a/Process/Collector/HashSetCollector.cs b/Process/Collector/HashSetCollector.cs index 6a14fb2..be15f77 100644 --- a/Process/Collector/HashSetCollector.cs +++ b/Process/Collector/HashSetCollector.cs @@ -1,13 +1,11 @@ -using LootDumpProcessor.Model.Processing; +using LootDumpProcessor.Model.Processing; namespace LootDumpProcessor.Process.Collector; public class HashSetCollector : ICollector { - private HashSet processedDumps = new HashSet(); - - private object lockObject = new object(); - + private readonly HashSet processedDumps = new(100_000); + private readonly object lockObject = new(); public void Setup() { diff --git a/Process/Collector/ICollector.cs b/Process/Collector/ICollector.cs index 9f22567..98eec27 100644 --- a/Process/Collector/ICollector.cs +++ b/Process/Collector/ICollector.cs @@ -1,4 +1,3 @@ -using LootDumpProcessor.Model.Config; using LootDumpProcessor.Model.Processing; namespace LootDumpProcessor.Process.Collector; diff --git a/Process/FilesGatherer.cs b/Process/FilesGatherer.cs deleted file mode 100644 index bc6af3d..0000000 --- a/Process/FilesGatherer.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace LootDumpProcessor.Process; - -public class FilesGatherer -{ - -} \ No newline at end of file diff --git a/Process/IPipeline.cs b/Process/IPipeline.cs index 1c6d825..1848ac3 100644 --- a/Process/IPipeline.cs +++ b/Process/IPipeline.cs @@ -1,4 +1,4 @@ -namespace LootDumpProcessor.Process; +namespace LootDumpProcessor.Process; public interface IPipeline { diff --git a/Process/OutputFileType.cs b/Process/OutputFileType.cs index ab9af3b..8cb1f9b 100644 --- a/Process/OutputFileType.cs +++ b/Process/OutputFileType.cs @@ -1,4 +1,4 @@ -namespace LootDumpProcessor.Process; +namespace LootDumpProcessor.Process; public enum OutputFileType { diff --git a/Process/PipelineFactory.cs b/Process/PipelineFactory.cs index dab8194..08867a2 100644 --- a/Process/PipelineFactory.cs +++ b/Process/PipelineFactory.cs @@ -1,4 +1,4 @@ -namespace LootDumpProcessor.Process; +namespace LootDumpProcessor.Process; public static class PipelineFactory { diff --git a/Process/Processor/DumpProcessor/DumpProcessorFactory.cs b/Process/Processor/DumpProcessor/DumpProcessorFactory.cs index c5ce51e..eaf3ee8 100644 --- a/Process/Processor/DumpProcessor/DumpProcessorFactory.cs +++ b/Process/Processor/DumpProcessor/DumpProcessorFactory.cs @@ -1,4 +1,4 @@ -namespace LootDumpProcessor.Process.Processor.DumpProcessor; +namespace LootDumpProcessor.Process.Processor.DumpProcessor; public static class DumpProcessorFactory { diff --git a/Process/Processor/DumpProcessor/IDumpProcessor.cs b/Process/Processor/DumpProcessor/IDumpProcessor.cs index 0a13c7f..8dedf59 100644 --- a/Process/Processor/DumpProcessor/IDumpProcessor.cs +++ b/Process/Processor/DumpProcessor/IDumpProcessor.cs @@ -1,4 +1,4 @@ -using LootDumpProcessor.Model.Processing; +using LootDumpProcessor.Model.Processing; namespace LootDumpProcessor.Process.Processor.DumpProcessor; diff --git a/Process/Processor/DumpProcessor/MultithreadSteppedDumpProcessor.cs b/Process/Processor/DumpProcessor/MultithreadSteppedDumpProcessor.cs index c4af432..82a1e63 100644 --- a/Process/Processor/DumpProcessor/MultithreadSteppedDumpProcessor.cs +++ b/Process/Processor/DumpProcessor/MultithreadSteppedDumpProcessor.cs @@ -1,4 +1,4 @@ -using System.Collections.Concurrent; +using System.Collections.Concurrent; using LootDumpProcessor.Logger; using LootDumpProcessor.Model; using LootDumpProcessor.Model.Input; @@ -7,6 +7,7 @@ using LootDumpProcessor.Model.Processing; using LootDumpProcessor.Serializers.Json; using LootDumpProcessor.Storage; using LootDumpProcessor.Storage.Collections; +using LootDumpProcessor.Utils; namespace LootDumpProcessor.Process.Processor.DumpProcessor; @@ -25,11 +26,13 @@ public class MultithreadSteppedDumpProcessor : IDumpProcessor public Dictionary ProcessDumps(List dumps) { - LoggerFactory.GetInstance().Log("Starting final dump processing", LogLevel.Info); + if (LoggerFactory.GetInstance().CanBeLogged(LogLevel.Info)) + LoggerFactory.GetInstance().Log("Starting final dump processing", LogLevel.Info); var output = new Dictionary(); var dumpProcessData = GetDumpProcessData(dumps); - LoggerFactory.GetInstance().Log("Heavy processing done!", LogLevel.Info); + if (LoggerFactory.GetInstance().CanBeLogged(LogLevel.Info)) + LoggerFactory.GetInstance().Log("Heavy processing done!", LogLevel.Info); var staticContainers = new Dictionary(); var staticContainersLock = new object(); @@ -42,13 +45,15 @@ public class MultithreadSteppedDumpProcessor : IDumpProcessor Runners.Clear(); // BSG changed the map data so static containers are now dynamic, so we need to scan all dumps for the static containers. - LoggerFactory.GetInstance().Log("Queuing dumps for static data processing", LogLevel.Info); + if (LoggerFactory.GetInstance().CanBeLogged(LogLevel.Info)) + LoggerFactory.GetInstance().Log("Queuing dumps for static data processing", LogLevel.Info); foreach (var dumped in dumps) { Runners.Add( Task.Factory.StartNew(() => { - LoggerFactory.GetInstance().Log($"Processing static data for file {dumped.BasicInfo.FileName}", LogLevel.Info); + if (LoggerFactory.GetInstance().CanBeLogged(LogLevel.Debug)) + LoggerFactory.GetInstance().Log($"Processing static data for file {dumped.BasicInfo.FileName}", LogLevel.Debug); var data = _jsonSerializer.Deserialize(File.ReadAllText(dumped.BasicInfo.FileName)); // the if statement below takes care of processing "forced" or real static data for each map, we only need // to do this once per map, so we dont care about doing it again @@ -56,7 +61,8 @@ public class MultithreadSteppedDumpProcessor : IDumpProcessor { if (!staticContainers.ContainsKey(data.Data.Name)) { - LoggerFactory.GetInstance().Log($"Doing first time process for map {data.Data.Name} of real static data", LogLevel.Info); + if (LoggerFactory.GetInstance().CanBeLogged(LogLevel.Info)) + LoggerFactory.GetInstance().Log($"Doing first time process for map {data.Data.Name} of real static data", LogLevel.Info); var mapStaticLoot = StaticLootProcessor.CreateRealStaticContainers(data); staticContainers[mapStaticLoot.Item1] = mapStaticLoot.Item2; } @@ -113,7 +119,8 @@ public class MultithreadSteppedDumpProcessor : IDumpProcessor } Task.WaitAll(Runners.ToArray()); - LoggerFactory.GetInstance().Log("All static data processing threads finished", LogLevel.Info); + if (LoggerFactory.GetInstance().CanBeLogged(LogLevel.Info)) + LoggerFactory.GetInstance().Log("All static data processing threads finished", LogLevel.Info); // Aggregate and calculate the probability of a static container mapStaticContainersAggregated.ToDictionary( kv => kv.Key, @@ -128,35 +135,39 @@ public class MultithreadSteppedDumpProcessor : IDumpProcessor // Static containers output.Add(OutputFileType.StaticContainer, staticContainers); - - LoggerFactory.GetInstance().Log("Processing ammo distribution", LogLevel.Info); + if (LoggerFactory.GetInstance().CanBeLogged(LogLevel.Info)) + LoggerFactory.GetInstance().Log("Processing ammo distribution", LogLevel.Info); // Ammo distribution output.Add( OutputFileType.StaticAmmo, StaticLootProcessor.CreateAmmoDistribution(dumpProcessData.ContainerCounts) ); - LoggerFactory.GetInstance().Log("Processing static loot distribution", LogLevel.Info); + if (LoggerFactory.GetInstance().CanBeLogged(LogLevel.Info)) + LoggerFactory.GetInstance().Log("Processing static loot distribution", LogLevel.Info); // Static loot distribution output.Add( OutputFileType.StaticLoot, StaticLootProcessor.CreateStaticLootDistribution(dumpProcessData.ContainerCounts) ); - LoggerFactory.GetInstance().Log("Processing loose loot distribution", LogLevel.Info); + if (LoggerFactory.GetInstance().CanBeLogged(LogLevel.Info)) + LoggerFactory.GetInstance().Log("Processing loose loot distribution", LogLevel.Info); // Loose loot distribution var looseLootDistribution = LooseLootProcessor.CreateLooseLootDistribution( dumpProcessData.MapCounts, dumpProcessData.LooseLootCounts ); - LoggerFactory.GetInstance().Log("Collecting loose loot distribution information", LogLevel.Info); + if (LoggerFactory.GetInstance().CanBeLogged(LogLevel.Info)) + LoggerFactory.GetInstance().Log("Collecting loose loot distribution information", LogLevel.Info); var loot = dumpProcessData.MapCounts .Select(mapCount => mapCount.Key) .ToDictionary(mi => mi, mi => looseLootDistribution[mi]); output.Add(OutputFileType.LooseLoot, loot); - LoggerFactory.GetInstance().Log("Dump processing fully completed!", LogLevel.Info); + if (LoggerFactory.GetInstance().CanBeLogged(LogLevel.Info)) + LoggerFactory.GetInstance().Log("Dump processing fully completed!", LogLevel.Info); return output; } @@ -175,10 +186,11 @@ public class MultithreadSteppedDumpProcessor : IDumpProcessor { var mapi = tuple.Key; var g = tuple.ToList(); - LoggerFactory.GetInstance().Log( - $"Processing map {mapi}, total dump data to process: {g.Count}", - LogLevel.Info - ); + if (LoggerFactory.GetInstance().CanBeLogged(LogLevel.Info)) + LoggerFactory.GetInstance().Log( + $"Processing map {mapi}, total dump data to process: {g.Count}", + LogLevel.Info + ); dumpProcessData.MapCounts[mapi] = g.Count; var lockObjectContainerCounts = new object(); @@ -274,18 +286,16 @@ public class MultithreadSteppedDumpProcessor : IDumpProcessor lock (lockObjectCounts) { - counts.MapSpawnpointCount.AddRange(new List - { - dumpData.LooseLoot.MapSpawnpointCount - }); + counts.MapSpawnpointCount.Add(dumpData.LooseLoot.MapSpawnpointCount); } } catch (Exception e) { - LoggerFactory.GetInstance().Log( - $"ERROR OCCURRED:{e.Message}\n{e.StackTrace}", - LogLevel.Error - ); + if (LoggerFactory.GetInstance().CanBeLogged(LogLevel.Error)) + LoggerFactory.GetInstance().Log( + $"ERROR OCCURRED:{e.Message}\n{e.StackTrace}", + LogLevel.Error + ); } } }, @@ -296,10 +306,11 @@ public class MultithreadSteppedDumpProcessor : IDumpProcessor // Wait until all runners are done processing while (!Runners.All(r => r.IsCompleted)) { - LoggerFactory.GetInstance().Log( - $"One or more file processors are still processing files. Waiting {LootDumpProcessorContext.GetConfig().ThreadPoolingTimeoutMs}ms before checking again", - LogLevel.Info - ); + if (LoggerFactory.GetInstance().CanBeLogged(LogLevel.Info)) + LoggerFactory.GetInstance().Log( + $"One or more file processors are still processing files. Waiting {LootDumpProcessorContext.GetConfig().ThreadPoolingTimeoutMs}ms before checking again", + LogLevel.Info + ); Thread.Sleep( TimeSpan.FromMilliseconds(LootDumpProcessorContext.GetConfig().ThreadPoolingTimeoutMs)); } diff --git a/Process/Processor/FileProcessor/FileProcessor.cs b/Process/Processor/FileProcessor/FileProcessor.cs index b90b36a..7528067 100644 --- a/Process/Processor/FileProcessor/FileProcessor.cs +++ b/Process/Processor/FileProcessor/FileProcessor.cs @@ -1,16 +1,16 @@ -using LootDumpProcessor.Logger; +using LootDumpProcessor.Logger; using LootDumpProcessor.Model; using LootDumpProcessor.Model.Processing; -using LootDumpProcessor.Process.Processor; using LootDumpProcessor.Storage; -namespace LootDumpProcessor.Process.Impl; +namespace LootDumpProcessor.Process.Processor.FileProcessor; public class FileProcessor : IFileProcessor { public PartialData Process(BasicInfo parsedData) { - LoggerFactory.GetInstance().Log($"Processing file {parsedData.FileName}...", LogLevel.Info); + if (LoggerFactory.GetInstance().CanBeLogged(LogLevel.Debug)) + LoggerFactory.GetInstance().Log($"Processing file {parsedData.FileName}...", LogLevel.Debug); List