mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-02-14 12:15:01 +00:00
Merge branch 'main' into hotfix/techroom-preset-recall-event
This commit is contained in:
@@ -71,7 +71,7 @@ namespace PepperDash.Essentials
|
|||||||
CrestronConsole.AddNewConsoleCommand(s =>
|
CrestronConsole.AddNewConsoleCommand(s =>
|
||||||
{
|
{
|
||||||
foreach (var tl in TieLineCollection.Default)
|
foreach (var tl in TieLineCollection.Default)
|
||||||
CrestronConsole.ConsoleCommandResponse(" {0}\r", tl);
|
CrestronConsole.ConsoleCommandResponse(" {0}\r\n", tl);
|
||||||
},
|
},
|
||||||
"listtielines", "Prints out all tie lines", ConsoleAccessLevelEnum.AccessOperator);
|
"listtielines", "Prints out all tie lines", ConsoleAccessLevelEnum.AccessOperator);
|
||||||
|
|
||||||
@@ -85,8 +85,8 @@ namespace PepperDash.Essentials
|
|||||||
|
|
||||||
CrestronConsole.AddNewConsoleCommand(s =>
|
CrestronConsole.AddNewConsoleCommand(s =>
|
||||||
{
|
{
|
||||||
CrestronConsole.ConsoleCommandResponse("This system can be found at the following URLs:\r" +
|
CrestronConsole.ConsoleCommandResponse("This system can be found at the following URLs:\r\n" +
|
||||||
"System URL: {0}\r" +
|
"System URL: {0}\r\n" +
|
||||||
"Template URL: {1}", ConfigReader.ConfigObject.SystemUrl, ConfigReader.ConfigObject.TemplateUrl);
|
"Template URL: {1}", ConfigReader.ConfigObject.SystemUrl, ConfigReader.ConfigObject.TemplateUrl);
|
||||||
}, "portalinfo", "Shows portal URLS from configuration", ConsoleAccessLevelEnum.AccessOperator);
|
}, "portalinfo", "Shows portal URLS from configuration", ConsoleAccessLevelEnum.AccessOperator);
|
||||||
|
|
||||||
|
|||||||
@@ -20,8 +20,23 @@ namespace PepperDash.Essentials.Core
|
|||||||
/// <param name="json"></param>
|
/// <param name="json"></param>
|
||||||
public static void DoDeviceActionWithJson(string json)
|
public static void DoDeviceActionWithJson(string json)
|
||||||
{
|
{
|
||||||
var action = JsonConvert.DeserializeObject<DeviceActionWrapper>(json);
|
if (String.IsNullOrEmpty(json))
|
||||||
DoDeviceAction(action);
|
{
|
||||||
|
CrestronConsole.ConsoleCommandResponse(
|
||||||
|
"Please provide a JSON object matching the format {\"deviceKey\":\"myDevice\", \"methodName\":\"someMethod\", \"params\": [\"param1\", true]}.\r\nIf the method has no parameters, the \"params\" object may be omitted.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var action = JsonConvert.DeserializeObject<DeviceActionWrapper>(json);
|
||||||
|
|
||||||
|
DoDeviceAction(action);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
CrestronConsole.ConsoleCommandResponse("Incorrect format for JSON. Please check that the format matches {\"deviceKey\":\"myDevice\", \"methodName\":\"someMethod\", \"params\": [\"param1\", true]}");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -33,29 +48,47 @@ namespace PepperDash.Essentials.Core
|
|||||||
{
|
{
|
||||||
var key = action.DeviceKey;
|
var key = action.DeviceKey;
|
||||||
var obj = FindObjectOnPath(key);
|
var obj = FindObjectOnPath(key);
|
||||||
if (obj == null)
|
if (obj == null)
|
||||||
return;
|
{
|
||||||
|
CrestronConsole.ConsoleCommandResponse("Unable to find object at path {0}", key);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
CType t = obj.GetType();
|
if (action.Params == null)
|
||||||
var method = t.GetMethod(action.MethodName);
|
{
|
||||||
if (method == null)
|
//no params, so setting action.Params to empty array
|
||||||
{
|
action.Params = new object[0];
|
||||||
Debug.Console(0, "Method '{0}' not found", action.MethodName);
|
}
|
||||||
return;
|
|
||||||
}
|
CType t = obj.GetType();
|
||||||
var mParams = method.GetParameters();
|
try
|
||||||
// Add empty params if not provided
|
{
|
||||||
if (action.Params == null) action.Params = new object[0];
|
var methods = t.GetMethods().Where(m => m.Name == action.MethodName).ToList();
|
||||||
if (mParams.Length > action.Params.Length)
|
|
||||||
{
|
var method = methods.Count == 1 ? methods[0] : methods.FirstOrDefault(m => m.GetParameters().Length == action.Params.Length);
|
||||||
Debug.Console(0, "Method '{0}' requires {1} params", action.MethodName, mParams.Length);
|
|
||||||
return;
|
if (method == null)
|
||||||
}
|
{
|
||||||
object[] convertedParams = mParams
|
CrestronConsole.ConsoleCommandResponse(
|
||||||
.Select((p, i) => Convert.ChangeType(action.Params[i], p.ParameterType,
|
"Unable to find method with name {0} and that matches parameters {1}", action.MethodName,
|
||||||
System.Globalization.CultureInfo.InvariantCulture))
|
action.Params);
|
||||||
.ToArray();
|
return;
|
||||||
object ret = method.Invoke(obj, convertedParams);
|
}
|
||||||
|
var mParams = method.GetParameters();
|
||||||
|
|
||||||
|
var convertedParams = mParams
|
||||||
|
.Select((p, i) => Convert.ChangeType(action.Params[i], p.ParameterType,
|
||||||
|
System.Globalization.CultureInfo.InvariantCulture))
|
||||||
|
.ToArray();
|
||||||
|
var ret = method.Invoke(obj, convertedParams);
|
||||||
|
|
||||||
|
CrestronConsole.ConsoleCommandResponse("Method {0} successfully called on device {1}", method.Name,
|
||||||
|
action.DeviceKey);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
CrestronConsole.ConsoleCommandResponse("Unable to call method with name {0}. {1}", action.MethodName,
|
||||||
|
ex.Message);}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user