mirror of
https://github.com/PepperDash/PepperDashCore.git
synced 2026-02-17 21:54:44 +00:00
Updated JsonToSimpMaster.cs and EventArgs and Constants.cs to implement passing resolved file path and filename to SIMPL. All edits are flagged with TODO: pdc-20 for easier review.
This commit is contained in:
@@ -6,9 +6,9 @@ using Crestron.SimplSharp;
|
||||
|
||||
namespace PepperDash.Core.JsonToSimpl
|
||||
{
|
||||
/// <summary>
|
||||
/// Constants for Simpl modules
|
||||
/// </summary>
|
||||
/// <summary>
|
||||
/// Constants for Simpl modules
|
||||
/// </summary>
|
||||
public class JsonToSimplConstants
|
||||
{
|
||||
public const ushort JsonIsValidBoolChange = 2;
|
||||
@@ -18,7 +18,11 @@ namespace PepperDash.Core.JsonToSimpl
|
||||
public const ushort UshortValueChange = 101;
|
||||
public const ushort StringValueChange = 201;
|
||||
public const ushort FullPathToArrayChange = 202;
|
||||
public const ushort ActualFilePathChange = 203;
|
||||
public const ushort ActualFilePathChange = 203;
|
||||
|
||||
// TODO: pdc-20: Added below constants for passing file path and filename back to S+
|
||||
public const ushort FilenameResolvedChange = 204;
|
||||
public const ushort FilePathResolvedChange = 205;
|
||||
}
|
||||
|
||||
//**************************************************************************************************//
|
||||
@@ -49,77 +53,77 @@ namespace PepperDash.Core.JsonToSimpl
|
||||
//**************************************************************************************************//
|
||||
public class BoolChangeEventArgs : EventArgs
|
||||
{
|
||||
public bool State { get; set; }
|
||||
public ushort IntValue { get { return (ushort)(State ? 1 : 0); } }
|
||||
public ushort Type { get; set; }
|
||||
public ushort Index { get; set; }
|
||||
public bool State { get; set; }
|
||||
public ushort IntValue { get { return (ushort)(State ? 1 : 0); } }
|
||||
public ushort Type { get; set; }
|
||||
public ushort Index { get; set; }
|
||||
|
||||
public BoolChangeEventArgs()
|
||||
{
|
||||
}
|
||||
public BoolChangeEventArgs()
|
||||
{
|
||||
}
|
||||
|
||||
public BoolChangeEventArgs(bool state, ushort type)
|
||||
{
|
||||
State = state;
|
||||
Type = type;
|
||||
}
|
||||
public BoolChangeEventArgs(bool state, ushort type)
|
||||
{
|
||||
State = state;
|
||||
Type = type;
|
||||
}
|
||||
|
||||
public BoolChangeEventArgs(bool state, ushort type, ushort index)
|
||||
{
|
||||
State = state;
|
||||
Type = type;
|
||||
Index = index;
|
||||
}
|
||||
public BoolChangeEventArgs(bool state, ushort type, ushort index)
|
||||
{
|
||||
State = state;
|
||||
Type = type;
|
||||
Index = index;
|
||||
}
|
||||
}
|
||||
|
||||
//**************************************************************************************************//
|
||||
public class UshrtChangeEventArgs : EventArgs
|
||||
{
|
||||
public ushort IntValue { get; set; }
|
||||
public ushort Type { get; set; }
|
||||
public ushort Index { get; set; }
|
||||
public ushort IntValue { get; set; }
|
||||
public ushort Type { get; set; }
|
||||
public ushort Index { get; set; }
|
||||
|
||||
public UshrtChangeEventArgs()
|
||||
{
|
||||
}
|
||||
public UshrtChangeEventArgs()
|
||||
{
|
||||
}
|
||||
|
||||
public UshrtChangeEventArgs(ushort intValue, ushort type)
|
||||
{
|
||||
IntValue = intValue;
|
||||
Type = type;
|
||||
}
|
||||
public UshrtChangeEventArgs(ushort intValue, ushort type)
|
||||
{
|
||||
IntValue = intValue;
|
||||
Type = type;
|
||||
}
|
||||
|
||||
public UshrtChangeEventArgs(ushort intValue, ushort type, ushort index)
|
||||
{
|
||||
IntValue = intValue;
|
||||
Type = type;
|
||||
Index = index;
|
||||
}
|
||||
public UshrtChangeEventArgs(ushort intValue, ushort type, ushort index)
|
||||
{
|
||||
IntValue = intValue;
|
||||
Type = type;
|
||||
Index = index;
|
||||
}
|
||||
}
|
||||
|
||||
//**************************************************************************************************//
|
||||
public class StringChangeEventArgs : EventArgs
|
||||
{
|
||||
public string StringValue { get; set; }
|
||||
public ushort Type { get; set; }
|
||||
public ushort Index { get; set; }
|
||||
public string StringValue { get; set; }
|
||||
public ushort Type { get; set; }
|
||||
public ushort Index { get; set; }
|
||||
|
||||
public StringChangeEventArgs()
|
||||
{
|
||||
}
|
||||
public StringChangeEventArgs()
|
||||
{
|
||||
}
|
||||
|
||||
public StringChangeEventArgs(string stringValue, ushort type)
|
||||
{
|
||||
StringValue = stringValue;
|
||||
Type = type;
|
||||
}
|
||||
public StringChangeEventArgs(string stringValue, ushort type)
|
||||
{
|
||||
StringValue = stringValue;
|
||||
Type = type;
|
||||
}
|
||||
|
||||
public StringChangeEventArgs(string stringValue, ushort type, ushort index)
|
||||
{
|
||||
StringValue = stringValue;
|
||||
Type = type;
|
||||
Index = index;
|
||||
}
|
||||
public StringChangeEventArgs(string stringValue, ushort type, ushort index)
|
||||
{
|
||||
StringValue = stringValue;
|
||||
Type = type;
|
||||
Index = index;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -10,8 +10,8 @@ using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace PepperDash.Core.JsonToSimpl
|
||||
{
|
||||
public class JsonToSimplFileMaster : JsonToSimplMaster
|
||||
{
|
||||
public class JsonToSimplFileMaster : JsonToSimplMaster
|
||||
{
|
||||
/// <summary>
|
||||
/// Sets the filepath as well as registers this with the Global.Masters list
|
||||
/// </summary>
|
||||
@@ -19,6 +19,10 @@ namespace PepperDash.Core.JsonToSimpl
|
||||
|
||||
public string ActualFilePath { get; private set; }
|
||||
|
||||
// TODO: pdc-20: added to return filename back to SIMPL
|
||||
public string Filename { get; private set; }
|
||||
public string FilePathName { get; private set; }
|
||||
|
||||
/*****************************************************************************************/
|
||||
/** Privates **/
|
||||
|
||||
@@ -32,10 +36,10 @@ namespace PepperDash.Core.JsonToSimpl
|
||||
/*****************************************************************************************/
|
||||
|
||||
/// <summary>
|
||||
/// SIMPL+ default constructor.
|
||||
/// </summary>
|
||||
/// SIMPL+ default constructor.
|
||||
/// </summary>
|
||||
public JsonToSimplFileMaster()
|
||||
{
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -59,18 +63,30 @@ namespace PepperDash.Core.JsonToSimpl
|
||||
var directory = new DirectoryInfo(dir);
|
||||
|
||||
var actualFile = directory.GetFiles(fileName).FirstOrDefault();
|
||||
if(actualFile == null)
|
||||
if (actualFile == null)
|
||||
{
|
||||
var msg = string.Format("JSON file not found: {0}", Filepath);
|
||||
CrestronConsole.PrintLine(msg);
|
||||
ErrorLog.Error(msg);
|
||||
return;
|
||||
}
|
||||
//var actualFileName = actualFile.FullName;
|
||||
|
||||
// \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(ActualFilePath, 0, JsonToSimplConstants.ActualFilePathChange);
|
||||
Debug.Console(1, "Actual JSON file is {0}", ActualFilePath);
|
||||
|
||||
// TODO: pdc-20: added to retrun filename to SIMPL
|
||||
Filename = actualFile.Name;
|
||||
OnStringChange(Filename, 0, JsonToSimplConstants.FilenameResolvedChange);
|
||||
Debug.Console(1, "JSON Filename is {0}", Filename);
|
||||
|
||||
// TODO: pdc-20: added to return the file path to SIMPL
|
||||
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);
|
||||
|
||||
try
|
||||
@@ -87,10 +103,11 @@ namespace PepperDash.Core.JsonToSimpl
|
||||
ErrorLog.Error(msg);
|
||||
return;
|
||||
}
|
||||
}
|
||||
public void setDebugLevel(int level) {
|
||||
Debug.SetDebugLevel(level);
|
||||
}
|
||||
}
|
||||
public void setDebugLevel(int level)
|
||||
{
|
||||
Debug.SetDebugLevel(level);
|
||||
}
|
||||
public override void Save()
|
||||
{
|
||||
// this code is duplicated in the other masters!!!!!!!!!!!!!
|
||||
@@ -123,38 +140,38 @@ namespace PepperDash.Core.JsonToSimpl
|
||||
//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]);
|
||||
// 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))
|
||||
|
||||
Reference in New Issue
Block a user