mirror of
https://github.com/PepperDash/PepperDashCore.git
synced 2026-02-16 13:14:49 +00:00
Merge pull request #139 from PepperDash/hotfix/vc4-simpl-json-evaluateFile
Hotfix/vc4 simpl json evaluate file
This commit is contained in:
@@ -20,6 +20,21 @@ namespace PepperDash.Core.JsonToSimpl
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public const ushort JsonIsValidBoolChange = 2;
|
public const ushort JsonIsValidBoolChange = 2;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Reports the if the device is 3-series compatible
|
||||||
|
/// </summary>
|
||||||
|
public const ushort ProgramCompatibility3SeriesChange = 3;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Reports the if the device is 4-series compatible
|
||||||
|
/// </summary>
|
||||||
|
public const ushort ProgramCompatibility4SeriesChange = 4;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Reports the device platform enum value
|
||||||
|
/// </summary>
|
||||||
|
public const ushort DevicePlatformValueChange = 5;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -46,6 +61,21 @@ namespace PepperDash.Core.JsonToSimpl
|
|||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public const ushort FilePathResolvedChange = 205;
|
public const ushort FilePathResolvedChange = 205;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Reports the root directory change
|
||||||
|
/// </summary>
|
||||||
|
public const ushort RootDirectoryChange = 206;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Reports the room ID change
|
||||||
|
/// </summary>
|
||||||
|
public const ushort RoomIdChange = 207;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Reports the room name change
|
||||||
|
/// </summary>
|
||||||
|
public const ushort RoomNameChange = 208;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
using Crestron.SimplSharp;
|
using Crestron.SimplSharp;
|
||||||
using Crestron.SimplSharp.CrestronIO;
|
using Crestron.SimplSharp.CrestronIO;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
@@ -58,25 +59,87 @@ namespace PepperDash.Core.JsonToSimpl
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public void EvaluateFile(string filepath)
|
public void EvaluateFile(string filepath)
|
||||||
{
|
{
|
||||||
Filepath = filepath;
|
try
|
||||||
|
{
|
||||||
OnBoolChange(false, 0, JsonToSimplConstants.JsonIsValidBoolChange);
|
OnBoolChange(false, 0, JsonToSimplConstants.JsonIsValidBoolChange);
|
||||||
|
|
||||||
|
var dirSeparator = Path.DirectorySeparatorChar;
|
||||||
|
var dirSeparatorAlt = Path.AltDirectorySeparatorChar;
|
||||||
|
|
||||||
|
var series = CrestronEnvironment.ProgramCompatibility;
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
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);
|
||||||
|
else
|
||||||
|
splusPath = filepath;
|
||||||
|
}
|
||||||
|
|
||||||
|
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.StringValueChange);
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(Filepath))
|
if (string.IsNullOrEmpty(Filepath))
|
||||||
{
|
{
|
||||||
|
OnStringChange(string.Format("Cannot evaluate file. JSON file path not set"), 0, JsonToSimplConstants.StringValueChange);
|
||||||
CrestronConsole.PrintLine("Cannot evaluate file. JSON file path not set");
|
CrestronConsole.PrintLine("Cannot evaluate file. JSON file path not set");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Resolve wildcard
|
// get file directory and name to search
|
||||||
var dir = Path.GetDirectoryName(Filepath);
|
var fileDirectory = Path.GetDirectoryName(Filepath);
|
||||||
Debug.Console(1, "Checking directory {0}", dir);
|
|
||||||
var fileName = Path.GetFileName(Filepath);
|
var fileName = Path.GetFileName(Filepath);
|
||||||
var directory = new DirectoryInfo(dir);
|
|
||||||
|
|
||||||
var actualFile = directory.GetFiles(fileName).FirstOrDefault();
|
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
|
||||||
|
var directoryInfo = new DirectoryInfo(fileDirectory);
|
||||||
|
|
||||||
|
// get the file to be read
|
||||||
|
var actualFile = directoryInfo.GetFiles(fileName).FirstOrDefault();
|
||||||
if (actualFile == null)
|
if (actualFile == null)
|
||||||
{
|
{
|
||||||
var msg = string.Format("JSON file not found: {0}", Filepath);
|
var msg = string.Format("JSON file not found: {0}", Filepath);
|
||||||
|
OnStringChange(msg, 0, JsonToSimplConstants.StringValueChange);
|
||||||
CrestronConsole.PrintLine(msg);
|
CrestronConsole.PrintLine(msg);
|
||||||
ErrorLog.Error(msg);
|
ErrorLog.Error(msg);
|
||||||
return;
|
return;
|
||||||
@@ -86,31 +149,45 @@ namespace PepperDash.Core.JsonToSimpl
|
|||||||
// \USER\PDT000-Template_Main_Config-Combined_DSP_v00.02.json
|
// \USER\PDT000-Template_Main_Config-Combined_DSP_v00.02.json
|
||||||
ActualFilePath = actualFile.FullName;
|
ActualFilePath = actualFile.FullName;
|
||||||
OnStringChange(ActualFilePath, 0, JsonToSimplConstants.ActualFilePathChange);
|
OnStringChange(ActualFilePath, 0, JsonToSimplConstants.ActualFilePathChange);
|
||||||
|
OnStringChange(string.Format("Actual JSON file is {0}", ActualFilePath), 0, JsonToSimplConstants.StringValueChange);
|
||||||
Debug.Console(1, "Actual JSON file is {0}", ActualFilePath);
|
Debug.Console(1, "Actual JSON file is {0}", ActualFilePath);
|
||||||
|
|
||||||
Filename = actualFile.Name;
|
Filename = actualFile.Name;
|
||||||
OnStringChange(Filename, 0, JsonToSimplConstants.FilenameResolvedChange);
|
OnStringChange(Filename, 0, JsonToSimplConstants.FilenameResolvedChange);
|
||||||
|
OnStringChange(string.Format("JSON Filename is {0}", Filename), 0, JsonToSimplConstants.StringValueChange);
|
||||||
Debug.Console(1, "JSON Filename is {0}", Filename);
|
Debug.Console(1, "JSON Filename is {0}", Filename);
|
||||||
|
|
||||||
FilePathName = string.Format(@"{0}\", actualFile.DirectoryName);
|
|
||||||
OnStringChange(FilePathName, 0, JsonToSimplConstants.FilePathResolvedChange);
|
FilePathName = string.Format(@"{0}{1}", actualFile.DirectoryName, dirSeparator);
|
||||||
|
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);
|
Debug.Console(1, "JSON File Path is {0}", FilePathName);
|
||||||
|
|
||||||
string json = File.ReadToEnd(ActualFilePath, System.Text.Encoding.ASCII);
|
var json = File.ReadToEnd(ActualFilePath, System.Text.Encoding.ASCII);
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
JsonObject = JObject.Parse(json);
|
JsonObject = JObject.Parse(json);
|
||||||
foreach (var child in Children)
|
foreach (var child in Children)
|
||||||
child.ProcessAll();
|
child.ProcessAll();
|
||||||
|
|
||||||
OnBoolChange(true, 0, JsonToSimplConstants.JsonIsValidBoolChange);
|
OnBoolChange(true, 0, JsonToSimplConstants.JsonIsValidBoolChange);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
OnStringChange(string.Format("'{0}' not found", fileDirectory), 0, JsonToSimplConstants.StringValueChange);
|
||||||
|
Debug.Console(1, "'{0}' not found", fileDirectory);
|
||||||
|
}
|
||||||
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
var msg = string.Format("JSON parsing failed:\r{0}", e);
|
var msg = string.Format("EvaluateFile Exception: Message\r{0}", e.Message);
|
||||||
|
OnStringChange(msg, 0, JsonToSimplConstants.StringValueChange);
|
||||||
CrestronConsole.PrintLine(msg);
|
CrestronConsole.PrintLine(msg);
|
||||||
ErrorLog.Error(msg);
|
ErrorLog.Error(msg);
|
||||||
return;
|
|
||||||
|
var stackTrace = string.Format("EvaluateFile: Stack Trace\r{0}", e.StackTrace);
|
||||||
|
OnStringChange(stackTrace, 0, JsonToSimplConstants.StringValueChange);
|
||||||
|
CrestronConsole.PrintLine(stackTrace);
|
||||||
|
ErrorLog.Error(stackTrace);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user