Merge remote-tracking branch 'origin/master' into bug/TcpSshExceptions

This commit is contained in:
Neil Dorin
2017-12-19 09:51:48 -07:00
11 changed files with 128 additions and 31 deletions

Binary file not shown.

View File

@@ -18,6 +18,7 @@ namespace PepperDash.Core.JsonToSimpl
/// master, this will fail /// master, this will fail
/// </summary> /// </summary>
/// <param name="master">New master to add</param> /// <param name="master">New master to add</param>
///
public static void AddMaster(JsonToSimplMaster master) public static void AddMaster(JsonToSimplMaster master)
{ {
if (master == null) if (master == null)
@@ -26,7 +27,7 @@ namespace PepperDash.Core.JsonToSimpl
if (string.IsNullOrEmpty(master.UniqueID)) if (string.IsNullOrEmpty(master.UniqueID))
throw new InvalidOperationException("JSON Master cannot be added with a null UniqueId"); throw new InvalidOperationException("JSON Master cannot be added with a null UniqueId");
Debug.Console(0, "JSON Global adding master {0}", master.UniqueID); Debug.Console(1, "JSON Global adding master {0}", master.UniqueID);
if (Masters.Contains(master)) return; if (Masters.Contains(master)) return;

View File

@@ -73,7 +73,7 @@ namespace PepperDash.Core.JsonToSimpl
} }
ArrayIndex = array.IndexOf(item); ArrayIndex = array.IndexOf(item);
Debug.Console(0, "Child[{0}] Found array match at index {1}", Key, ArrayIndex); Debug.Console(1, "Child[{0}] Found array match at index {1}", Key, ArrayIndex);
return true; return true;
} }
catch (Exception e) catch (Exception e)

View File

@@ -59,15 +59,18 @@ namespace PepperDash.Core.JsonToSimpl
if (Master != null) if (Master != null)
Master.AddChild(this); Master.AddChild(this);
else else
Debug.Console(0, "JSON Child [{0}] cannot link to master {1}", key, masterUniqueId); Debug.Console(1, "JSON Child [{0}] cannot link to master {1}", key, masterUniqueId);
} }
public void SetPathPrefix(string pathPrefix) {
PathPrefix = pathPrefix;
}
/// <summary> /// <summary>
/// Set the JPath to evaluate for a given bool out index. /// Set the JPath to evaluate for a given bool out index.
/// </summary> /// </summary>
public void SetBoolPath(ushort index, string path) public void SetBoolPath(ushort index, string path)
{ {
Debug.Console(0, "JSON Child[{0}] SetBoolPath {1}={2}", Key, index, path); Debug.Console(1, "JSON Child[{0}] SetBoolPath {1}={2}", Key, index, path);
if (path == null || path.Trim() == string.Empty) return; if (path == null || path.Trim() == string.Empty) return;
BoolPaths[index] = path; BoolPaths[index] = path;
} }
@@ -77,7 +80,7 @@ namespace PepperDash.Core.JsonToSimpl
/// </summary> /// </summary>
public void SetUshortPath(ushort index, string path) public void SetUshortPath(ushort index, string path)
{ {
Debug.Console(0, "JSON Child[{0}] SetUshortPath {1}={2}", Key, index, path); Debug.Console(1, "JSON Child[{0}] SetUshortPath {1}={2}", Key, index, path);
if (path == null || path.Trim() == string.Empty) return; if (path == null || path.Trim() == string.Empty) return;
UshortPaths[index] = path; UshortPaths[index] = path;
} }
@@ -87,7 +90,7 @@ namespace PepperDash.Core.JsonToSimpl
/// </summary> /// </summary>
public void SetStringPath(ushort index, string path) public void SetStringPath(ushort index, string path)
{ {
Debug.Console(0, "JSON Child[{0}] SetStringPath {1}={2}", Key, index, path); Debug.Console(1, "JSON Child[{0}] SetStringPath {1}={2}", Key, index, path);
if (path == null || path.Trim() == string.Empty) return; if (path == null || path.Trim() == string.Empty) return;
StringPaths[index] = path; StringPaths[index] = path;
} }
@@ -121,23 +124,21 @@ namespace PepperDash.Core.JsonToSimpl
if (Process(BoolPaths[index], out response)) if (Process(BoolPaths[index], out response))
OnBoolChange(response.Equals("true", StringComparison.OrdinalIgnoreCase), OnBoolChange(response.Equals("true", StringComparison.OrdinalIgnoreCase),
index, JsonToSimplConstants.BoolValueChange); index, JsonToSimplConstants.BoolValueChange);
else else { }
OnBoolChange(false, index, JsonToSimplConstants.BoolValueChange); // OnBoolChange(false, index, JsonToSimplConstants.BoolValueChange);
} }
// Processes the path to a ushort, converting to ushort if able, firing off UshrtChange event // Processes the path to a ushort, converting to ushort if able, firing off UshrtChange event
void ProcessUshortPath(ushort index) void ProcessUshortPath(ushort index)
{ {
string response; string response;
if (Process(UshortPaths[index], out response)) if (Process(UshortPaths[index], out response)) {
{
ushort val; ushort val;
try { val = Convert.ToUInt16(response); } try { val = Convert.ToUInt16(response); } catch { val = 0; }
catch { val = 0; }
OnUShortChange(val, index, JsonToSimplConstants.UshortValueChange); OnUShortChange(val, index, JsonToSimplConstants.UshortValueChange);
} }
else else { }
OnUShortChange(0, index, JsonToSimplConstants.UshortValueChange); // OnUShortChange(0, index, JsonToSimplConstants.UshortValueChange);
} }
// Processes the path to a string property and fires of a StringChange event. // Processes the path to a string property and fires of a StringChange event.
@@ -146,8 +147,8 @@ namespace PepperDash.Core.JsonToSimpl
string response; string response;
if (Process(StringPaths[index], out response)) if (Process(StringPaths[index], out response))
OnStringChange(response, index, JsonToSimplConstants.StringValueChange); OnStringChange(response, index, JsonToSimplConstants.StringValueChange);
else else { }
OnStringChange("", index, JsonToSimplConstants.StringValueChange); // OnStringChange("", index, JsonToSimplConstants.StringValueChange);
} }
/// <summary> /// <summary>
@@ -161,7 +162,7 @@ namespace PepperDash.Core.JsonToSimpl
bool Process(string path, out string response) bool Process(string path, out string response)
{ {
path = GetFullPath(path); path = GetFullPath(path);
Debug.Console(0, "Child[{0}] Processing {1}", Key, path); Debug.Console(1, "Child[{0}] Processing {1}", Key, path);
response = ""; response = "";
if (Master == null) if (Master == null)
{ {
@@ -188,7 +189,7 @@ namespace PepperDash.Core.JsonToSimpl
response = (t.HasValues ? t.Children().Count() : 0).ToString(); response = (t.HasValues ? t.Children().Count() : 0).ToString();
else else
response = t.Value<string>(); response = t.Value<string>();
Debug.Console(0, " ='{0}'", response); Debug.Console(1, " ='{0}'", response);
return true; return true;
} }
} }
@@ -251,7 +252,7 @@ namespace PepperDash.Core.JsonToSimpl
var path = GetFullPath(keyPath); var path = GetFullPath(keyPath);
try try
{ {
Debug.Console(0, "Child[{0}] Queueing value on master {1}='{2}'", Key, path, valueToSave); Debug.Console(1, "Child[{0}] Queueing value on master {1}='{2}'", Key, path, valueToSave);
//var token = Master.JsonObject.SelectToken(path); //var token = Master.JsonObject.SelectToken(path);
//if (token != null) // The path exists in the file //if (token != null) // The path exists in the file

View File

@@ -54,7 +54,7 @@ namespace PepperDash.Core.JsonToSimpl
// Resolve wildcard // Resolve wildcard
var dir = Path.GetDirectoryName(Filepath); var dir = Path.GetDirectoryName(Filepath);
Debug.Console(0, "Checking directory {0}", dir); Debug.Console(1, "Checking directory {0}", dir);
var fileName = Path.GetFileName(Filepath); var fileName = Path.GetFileName(Filepath);
var directory = new DirectoryInfo(dir); var directory = new DirectoryInfo(dir);
@@ -68,7 +68,7 @@ namespace PepperDash.Core.JsonToSimpl
} }
//var actualFileName = actualFile.FullName; //var actualFileName = actualFile.FullName;
ActualFilePath = actualFile.FullName; ActualFilePath = actualFile.FullName;
Debug.Console(0, "Actual JSON file is {0}", ActualFilePath); Debug.Console(1, "Actual JSON file is {0}", ActualFilePath);
string json = File.ReadToEnd(ActualFilePath, System.Text.Encoding.ASCII); string json = File.ReadToEnd(ActualFilePath, System.Text.Encoding.ASCII);
@@ -87,7 +87,9 @@ namespace PepperDash.Core.JsonToSimpl
return; return;
} }
} }
public void setDebugLevel(int level) {
Debug.SetDebugLevel(level);
}
public override void Save() public override void Save()
{ {
// this code is duplicated in the other masters!!!!!!!!!!!!! // this code is duplicated in the other masters!!!!!!!!!!!!!
@@ -95,30 +97,30 @@ namespace PepperDash.Core.JsonToSimpl
// Make each child update their values into master object // Make each child update their values into master object
foreach (var child in Children) foreach (var child in Children)
{ {
Debug.Console(0, "Master [{0}] checking child [{1}] for updates to save", UniqueID, child.Key); Debug.Console(1, "Master [{0}] checking child [{1}] for updates to save", UniqueID, child.Key);
child.UpdateInputsForMaster(); child.UpdateInputsForMaster();
} }
if (UnsavedValues == null || UnsavedValues.Count == 0) if (UnsavedValues == null || UnsavedValues.Count == 0)
{ {
Debug.Console(0, "Master [{0}] No updated values to save. Skipping", UniqueID); Debug.Console(1, "Master [{0}] No updated values to save. Skipping", UniqueID);
return; return;
} }
lock (FileLock) lock (FileLock)
{ {
Debug.Console(0, "Saving"); Debug.Console(1, "Saving");
foreach (var path in UnsavedValues.Keys) foreach (var path in UnsavedValues.Keys)
{ {
var tokenToReplace = JsonObject.SelectToken(path); var tokenToReplace = JsonObject.SelectToken(path);
if (tokenToReplace != null) if (tokenToReplace != null)
{// It's found {// It's found
tokenToReplace.Replace(UnsavedValues[path]); tokenToReplace.Replace(UnsavedValues[path]);
Debug.Console(0, "JSON Master[{0}] Updating '{1}'", UniqueID, path); Debug.Console(1, "JSON Master[{0}] Updating '{1}'", UniqueID, path);
} }
else // No token. Let's make one else // No token. Let's make one
{ {
//http://stackoverflow.com/questions/17455052/how-to-set-the-value-of-a-json-path-using-json-net //http://stackoverflow.com/questions/17455052/how-to-set-the-value-of-a-json-path-using-json-net
Debug.Console(0, "JSON Master[{0}] Cannot write value onto missing property: '{1}'", UniqueID, path); Debug.Console(1, "JSON Master[{0}] Cannot write value onto missing property: '{1}'", UniqueID, path);
// JContainer jpart = JsonObject; // JContainer jpart = JsonObject;
// // walk down the path and find where it goes // // walk down the path and find where it goes

View File

@@ -106,7 +106,9 @@ namespace PepperDash.Core.JsonToSimpl
/// <param name="child"></param> /// <param name="child"></param>
public void AddChild(JsonToSimplChildObjectBase child) public void AddChild(JsonToSimplChildObjectBase child)
{ {
if (Children.Contains(child)) return; if (Children.Contains(child)) {
Children.Remove(child);
}
Children.Add(child); Children.Add(child);
} }

View File

@@ -2,6 +2,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.CrestronLogger; using Crestron.SimplSharp.CrestronLogger;
using Crestron.SimplSharp.CrestronIO; using Crestron.SimplSharp.CrestronIO;
@@ -32,8 +33,20 @@ namespace PepperDash.Core
static CTimer SaveTimer; static CTimer SaveTimer;
/// <summary>
/// When true, the IncludedExcludedKeys dict will contain keys to include.
/// When false (default), IncludedExcludedKeys will contain keys to exclude.
/// </summary>
static bool ExcludeAllMode;
static bool ExcludeNoKeyMessages;
static Dictionary<string, object> IncludedExcludedKeys;
static Debug() static Debug()
{ {
IncludedExcludedKeys = new Dictionary<string, object>();
//CrestronDataStoreStatic.InitCrestronDataStore(); //CrestronDataStoreStatic.InitCrestronDataStore();
if (CrestronEnvironment.RuntimeEnvironment == eRuntimeEnvironment.SimplSharpPro) if (CrestronEnvironment.RuntimeEnvironment == eRuntimeEnvironment.SimplSharpPro)
{ {
@@ -47,6 +60,8 @@ namespace PepperDash.Core
CrestronConsole.AddNewConsoleCommand(s => CrestronLogger.Clear(false), "appdebugclear", CrestronConsole.AddNewConsoleCommand(s => CrestronLogger.Clear(false), "appdebugclear",
"appdebugclear:P Clears the current custom log", "appdebugclear:P Clears the current custom log",
ConsoleAccessLevelEnum.AccessOperator); ConsoleAccessLevelEnum.AccessOperator);
CrestronConsole.AddNewConsoleCommand(SetDebugFilterFromConsole, "appdebugfilter",
"appdebugfilter [params]", ConsoleAccessLevelEnum.AccessOperator);
} }
CrestronEnvironment.ProgramStatusEventHandler += CrestronEnvironment_ProgramStatusEventHandler; CrestronEnvironment.ProgramStatusEventHandler += CrestronEnvironment_ProgramStatusEventHandler;
@@ -97,6 +112,82 @@ namespace PepperDash.Core
} }
} }
public static void SetDebugFilterFromConsole(string items)
{
var str = items.Trim();
if (str == "?")
{
CrestronConsole.ConsoleCommandResponse("Usage:\r APPDEBUGFILTER key1 key2 key3....\r " +
"+all: at beginning puts filter into 'default include' mode\r" +
" All keys that follow will be excluded from output.\r" +
"-all: at beginning puts filter into 'default excluse all' mode.\r" +
" All keys that follow will be the only keys that are shown\r" +
"+nokey: Enables messages with no key (default)\r" +
"-nokey: Disables messages with no key.\r" +
"(nokey settings are independent of all other settings)");
return;
}
var keys = Regex.Split(str, @"\s*");
foreach (var keyToken in keys)
{
var lkey = keyToken.ToLower();
if (lkey == "+all")
{
IncludedExcludedKeys.Clear();
ExcludeAllMode = false;
}
else if (lkey == "-all")
{
IncludedExcludedKeys.Clear();
ExcludeAllMode = true;
}
else if (lkey == "+nokey")
{
ExcludeNoKeyMessages = false;
}
else if (lkey == "-nokey")
{
ExcludeNoKeyMessages = true;
}
else
{
string key = null; ;
if (lkey.StartsWith("-"))
{
key = lkey.Substring(1);
// if in exclude all mode, we need to remove this from the inclusions
if (ExcludeAllMode)
{
if (IncludedExcludedKeys.ContainsKey(key))
IncludedExcludedKeys.Remove(key);
}
// otherwise include all mode, add to the exclusions
else
{
IncludedExcludedKeys[key] = new object();
}
}
else if (lkey.StartsWith("+"))
{
key = lkey.Substring(1);
// if in exclude all mode, we need to add this as inclusion
if (ExcludeAllMode)
{
IncludedExcludedKeys[key] = new object();
}
// otherwise include all mode, remove this from exclusions
else
{
if (IncludedExcludedKeys.ContainsKey(key))
IncludedExcludedKeys.Remove(key);
}
}
}
}
}
/// <summary> /// <summary>
/// Sets the debug level /// Sets the debug level
/// </summary> /// </summary>
@@ -274,7 +365,7 @@ namespace PepperDash.Core
if (Contexts != null) if (Contexts != null)
{ {
Debug.Console(0, "Debug memory restored from file"); Debug.Console(1, "Debug memory restored from file");
return; return;
} }
} }

View File

@@ -230,7 +230,7 @@ namespace PepperDash.Core
if (data != null) if (data != null)
{ {
SaveData = data; SaveData = data;
Debug.Console(0, "Debug memory restored from file"); Debug.Console(1, "Debug memory restored from file");
return; return;
} }
else else