From d8c905719c2cc2b5d5d42b5df239c3698962e1df Mon Sep 17 00:00:00 2001 From: Chomp Date: Tue, 24 Aug 2021 12:08:30 +0100 Subject: [PATCH] use common project --- Generator/BaseBotGenerator.cs | 4 +++- Generator/BotGearGenerator.cs | 3 ++- Generator/BotLootGenerator.cs | 4 +++- Generator/BotParser.cs | 14 ++------------ Generator/Generator.csproj | 4 ++++ Generator/Helpers/Gear/GearHelpers.cs | 3 ++- Generator/Helpers/LoggingHelpers.cs | 28 --------------------------- Generator/JsonWriter.cs | 14 +++----------- Generator/Program.cs | 7 ++++--- Generator/StringToolsExtensions.cs | 16 --------------- 10 files changed, 23 insertions(+), 74 deletions(-) delete mode 100644 Generator/Helpers/LoggingHelpers.cs delete mode 100644 Generator/StringToolsExtensions.cs diff --git a/Generator/BaseBotGenerator.cs b/Generator/BaseBotGenerator.cs index fabba07..f93ab8c 100644 --- a/Generator/BaseBotGenerator.cs +++ b/Generator/BaseBotGenerator.cs @@ -1,4 +1,6 @@ -using Generator.Helpers; +using Common; +using Common.Extensions; +using Generator.Helpers; using Generator.Models; using Generator.Models.Input; using Generator.Models.Output; diff --git a/Generator/BotGearGenerator.cs b/Generator/BotGearGenerator.cs index a0212de..8f383e6 100644 --- a/Generator/BotGearGenerator.cs +++ b/Generator/BotGearGenerator.cs @@ -1,4 +1,5 @@ -using Generator.Helpers; +using Common; +using Generator.Helpers; using Generator.Helpers.Gear; using Generator.Models.Input; using Generator.Models.Output; diff --git a/Generator/BotLootGenerator.cs b/Generator/BotLootGenerator.cs index a27cd14..2a249da 100644 --- a/Generator/BotLootGenerator.cs +++ b/Generator/BotLootGenerator.cs @@ -1,4 +1,6 @@ -using Generator.Helpers; +using Common; +using Common.Extensions; +using Generator.Helpers; using Generator.Models.Input; using Generator.Models.Output; using System; diff --git a/Generator/BotParser.cs b/Generator/BotParser.cs index 3d55494..e5f38f5 100644 --- a/Generator/BotParser.cs +++ b/Generator/BotParser.cs @@ -1,6 +1,5 @@ -using Generator.Helpers; +using Common; using Generator.Models.Input; -using Generator.Models.Output; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System; @@ -25,7 +24,7 @@ namespace Generator var stopwatch = Stopwatch.StartNew(); var failedFilesCount = 0; - CreateDirIfDoesntExist(_dumpPath); + DiskHelpers.CreateDirIfDoesntExist(_dumpPath); var botFiles = Directory.GetFiles(_dumpPath, "*.json", SearchOption.TopDirectoryOnly).ToList(); Console.WriteLine($"{botFiles.Count} bot dump files found"); @@ -88,15 +87,6 @@ namespace Generator return o.ToString(); } - private void CreateDirIfDoesntExist(string path) - { - if (!Directory.Exists($"{path}")) - { - //create dump dir - Directory.CreateDirectory($"{path}"); - } - } - private static List ParseJson(string json, string file) { //Console.WriteLine($"parsing file {file}"); diff --git a/Generator/Generator.csproj b/Generator/Generator.csproj index 9d5e978..20725c6 100644 --- a/Generator/Generator.csproj +++ b/Generator/Generator.csproj @@ -151,4 +151,8 @@ + + + + diff --git a/Generator/Helpers/Gear/GearHelpers.cs b/Generator/Helpers/Gear/GearHelpers.cs index 55f671b..65f86b2 100644 --- a/Generator/Helpers/Gear/GearHelpers.cs +++ b/Generator/Helpers/Gear/GearHelpers.cs @@ -1,4 +1,5 @@ -using Generator.Models.Input; +using Common.Extensions; +using Generator.Models.Input; using Generator.Models.Output; using Newtonsoft.Json; using System.Collections.Generic; diff --git a/Generator/Helpers/LoggingHelpers.cs b/Generator/Helpers/LoggingHelpers.cs deleted file mode 100644 index 0005f88..0000000 --- a/Generator/Helpers/LoggingHelpers.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; - -namespace Generator.Helpers -{ - public static class LoggingHelpers - { - internal static string LogTimeTaken(double totalSeconds) - { - return Math.Round(totalSeconds, 2, MidpointRounding.ToEven).ToString(); - } - - public static void LogToConsole(string message, ConsoleColor backgroundColour = ConsoleColor.Green) - { - Console.BackgroundColor = backgroundColour; - Console.ForegroundColor = ConsoleColor.Black; - - Console.WriteLine(message); - - ResetConsoleColours(); - } - - private static void ResetConsoleColours() - { - Console.BackgroundColor = ConsoleColor.Black; - Console.ForegroundColor = ConsoleColor.White; - } - } -} diff --git a/Generator/JsonWriter.cs b/Generator/JsonWriter.cs index 94a5f85..34c62ef 100644 --- a/Generator/JsonWriter.cs +++ b/Generator/JsonWriter.cs @@ -3,6 +3,7 @@ using Newtonsoft.Json; using System; using System.Collections.Generic; using System.IO; +using Common; namespace Generator { @@ -20,13 +21,13 @@ namespace Generator public void WriteJson(List bots) { var outputPath = $"{_workingPath}\\{_outputFolderName}"; - CreateDirIfDoesntExist(outputPath); + DiskHelpers.CreateDirIfDoesntExist(outputPath); foreach (var bot in bots) { if (bot.appearance.body.Count == 0) // only process files that have data in them, no body = no dumps { - Helpers.LoggingHelpers.LogToConsole($"Unable to process bot type: {bot.botType}, skipping", ConsoleColor.DarkRed); + LoggingHelpers.LogToConsole($"Unable to process bot type: {bot.botType}, skipping", ConsoleColor.DarkRed); continue; } var output = JsonConvert.SerializeObject(bot, Formatting.Indented); @@ -36,14 +37,5 @@ namespace Generator } } - - private void CreateDirIfDoesntExist(string path) - { - if (!Directory.Exists($"{path}")) - { - //create dump dir - Directory.CreateDirectory($"{path}"); - } - } } } diff --git a/Generator/Program.cs b/Generator/Program.cs index 8fb1c80..82bc573 100644 --- a/Generator/Program.cs +++ b/Generator/Program.cs @@ -1,4 +1,5 @@ -using System.IO; +using Common; +using System.IO; namespace Generator { @@ -41,8 +42,8 @@ namespace Generator if (parsedBots.Count == 0) { - Helpers.LoggingHelpers.LogToConsole("no bots found, unable to continue"); - Helpers.LoggingHelpers.LogToConsole("Check your dumps are in 'Generator\\bin\\Debug\\netcoreapp3.1\\dumps' and start with 'resp.' NOT 'req.'"); + LoggingHelpers.LogToConsole("no bots found, unable to continue"); + LoggingHelpers.LogToConsole("Check your dumps are in 'Generator\\bin\\Debug\\netcoreapp3.1\\dumps' and start with 'resp.' NOT 'req.'"); return; } diff --git a/Generator/StringToolsExtensions.cs b/Generator/StringToolsExtensions.cs deleted file mode 100644 index 32efb9d..0000000 --- a/Generator/StringToolsExtensions.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System.Collections.Generic; - -namespace Generator -{ - public static class StringToolsExtensions - { - /// - /// Add a string to a list only if it doesnt already exist - /// - public static void AddUnique(this IList self, string item) - { - if (!self.Contains(item)) - self.Add(item); - } - } -}