mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-02-14 20:24:57 +00:00
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
using Crestron.SimplSharp;
|
using Crestron.SimplSharp;
|
||||||
using Crestron.SimplSharp.CrestronIO;
|
using Crestron.SimplSharp.CrestronIO;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
@@ -15,23 +16,10 @@ namespace PepperDash.Essentials.Core.Config
|
|||||||
public class ConfigReader
|
public class ConfigReader
|
||||||
{
|
{
|
||||||
public const string LocalConfigPresent =
|
public const string LocalConfigPresent =
|
||||||
@"
|
@"
|
||||||
_ _ _____ __ _
|
***************************************************
|
||||||
| | | | / __ \ / _(_)
|
************* Using Local config file *************
|
||||||
| | ___ ___ __ _| | | / \/ ___ _ __ | |_ _ __ _
|
***************************************************";
|
||||||
| | / _ \ / __/ _` | | | | / _ \| '_ \| _| |/ _` |
|
|
||||||
| |___| (_) | (_| (_| | | | \__/\ (_) | | | | | | | (_| |
|
|
||||||
\_____/\___/ \___\__,_|_| \____/\___/|_| |_|_| |_|\__, |
|
|
||||||
__/ |
|
|
||||||
|___/
|
|
||||||
______ _ _ _ _
|
|
||||||
| ___ \ | | | | | |
|
|
||||||
| |_/ / __ ___ ___ ___ _ __ | |_ | | | |
|
|
||||||
| __/ '__/ _ \/ __|/ _ \ '_ \| __| | | | |
|
|
||||||
| | | | | __/\__ \ __/ | | | |_ |_|_|_|
|
|
||||||
\_| |_| \___||___/\___|_| |_|\__| (_|_|_)
|
|
||||||
|
|
||||||
";
|
|
||||||
|
|
||||||
public static EssentialsConfig ConfigObject { get; private set; }
|
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.****");
|
"****Error: Multiple Local Configuration files present. Please ensure only a single file exists and reset program.****");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else if(configFiles.Length == 1)
|
if(configFiles.Length == 1)
|
||||||
{
|
{
|
||||||
localConfigFound = true;
|
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!");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -112,7 +98,13 @@ ______ _ _ _ _
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get the actual file path
|
// 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
|
// Read the file
|
||||||
using (StreamReader fs = new StreamReader(filePath))
|
using (StreamReader fs = new StreamReader(filePath))
|
||||||
@@ -198,7 +190,65 @@ ______ _ _ _ _
|
|||||||
{
|
{
|
||||||
var dev = ConfigObject.Devices.FirstOrDefault(d => d.Key.Equals(key, StringComparison.OrdinalIgnoreCase));
|
var dev = ConfigObject.Devices.FirstOrDefault(d => d.Key.Equals(key, StringComparison.OrdinalIgnoreCase));
|
||||||
return dev == null ? null : dev.Group;
|
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());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Linq;
|
||||||
using Crestron.SimplSharpPro;
|
using Crestron.SimplSharpPro;
|
||||||
using Crestron.SimplSharpPro.DeviceSupport;
|
using Crestron.SimplSharpPro.DeviceSupport;
|
||||||
using Crestron.SimplSharpPro.DM;
|
using Crestron.SimplSharpPro.DM;
|
||||||
|
|||||||
Reference in New Issue
Block a user