From 6d9ea8a13c72d75479c06ba8dfcf96df503dae0b Mon Sep 17 00:00:00 2001 From: Trevor Payne Date: Wed, 9 Sep 2020 09:34:52 -0500 Subject: [PATCH] Made the LocalConfig notice cleaner Resolves #399 --- .../Config/Essentials/ConfigReader.cs | 100 +++++++++++++----- .../Receivers/DmRmc4kZScalerCController.cs | 1 + 2 files changed, 76 insertions(+), 25 deletions(-) diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Config/Essentials/ConfigReader.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Config/Essentials/ConfigReader.cs index 8de89ab1..48a026c2 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Config/Essentials/ConfigReader.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Config/Essentials/ConfigReader.cs @@ -1,5 +1,6 @@ using System; -using System.Linq; +using System.Linq; +using System.Text; using Crestron.SimplSharp; using Crestron.SimplSharp.CrestronIO; using Newtonsoft.Json; @@ -15,23 +16,10 @@ namespace PepperDash.Essentials.Core.Config public class ConfigReader { public const string LocalConfigPresent = - @" - _ _ _____ __ _ -| | | | / __ \ / _(_) -| | ___ ___ __ _| | | / \/ ___ _ __ | |_ _ __ _ -| | / _ \ / __/ _` | | | | / _ \| '_ \| _| |/ _` | -| |___| (_) | (_| (_| | | | \__/\ (_) | | | | | | | (_| | -\_____/\___/ \___\__,_|_| \____/\___/|_| |_|_| |_|\__, | - __/ | - |___/ -______ _ _ _ _ -| ___ \ | | | | | | -| |_/ / __ ___ ___ ___ _ __ | |_ | | | | -| __/ '__/ _ \/ __|/ _ \ '_ \| __| | | | | -| | | | | __/\__ \ __/ | | | |_ |_|_|_| -\_| |_| \___||___/\___|_| |_|\__| (_|_|_) - - "; + @" +*************************************************** +************* Using Local config file ************* +***************************************************"; public static EssentialsConfig ConfigObject { get; private set; } @@ -59,12 +47,10 @@ ______ _ _ _ _ "****Error: Multiple Local Configuration files present. Please ensure only a single file exists and reset program.****"); return false; } - else if(configFiles.Length == 1) + if(configFiles.Length == 1) { - localConfigFound = true; - Debug.Console(0, Debug.ErrorLogLevel.Notice, "Found Local config file: '{0}'", filePath); - Debug.Console(0, LocalConfigPresent); - Debug.Console(0, "Local config files are valid, but be sure this is your intention. Spinning your wheels chasing down a configuration issue is not fun!"); + localConfigFound = true; + } } else @@ -112,7 +98,13 @@ ______ _ _ _ _ } // Get the actual file path - filePath = configFiles[0].FullName; + filePath = configFiles[0].FullName; + + // Generate debug statement if using a local file. + if (localConfigFound) + { + GetLocalFileMessage(filePath); + } // Read the file using (StreamReader fs = new StreamReader(filePath)) @@ -198,7 +190,65 @@ ______ _ _ _ _ { var dev = ConfigObject.Devices.FirstOrDefault(d => d.Key.Equals(key, StringComparison.OrdinalIgnoreCase)); return dev == null ? null : dev.Group; - } + } + + private static void GetLocalFileMessage(string filePath) + { + var filePathLength = filePath.Length + 2; + var debugStringWidth = filePathLength + 12; + + if (debugStringWidth < 51) + { + debugStringWidth = 51; + } + var qualifier = (filePathLength % 2 != 0) + ? " Using Local Config File " + : " Using Local Config File "; + var bookend1 = (debugStringWidth - qualifier.Length) / 2; + var bookend2 = (debugStringWidth - filePathLength) / 2; + + + var newDebugString = new StringBuilder() + .Append(CrestronEnvironment.NewLine) + // Line 1 + .Append(new string('*', debugStringWidth)) + .Append(CrestronEnvironment.NewLine) + // Line 2 + .Append(new string('*', debugStringWidth)) + .Append(CrestronEnvironment.NewLine) + // Line 3 + .Append(new string('*', 2)) + .Append(new string(' ', debugStringWidth - 4)) + .Append(new string('*', 2)) + .Append(CrestronEnvironment.NewLine) + // Line 4 + .Append(new string('*', 2)) + .Append(new string(' ', bookend1 - 2)) + .Append(qualifier) + .Append(new string(' ', bookend1 - 2)) + .Append(new string('*', 2)) + .Append(CrestronEnvironment.NewLine) + // Line 5 + .Append(new string('*', 2)) + .Append(new string(' ', bookend2 - 2)) + .Append(" " + filePath + " ") + .Append(new string(' ', bookend2 - 2)) + .Append(new string('*', 2)) + .Append(CrestronEnvironment.NewLine) + // Line 6 + .Append(new string('*', 2)) + .Append(new string(' ', debugStringWidth - 4)) + .Append(new string('*', 2)) + .Append(CrestronEnvironment.NewLine) + // Line 7 + .Append(new string('*', debugStringWidth)) + .Append(CrestronEnvironment.NewLine) + // Line 8 + .Append(new string('*', debugStringWidth)); + + Debug.Console(2, Debug.ErrorLogLevel.Notice, "Found Local config file: '{0}'", filePath); + Debug.Console(0, newDebugString.ToString()); + } } } \ No newline at end of file diff --git a/essentials-framework/Essentials DM/Essentials_DM/Endpoints/Receivers/DmRmc4kZScalerCController.cs b/essentials-framework/Essentials DM/Essentials_DM/Endpoints/Receivers/DmRmc4kZScalerCController.cs index 70afc5eb..f0238936 100644 --- a/essentials-framework/Essentials DM/Essentials_DM/Endpoints/Receivers/DmRmc4kZScalerCController.cs +++ b/essentials-framework/Essentials DM/Essentials_DM/Endpoints/Receivers/DmRmc4kZScalerCController.cs @@ -1,4 +1,5 @@ using System; +using System.Linq; using Crestron.SimplSharpPro; using Crestron.SimplSharpPro.DeviceSupport; using Crestron.SimplSharpPro.DM;