Added logic to read local config if found, instead of Portal config by default

This commit is contained in:
Neil Dorin
2018-09-04 14:28:16 -06:00
parent c3bea683fc
commit 0487099ee4
3 changed files with 70 additions and 32 deletions

View File

@@ -22,38 +22,73 @@ namespace PepperDash.Essentials
Debug.Console(0, Debug.ErrorLogLevel.Notice, "Loading unmerged system/template portal configuration file."); Debug.Console(0, Debug.ErrorLogLevel.Notice, "Loading unmerged system/template portal configuration file.");
try try
{ {
var filePath = Global.FilePathPrefix + "configurationFile.json"; // Check for local config file first
var filePath = Global.FilePathPrefix + ConfigWriter.LocalConfigFolder + Global.DirectorySeparator + "configurationFile.json";
Debug.Console(0, Debug.ErrorLogLevel.Notice, "Attempting to load config file: '{0}'", filePath); bool localConfigFound = false;
if (!File.Exists(filePath)) Debug.Console(0, Debug.ErrorLogLevel.Notice, "Attempting to load Local config file: '{0}'", filePath);
{
Debug.Console(0, Debug.ErrorLogLevel.Error, // Check for local config directory first
"ERROR: Configuration file not present. Please load file to {0} and reset program", filePath); if (Directory.Exists(Global.FilePathPrefix + ConfigWriter.LocalConfigFolder))
{
if (!File.Exists(filePath))
{
Debug.Console(0, Debug.ErrorLogLevel.Notice,
"Local Configuration file not present.", filePath);
}
else
localConfigFound = true;
}
// Check for Portal Config
if(!localConfigFound)
{
filePath = Global.FilePathPrefix + "configurationFile.json";
Debug.Console(0, Debug.ErrorLogLevel.Notice, "Attempting to load Portal config file: '{0}'", filePath);
if (!File.Exists(filePath))
{
Debug.Console(0, Debug.ErrorLogLevel.Notice,
"ERROR: Local Configuration file not present. Please load file to {0} and reset program", filePath);
return false; return false;
} }
}
using (StreamReader fs = new StreamReader(filePath)) // Read the file
{ using (StreamReader fs = new StreamReader(filePath))
var doubleObj = JObject.Parse(fs.ReadToEnd()); {
ConfigObject = MergeConfigs(doubleObj).ToObject<EssentialsConfig>(); if (localConfigFound)
// Extract SystemUrl and TemplateUrl into final config output
if (doubleObj["system_url"] != null)
{ {
ConfigObject.SystemUrl = doubleObj["system_url"].Value<string>(); ConfigObject = JObject.Parse(fs.ReadToEnd()).ToObject<EssentialsConfig>();
Debug.Console(0, Debug.ErrorLogLevel.Notice, "Successfully Loaded Local Config");
return true;
}
else
{
var doubleObj = JObject.Parse(fs.ReadToEnd());
ConfigObject = MergeConfigs(doubleObj).ToObject<EssentialsConfig>();
// Extract SystemUrl and TemplateUrl into final config output
if (doubleObj["system_url"] != null)
{
ConfigObject.SystemUrl = doubleObj["system_url"].Value<string>();
}
if (doubleObj["template_url"] != null)
{
ConfigObject.TemplateUrl = doubleObj["template_url"].Value<string>();
}
} }
if (doubleObj["template_url"] != null) Debug.Console(0, Debug.ErrorLogLevel.Notice, "Successfully Loaded Merged Config");
{
ConfigObject.TemplateUrl= doubleObj["template_url"].Value<string>();
}
}
Debug.Console(0, Debug.ErrorLogLevel.Notice, "Successfully Loaded Merged Config"); return true;
}
return true;
} }
catch (Exception e) catch (Exception e)
{ {

View File

@@ -14,6 +14,7 @@ namespace PepperDash.Essentials
{ {
public class ConfigWriter public class ConfigWriter
{ {
public const string LocalConfigFolder = "LocalConfig";
public static bool WriteConfig() public static bool WriteConfig()
{ {
@@ -24,7 +25,7 @@ namespace PepperDash.Essentials
var fileLock = new CCriticalSection(); var fileLock = new CCriticalSection();
var filePath = Global.FilePathPrefix + "LocalConfig" + Global.DirectorySeparator + "configurationFile.json"; var filePath = Global.FilePathPrefix + LocalConfigFolder + Global.DirectorySeparator + "configurationFile.json";
Debug.Console(0, Debug.ErrorLogLevel.Notice, "Attempting to write config file: '{0}'", filePath); Debug.Console(0, Debug.ErrorLogLevel.Notice, "Attempting to write config file: '{0}'", filePath);

View File

@@ -169,7 +169,9 @@ namespace PepperDash.Essentials.Room.Behaviours
if(Config.EnableRoomOnWhenOccupied) if(Config.EnableRoomOnWhenOccupied)
{ {
if (DateTime.Now.CompareTo(FeatureEnabledTime) > 0 && FeatureDisabledTime.CompareTo(DateTime.Now) >= 0) Debug.Console(1, this, "Current Time: {0} \n FeatureEnabledTime: {1} \n FeatureDisabledTime: {2}", DateTime.Now, FeatureEnabledTime, FeatureDisabledTime);
if (DateTime.Now.TimeOfDay.CompareTo(FeatureEnabledTime.TimeOfDay) >= 0 && FeatureDisabledTime.TimeOfDay.CompareTo(DateTime.Now.TimeOfDay) > 0)
{ {
if (SchedulerUtilities.CheckIfDayOfWeekMatchesRecurrenceDays(DateTime.Now, FeatureEnableEvent.Recurrence.RecurrenceDays)) if (SchedulerUtilities.CheckIfDayOfWeekMatchesRecurrenceDays(DateTime.Now, FeatureEnableEvent.Recurrence.RecurrenceDays))
{ {