From 8be02fa45884c1a2cf0657a15bf0202b7cad32f0 Mon Sep 17 00:00:00 2001 From: Jason DeVito Date: Tue, 14 Jun 2022 20:19:23 -0500 Subject: [PATCH 1/3] fix: updated JsonToSimplFileMaster EvaluateFile method, added event arg constant in support of data being passed to simpl --- .../Pepperdash Core/JsonToSimpl/Constants.cs | 20 + .../JsonToSimpl/JsonToSimplFileMaster.cs | 380 ++++++++++-------- 2 files changed, 239 insertions(+), 161 deletions(-) diff --git a/Pepperdash Core/Pepperdash Core/JsonToSimpl/Constants.cs b/Pepperdash Core/Pepperdash Core/JsonToSimpl/Constants.cs index e04bc93..3e33f3e 100644 --- a/Pepperdash Core/Pepperdash Core/JsonToSimpl/Constants.cs +++ b/Pepperdash Core/Pepperdash Core/JsonToSimpl/Constants.cs @@ -24,6 +24,16 @@ namespace PepperDash.Core.JsonToSimpl /// /// public const ushort UshortValueChange = 101; + + /// + /// Reports the Crestron Series enum value + /// + public const ushort CrestronSeriesValueChange = 102; + + /// + /// Reports the device platform enum value + /// + public const ushort DevicePlatformValueChange = 103; /// /// @@ -46,6 +56,16 @@ namespace PepperDash.Core.JsonToSimpl /// /// public const ushort FilePathResolvedChange = 205; + + /// + /// + /// + public const ushort MessageToSimpl = 206; + + /// + /// Reports the root directory + /// + public const ushort RootDirectory = 207; } /// diff --git a/Pepperdash Core/Pepperdash Core/JsonToSimpl/JsonToSimplFileMaster.cs b/Pepperdash Core/Pepperdash Core/JsonToSimpl/JsonToSimplFileMaster.cs index 4f03e45..1965a25 100644 --- a/Pepperdash Core/Pepperdash Core/JsonToSimpl/JsonToSimplFileMaster.cs +++ b/Pepperdash Core/Pepperdash Core/JsonToSimpl/JsonToSimplFileMaster.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; +using System.Text.RegularExpressions; using Crestron.SimplSharp; using Crestron.SimplSharp.CrestronIO; using Newtonsoft.Json; @@ -13,202 +14,259 @@ namespace PepperDash.Core.JsonToSimpl /// /// Represents a JSON file that can be read and written to /// - public class JsonToSimplFileMaster : JsonToSimplMaster - { - /// - /// Sets the filepath as well as registers this with the Global.Masters list - /// - public string Filepath { get; private set; } + public class JsonToSimplFileMaster : JsonToSimplMaster + { + /// + /// Sets the filepath as well as registers this with the Global.Masters list + /// + public string Filepath { get; private set; } /// /// Filepath to the actual file that will be read (Portal or local) /// - public string ActualFilePath { get; private set; } + public string ActualFilePath { get; private set; } - /// - /// - /// - public string Filename { get; private set; } /// /// /// - public string FilePathName { get; private set; } + public string Filename { get; private set; } + /// + /// + /// + public string FilePathName { get; private set; } - /*****************************************************************************************/ - /** Privates **/ + /*****************************************************************************************/ + /** Privates **/ - // The JSON file in JObject form - // For gathering the incoming data - object StringBuilderLock = new object(); - // To prevent multiple same-file access - static object FileLock = new object(); + // The JSON file in JObject form + // For gathering the incoming data + object StringBuilderLock = new object(); + // To prevent multiple same-file access + static object FileLock = new object(); - /*****************************************************************************************/ + /*****************************************************************************************/ - /// - /// SIMPL+ default constructor. - /// - public JsonToSimplFileMaster() - { - } + /// + /// SIMPL+ default constructor. + /// + public JsonToSimplFileMaster() + { + } - /// - /// Read, evaluate and udpate status - /// - public void EvaluateFile(string filepath) - { - Filepath = filepath; + /// + /// Read, evaluate and udpate status + /// + public void EvaluateFile(string filepath) + { + try + { + OnBoolChange(false, 0, JsonToSimplConstants.JsonIsValidBoolChange); - OnBoolChange(false, 0, JsonToSimplConstants.JsonIsValidBoolChange); - if (string.IsNullOrEmpty(Filepath)) - { - CrestronConsole.PrintLine("Cannot evaluate file. JSON file path not set"); - return; - } - // Resolve wildcard - var dir = Path.GetDirectoryName(Filepath); - Debug.Console(1, "Checking directory {0}", dir); - var fileName = Path.GetFileName(Filepath); - var directory = new DirectoryInfo(dir); + var dirSeparator = Path.DirectorySeparatorChar; // win-'\', linux-'/' + var dirSeparatorAlt = Path.AltDirectorySeparatorChar; // win-'\', linux-'/' - var actualFile = directory.GetFiles(fileName).FirstOrDefault(); - if (actualFile == null) - { - var msg = string.Format("JSON file not found: {0}", Filepath); - CrestronConsole.PrintLine(msg); - ErrorLog.Error(msg); - return; - } + var is4Series = CrestronEnvironment.ProgramCompatibility == eCrestronSeries.Series4; + var isServer = CrestronEnvironment.DevicePlatform == eDevicePlatform.Server; - // \xSE\xR\PDT000-Template_Main_Config-Combined_DSP_v00.02.json - // \USER\PDT000-Template_Main_Config-Combined_DSP_v00.02.json - ActualFilePath = actualFile.FullName; - OnStringChange(ActualFilePath, 0, JsonToSimplConstants.ActualFilePathChange); - Debug.Console(1, "Actual JSON file is {0}", ActualFilePath); + OnUshrtChange((ushort)CrestronEnvironment.ProgramCompatibility, 0, + JsonToSimplConstants.CrestronSeriesValueChange); + + OnUshrtChange((ushort) CrestronEnvironment.DevicePlatform, 0, + JsonToSimplConstants.DevicePlatformValueChange); + - Filename = actualFile.Name; - OnStringChange(Filename, 0, JsonToSimplConstants.FilenameResolvedChange); - Debug.Console(1, "JSON Filename is {0}", Filename); + var rootDirectory = Directory.GetApplicationRootDirectory(); + OnStringChange(rootDirectory, 0, JsonToSimplConstants.RootDirectory); - FilePathName = string.Format(@"{0}\", actualFile.DirectoryName); - OnStringChange(FilePathName, 0, JsonToSimplConstants.FilePathResolvedChange); - Debug.Console(1, "JSON File Path is {0}", FilePathName); - string json = File.ReadToEnd(ActualFilePath, System.Text.Encoding.ASCII); + var splusPath = string.Empty; + if (Regex.IsMatch(filepath, @"user", RegexOptions.IgnoreCase)) + { + if (is4Series) + splusPath = Regex.Replace(filepath, "user", "user", RegexOptions.IgnoreCase); + else if (isServer) + splusPath = Regex.Replace(filepath, "user", "User", RegexOptions.IgnoreCase); + } - try - { - JsonObject = JObject.Parse(json); - foreach (var child in Children) - child.ProcessAll(); - OnBoolChange(true, 0, JsonToSimplConstants.JsonIsValidBoolChange); - } - catch (Exception e) - { - var msg = string.Format("JSON parsing failed:\r{0}", e); - CrestronConsole.PrintLine(msg); - ErrorLog.Error(msg); - return; - } - } + filepath = splusPath.Replace(dirSeparatorAlt, dirSeparator); + + Filepath = string.Format("{1}{0}{2}", dirSeparator, rootDirectory, + filepath.TrimStart(dirSeparator, dirSeparatorAlt)); + + OnStringChange(string.Format("Attempting to evaluate {0}", Filepath), 0, JsonToSimplConstants.MessageToSimpl); + + if (string.IsNullOrEmpty(Filepath)) + { + OnStringChange(string.Format("Cannot evaluate file. JSON file path not set"), 0, JsonToSimplConstants.MessageToSimpl); + CrestronConsole.PrintLine("Cannot evaluate file. JSON file path not set"); + return; + } + + // get file directory and name to search + var fileDirectory = Path.GetDirectoryName(Filepath); + var fileName = Path.GetFileName(Filepath); + + OnStringChange(string.Format("Checking '{0}' for '{1}'", fileDirectory, fileName), 0, JsonToSimplConstants.MessageToSimpl); + Debug.Console(1, "Checking '{0}' for '{1}'", fileDirectory, fileName); + + if (Directory.Exists(fileDirectory)) + { + // get the directory info + var directoryInfo = new DirectoryInfo(fileDirectory); + var actualFile = directoryInfo.GetFiles(fileName).FirstOrDefault(); + //var actualFile = new DirectoryInfo(Filepath).GetFiles(fileName).FirstOrDefault(); + if (actualFile == null) + { + var msg = string.Format("JSON file not found: {0}", Filepath); + OnStringChange(msg, 0, JsonToSimplConstants.MessageToSimpl); + CrestronConsole.PrintLine(msg); + ErrorLog.Error(msg); + return; + } + + // \xSE\xR\PDT000-Template_Main_Config-Combined_DSP_v00.02.json + // \USER\PDT000-Template_Main_Config-Combined_DSP_v00.02.json + ActualFilePath = actualFile.FullName; + OnStringChange(ActualFilePath, 0, JsonToSimplConstants.ActualFilePathChange); + OnStringChange(string.Format("Actual JSON file is {0}", ActualFilePath), 0, JsonToSimplConstants.MessageToSimpl); + Debug.Console(1, "Actual JSON file is {0}", ActualFilePath); + + Filename = actualFile.Name; + OnStringChange(Filename, 0, JsonToSimplConstants.FilenameResolvedChange); + OnStringChange(string.Format("JSON Filename is {0}", Filename), 0, JsonToSimplConstants.MessageToSimpl); + Debug.Console(1, "JSON Filename is {0}", Filename); + + + FilePathName = string.Format(@"{0}{1}", actualFile.DirectoryName, dirSeparator); + OnStringChange(FilePathName, 0, JsonToSimplConstants.FilePathResolvedChange); + OnStringChange(string.Format("JSON File Path is {0}", FilePathName), 0, JsonToSimplConstants.MessageToSimpl); + Debug.Console(1, "JSON File Path is {0}", FilePathName); + + var json = File.ReadToEnd(ActualFilePath, System.Text.Encoding.ASCII); + + JsonObject = JObject.Parse(json); + foreach (var child in Children) + child.ProcessAll(); + OnBoolChange(true, 0, JsonToSimplConstants.JsonIsValidBoolChange); + } + else + { + OnStringChange(string.Format("'{0}' not found", fileDirectory), 0, JsonToSimplConstants.MessageToSimpl); + Debug.Console(1, "'{0}' not found", fileDirectory); + } + } + catch (Exception e) + { + var msg = string.Format("EvaluateFile Exception: Message\r{0}", e.Message); + OnStringChange(msg, 0, JsonToSimplConstants.MessageToSimpl); + CrestronConsole.PrintLine(msg); + ErrorLog.Error(msg); + + var stackTrace = string.Format("EvaluateFile: Stack Trace\r{0}", e.StackTrace); + OnStringChange(stackTrace, 0, JsonToSimplConstants.MessageToSimpl); + CrestronConsole.PrintLine(stackTrace); + ErrorLog.Error(stackTrace); + return; + } + } /// /// Sets the debug level /// /// - public void setDebugLevel(int level) - { - Debug.SetDebugLevel(level); - } + public void setDebugLevel(int level) + { + Debug.SetDebugLevel(level); + } /// /// Saves the values to the file /// - public override void Save() - { - // this code is duplicated in the other masters!!!!!!!!!!!!! - UnsavedValues = new Dictionary(); - // Make each child update their values into master object - foreach (var child in Children) - { - Debug.Console(1, "Master [{0}] checking child [{1}] for updates to save", UniqueID, child.Key); - child.UpdateInputsForMaster(); - } + public override void Save() + { + // this code is duplicated in the other masters!!!!!!!!!!!!! + UnsavedValues = new Dictionary(); + // Make each child update their values into master object + foreach (var child in Children) + { + Debug.Console(1, "Master [{0}] checking child [{1}] for updates to save", UniqueID, child.Key); + child.UpdateInputsForMaster(); + } - if (UnsavedValues == null || UnsavedValues.Count == 0) - { - Debug.Console(1, "Master [{0}] No updated values to save. Skipping", UniqueID); - return; - } - lock (FileLock) - { - Debug.Console(1, "Saving"); - foreach (var path in UnsavedValues.Keys) - { - var tokenToReplace = JsonObject.SelectToken(path); - if (tokenToReplace != null) - {// It's found - tokenToReplace.Replace(UnsavedValues[path]); - Debug.Console(1, "JSON Master[{0}] Updating '{1}'", UniqueID, path); - } - else // No token. Let's make one - { - //http://stackoverflow.com/questions/17455052/how-to-set-the-value-of-a-json-path-using-json-net - Debug.Console(1, "JSON Master[{0}] Cannot write value onto missing property: '{1}'", UniqueID, path); + if (UnsavedValues == null || UnsavedValues.Count == 0) + { + Debug.Console(1, "Master [{0}] No updated values to save. Skipping", UniqueID); + return; + } + lock (FileLock) + { + Debug.Console(1, "Saving"); + foreach (var path in UnsavedValues.Keys) + { + var tokenToReplace = JsonObject.SelectToken(path); + if (tokenToReplace != null) + {// It's found + tokenToReplace.Replace(UnsavedValues[path]); + Debug.Console(1, "JSON Master[{0}] Updating '{1}'", UniqueID, path); + } + else // No token. Let's make one + { + //http://stackoverflow.com/questions/17455052/how-to-set-the-value-of-a-json-path-using-json-net + Debug.Console(1, "JSON Master[{0}] Cannot write value onto missing property: '{1}'", UniqueID, path); - // JContainer jpart = JsonObject; - // // walk down the path and find where it goes - //#warning Does not handle arrays. - // foreach (var part in path.Split('.')) - // { + // JContainer jpart = JsonObject; + // // walk down the path and find where it goes + //#warning Does not handle arrays. + // foreach (var part in path.Split('.')) + // { - // var openPos = part.IndexOf('['); - // if (openPos > -1) - // { - // openPos++; // move to number - // var closePos = part.IndexOf(']'); - // var arrayName = part.Substring(0, openPos - 1); // get the name - // var index = Convert.ToInt32(part.Substring(openPos, closePos - openPos)); + // var openPos = part.IndexOf('['); + // if (openPos > -1) + // { + // openPos++; // move to number + // var closePos = part.IndexOf(']'); + // var arrayName = part.Substring(0, openPos - 1); // get the name + // var index = Convert.ToInt32(part.Substring(openPos, closePos - openPos)); - // // Check if the array itself exists and add the item if so - // if (jpart[arrayName] != null) - // { - // var arrayObj = jpart[arrayName] as JArray; - // var item = arrayObj[index]; - // if (item == null) - // arrayObj.Add(new JObject()); - // } + // // Check if the array itself exists and add the item if so + // if (jpart[arrayName] != null) + // { + // var arrayObj = jpart[arrayName] as JArray; + // var item = arrayObj[index]; + // if (item == null) + // arrayObj.Add(new JObject()); + // } - // Debug.Console(0, "IGNORING MISSING ARRAY VALUE FOR NOW"); - // continue; - // } - // // Build the - // if (jpart[part] == null) - // jpart.Add(new JProperty(part, new JObject())); - // jpart = jpart[part] as JContainer; - // } - // jpart.Replace(UnsavedValues[path]); - } - } - using (StreamWriter sw = new StreamWriter(ActualFilePath)) - { - try - { - sw.Write(JsonObject.ToString()); - sw.Flush(); - } - catch (Exception e) - { - string err = string.Format("Error writing JSON file:\r{0}", e); - Debug.Console(0, err); - ErrorLog.Warn(err); - return; - } - } - } - } - } + // Debug.Console(0, "IGNORING MISSING ARRAY VALUE FOR NOW"); + // continue; + // } + // // Build the + // if (jpart[part] == null) + // jpart.Add(new JProperty(part, new JObject())); + // jpart = jpart[part] as JContainer; + // } + // jpart.Replace(UnsavedValues[path]); + } + } + using (StreamWriter sw = new StreamWriter(ActualFilePath)) + { + try + { + sw.Write(JsonObject.ToString()); + sw.Flush(); + } + catch (Exception e) + { + string err = string.Format("Error writing JSON file:\r{0}", e); + Debug.Console(0, err); + ErrorLog.Warn(err); + return; + } + } + } + } + } } From 3fa94a92d2910ddd65aba0cc1f5428cde8088363 Mon Sep 17 00:00:00 2001 From: Jason DeVito Date: Wed, 15 Jun 2022 10:01:19 -0500 Subject: [PATCH 2/3] fix: updated EvaluateFile method to resolve issues reading files on an appliance discovered when testing on a 3-series --- .../Pepperdash Core/JsonToSimpl/Constants.cs | 12 ++--- .../JsonToSimpl/JsonToSimplFileMaster.cs | 54 +++++++++++-------- 2 files changed, 37 insertions(+), 29 deletions(-) diff --git a/Pepperdash Core/Pepperdash Core/JsonToSimpl/Constants.cs b/Pepperdash Core/Pepperdash Core/JsonToSimpl/Constants.cs index 3e33f3e..e69efb0 100644 --- a/Pepperdash Core/Pepperdash Core/JsonToSimpl/Constants.cs +++ b/Pepperdash Core/Pepperdash Core/JsonToSimpl/Constants.cs @@ -57,15 +57,15 @@ namespace PepperDash.Core.JsonToSimpl /// public const ushort FilePathResolvedChange = 205; - /// - /// - /// - public const ushort MessageToSimpl = 206; - /// /// Reports the root directory /// - public const ushort RootDirectory = 207; + public const ushort RootDirectoryChange = 206; + + /// + /// Reports the room ID + /// + public const ushort RoomIdChange = 207; } /// diff --git a/Pepperdash Core/Pepperdash Core/JsonToSimpl/JsonToSimplFileMaster.cs b/Pepperdash Core/Pepperdash Core/JsonToSimpl/JsonToSimplFileMaster.cs index 1965a25..9906462 100644 --- a/Pepperdash Core/Pepperdash Core/JsonToSimpl/JsonToSimplFileMaster.cs +++ b/Pepperdash Core/Pepperdash Core/JsonToSimpl/JsonToSimplFileMaster.cs @@ -63,9 +63,8 @@ namespace PepperDash.Core.JsonToSimpl { OnBoolChange(false, 0, JsonToSimplConstants.JsonIsValidBoolChange); - - var dirSeparator = Path.DirectorySeparatorChar; // win-'\', linux-'/' - var dirSeparatorAlt = Path.AltDirectorySeparatorChar; // win-'\', linux-'/' + var dirSeparator = Path.DirectorySeparatorChar; + var dirSeparatorAlt = Path.AltDirectorySeparatorChar; var is4Series = CrestronEnvironment.ProgramCompatibility == eCrestronSeries.Series4; var isServer = CrestronEnvironment.DevicePlatform == eDevicePlatform.Server; @@ -78,16 +77,17 @@ namespace PepperDash.Core.JsonToSimpl var rootDirectory = Directory.GetApplicationRootDirectory(); - OnStringChange(rootDirectory, 0, JsonToSimplConstants.RootDirectory); - - + OnStringChange(rootDirectory, 0, JsonToSimplConstants.RootDirectoryChange); + var splusPath = string.Empty; if (Regex.IsMatch(filepath, @"user", RegexOptions.IgnoreCase)) { if (is4Series) splusPath = Regex.Replace(filepath, "user", "user", RegexOptions.IgnoreCase); - else if (isServer) + else if (isServer) splusPath = Regex.Replace(filepath, "user", "User", RegexOptions.IgnoreCase); + else + splusPath = filepath; } filepath = splusPath.Replace(dirSeparatorAlt, dirSeparator); @@ -95,11 +95,11 @@ namespace PepperDash.Core.JsonToSimpl Filepath = string.Format("{1}{0}{2}", dirSeparator, rootDirectory, filepath.TrimStart(dirSeparator, dirSeparatorAlt)); - OnStringChange(string.Format("Attempting to evaluate {0}", Filepath), 0, JsonToSimplConstants.MessageToSimpl); + OnStringChange(string.Format("Attempting to evaluate {0}", Filepath), 0, JsonToSimplConstants.StringValueChange); if (string.IsNullOrEmpty(Filepath)) { - OnStringChange(string.Format("Cannot evaluate file. JSON file path not set"), 0, JsonToSimplConstants.MessageToSimpl); + OnStringChange(string.Format("Cannot evaluate file. JSON file path not set"), 0, JsonToSimplConstants.StringValueChange); CrestronConsole.PrintLine("Cannot evaluate file. JSON file path not set"); return; } @@ -108,19 +108,27 @@ namespace PepperDash.Core.JsonToSimpl var fileDirectory = Path.GetDirectoryName(Filepath); var fileName = Path.GetFileName(Filepath); - OnStringChange(string.Format("Checking '{0}' for '{1}'", fileDirectory, fileName), 0, JsonToSimplConstants.MessageToSimpl); + OnStringChange(string.Format("Checking '{0}' for '{1}'", fileDirectory, fileName), 0, JsonToSimplConstants.StringValueChange); Debug.Console(1, "Checking '{0}' for '{1}'", fileDirectory, fileName); if (Directory.Exists(fileDirectory)) { - // get the directory info + // get the directory info var directoryInfo = new DirectoryInfo(fileDirectory); - var actualFile = directoryInfo.GetFiles(fileName).FirstOrDefault(); - //var actualFile = new DirectoryInfo(Filepath).GetFiles(fileName).FirstOrDefault(); + + // get the roomID + if (!string.IsNullOrEmpty(rootDirectory)) + { + var roomId = directoryInfo.Name; + OnStringChange(roomId, 0, JsonToSimplConstants.RoomIdChange); + } + + // get the file to be read + var actualFile = directoryInfo.GetFiles(fileName).FirstOrDefault(); if (actualFile == null) { var msg = string.Format("JSON file not found: {0}", Filepath); - OnStringChange(msg, 0, JsonToSimplConstants.MessageToSimpl); + OnStringChange(msg, 0, JsonToSimplConstants.StringValueChange); CrestronConsole.PrintLine(msg); ErrorLog.Error(msg); return; @@ -130,45 +138,45 @@ namespace PepperDash.Core.JsonToSimpl // \USER\PDT000-Template_Main_Config-Combined_DSP_v00.02.json ActualFilePath = actualFile.FullName; OnStringChange(ActualFilePath, 0, JsonToSimplConstants.ActualFilePathChange); - OnStringChange(string.Format("Actual JSON file is {0}", ActualFilePath), 0, JsonToSimplConstants.MessageToSimpl); + OnStringChange(string.Format("Actual JSON file is {0}", ActualFilePath), 0, JsonToSimplConstants.StringValueChange); Debug.Console(1, "Actual JSON file is {0}", ActualFilePath); Filename = actualFile.Name; OnStringChange(Filename, 0, JsonToSimplConstants.FilenameResolvedChange); - OnStringChange(string.Format("JSON Filename is {0}", Filename), 0, JsonToSimplConstants.MessageToSimpl); + OnStringChange(string.Format("JSON Filename is {0}", Filename), 0, JsonToSimplConstants.StringValueChange); Debug.Console(1, "JSON Filename is {0}", Filename); FilePathName = string.Format(@"{0}{1}", actualFile.DirectoryName, dirSeparator); - OnStringChange(FilePathName, 0, JsonToSimplConstants.FilePathResolvedChange); - OnStringChange(string.Format("JSON File Path is {0}", FilePathName), 0, JsonToSimplConstants.MessageToSimpl); - Debug.Console(1, "JSON File Path is {0}", FilePathName); + OnStringChange(string.Format(@"{0}", actualFile.DirectoryName), 0, JsonToSimplConstants.FilePathResolvedChange); + OnStringChange(string.Format(@"JSON File Path is {0}", actualFile.DirectoryName), 0, JsonToSimplConstants.StringValueChange); + Debug.Console(1, "JSON File Path is {0}", FilePathName); var json = File.ReadToEnd(ActualFilePath, System.Text.Encoding.ASCII); JsonObject = JObject.Parse(json); foreach (var child in Children) child.ProcessAll(); + OnBoolChange(true, 0, JsonToSimplConstants.JsonIsValidBoolChange); } else { - OnStringChange(string.Format("'{0}' not found", fileDirectory), 0, JsonToSimplConstants.MessageToSimpl); + OnStringChange(string.Format("'{0}' not found", fileDirectory), 0, JsonToSimplConstants.StringValueChange); Debug.Console(1, "'{0}' not found", fileDirectory); } } catch (Exception e) { var msg = string.Format("EvaluateFile Exception: Message\r{0}", e.Message); - OnStringChange(msg, 0, JsonToSimplConstants.MessageToSimpl); + OnStringChange(msg, 0, JsonToSimplConstants.StringValueChange); CrestronConsole.PrintLine(msg); ErrorLog.Error(msg); var stackTrace = string.Format("EvaluateFile: Stack Trace\r{0}", e.StackTrace); - OnStringChange(stackTrace, 0, JsonToSimplConstants.MessageToSimpl); + OnStringChange(stackTrace, 0, JsonToSimplConstants.StringValueChange); CrestronConsole.PrintLine(stackTrace); ErrorLog.Error(stackTrace); - return; } } From 33c3aa99791dd3ce4cefe67e35e50b630da16d85 Mon Sep 17 00:00:00 2001 From: Jason DeVito Date: Wed, 15 Jun 2022 11:16:45 -0500 Subject: [PATCH 3/3] feat: added roomName reporting to EvaluateFile, updated constants used by JSON wrapper modules, refactored programCompatibility checks --- .../Pepperdash Core/JsonToSimpl/Constants.cs | 24 +++++++---- .../JsonToSimpl/JsonToSimplFileMaster.cs | 41 ++++++++++++------- 2 files changed, 43 insertions(+), 22 deletions(-) diff --git a/Pepperdash Core/Pepperdash Core/JsonToSimpl/Constants.cs b/Pepperdash Core/Pepperdash Core/JsonToSimpl/Constants.cs index e69efb0..0bf9872 100644 --- a/Pepperdash Core/Pepperdash Core/JsonToSimpl/Constants.cs +++ b/Pepperdash Core/Pepperdash Core/JsonToSimpl/Constants.cs @@ -21,19 +21,24 @@ namespace PepperDash.Core.JsonToSimpl public const ushort JsonIsValidBoolChange = 2; /// - /// + /// Reports the if the device is 3-series compatible /// - public const ushort UshortValueChange = 101; + public const ushort ProgramCompatibility3SeriesChange = 3; /// - /// Reports the Crestron Series enum value + /// Reports the if the device is 4-series compatible /// - public const ushort CrestronSeriesValueChange = 102; + public const ushort ProgramCompatibility4SeriesChange = 4; /// /// Reports the device platform enum value /// - public const ushort DevicePlatformValueChange = 103; + public const ushort DevicePlatformValueChange = 5; + + /// + /// + /// + public const ushort UshortValueChange = 101; /// /// @@ -58,14 +63,19 @@ namespace PepperDash.Core.JsonToSimpl public const ushort FilePathResolvedChange = 205; /// - /// Reports the root directory + /// Reports the root directory change /// public const ushort RootDirectoryChange = 206; /// - /// Reports the room ID + /// Reports the room ID change /// public const ushort RoomIdChange = 207; + + /// + /// Reports the room name change + /// + public const ushort RoomNameChange = 208; } /// diff --git a/Pepperdash Core/Pepperdash Core/JsonToSimpl/JsonToSimplFileMaster.cs b/Pepperdash Core/Pepperdash Core/JsonToSimpl/JsonToSimplFileMaster.cs index 9906462..c5f50d5 100644 --- a/Pepperdash Core/Pepperdash Core/JsonToSimpl/JsonToSimplFileMaster.cs +++ b/Pepperdash Core/Pepperdash Core/JsonToSimpl/JsonToSimplFileMaster.cs @@ -66,15 +66,33 @@ namespace PepperDash.Core.JsonToSimpl var dirSeparator = Path.DirectorySeparatorChar; var dirSeparatorAlt = Path.AltDirectorySeparatorChar; - var is4Series = CrestronEnvironment.ProgramCompatibility == eCrestronSeries.Series4; - var isServer = CrestronEnvironment.DevicePlatform == eDevicePlatform.Server; + var series = CrestronEnvironment.ProgramCompatibility; - OnUshrtChange((ushort)CrestronEnvironment.ProgramCompatibility, 0, - JsonToSimplConstants.CrestronSeriesValueChange); - - OnUshrtChange((ushort) CrestronEnvironment.DevicePlatform, 0, + var is3Series = (eCrestronSeries.Series3 == (series & eCrestronSeries.Series3)); + OnBoolChange(is3Series, 0, + JsonToSimplConstants.ProgramCompatibility3SeriesChange); + + var is4Series = (eCrestronSeries.Series4 == (series & eCrestronSeries.Series4)); + OnBoolChange(is4Series, 0, + JsonToSimplConstants.ProgramCompatibility4SeriesChange); + + var isServer = CrestronEnvironment.DevicePlatform == eDevicePlatform.Server; + OnBoolChange(isServer, 0, JsonToSimplConstants.DevicePlatformValueChange); - + + // get the roomID + var roomId = Crestron.SimplSharp.InitialParametersClass.RoomId; + if (!string.IsNullOrEmpty(roomId)) + { + OnStringChange(roomId, 0, JsonToSimplConstants.RoomIdChange); + } + + // get the roomName + var roomName = Crestron.SimplSharp.InitialParametersClass.RoomName; + if (!string.IsNullOrEmpty(roomName)) + { + OnStringChange(roomName, 0, JsonToSimplConstants.RoomNameChange); + } var rootDirectory = Directory.GetApplicationRootDirectory(); OnStringChange(rootDirectory, 0, JsonToSimplConstants.RootDirectoryChange); @@ -114,14 +132,7 @@ namespace PepperDash.Core.JsonToSimpl if (Directory.Exists(fileDirectory)) { // get the directory info - var directoryInfo = new DirectoryInfo(fileDirectory); - - // get the roomID - if (!string.IsNullOrEmpty(rootDirectory)) - { - var roomId = directoryInfo.Name; - OnStringChange(roomId, 0, JsonToSimplConstants.RoomIdChange); - } + var directoryInfo = new DirectoryInfo(fileDirectory); // get the file to be read var actualFile = directoryInfo.GetFiles(fileName).FirstOrDefault();