diff --git a/Generator/BotLootGenerator.cs b/Generator/BotLootGenerator.cs index 9efef04..24fee31 100644 --- a/Generator/BotLootGenerator.cs +++ b/Generator/BotLootGenerator.cs @@ -8,6 +8,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; +using System.Threading.Tasks; namespace Generator { @@ -28,15 +29,15 @@ namespace Generator LoggingHelpers.LogToConsole("Started processing bot loot"); // Iterate over assault/raider etc - foreach (var botToUpdate in _botsWithGear) + Parallel.ForEach(_botsWithGear, botToUpdate => { var rawBotsOfSameType = _rawParsedBots - .Where(x => x.Info.Settings.Role.Equals(botToUpdate.botType.ToString(), StringComparison.OrdinalIgnoreCase)) - .ToList(); + .Where(x => x.Info.Settings.Role.Equals(botToUpdate.botType.ToString(), StringComparison.OrdinalIgnoreCase)) + .ToList(); if (rawBotsOfSameType.Count == 0) { - continue; + return; } foreach (var rawParsedBot in rawBotsOfSameType) @@ -48,7 +49,7 @@ namespace Generator AddBackbackLoot(botToUpdate, rawBotsOfSameType); AddSecureContainerLoot(botToUpdate, rawBotsOfSameType); AddSpecialLoot(botToUpdate); - } + }); stopwatch.Stop(); LoggingHelpers.LogToConsole($"Finished processing bot loot. Took: {LoggingHelpers.LogTimeTaken(stopwatch.Elapsed.TotalSeconds)} seconds"); diff --git a/Generator/BotParser.cs b/Generator/BotParser.cs index e5f38f5..a625ed8 100644 --- a/Generator/BotParser.cs +++ b/Generator/BotParser.cs @@ -7,6 +7,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; +using System.Threading.Tasks; namespace Generator { @@ -30,22 +31,20 @@ namespace Generator Console.WriteLine($"{botFiles.Count} bot dump files found"); var parsedBots = new List(); - foreach (var file in botFiles) - { + Parallel.ForEach(botFiles, file => { var splitFile = file.Split("\\"); - var json = File.ReadAllText(file); try { json = PruneMalformedBsgJson(json, splitFile.Last()); - var bots = ParseJson(json, file); + var bots = ParseJson(json); if (bots == null || bots.Count == 0) { Console.WriteLine($"skipping file: {splitFile.Last()}. no bots found, "); - continue; + return; } Console.WriteLine($"parsing: {bots.Count} bots in file {splitFile.Last()}"); @@ -59,7 +58,7 @@ namespace Generator failedFilesCount++; Console.WriteLine($"JSON Error message: {jex.Message} || file: {splitFile.Last()}"); } - } + }); stopwatch.Stop(); LoggingHelpers.LogToConsole($"Cleaned and Parsed: {parsedBots.Count} bots. Failed: {failedFilesCount}. Took {LoggingHelpers.LogTimeTaken(stopwatch.Elapsed.TotalSeconds)} seconds"); @@ -87,10 +86,10 @@ namespace Generator return o.ToString(); } - private static List ParseJson(string json, string file) + private static List ParseJson(string json) { - //Console.WriteLine($"parsing file {file}"); - var serialisedObject = JsonConvert.DeserializeObject(json); + var serialisedObject = JsonConvert.DeserializeObject(json); + return serialisedObject.data; } }