mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-02-16 05:05:00 +00:00
Merge pull request #1196 from PepperDash/feature-2.0.0/routing-cooldown-fixes
Feature 2.0.0/routing cooldown fixes
This commit is contained in:
@@ -5,6 +5,7 @@ using System.Linq;
|
|||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
|
using PepperDash.Essentials.Core.Devices;
|
||||||
|
|
||||||
namespace PepperDash.Essentials.Core.Config
|
namespace PepperDash.Essentials.Core.Config
|
||||||
{
|
{
|
||||||
@@ -28,6 +29,9 @@ namespace PepperDash.Essentials.Core.Config
|
|||||||
[JsonProperty("audioControlPointLists")]
|
[JsonProperty("audioControlPointLists")]
|
||||||
public Dictionary<string, AudioControlPointListItem> AudioControlPointLists { get; set; }
|
public Dictionary<string, AudioControlPointListItem> AudioControlPointLists { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("cameraLists")]
|
||||||
|
public Dictionary<string, Dictionary<string, CameraListItem>> CameraLists { get; set; }
|
||||||
|
|
||||||
[JsonProperty("tieLines")]
|
[JsonProperty("tieLines")]
|
||||||
public List<TieLineConfig> TieLines { get; set; }
|
public List<TieLineConfig> TieLines { get; set; }
|
||||||
|
|
||||||
@@ -41,6 +45,7 @@ namespace PepperDash.Essentials.Core.Config
|
|||||||
SourceLists = new Dictionary<string, Dictionary<string, SourceListItem>>();
|
SourceLists = new Dictionary<string, Dictionary<string, SourceListItem>>();
|
||||||
DestinationLists = new Dictionary<string, Dictionary<string, DestinationListItem>>();
|
DestinationLists = new Dictionary<string, Dictionary<string, DestinationListItem>>();
|
||||||
AudioControlPointLists = new Dictionary<string, AudioControlPointListItem>();
|
AudioControlPointLists = new Dictionary<string, AudioControlPointListItem>();
|
||||||
|
CameraLists = new Dictionary<string, Dictionary<string, CameraListItem>>();
|
||||||
TieLines = new List<TieLineConfig>();
|
TieLines = new List<TieLineConfig>();
|
||||||
JoinMaps = new Dictionary<string, JObject>();
|
JoinMaps = new Dictionary<string, JObject>();
|
||||||
}
|
}
|
||||||
@@ -84,6 +89,17 @@ namespace PepperDash.Essentials.Core.Config
|
|||||||
return AudioControlPointLists[key];
|
return AudioControlPointLists[key];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Checks CameraLists for a given list and returns it if found. Otherwise, returns null
|
||||||
|
/// </summary>
|
||||||
|
public Dictionary<string, CameraListItem> GetCameraListForKey(string key)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(key) || !CameraLists.ContainsKey(key))
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return CameraLists[key];
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Checks Devices for an item with a Key that matches and returns it if found. Otherwise, retunes null
|
/// Checks Devices for an item with a Key that matches and returns it if found. Otherwise, retunes null
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
76
src/PepperDash.Essentials.Core/Devices/CameraListItem.cs
Normal file
76
src/PepperDash.Essentials.Core/Devices/CameraListItem.cs
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
using Newtonsoft.Json;
|
||||||
|
using PepperDash.Core;
|
||||||
|
|
||||||
|
namespace PepperDash.Essentials.Core
|
||||||
|
{
|
||||||
|
public class CameraListItem
|
||||||
|
{
|
||||||
|
[JsonProperty("deviceKey")]
|
||||||
|
public string DeviceKey { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the source Device for this, if it exists in DeviceManager
|
||||||
|
/// </summary>
|
||||||
|
[JsonIgnore]
|
||||||
|
public Device CameraDevice
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_cameraDevice == null)
|
||||||
|
_cameraDevice = DeviceManager.GetDeviceForKey(DeviceKey) as Device;
|
||||||
|
return _cameraDevice;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Device _cameraDevice;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets either the source's Name or this AlternateName property, if
|
||||||
|
/// defined. If source doesn't exist, returns "Missing source"
|
||||||
|
/// </summary>
|
||||||
|
[JsonProperty("preferredName")]
|
||||||
|
public string PreferredName
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(Name))
|
||||||
|
{
|
||||||
|
if (CameraDevice == null)
|
||||||
|
return "---";
|
||||||
|
return CameraDevice.Name;
|
||||||
|
}
|
||||||
|
return Name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A name that will override the source's name on the UI
|
||||||
|
/// </summary>
|
||||||
|
[JsonProperty("name")]
|
||||||
|
public string Name { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Specifies and icon for the source list item
|
||||||
|
/// </summary>
|
||||||
|
[JsonProperty("icon")]
|
||||||
|
public string Icon { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Alternate icon
|
||||||
|
/// </summary>
|
||||||
|
[JsonProperty("altIcon", NullValueHandling = NullValueHandling.Ignore)]
|
||||||
|
public string AltIcon { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Indicates if the item should be included in the user facing list
|
||||||
|
/// </summary>
|
||||||
|
[JsonProperty("includeInUserList")]
|
||||||
|
public bool IncludeInUserList { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Used to specify the order of the items in the source list when displayed
|
||||||
|
/// </summary>
|
||||||
|
[JsonProperty("order")]
|
||||||
|
public int Order { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,83 +1,81 @@
|
|||||||
|
|
||||||
|
|
||||||
|
using Crestron.SimplSharp;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using PepperDash.Core;
|
||||||
|
using Serilog.Events;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Crestron.SimplSharp;
|
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using Newtonsoft.Json;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
using PepperDash.Core;
|
|
||||||
using Serilog.Events;
|
|
||||||
|
|
||||||
|
|
||||||
namespace PepperDash.Essentials.Core
|
namespace PepperDash.Essentials.Core
|
||||||
{
|
{
|
||||||
public class DeviceJsonApi
|
public class DeviceJsonApi
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="json"></param>
|
/// <param name="json"></param>
|
||||||
public static void DoDeviceActionWithJson(string json)
|
public static void DoDeviceActionWithJson(string json)
|
||||||
{
|
{
|
||||||
if (String.IsNullOrEmpty(json))
|
if (String.IsNullOrEmpty(json))
|
||||||
{
|
{
|
||||||
CrestronConsole.ConsoleCommandResponse(
|
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.");
|
"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;
|
return;
|
||||||
}
|
}
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var action = JsonConvert.DeserializeObject<DeviceActionWrapper>(json);
|
var action = JsonConvert.DeserializeObject<DeviceActionWrapper>(json);
|
||||||
|
|
||||||
DoDeviceAction(action);
|
DoDeviceAction(action);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
CrestronConsole.ConsoleCommandResponse("Incorrect format for JSON. Please check that the format matches {\"deviceKey\":\"myDevice\", \"methodName\":\"someMethod\", \"params\": [\"param1\", true]}");
|
CrestronConsole.ConsoleCommandResponse("Incorrect format for JSON. Please check that the format matches {\"deviceKey\":\"myDevice\", \"methodName\":\"someMethod\", \"params\": [\"param1\", true]}");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="action"></param>
|
/// <param name="action"></param>
|
||||||
public static void DoDeviceAction(DeviceActionWrapper action)
|
public static void DoDeviceAction(DeviceActionWrapper action)
|
||||||
{
|
{
|
||||||
var key = action.DeviceKey;
|
var key = action.DeviceKey;
|
||||||
var obj = FindObjectOnPath(key);
|
var obj = FindObjectOnPath(key);
|
||||||
if (obj == null)
|
if (obj == null)
|
||||||
{
|
{
|
||||||
CrestronConsole.ConsoleCommandResponse("Unable to find object at path {0}", key);
|
CrestronConsole.ConsoleCommandResponse("Unable to find object at path {0}", key);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (action.Params == null)
|
if (action.Params == null)
|
||||||
{
|
{
|
||||||
//no params, so setting action.Params to empty array
|
//no params, so setting action.Params to empty array
|
||||||
action.Params = new object[0];
|
action.Params = new object[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
Type t = obj.GetType();
|
Type t = obj.GetType();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var methods = t.GetMethods().Where(m => m.Name == action.MethodName).ToList();
|
var methods = t.GetMethods().Where(m => m.Name == action.MethodName).ToList();
|
||||||
|
|
||||||
var method = methods.Count == 1 ? methods[0] : methods.FirstOrDefault(m => m.GetParameters().Length == action.Params.Length);
|
var method = methods.Count == 1 ? methods[0] : methods.FirstOrDefault(m => m.GetParameters().Length == action.Params.Length);
|
||||||
|
|
||||||
if (method == null)
|
if (method == null)
|
||||||
{
|
{
|
||||||
CrestronConsole.ConsoleCommandResponse(
|
CrestronConsole.ConsoleCommandResponse(
|
||||||
"Unable to find method with name {0} and that matches parameters {1}", action.MethodName,
|
"Unable to find method with name {0} and that matches parameters {1}", action.MethodName,
|
||||||
action.Params);
|
action.Params);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var mParams = method.GetParameters();
|
var mParams = method.GetParameters();
|
||||||
|
|
||||||
var convertedParams = mParams
|
var convertedParams = mParams
|
||||||
@@ -85,60 +83,116 @@ namespace PepperDash.Essentials.Core
|
|||||||
.ToArray();
|
.ToArray();
|
||||||
|
|
||||||
Task.Run(() =>
|
Task.Run(() =>
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Debug.LogMessage(LogEventLevel.Verbose, "Calling method {methodName} on device {deviceKey}", null, method.Name, action.DeviceKey);
|
Debug.LogMessage(LogEventLevel.Verbose, "Calling method {methodName} on device {deviceKey}", null, method.Name, action.DeviceKey);
|
||||||
method.Invoke(obj, convertedParams);
|
method.Invoke(obj, convertedParams);
|
||||||
}
|
}
|
||||||
catch(Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Debug.LogMessage(e, "Error invoking method {methodName} on device {deviceKey}", null, method.Name, action.DeviceKey);
|
Debug.LogMessage(e, "Error invoking method {methodName} on device {deviceKey}", null, method.Name, action.DeviceKey);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
CrestronConsole.ConsoleCommandResponse("Method {0} successfully called on device {1}", method.Name,
|
CrestronConsole.ConsoleCommandResponse("Method {0} successfully called on device {1}", method.Name,
|
||||||
action.DeviceKey);
|
action.DeviceKey);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
CrestronConsole.ConsoleCommandResponse("Unable to call method with name {0}. {1}", action.MethodName,
|
CrestronConsole.ConsoleCommandResponse("Unable to call method with name {0}. {1}", action.MethodName,
|
||||||
ex.Message);}
|
ex.Message);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static object ConvertType(object value, Type conversionType)
|
public static async Task DoDeviceActionAsync(DeviceActionWrapper action)
|
||||||
{
|
{
|
||||||
if (!conversionType.IsEnum)
|
var key = action.DeviceKey;
|
||||||
{
|
var obj = FindObjectOnPath(key);
|
||||||
return Convert.ChangeType(value, conversionType, System.Globalization.CultureInfo.InvariantCulture);
|
if (obj == null)
|
||||||
}
|
{
|
||||||
|
Debug.LogMessage(LogEventLevel.Warning, "Unable to find object at path {deviceKey}", null, key);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var stringValue = Convert.ToString(value);
|
if (action.Params == null)
|
||||||
|
{
|
||||||
|
//no params, so setting action.Params to empty array
|
||||||
|
action.Params = new object[0];
|
||||||
|
}
|
||||||
|
|
||||||
if (String.IsNullOrEmpty(stringValue))
|
Type t = obj.GetType();
|
||||||
{
|
try
|
||||||
throw new InvalidCastException(
|
{
|
||||||
String.Format("{0} cannot be converted to a string prior to conversion to enum"));
|
var methods = t.GetMethods().Where(m => m.Name == action.MethodName).ToList();
|
||||||
}
|
|
||||||
return Enum.Parse(conversionType, stringValue, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
var method = methods.Count == 1 ? methods[0] : methods.FirstOrDefault(m => m.GetParameters().Length == action.Params.Length);
|
||||||
/// Gets the properties on a device
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="key"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static string GetProperties(string deviceObjectPath)
|
|
||||||
{
|
|
||||||
var obj = FindObjectOnPath(deviceObjectPath);
|
|
||||||
if (obj == null)
|
|
||||||
return "{ \"error\":\"No Device\"}";
|
|
||||||
|
|
||||||
Type t = obj.GetType();
|
if (method == null)
|
||||||
// get the properties and set them into a new collection of NameType wrappers
|
{
|
||||||
var props = t.GetProperties().Select(p => new PropertyNameType(p, obj));
|
Debug.LogMessage(LogEventLevel.Warning,
|
||||||
return JsonConvert.SerializeObject(props, Formatting.Indented);
|
"Unable to find method with name {methodName} and that matches parameters {@parameters}", null, action.MethodName,
|
||||||
}
|
action.Params);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var mParams = method.GetParameters();
|
||||||
|
|
||||||
|
var convertedParams = mParams
|
||||||
|
.Select((p, i) => ConvertType(action.Params[i], p.ParameterType))
|
||||||
|
.ToArray();
|
||||||
|
|
||||||
|
await Task.Run(() =>
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Debug.LogMessage(LogEventLevel.Verbose, "Calling method {methodName} on device {deviceKey} with {@params}", null, method.Name, action.DeviceKey, action.Params);
|
||||||
|
method.Invoke(obj, convertedParams);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Debug.LogMessage(e, "Error invoking method {methodName} on device {deviceKey}", null, method.Name, action.DeviceKey);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Debug.LogMessage(ex, "Unable to call method with name {methodName} with {@parameters}", null, action.MethodName, action.Params);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static object ConvertType(object value, Type conversionType)
|
||||||
|
{
|
||||||
|
if (!conversionType.IsEnum)
|
||||||
|
{
|
||||||
|
return Convert.ChangeType(value, conversionType, System.Globalization.CultureInfo.InvariantCulture);
|
||||||
|
}
|
||||||
|
|
||||||
|
var stringValue = Convert.ToString(value);
|
||||||
|
|
||||||
|
if (String.IsNullOrEmpty(stringValue))
|
||||||
|
{
|
||||||
|
throw new InvalidCastException(
|
||||||
|
String.Format("{0} cannot be converted to a string prior to conversion to enum"));
|
||||||
|
}
|
||||||
|
return Enum.Parse(conversionType, stringValue, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the properties on a device
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="key"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static string GetProperties(string deviceObjectPath)
|
||||||
|
{
|
||||||
|
var obj = FindObjectOnPath(deviceObjectPath);
|
||||||
|
if (obj == null)
|
||||||
|
return "{ \"error\":\"No Device\"}";
|
||||||
|
|
||||||
|
Type t = obj.GetType();
|
||||||
|
// get the properties and set them into a new collection of NameType wrappers
|
||||||
|
var props = t.GetProperties().Select(p => new PropertyNameType(p, obj));
|
||||||
|
return JsonConvert.SerializeObject(props, Formatting.Indented);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a property from a device path by name
|
/// Gets a property from a device path by name
|
||||||
@@ -149,9 +203,9 @@ namespace PepperDash.Essentials.Core
|
|||||||
public static object GetPropertyByName(string deviceObjectPath, string propertyName)
|
public static object GetPropertyByName(string deviceObjectPath, string propertyName)
|
||||||
{
|
{
|
||||||
var dev = FindObjectOnPath(deviceObjectPath);
|
var dev = FindObjectOnPath(deviceObjectPath);
|
||||||
if(dev == null)
|
if (dev == null)
|
||||||
return "{ \"error\":\"No Device\"}";
|
return "{ \"error\":\"No Device\"}";
|
||||||
|
|
||||||
object prop = dev.GetType().GetType().GetProperty(propertyName).GetValue(dev, null);
|
object prop = dev.GetType().GetType().GetProperty(propertyName).GetValue(dev, null);
|
||||||
|
|
||||||
// var prop = t.GetProperty(propertyName);
|
// var prop = t.GetProperty(propertyName);
|
||||||
@@ -166,126 +220,126 @@ namespace PepperDash.Essentials.Core
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the methods on a device
|
/// Gets the methods on a device
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="key"></param>
|
/// <param name="key"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static string GetMethods(string deviceObjectPath)
|
public static string GetMethods(string deviceObjectPath)
|
||||||
{
|
{
|
||||||
var obj = FindObjectOnPath(deviceObjectPath);
|
var obj = FindObjectOnPath(deviceObjectPath);
|
||||||
if (obj == null)
|
if (obj == null)
|
||||||
return "{ \"error\":\"No Device\"}";
|
return "{ \"error\":\"No Device\"}";
|
||||||
|
|
||||||
// Package up method names using helper objects
|
// Package up method names using helper objects
|
||||||
Type t = obj.GetType();
|
Type t = obj.GetType();
|
||||||
var methods = t.GetMethods()
|
var methods = t.GetMethods()
|
||||||
.Where(m => !m.IsSpecialName)
|
.Where(m => !m.IsSpecialName)
|
||||||
.Select(p => new MethodNameParams(p));
|
.Select(p => new MethodNameParams(p));
|
||||||
return JsonConvert.SerializeObject(methods, Formatting.Indented);
|
return JsonConvert.SerializeObject(methods, Formatting.Indented);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string GetApiMethods(string deviceObjectPath)
|
public static string GetApiMethods(string deviceObjectPath)
|
||||||
{
|
{
|
||||||
var obj = FindObjectOnPath(deviceObjectPath);
|
var obj = FindObjectOnPath(deviceObjectPath);
|
||||||
if (obj == null)
|
if (obj == null)
|
||||||
return "{ \"error\":\"No Device\"}";
|
return "{ \"error\":\"No Device\"}";
|
||||||
|
|
||||||
// Package up method names using helper objects
|
// Package up method names using helper objects
|
||||||
Type t = obj.GetType();
|
Type t = obj.GetType();
|
||||||
var methods = t.GetMethods()
|
var methods = t.GetMethods()
|
||||||
.Where(m => !m.IsSpecialName)
|
.Where(m => !m.IsSpecialName)
|
||||||
.Where(m => m.GetCustomAttributes(typeof(ApiAttribute), true).Any())
|
.Where(m => m.GetCustomAttributes(typeof(ApiAttribute), true).Any())
|
||||||
.Select(p => new MethodNameParams(p));
|
.Select(p => new MethodNameParams(p));
|
||||||
return JsonConvert.SerializeObject(methods, Formatting.Indented);
|
return JsonConvert.SerializeObject(methods, Formatting.Indented);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Walks down a dotted object path, starting with a Device, and returns the object
|
|
||||||
/// at the end of the path
|
|
||||||
/// </summary>
|
|
||||||
public static object FindObjectOnPath(string deviceObjectPath)
|
|
||||||
{
|
|
||||||
var path = deviceObjectPath.Split('.');
|
|
||||||
|
|
||||||
var dev = DeviceManager.GetDeviceForKey(path[0]);
|
/// <summary>
|
||||||
if (dev == null)
|
/// Walks down a dotted object path, starting with a Device, and returns the object
|
||||||
{
|
/// at the end of the path
|
||||||
Debug.LogMessage(LogEventLevel.Information, "Device {0} not found", path[0]);
|
/// </summary>
|
||||||
return null;
|
public static object FindObjectOnPath(string deviceObjectPath)
|
||||||
}
|
{
|
||||||
|
var path = deviceObjectPath.Split('.');
|
||||||
|
|
||||||
// loop through any dotted properties
|
var dev = DeviceManager.GetDeviceForKey(path[0]);
|
||||||
object obj = dev;
|
if (dev == null)
|
||||||
if (path.Length > 1)
|
{
|
||||||
{
|
Debug.LogMessage(LogEventLevel.Information, "Device {0} not found", path[0]);
|
||||||
for (int i = 1; i < path.Length; i++)
|
return null;
|
||||||
{
|
}
|
||||||
var objName = path[i];
|
|
||||||
string indexStr = null;
|
|
||||||
var indexOpen = objName.IndexOf('[');
|
|
||||||
if (indexOpen != -1)
|
|
||||||
{
|
|
||||||
var indexClose = objName.IndexOf(']');
|
|
||||||
if (indexClose == -1)
|
|
||||||
{
|
|
||||||
Debug.LogMessage(LogEventLevel.Information, dev, "ERROR Unmatched index brackets");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
// Get the index and strip quotes if any
|
|
||||||
indexStr = objName.Substring(indexOpen + 1, indexClose - indexOpen - 1).Replace("\"", "");
|
|
||||||
objName = objName.Substring(0, indexOpen);
|
|
||||||
Debug.LogMessage(LogEventLevel.Information, dev, " Checking for collection '{0}', index '{1}'", objName, indexStr);
|
|
||||||
}
|
|
||||||
|
|
||||||
Type oType = obj.GetType();
|
// loop through any dotted properties
|
||||||
var prop = oType.GetProperty(objName);
|
object obj = dev;
|
||||||
if (prop == null)
|
if (path.Length > 1)
|
||||||
{
|
{
|
||||||
Debug.LogMessage(LogEventLevel.Information, dev, "Property {0} not found on {1}", objName, path[i - 1]);
|
for (int i = 1; i < path.Length; i++)
|
||||||
return null;
|
{
|
||||||
}
|
var objName = path[i];
|
||||||
// if there's an index, try to get the property
|
string indexStr = null;
|
||||||
if (indexStr != null)
|
var indexOpen = objName.IndexOf('[');
|
||||||
{
|
if (indexOpen != -1)
|
||||||
if (!typeof(ICollection).IsAssignableFrom(prop.PropertyType))
|
{
|
||||||
{
|
var indexClose = objName.IndexOf(']');
|
||||||
Debug.LogMessage(LogEventLevel.Information, dev, "Property {0} is not collection", objName);
|
if (indexClose == -1)
|
||||||
return null;
|
{
|
||||||
}
|
Debug.LogMessage(LogEventLevel.Information, dev, "ERROR Unmatched index brackets");
|
||||||
var collection = prop.GetValue(obj, null) as ICollection;
|
return null;
|
||||||
// Get the indexed items "property"
|
}
|
||||||
var indexedPropInfo = prop.PropertyType.GetProperty("Item");
|
// Get the index and strip quotes if any
|
||||||
// These are the parameters for the indexing. Only care about one
|
indexStr = objName.Substring(indexOpen + 1, indexClose - indexOpen - 1).Replace("\"", "");
|
||||||
var indexParams = indexedPropInfo.GetIndexParameters();
|
objName = objName.Substring(0, indexOpen);
|
||||||
if (indexParams.Length > 0)
|
Debug.LogMessage(LogEventLevel.Information, dev, " Checking for collection '{0}', index '{1}'", objName, indexStr);
|
||||||
{
|
}
|
||||||
Debug.LogMessage(LogEventLevel.Information, " Indexed, param type: {0}", indexParams[0].ParameterType.Name);
|
|
||||||
var properParam = Convert.ChangeType(indexStr, indexParams[0].ParameterType,
|
|
||||||
System.Globalization.CultureInfo.InvariantCulture);
|
|
||||||
try
|
|
||||||
{
|
|
||||||
obj = indexedPropInfo.GetValue(collection, new object[] { properParam });
|
|
||||||
}
|
|
||||||
// if the index is bad, catch it here.
|
|
||||||
catch (TargetInvocationException e)
|
|
||||||
{
|
|
||||||
if (e.InnerException is ArgumentOutOfRangeException)
|
|
||||||
Debug.LogMessage(LogEventLevel.Information, " Index Out of range");
|
|
||||||
else if (e.InnerException is KeyNotFoundException)
|
|
||||||
Debug.LogMessage(LogEventLevel.Information, " Key not found");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
Type oType = obj.GetType();
|
||||||
else
|
var prop = oType.GetProperty(objName);
|
||||||
obj = prop.GetValue(obj, null);
|
if (prop == null)
|
||||||
}
|
{
|
||||||
}
|
Debug.LogMessage(LogEventLevel.Information, dev, "Property {0} not found on {1}", objName, path[i - 1]);
|
||||||
return obj;
|
return null;
|
||||||
}
|
}
|
||||||
|
// if there's an index, try to get the property
|
||||||
|
if (indexStr != null)
|
||||||
|
{
|
||||||
|
if (!typeof(ICollection).IsAssignableFrom(prop.PropertyType))
|
||||||
|
{
|
||||||
|
Debug.LogMessage(LogEventLevel.Information, dev, "Property {0} is not collection", objName);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
var collection = prop.GetValue(obj, null) as ICollection;
|
||||||
|
// Get the indexed items "property"
|
||||||
|
var indexedPropInfo = prop.PropertyType.GetProperty("Item");
|
||||||
|
// These are the parameters for the indexing. Only care about one
|
||||||
|
var indexParams = indexedPropInfo.GetIndexParameters();
|
||||||
|
if (indexParams.Length > 0)
|
||||||
|
{
|
||||||
|
Debug.LogMessage(LogEventLevel.Information, " Indexed, param type: {0}", indexParams[0].ParameterType.Name);
|
||||||
|
var properParam = Convert.ChangeType(indexStr, indexParams[0].ParameterType,
|
||||||
|
System.Globalization.CultureInfo.InvariantCulture);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
obj = indexedPropInfo.GetValue(collection, new object[] { properParam });
|
||||||
|
}
|
||||||
|
// if the index is bad, catch it here.
|
||||||
|
catch (TargetInvocationException e)
|
||||||
|
{
|
||||||
|
if (e.InnerException is ArgumentOutOfRangeException)
|
||||||
|
Debug.LogMessage(LogEventLevel.Information, " Index Out of range");
|
||||||
|
else if (e.InnerException is KeyNotFoundException)
|
||||||
|
Debug.LogMessage(LogEventLevel.Information, " Key not found");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
obj = prop.GetValue(obj, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sets a property on an object.
|
/// Sets a property on an object.
|
||||||
@@ -308,78 +362,85 @@ namespace PepperDash.Essentials.Core
|
|||||||
//return JsonConvert.SerializeObject(props, Formatting.Indented);
|
//return JsonConvert.SerializeObject(props, Formatting.Indented);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public class DeviceActionWrapper
|
}
|
||||||
{
|
|
||||||
public string DeviceKey { get; set; }
|
|
||||||
public string MethodName { get; set; }
|
|
||||||
public object[] Params { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class PropertyNameType
|
public class DeviceActionWrapper
|
||||||
{
|
{
|
||||||
object Parent;
|
public string DeviceKey { get; set; }
|
||||||
|
public string MethodName { get; set; }
|
||||||
|
public object[] Params { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
[JsonIgnore]
|
public class PropertyNameType
|
||||||
public PropertyInfo PropInfo { get; private set; }
|
{
|
||||||
public string Name { get { return PropInfo.Name; } }
|
private object Parent;
|
||||||
public string Type { get { return PropInfo.PropertyType.Name; } }
|
|
||||||
public string Value { get
|
[JsonIgnore]
|
||||||
|
public PropertyInfo PropInfo { get; private set; }
|
||||||
|
public string Name { get { return PropInfo.Name; } }
|
||||||
|
public string Type { get { return PropInfo.PropertyType.Name; } }
|
||||||
|
public string Value
|
||||||
{
|
{
|
||||||
if (PropInfo.CanRead)
|
get
|
||||||
{
|
{
|
||||||
try
|
if (PropInfo.CanRead)
|
||||||
{
|
{
|
||||||
return PropInfo.GetValue(Parent, null).ToString();
|
try
|
||||||
|
{
|
||||||
|
return PropInfo.GetValue(Parent, null).ToString();
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception)
|
else
|
||||||
{
|
|
||||||
return null;
|
return null;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
return null;
|
|
||||||
} }
|
|
||||||
|
|
||||||
public bool CanRead { get { return PropInfo.CanRead; } }
|
public bool CanRead { get { return PropInfo.CanRead; } }
|
||||||
public bool CanWrite { get { return PropInfo.CanWrite; } }
|
public bool CanWrite { get { return PropInfo.CanWrite; } }
|
||||||
|
|
||||||
|
|
||||||
public PropertyNameType(PropertyInfo info, object parent)
|
public PropertyNameType(PropertyInfo info, object parent)
|
||||||
{
|
{
|
||||||
PropInfo = info;
|
PropInfo = info;
|
||||||
Parent = parent;
|
Parent = parent;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class MethodNameParams
|
public class MethodNameParams
|
||||||
{
|
{
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public MethodInfo MethodInfo { get; private set; }
|
public MethodInfo MethodInfo { get; private set; }
|
||||||
|
|
||||||
public string Name { get { return MethodInfo.Name; } }
|
public string Name { get { return MethodInfo.Name; } }
|
||||||
public IEnumerable<NameType> Params { get {
|
public IEnumerable<NameType> Params
|
||||||
return MethodInfo.GetParameters().Select(p =>
|
{
|
||||||
new NameType { Name = p.Name, Type = p.ParameterType.Name });
|
get
|
||||||
} }
|
{
|
||||||
|
return MethodInfo.GetParameters().Select(p =>
|
||||||
|
new NameType { Name = p.Name, Type = p.ParameterType.Name });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public MethodNameParams(MethodInfo info)
|
public MethodNameParams(MethodInfo info)
|
||||||
{
|
{
|
||||||
MethodInfo = info;
|
MethodInfo = info;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class NameType
|
public class NameType
|
||||||
{
|
{
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
public string Type { get; set; }
|
public string Type { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
[AttributeUsage(AttributeTargets.All)]
|
[AttributeUsage(AttributeTargets.All)]
|
||||||
public class ApiAttribute : Attribute
|
public class ApiAttribute : Attribute
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,50 +1,49 @@
|
|||||||
using System;
|
using Crestron.SimplSharp;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Text.RegularExpressions;
|
|
||||||
using Crestron.SimplSharp;
|
|
||||||
using Crestron.SimplSharpPro;
|
using Crestron.SimplSharpPro;
|
||||||
|
|
||||||
using PepperDash.Core;
|
using PepperDash.Core;
|
||||||
using Serilog.Events;
|
using Serilog.Events;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
|
|
||||||
namespace PepperDash.Essentials.Core
|
namespace PepperDash.Essentials.Core
|
||||||
{
|
{
|
||||||
public static class DeviceManager
|
public static class DeviceManager
|
||||||
{
|
{
|
||||||
public static event EventHandler<EventArgs> AllDevicesActivated;
|
public static event EventHandler<EventArgs> AllDevicesActivated;
|
||||||
public static event EventHandler<EventArgs> AllDevicesRegistered;
|
public static event EventHandler<EventArgs> AllDevicesRegistered;
|
||||||
|
|
||||||
private static readonly CCriticalSection DeviceCriticalSection = new CCriticalSection();
|
private static readonly CCriticalSection DeviceCriticalSection = new CCriticalSection();
|
||||||
private static readonly CEvent AllowAddDevicesCEvent = new CEvent(false, true);
|
private static readonly CEvent AllowAddDevicesCEvent = new CEvent(false, true);
|
||||||
//public static List<Device> Devices { get { return _Devices; } }
|
|
||||||
//static List<Device> _Devices = new List<Device>();
|
|
||||||
|
|
||||||
static readonly Dictionary<string, IKeyed> Devices = new Dictionary<string, IKeyed>(StringComparer.OrdinalIgnoreCase);
|
//public static List<Device> Devices { get { return _Devices; } }
|
||||||
|
//static List<Device> _Devices = new List<Device>();
|
||||||
|
|
||||||
/// <summary>
|
private static readonly Dictionary<string, IKeyed> Devices = new Dictionary<string, IKeyed>(StringComparer.OrdinalIgnoreCase);
|
||||||
/// Returns a copy of all the devices in a list
|
|
||||||
/// </summary>
|
|
||||||
public static List<IKeyed> AllDevices { get { return new List<IKeyed>(Devices.Values); } }
|
|
||||||
|
|
||||||
public static bool AddDeviceEnabled;
|
/// <summary>
|
||||||
|
/// Returns a copy of all the devices in a list
|
||||||
|
/// </summary>
|
||||||
|
public static List<IKeyed> AllDevices { get { return new List<IKeyed>(Devices.Values); } }
|
||||||
|
|
||||||
public static void Initialize(CrestronControlSystem cs)
|
public static bool AddDeviceEnabled;
|
||||||
{
|
|
||||||
AddDeviceEnabled = true;
|
public static void Initialize(CrestronControlSystem cs)
|
||||||
CrestronConsole.AddNewConsoleCommand(ListDeviceCommStatuses, "devcommstatus", "Lists the communication status of all devices",
|
{
|
||||||
ConsoleAccessLevelEnum.AccessOperator);
|
AddDeviceEnabled = true;
|
||||||
CrestronConsole.AddNewConsoleCommand(ListDeviceFeedbacks, "devfb", "Lists current feedbacks",
|
CrestronConsole.AddNewConsoleCommand(ListDeviceCommStatuses, "devcommstatus", "Lists the communication status of all devices",
|
||||||
ConsoleAccessLevelEnum.AccessOperator);
|
ConsoleAccessLevelEnum.AccessOperator);
|
||||||
CrestronConsole.AddNewConsoleCommand(ListDevices, "devlist", "Lists current managed devices",
|
CrestronConsole.AddNewConsoleCommand(ListDeviceFeedbacks, "devfb", "Lists current feedbacks",
|
||||||
ConsoleAccessLevelEnum.AccessOperator);
|
ConsoleAccessLevelEnum.AccessOperator);
|
||||||
CrestronConsole.AddNewConsoleCommand(DeviceJsonApi.DoDeviceActionWithJson, "devjson", "",
|
CrestronConsole.AddNewConsoleCommand(ListDevices, "devlist", "Lists current managed devices",
|
||||||
ConsoleAccessLevelEnum.AccessOperator);
|
ConsoleAccessLevelEnum.AccessOperator);
|
||||||
CrestronConsole.AddNewConsoleCommand(s => CrestronConsole.ConsoleCommandResponse(DeviceJsonApi.GetProperties(s)), "devprops", "", ConsoleAccessLevelEnum.AccessOperator);
|
CrestronConsole.AddNewConsoleCommand(DeviceJsonApi.DoDeviceActionWithJson, "devjson", "",
|
||||||
CrestronConsole.AddNewConsoleCommand(s => CrestronConsole.ConsoleCommandResponse(DeviceJsonApi.GetMethods(s)), "devmethods", "", ConsoleAccessLevelEnum.AccessOperator);
|
ConsoleAccessLevelEnum.AccessOperator);
|
||||||
CrestronConsole.AddNewConsoleCommand(s => CrestronConsole.ConsoleCommandResponse(DeviceJsonApi.GetApiMethods(s)), "apimethods", "", ConsoleAccessLevelEnum.AccessOperator);
|
CrestronConsole.AddNewConsoleCommand(s => CrestronConsole.ConsoleCommandResponse(DeviceJsonApi.GetProperties(s)), "devprops", "", ConsoleAccessLevelEnum.AccessOperator);
|
||||||
|
CrestronConsole.AddNewConsoleCommand(s => CrestronConsole.ConsoleCommandResponse(DeviceJsonApi.GetMethods(s)), "devmethods", "", ConsoleAccessLevelEnum.AccessOperator);
|
||||||
|
CrestronConsole.AddNewConsoleCommand(s => CrestronConsole.ConsoleCommandResponse(DeviceJsonApi.GetApiMethods(s)), "apimethods", "", ConsoleAccessLevelEnum.AccessOperator);
|
||||||
CrestronConsole.AddNewConsoleCommand(SimulateComReceiveOnDevice, "devsimreceive",
|
CrestronConsole.AddNewConsoleCommand(SimulateComReceiveOnDevice, "devsimreceive",
|
||||||
"Simulates incoming data on a com device", ConsoleAccessLevelEnum.AccessOperator);
|
"Simulates incoming data on a com device", ConsoleAccessLevelEnum.AccessOperator);
|
||||||
|
|
||||||
@@ -52,77 +51,77 @@ namespace PepperDash.Essentials.Core
|
|||||||
CrestronConsole.AddNewConsoleCommand(s => DisableAllDeviceStreamDebugging(), "disableallstreamdebug", "disables stream debugging on all devices", ConsoleAccessLevelEnum.AccessOperator);
|
CrestronConsole.AddNewConsoleCommand(s => DisableAllDeviceStreamDebugging(), "disableallstreamdebug", "disables stream debugging on all devices", ConsoleAccessLevelEnum.AccessOperator);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Calls activate steps on all Device class items
|
/// Calls activate steps on all Device class items
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static void ActivateAll()
|
public static void ActivateAll()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
OnAllDevicesRegistered();
|
OnAllDevicesRegistered();
|
||||||
|
|
||||||
DeviceCriticalSection.Enter();
|
DeviceCriticalSection.Enter();
|
||||||
AddDeviceEnabled = false;
|
AddDeviceEnabled = false;
|
||||||
// PreActivate all devices
|
// PreActivate all devices
|
||||||
Debug.LogMessage(LogEventLevel.Information,"****PreActivation starting...****");
|
Debug.LogMessage(LogEventLevel.Information, "****PreActivation starting...****");
|
||||||
foreach (var d in Devices.Values)
|
foreach (var d in Devices.Values)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (d is Device)
|
if (d is Device)
|
||||||
(d as Device).PreActivate();
|
(d as Device).PreActivate();
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Debug.LogMessage(LogEventLevel.Information, d, "ERROR: Device {1} PreActivation failure: {0}", e.Message, d.Key);
|
Debug.LogMessage(LogEventLevel.Information, d, "ERROR: Device {1} PreActivation failure: {0}", e.Message, d.Key);
|
||||||
Debug.LogMessage(LogEventLevel.Debug, d, "Stack Trace: {0}", e.StackTrace);
|
Debug.LogMessage(LogEventLevel.Debug, d, "Stack Trace: {0}", e.StackTrace);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Debug.LogMessage(LogEventLevel.Information, "****PreActivation complete****");
|
Debug.LogMessage(LogEventLevel.Information, "****PreActivation complete****");
|
||||||
Debug.LogMessage(LogEventLevel.Information, "****Activation starting...****");
|
Debug.LogMessage(LogEventLevel.Information, "****Activation starting...****");
|
||||||
|
|
||||||
// Activate all devices
|
// Activate all devices
|
||||||
foreach (var d in Devices.Values)
|
foreach (var d in Devices.Values)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (d is Device)
|
if (d is Device)
|
||||||
(d as Device).Activate();
|
(d as Device).Activate();
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Debug.LogMessage(LogEventLevel.Information, d, "ERROR: Device {1} Activation failure: {0}", e.Message, d.Key);
|
Debug.LogMessage(LogEventLevel.Information, d, "ERROR: Device {1} Activation failure: {0}", e.Message, d.Key);
|
||||||
Debug.LogMessage(LogEventLevel.Debug, d, "Stack Trace: {0}", e.StackTrace);
|
Debug.LogMessage(LogEventLevel.Debug, d, "Stack Trace: {0}", e.StackTrace);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Debug.LogMessage(LogEventLevel.Information, "****Activation complete****");
|
Debug.LogMessage(LogEventLevel.Information, "****Activation complete****");
|
||||||
Debug.LogMessage(LogEventLevel.Information, "****PostActivation starting...****");
|
Debug.LogMessage(LogEventLevel.Information, "****PostActivation starting...****");
|
||||||
|
|
||||||
// PostActivate all devices
|
// PostActivate all devices
|
||||||
foreach (var d in Devices.Values)
|
foreach (var d in Devices.Values)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (d is Device)
|
if (d is Device)
|
||||||
(d as Device).PostActivate();
|
(d as Device).PostActivate();
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Debug.LogMessage(LogEventLevel.Information, d, "ERROR: Device {1} PostActivation failure: {0}", e.Message, d.Key);
|
Debug.LogMessage(LogEventLevel.Information, d, "ERROR: Device {1} PostActivation failure: {0}", e.Message, d.Key);
|
||||||
Debug.LogMessage(LogEventLevel.Debug, d, "Stack Trace: {0}", e.StackTrace);
|
Debug.LogMessage(LogEventLevel.Debug, d, "Stack Trace: {0}", e.StackTrace);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Debug.LogMessage(LogEventLevel.Information, "****PostActivation complete****");
|
Debug.LogMessage(LogEventLevel.Information, "****PostActivation complete****");
|
||||||
|
|
||||||
OnAllDevicesActivated();
|
OnAllDevicesActivated();
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
DeviceCriticalSection.Leave();
|
DeviceCriticalSection.Leave();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void OnAllDevicesActivated()
|
private static void OnAllDevicesActivated()
|
||||||
{
|
{
|
||||||
@@ -142,77 +141,76 @@ namespace PepperDash.Essentials.Core
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Calls activate on all Device class items
|
/// Calls activate on all Device class items
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static void DeactivateAll()
|
public static void DeactivateAll()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
DeviceCriticalSection.Enter();
|
DeviceCriticalSection.Enter();
|
||||||
foreach (var d in Devices.Values.OfType<Device>())
|
foreach (var d in Devices.Values.OfType<Device>())
|
||||||
{
|
{
|
||||||
d.Deactivate();
|
d.Deactivate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
DeviceCriticalSection.Leave();
|
DeviceCriticalSection.Leave();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//static void ListMethods(string devKey)
|
//static void ListMethods(string devKey)
|
||||||
//{
|
//{
|
||||||
// var dev = GetDeviceForKey(devKey);
|
// var dev = GetDeviceForKey(devKey);
|
||||||
// if(dev != null)
|
// if(dev != null)
|
||||||
// {
|
// {
|
||||||
// var type = dev.GetType().GetType();
|
// var type = dev.GetType().GetType();
|
||||||
// var methods = type.GetMethods(BindingFlags.Public|BindingFlags.Instance);
|
// var methods = type.GetMethods(BindingFlags.Public|BindingFlags.Instance);
|
||||||
// var sb = new StringBuilder();
|
// var sb = new StringBuilder();
|
||||||
// sb.AppendLine(string.Format("{2} methods on [{0}] ({1}):", dev.Key, type.Name, methods.Length));
|
// sb.AppendLine(string.Format("{2} methods on [{0}] ({1}):", dev.Key, type.Name, methods.Length));
|
||||||
// foreach (var m in methods)
|
// foreach (var m in methods)
|
||||||
// {
|
// {
|
||||||
// sb.Append(string.Format("{0}(", m.Name));
|
// sb.Append(string.Format("{0}(", m.Name));
|
||||||
// var pars = m.GetParameters();
|
// var pars = m.GetParameters();
|
||||||
// foreach (var p in pars)
|
// foreach (var p in pars)
|
||||||
// sb.Append(string.Format("({1}){0} ", p.Name, p.ParameterType.Name));
|
// sb.Append(string.Format("({1}){0} ", p.Name, p.ParameterType.Name));
|
||||||
// sb.AppendLine(")");
|
// sb.AppendLine(")");
|
||||||
// }
|
// }
|
||||||
// CrestronConsole.ConsoleCommandResponse(sb.ToString());
|
// CrestronConsole.ConsoleCommandResponse(sb.ToString());
|
||||||
// }
|
// }
|
||||||
//}
|
//}
|
||||||
|
|
||||||
private static void ListDevices(string s)
|
private static void ListDevices(string s)
|
||||||
{
|
{
|
||||||
Debug.LogMessage(LogEventLevel.Information, "{0} Devices registered with Device Manager:", Devices.Count);
|
Debug.LogMessage(LogEventLevel.Information, "{0} Devices registered with Device Manager:", Devices.Count);
|
||||||
var sorted = Devices.Values.ToList();
|
var sorted = Devices.Values.ToList();
|
||||||
sorted.Sort((a, b) => a.Key.CompareTo(b.Key));
|
sorted.Sort((a, b) => a.Key.CompareTo(b.Key));
|
||||||
|
|
||||||
foreach (var d in sorted)
|
foreach (var d in sorted)
|
||||||
{
|
{
|
||||||
var name = d is IKeyName ? (d as IKeyName).Name : "---";
|
var name = d is IKeyName ? (d as IKeyName).Name : "---";
|
||||||
Debug.LogMessage(LogEventLevel.Information, " [{0}] {1}", d.Key, name);
|
Debug.LogMessage(LogEventLevel.Information, " [{0}] {1}", d.Key, name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void ListDeviceFeedbacks(string devKey)
|
private static void ListDeviceFeedbacks(string devKey)
|
||||||
{
|
{
|
||||||
var dev = GetDeviceForKey(devKey);
|
var dev = GetDeviceForKey(devKey);
|
||||||
if (dev == null)
|
if (dev == null)
|
||||||
{
|
{
|
||||||
Debug.LogMessage(LogEventLevel.Information, "Device '{0}' not found", devKey);
|
Debug.LogMessage(LogEventLevel.Information, "Device '{0}' not found", devKey);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var statusDev = dev as IHasFeedback;
|
if (!(dev is IHasFeedback statusDev))
|
||||||
if (statusDev == null)
|
{
|
||||||
{
|
Debug.LogMessage(LogEventLevel.Information, "Device '{0}' does not have visible feedbacks", devKey);
|
||||||
Debug.LogMessage(LogEventLevel.Information, "Device '{0}' does not have visible feedbacks", devKey);
|
return;
|
||||||
return;
|
}
|
||||||
}
|
statusDev.DumpFeedbacksToConsole(true);
|
||||||
statusDev.DumpFeedbacksToConsole(true);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
//static void ListDeviceCommands(string devKey)
|
//static void ListDeviceCommands(string devKey)
|
||||||
//{
|
//{
|
||||||
// var dev = GetDeviceForKey(devKey);
|
// var dev = GetDeviceForKey(devKey);
|
||||||
// if (dev == null)
|
// if (dev == null)
|
||||||
@@ -223,134 +221,132 @@ namespace PepperDash.Essentials.Core
|
|||||||
// Debug.LogMessage(LogEventLevel.Information, "This needs to be reworked. Stay tuned.", devKey);
|
// Debug.LogMessage(LogEventLevel.Information, "This needs to be reworked. Stay tuned.", devKey);
|
||||||
//}
|
//}
|
||||||
|
|
||||||
private static void ListDeviceCommStatuses(string input)
|
private static void ListDeviceCommStatuses(string input)
|
||||||
{
|
{
|
||||||
var sb = new StringBuilder();
|
|
||||||
foreach (var dev in Devices.Values.OfType<ICommunicationMonitor>())
|
foreach (var dev in Devices.Values.OfType<ICommunicationMonitor>())
|
||||||
{
|
{
|
||||||
sb.Append(string.Format("{0}: {1}\r", dev,
|
CrestronConsole.ConsoleCommandResponse($"{dev}: {dev.CommunicationMonitor.Status}{Environment.NewLine}");
|
||||||
dev.CommunicationMonitor.Status));
|
}
|
||||||
}
|
}
|
||||||
CrestronConsole.ConsoleCommandResponse(sb.ToString());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//static void DoDeviceCommand(string command)
|
//static void DoDeviceCommand(string command)
|
||||||
//{
|
//{
|
||||||
// Debug.LogMessage(LogEventLevel.Information, "Not yet implemented. Stay tuned");
|
// Debug.LogMessage(LogEventLevel.Information, "Not yet implemented. Stay tuned");
|
||||||
//}
|
//}
|
||||||
|
|
||||||
public static void AddDevice(IKeyed newDev)
|
public static void AddDevice(IKeyed newDev)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (!DeviceCriticalSection.TryEnter())
|
if (!DeviceCriticalSection.TryEnter())
|
||||||
{
|
{
|
||||||
Debug.LogMessage(LogEventLevel.Information, "Currently unable to add devices to Device Manager. Please try again");
|
Debug.LogMessage(LogEventLevel.Information, "Currently unable to add devices to Device Manager. Please try again");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Check for device with same key
|
// Check for device with same key
|
||||||
//var existingDevice = _Devices.FirstOrDefault(d => d.Key.Equals(newDev.Key, StringComparison.OrdinalIgnoreCase));
|
//var existingDevice = _Devices.FirstOrDefault(d => d.Key.Equals(newDev.Key, StringComparison.OrdinalIgnoreCase));
|
||||||
////// If it exists, remove or warn??
|
////// If it exists, remove or warn??
|
||||||
//if (existingDevice != null)
|
//if (existingDevice != null)
|
||||||
|
|
||||||
if (!AddDeviceEnabled)
|
if (!AddDeviceEnabled)
|
||||||
{
|
{
|
||||||
Debug.LogMessage(LogEventLevel.Information, "All devices have been activated. Adding new devices is not allowed.");
|
Debug.LogMessage(LogEventLevel.Information, "All devices have been activated. Adding new devices is not allowed.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Devices.ContainsKey(newDev.Key))
|
if (Devices.ContainsKey(newDev.Key))
|
||||||
{
|
{
|
||||||
Debug.LogMessage(LogEventLevel.Information, newDev, "WARNING: A device with this key already exists. Not added to manager");
|
Debug.LogMessage(LogEventLevel.Information, newDev, "WARNING: A device with this key already exists. Not added to manager");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Devices.Add(newDev.Key, newDev);
|
Devices.Add(newDev.Key, newDev);
|
||||||
//if (!(_Devices.Contains(newDev)))
|
//if (!(_Devices.Contains(newDev)))
|
||||||
// _Devices.Add(newDev);
|
// _Devices.Add(newDev);
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
DeviceCriticalSection.Leave();
|
DeviceCriticalSection.Leave();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void AddDevice(IEnumerable<IKeyed> devicesToAdd)
|
public static void AddDevice(IEnumerable<IKeyed> devicesToAdd)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (!DeviceCriticalSection.TryEnter())
|
if (!DeviceCriticalSection.TryEnter())
|
||||||
{
|
{
|
||||||
Debug.LogMessage(LogEventLevel.Information,
|
Debug.LogMessage(LogEventLevel.Information,
|
||||||
"Currently unable to add devices to Device Manager. Please try again");
|
"Currently unable to add devices to Device Manager. Please try again");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!AddDeviceEnabled)
|
if (!AddDeviceEnabled)
|
||||||
{
|
{
|
||||||
Debug.LogMessage(LogEventLevel.Information,
|
Debug.LogMessage(LogEventLevel.Information,
|
||||||
"All devices have been activated. Adding new devices is not allowed.");
|
"All devices have been activated. Adding new devices is not allowed.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var dev in devicesToAdd)
|
foreach (var dev in devicesToAdd)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Devices.Add(dev.Key, dev);
|
Devices.Add(dev.Key, dev);
|
||||||
}
|
}
|
||||||
catch (ArgumentException ex)
|
catch (ArgumentException ex)
|
||||||
{
|
{
|
||||||
Debug.LogMessage(LogEventLevel.Information, "Error adding device with key {0} to Device Manager: {1}\r\nStack Trace: {2}",
|
Debug.LogMessage(LogEventLevel.Information, "Error adding device with key {0} to Device Manager: {1}\r\nStack Trace: {2}",
|
||||||
dev.Key, ex.Message, ex.StackTrace);
|
dev.Key, ex.Message, ex.StackTrace);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
DeviceCriticalSection.Leave();
|
DeviceCriticalSection.Leave();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void RemoveDevice(IKeyed newDev)
|
public static void RemoveDevice(IKeyed newDev)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
DeviceCriticalSection.Enter();
|
DeviceCriticalSection.Enter();
|
||||||
if (newDev == null)
|
if (newDev == null)
|
||||||
return;
|
return;
|
||||||
if (Devices.ContainsKey(newDev.Key))
|
if (Devices.ContainsKey(newDev.Key))
|
||||||
Devices.Remove(newDev.Key);
|
Devices.Remove(newDev.Key);
|
||||||
//if (_Devices.Contains(newDev))
|
//if (_Devices.Contains(newDev))
|
||||||
// _Devices.Remove(newDev);
|
// _Devices.Remove(newDev);
|
||||||
else
|
else
|
||||||
Debug.LogMessage(LogEventLevel.Information, "Device manager: Device '{0}' does not exist in manager. Cannot remove", newDev.Key);
|
Debug.LogMessage(LogEventLevel.Information, "Device manager: Device '{0}' does not exist in manager. Cannot remove", newDev.Key);
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
DeviceCriticalSection.Leave();
|
DeviceCriticalSection.Leave();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IEnumerable<string> GetDeviceKeys()
|
public static IEnumerable<string> GetDeviceKeys()
|
||||||
{
|
{
|
||||||
//return _Devices.Select(d => d.Key).ToList();
|
//return _Devices.Select(d => d.Key).ToList();
|
||||||
return Devices.Keys;
|
return Devices.Keys;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IEnumerable<IKeyed> GetDevices()
|
public static IEnumerable<IKeyed> GetDevices()
|
||||||
{
|
{
|
||||||
//return _Devices.Select(d => d.Key).ToList();
|
//return _Devices.Select(d => d.Key).ToList();
|
||||||
return Devices.Values;
|
return Devices.Values;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IKeyed GetDeviceForKey(string key)
|
public static IKeyed GetDeviceForKey(string key)
|
||||||
{
|
{
|
||||||
//return _Devices.FirstOrDefault(d => d.Key.Equals(key, StringComparison.OrdinalIgnoreCase));
|
//return _Devices.FirstOrDefault(d => d.Key.Equals(key, StringComparison.OrdinalIgnoreCase));
|
||||||
if (key != null && Devices.ContainsKey(key))
|
if (key != null && Devices.ContainsKey(key))
|
||||||
return Devices[key];
|
return Devices[key];
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Console handler that simulates com port data receive
|
/// Console handler that simulates com port data receive
|
||||||
@@ -367,8 +363,7 @@ namespace PepperDash.Essentials.Core
|
|||||||
}
|
}
|
||||||
//Debug.LogMessage(LogEventLevel.Verbose, "**** {0} - {1} ****", match.Groups[1].Value, match.Groups[2].Value);
|
//Debug.LogMessage(LogEventLevel.Verbose, "**** {0} - {1} ****", match.Groups[1].Value, match.Groups[2].Value);
|
||||||
|
|
||||||
var com = GetDeviceForKey(match.Groups[1].Value) as ComPortController;
|
if (!(GetDeviceForKey(match.Groups[1].Value) is ComPortController com))
|
||||||
if (com == null)
|
|
||||||
{
|
{
|
||||||
CrestronConsole.ConsoleCommandResponse("'{0}' is not a comm port device", match.Groups[1].Value);
|
CrestronConsole.ConsoleCommandResponse("'{0}' is not a comm port device", match.Groups[1].Value);
|
||||||
return;
|
return;
|
||||||
@@ -423,16 +418,15 @@ namespace PepperDash.Essentials.Core
|
|||||||
var deviceKey = args[0];
|
var deviceKey = args[0];
|
||||||
var setting = args[1];
|
var setting = args[1];
|
||||||
|
|
||||||
var timeout= String.Empty;
|
var timeout = String.Empty;
|
||||||
|
|
||||||
if (args.Length >= 3)
|
if (args.Length >= 3)
|
||||||
{
|
{
|
||||||
timeout = args[2];
|
timeout = args[2];
|
||||||
}
|
}
|
||||||
|
|
||||||
var device = GetDeviceForKey(deviceKey) as IStreamDebugging;
|
|
||||||
|
|
||||||
if (device == null)
|
if (!(GetDeviceForKey(deviceKey) is IStreamDebugging device))
|
||||||
{
|
{
|
||||||
CrestronConsole.ConsoleCommandResponse("Unable to get device with key: {0}", deviceKey);
|
CrestronConsole.ConsoleCommandResponse("Unable to get device with key: {0}", deviceKey);
|
||||||
return;
|
return;
|
||||||
@@ -479,13 +473,11 @@ namespace PepperDash.Essentials.Core
|
|||||||
{
|
{
|
||||||
foreach (var device in AllDevices)
|
foreach (var device in AllDevices)
|
||||||
{
|
{
|
||||||
var streamDevice = device as IStreamDebugging;
|
if (device is IStreamDebugging streamDevice)
|
||||||
|
|
||||||
if (streamDevice != null)
|
|
||||||
{
|
{
|
||||||
streamDevice.StreamDebugging.SetDebuggingWithDefaultTimeout(eStreamDebuggingSetting.Off);
|
streamDevice.StreamDebugging.SetDebuggingWithDefaultTimeout(eStreamDebuggingSetting.Off);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -65,8 +65,8 @@ namespace PepperDash.Essentials.Core
|
|||||||
[Flags]
|
[Flags]
|
||||||
public enum eLevelControlType
|
public enum eLevelControlType
|
||||||
{
|
{
|
||||||
Level = 0,
|
Level = 1,
|
||||||
Mute = 1,
|
Mute = 2,
|
||||||
LevelAndMute = Level | Mute,
|
LevelAndMute = Level | Mute,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,128 +1,121 @@
|
|||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using Crestron.SimplSharp;
|
|
||||||
using Crestron.SimplSharp.CrestronIO;
|
|
||||||
using Crestron.SimplSharpPro;
|
|
||||||
|
|
||||||
using Newtonsoft.Json;
|
|
||||||
using Newtonsoft.Json.Converters;
|
using Newtonsoft.Json.Converters;
|
||||||
using Newtonsoft.Json.Linq;
|
|
||||||
using PepperDash.Core;
|
using PepperDash.Core;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace PepperDash.Essentials.Core
|
namespace PepperDash.Essentials.Core
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public enum eSourceListItemType
|
public enum eSourceListItemType
|
||||||
{
|
{
|
||||||
Route, Off, Other, SomethingAwesomerThanThese
|
Route, Off, Other, SomethingAwesomerThanThese
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents an item in a source list - can be deserialized into.
|
/// Represents an item in a source list - can be deserialized into.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class SourceListItem
|
public class SourceListItem
|
||||||
{
|
{
|
||||||
[JsonProperty("sourceKey")]
|
[JsonProperty("sourceKey")]
|
||||||
public string SourceKey { get; set; }
|
public string SourceKey { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns the source Device for this, if it exists in DeviceManager
|
/// Returns the source Device for this, if it exists in DeviceManager
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public Device SourceDevice
|
public Device SourceDevice
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (_SourceDevice == null)
|
if (_SourceDevice == null)
|
||||||
_SourceDevice = DeviceManager.GetDeviceForKey(SourceKey) as Device;
|
_SourceDevice = DeviceManager.GetDeviceForKey(SourceKey) as Device;
|
||||||
return _SourceDevice;
|
return _SourceDevice;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Device _SourceDevice;
|
|
||||||
|
|
||||||
/// <summary>
|
private Device _SourceDevice;
|
||||||
/// Gets either the source's Name or this AlternateName property, if
|
|
||||||
/// defined. If source doesn't exist, returns "Missing source"
|
|
||||||
/// </summary>
|
|
||||||
[JsonProperty("preferredName")]
|
|
||||||
public string PreferredName
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (string.IsNullOrEmpty(Name))
|
|
||||||
{
|
|
||||||
if (SourceDevice == null)
|
|
||||||
return "---";
|
|
||||||
return SourceDevice.Name;
|
|
||||||
}
|
|
||||||
return Name;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A name that will override the source's name on the UI
|
/// Gets either the source's Name or this AlternateName property, if
|
||||||
/// </summary>
|
/// defined. If source doesn't exist, returns "Missing source"
|
||||||
[JsonProperty("name")]
|
/// </summary>
|
||||||
public string Name { get; set; }
|
[JsonProperty("preferredName")]
|
||||||
|
public string PreferredName
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(Name))
|
||||||
|
{
|
||||||
|
if (SourceDevice == null)
|
||||||
|
return "---";
|
||||||
|
return SourceDevice.Name;
|
||||||
|
}
|
||||||
|
return Name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A name that will override the source's name on the UI
|
||||||
|
/// </summary>
|
||||||
|
[JsonProperty("name")]
|
||||||
|
public string Name { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Specifies and icon for the source list item
|
/// Specifies and icon for the source list item
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty("icon")]
|
[JsonProperty("icon")]
|
||||||
public string Icon { get; set; }
|
public string Icon { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Alternate icon
|
/// Alternate icon
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty("altIcon")]
|
[JsonProperty("altIcon")]
|
||||||
public string AltIcon { get; set; }
|
public string AltIcon { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Indicates if the item should be included in the source list
|
/// Indicates if the item should be included in the source list
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty("includeInSourceList")]
|
[JsonProperty("includeInSourceList")]
|
||||||
public bool IncludeInSourceList { get; set; }
|
public bool IncludeInSourceList { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Used to specify the order of the items in the source list when displayed
|
/// Used to specify the order of the items in the source list when displayed
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty("order")]
|
[JsonProperty("order")]
|
||||||
public int Order { get; set; }
|
public int Order { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The key of the device for volume control
|
/// The key of the device for volume control
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty("volumeControlKey")]
|
[JsonProperty("volumeControlKey")]
|
||||||
public string VolumeControlKey { get; set; }
|
public string VolumeControlKey { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The type of source list item
|
/// The type of source list item
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty("type")]
|
[JsonProperty("type")]
|
||||||
[JsonConverter(typeof(StringEnumConverter))]
|
[JsonConverter(typeof(StringEnumConverter))]
|
||||||
public eSourceListItemType Type { get; set; }
|
public eSourceListItemType Type { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The list of routes to execute for this source list item
|
/// The list of routes to execute for this source list item
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty("routeList")]
|
[JsonProperty("routeList")]
|
||||||
public List<SourceRouteListItem> RouteList { get; set; }
|
public List<SourceRouteListItem> RouteList { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Indicates if this source should be disabled for sharing to the far end call participants via codec content
|
/// Indicates if this source should be disabled for sharing to the far end call participants via codec content
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty("disableCodecSharing")]
|
[JsonProperty("disableCodecSharing")]
|
||||||
public bool DisableCodecSharing { get; set; }
|
public bool DisableCodecSharing { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Indicates if this source should be disabled for routing to a shared output
|
/// Indicates if this source should be disabled for routing to a shared output
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty("disableRoutedSharing")]
|
[JsonProperty("disableRoutedSharing")]
|
||||||
public bool DisableRoutedSharing { get; set; }
|
public bool DisableRoutedSharing { get; set; }
|
||||||
|
|
||||||
[JsonProperty("destinations")]
|
[JsonProperty("destinations")]
|
||||||
public List<eSourceListItemDestinationTypes> Destinations { get; set; }
|
public List<eSourceListItemDestinationTypes> Destinations { get; set; }
|
||||||
@@ -156,10 +149,10 @@ namespace PepperDash.Essentials.Core
|
|||||||
[JsonProperty("disableSimpleRouting")]
|
[JsonProperty("disableSimpleRouting")]
|
||||||
public bool DisableSimpleRouting { get; set; }
|
public bool DisableSimpleRouting { get; set; }
|
||||||
|
|
||||||
public SourceListItem()
|
public SourceListItem()
|
||||||
{
|
{
|
||||||
Icon = "Blank";
|
Icon = "Blank";
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
@@ -167,23 +160,23 @@ namespace PepperDash.Essentials.Core
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class SourceRouteListItem
|
public class SourceRouteListItem
|
||||||
{
|
{
|
||||||
[JsonProperty("sourceKey")]
|
[JsonProperty("sourceKey")]
|
||||||
public string SourceKey { get; set; }
|
public string SourceKey { get; set; }
|
||||||
|
|
||||||
[JsonProperty("sourcePortKey")]
|
[JsonProperty("sourcePortKey")]
|
||||||
public string SourcePortKey { get; set; }
|
public string SourcePortKey { get; set; }
|
||||||
|
|
||||||
[JsonProperty("destinationKey")]
|
[JsonProperty("destinationKey")]
|
||||||
public string DestinationKey { get; set; }
|
public string DestinationKey { get; set; }
|
||||||
|
|
||||||
[JsonProperty("destinationPortKey")]
|
[JsonProperty("destinationPortKey")]
|
||||||
public string DestinationPortKey { get; set; }
|
public string DestinationPortKey { get; set; }
|
||||||
|
|
||||||
[JsonProperty("type")]
|
[JsonProperty("type")]
|
||||||
public eRoutingSignalType Type { get; set; }
|
public eRoutingSignalType Type { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Defines the valid destination types for SourceListItems in a room
|
/// Defines the valid destination types for SourceListItems in a room
|
||||||
@@ -193,7 +186,12 @@ namespace PepperDash.Essentials.Core
|
|||||||
defaultDisplay,
|
defaultDisplay,
|
||||||
leftDisplay,
|
leftDisplay,
|
||||||
rightDisplay,
|
rightDisplay,
|
||||||
|
centerDisplay,
|
||||||
programAudio,
|
programAudio,
|
||||||
codecContent
|
codecContent,
|
||||||
|
frontLeftDisplay,
|
||||||
|
frontRightDisplay,
|
||||||
|
rearLeftDisplay,
|
||||||
|
rearRightDisplay,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,9 +1,5 @@
|
|||||||
using System;
|
using PepperDash.Core;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using Crestron.SimplSharp;
|
|
||||||
using PepperDash.Core;
|
|
||||||
|
|
||||||
namespace PepperDash.Essentials.Core
|
namespace PepperDash.Essentials.Core
|
||||||
{
|
{
|
||||||
@@ -26,6 +22,11 @@ namespace PepperDash.Essentials.Core
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
|
if (IsInAutoMode)
|
||||||
|
{
|
||||||
|
return _partitionSensor.PartitionPresentFeedback.BoolValue;
|
||||||
|
}
|
||||||
|
|
||||||
return _partitionPresent;
|
return _partitionPresent;
|
||||||
}
|
}
|
||||||
set
|
set
|
||||||
@@ -73,11 +74,11 @@ namespace PepperDash.Essentials.Core
|
|||||||
PartitionPresentFeedback.FireUpdate();
|
PartitionPresentFeedback.FireUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PartitionPresentFeedback_OutputChange(object sender, FeedbackEventArgs e)
|
private void PartitionPresentFeedback_OutputChange(object sender, FeedbackEventArgs e)
|
||||||
{
|
{
|
||||||
if (IsInAutoMode)
|
if (IsInAutoMode)
|
||||||
{
|
{
|
||||||
PartitionPresentFeedback.FireUpdate();
|
PartitionPresent = e.BoolValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,6 +88,8 @@ namespace PepperDash.Essentials.Core
|
|||||||
|
|
||||||
public void SetAutoMode()
|
public void SetAutoMode()
|
||||||
{
|
{
|
||||||
|
Debug.LogMessage(Serilog.Events.LogEventLevel.Verbose, $"Setting {Key} to Auto Mode", this);
|
||||||
|
|
||||||
IsInAutoMode = true;
|
IsInAutoMode = true;
|
||||||
if (PartitionPresentFeedback != null)
|
if (PartitionPresentFeedback != null)
|
||||||
{
|
{
|
||||||
@@ -101,11 +104,16 @@ namespace PepperDash.Essentials.Core
|
|||||||
{
|
{
|
||||||
_partitionSensor.PartitionPresentFeedback.OutputChange -= PartitionPresentFeedback_OutputChange;
|
_partitionSensor.PartitionPresentFeedback.OutputChange -= PartitionPresentFeedback_OutputChange;
|
||||||
_partitionSensor.PartitionPresentFeedback.OutputChange += PartitionPresentFeedback_OutputChange;
|
_partitionSensor.PartitionPresentFeedback.OutputChange += PartitionPresentFeedback_OutputChange;
|
||||||
|
PartitionPresent = _partitionSensor.PartitionPresentFeedback.BoolValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PartitionPresentFeedback.FireUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetManualMode()
|
public void SetManualMode()
|
||||||
{
|
{
|
||||||
|
Debug.LogMessage(Serilog.Events.LogEventLevel.Verbose, $"Setting {Key} to Manual Mode", this);
|
||||||
|
|
||||||
IsInAutoMode = false;
|
IsInAutoMode = false;
|
||||||
if (PartitionPresentFeedback != null)
|
if (PartitionPresentFeedback != null)
|
||||||
{
|
{
|
||||||
@@ -119,7 +127,10 @@ namespace PepperDash.Essentials.Core
|
|||||||
if (_partitionSensor != null)
|
if (_partitionSensor != null)
|
||||||
{
|
{
|
||||||
_partitionSensor.PartitionPresentFeedback.OutputChange -= PartitionPresentFeedback_OutputChange;
|
_partitionSensor.PartitionPresentFeedback.OutputChange -= PartitionPresentFeedback_OutputChange;
|
||||||
|
PartitionPresent = _partitionSensor.PartitionPresentFeedback.BoolValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PartitionPresentFeedback.FireUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
using System;
|
using Crestron.SimplSharp;
|
||||||
|
using PepperDash.Core;
|
||||||
|
using PepperDash.Core.Logging;
|
||||||
|
using Serilog.Events;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Crestron.SimplSharp;
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using PepperDash.Core;
|
|
||||||
using Serilog.Events;
|
|
||||||
using Newtonsoft.Json;
|
|
||||||
|
|
||||||
namespace PepperDash.Essentials.Core
|
namespace PepperDash.Essentials.Core
|
||||||
{
|
{
|
||||||
@@ -35,7 +36,7 @@ namespace PepperDash.Essentials.Core
|
|||||||
}
|
}
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if(value == _isInAutoMode)
|
if (value == _isInAutoMode)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -49,6 +50,8 @@ namespace PepperDash.Essentials.Core
|
|||||||
|
|
||||||
private int _scenarioChangeDebounceTimeSeconds = 10; // default to 10s
|
private int _scenarioChangeDebounceTimeSeconds = 10; // default to 10s
|
||||||
|
|
||||||
|
private Mutex _scenarioChange = new Mutex();
|
||||||
|
|
||||||
public EssentialsRoomCombiner(string key, EssentialsRoomCombinerPropertiesConfig props)
|
public EssentialsRoomCombiner(string key, EssentialsRoomCombinerPropertiesConfig props)
|
||||||
: base(key)
|
: base(key)
|
||||||
{
|
{
|
||||||
@@ -93,7 +96,7 @@ namespace PepperDash.Essentials.Core
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void CreateScenarios()
|
private void CreateScenarios()
|
||||||
{
|
{
|
||||||
foreach (var scenarioConfig in _propertiesConfig.Scenarios)
|
foreach (var scenarioConfig in _propertiesConfig.Scenarios)
|
||||||
{
|
{
|
||||||
@@ -102,21 +105,29 @@ namespace PepperDash.Essentials.Core
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetRooms()
|
private void SetRooms()
|
||||||
{
|
{
|
||||||
_rooms = new List<IEssentialsRoom>();
|
_rooms = new List<IEssentialsRoom>();
|
||||||
|
|
||||||
foreach (var roomKey in _propertiesConfig.RoomKeys)
|
foreach (var roomKey in _propertiesConfig.RoomKeys)
|
||||||
{
|
{
|
||||||
var room = DeviceManager.GetDeviceForKey(roomKey) as IEssentialsRoom;
|
var room = DeviceManager.GetDeviceForKey(roomKey);
|
||||||
if (room != null)
|
|
||||||
|
if (DeviceManager.GetDeviceForKey(roomKey) is IEssentialsRoom essentialsRoom)
|
||||||
{
|
{
|
||||||
_rooms.Add(room);
|
_rooms.Add(essentialsRoom);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var rooms = DeviceManager.AllDevices.OfType<IEssentialsRoom>().Cast<Device>();
|
||||||
|
|
||||||
|
foreach (var room in rooms)
|
||||||
|
{
|
||||||
|
room.Deactivate();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetupPartitionStateProviders()
|
private void SetupPartitionStateProviders()
|
||||||
{
|
{
|
||||||
foreach (var pConfig in _propertiesConfig.Partitions)
|
foreach (var pConfig in _propertiesConfig.Partitions)
|
||||||
{
|
{
|
||||||
@@ -130,18 +141,18 @@ namespace PepperDash.Essentials.Core
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PartitionPresentFeedback_OutputChange(object sender, FeedbackEventArgs e)
|
private void PartitionPresentFeedback_OutputChange(object sender, FeedbackEventArgs e)
|
||||||
{
|
{
|
||||||
StartDebounceTimer();
|
StartDebounceTimer();
|
||||||
}
|
}
|
||||||
|
|
||||||
void StartDebounceTimer()
|
private void StartDebounceTimer()
|
||||||
{
|
{
|
||||||
// default to 500ms for manual mode
|
// default to 500ms for manual mode
|
||||||
var time = 500;
|
var time = 500;
|
||||||
|
|
||||||
// if in auto mode, debounce the scenario change
|
// if in auto mode, debounce the scenario change
|
||||||
if(IsInAutoMode) time = _scenarioChangeDebounceTimeSeconds * 1000;
|
if (IsInAutoMode) time = _scenarioChangeDebounceTimeSeconds * 1000;
|
||||||
|
|
||||||
if (_scenarioChangeDebounceTimer == null)
|
if (_scenarioChangeDebounceTimer == null)
|
||||||
{
|
{
|
||||||
@@ -156,7 +167,7 @@ namespace PepperDash.Essentials.Core
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Determines the current room combination scenario based on the state of the partition sensors
|
/// Determines the current room combination scenario based on the state of the partition sensors
|
||||||
/// </summary>
|
/// </summary>
|
||||||
void DetermineRoomCombinationScenario()
|
private void DetermineRoomCombinationScenario()
|
||||||
{
|
{
|
||||||
if (_scenarioChangeDebounceTimer != null)
|
if (_scenarioChangeDebounceTimer != null)
|
||||||
{
|
{
|
||||||
@@ -164,14 +175,20 @@ namespace PepperDash.Essentials.Core
|
|||||||
_scenarioChangeDebounceTimer = null;
|
_scenarioChangeDebounceTimer = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.LogInformation("Determining Combination Scenario");
|
||||||
|
|
||||||
var currentScenario = RoomCombinationScenarios.FirstOrDefault((s) =>
|
var currentScenario = RoomCombinationScenarios.FirstOrDefault((s) =>
|
||||||
{
|
{
|
||||||
|
this.LogDebug("Checking scenario {scenarioKey}", s.Key);
|
||||||
// iterate the partition states
|
// iterate the partition states
|
||||||
foreach (var partitionState in s.PartitionStates)
|
foreach (var partitionState in s.PartitionStates)
|
||||||
{
|
{
|
||||||
|
this.LogDebug("checking PartitionState {partitionStateKey}", partitionState.PartitionKey);
|
||||||
// get the partition by key
|
// get the partition by key
|
||||||
var partition = Partitions.FirstOrDefault((p) => p.Key.Equals(partitionState.PartitionKey));
|
var partition = Partitions.FirstOrDefault((p) => p.Key.Equals(partitionState.PartitionKey));
|
||||||
|
|
||||||
|
this.LogDebug("Expected State: {partitionPresent} Actual State: {partitionState}", partitionState.PartitionPresent, partition.PartitionPresentFeedback.BoolValue);
|
||||||
|
|
||||||
if (partition != null && partitionState.PartitionPresent != partition.PartitionPresentFeedback.BoolValue)
|
if (partition != null && partitionState.PartitionPresent != partition.PartitionPresentFeedback.BoolValue)
|
||||||
{
|
{
|
||||||
// the partition can't be found or the state doesn't match
|
// the partition can't be found or the state doesn't match
|
||||||
@@ -184,10 +201,41 @@ namespace PepperDash.Essentials.Core
|
|||||||
|
|
||||||
if (currentScenario != null)
|
if (currentScenario != null)
|
||||||
{
|
{
|
||||||
CurrentScenario = currentScenario;
|
this.LogInformation("Found combination Scenario {scenarioKey}", currentScenario.Key);
|
||||||
|
ChangeScenario(currentScenario);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task ChangeScenario(IRoomCombinationScenario newScenario)
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
if (newScenario == _currentScenario)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deactivate the old scenario first
|
||||||
|
if (_currentScenario != null)
|
||||||
|
{
|
||||||
|
Debug.LogMessage(LogEventLevel.Information, "Deactivating scenario {currentScenario}", this, _currentScenario.Name);
|
||||||
|
await _currentScenario.Deactivate();
|
||||||
|
}
|
||||||
|
|
||||||
|
_currentScenario = newScenario;
|
||||||
|
|
||||||
|
// Activate the new scenario
|
||||||
|
if (_currentScenario != null)
|
||||||
|
{
|
||||||
|
Debug.LogMessage(LogEventLevel.Debug, $"Current Scenario: {_currentScenario.Name}", this);
|
||||||
|
await _currentScenario.Activate();
|
||||||
|
}
|
||||||
|
|
||||||
|
RoomCombinationScenarioChanged?.Invoke(this, new EventArgs());
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
#region IEssentialsRoomCombiner Members
|
#region IEssentialsRoomCombiner Members
|
||||||
|
|
||||||
public event EventHandler<EventArgs> RoomCombinationScenarioChanged;
|
public event EventHandler<EventArgs> RoomCombinationScenarioChanged;
|
||||||
@@ -198,33 +246,6 @@ namespace PepperDash.Essentials.Core
|
|||||||
{
|
{
|
||||||
return _currentScenario;
|
return _currentScenario;
|
||||||
}
|
}
|
||||||
private set
|
|
||||||
{
|
|
||||||
if (value != _currentScenario)
|
|
||||||
{
|
|
||||||
// Deactivate the old scenario first
|
|
||||||
if (_currentScenario != null)
|
|
||||||
{
|
|
||||||
_currentScenario.Deactivate();
|
|
||||||
}
|
|
||||||
|
|
||||||
_currentScenario = value;
|
|
||||||
|
|
||||||
// Activate the new scenario
|
|
||||||
if (_currentScenario != null)
|
|
||||||
{
|
|
||||||
_currentScenario.Activate();
|
|
||||||
|
|
||||||
Debug.LogMessage(LogEventLevel.Debug, $"Current Scenario: {_currentScenario.Name}", this);
|
|
||||||
}
|
|
||||||
|
|
||||||
var handler = RoomCombinationScenarioChanged;
|
|
||||||
if (handler != null)
|
|
||||||
{
|
|
||||||
handler(this, new EventArgs());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public BoolFeedback IsInAutoModeFeedback { get; private set; }
|
public BoolFeedback IsInAutoModeFeedback { get; private set; }
|
||||||
@@ -232,16 +253,35 @@ namespace PepperDash.Essentials.Core
|
|||||||
public void SetAutoMode()
|
public void SetAutoMode()
|
||||||
{
|
{
|
||||||
IsInAutoMode = true;
|
IsInAutoMode = true;
|
||||||
|
|
||||||
|
foreach (var partition in Partitions)
|
||||||
|
{
|
||||||
|
partition.SetAutoMode();
|
||||||
|
}
|
||||||
|
|
||||||
|
DetermineRoomCombinationScenario();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetManualMode()
|
public void SetManualMode()
|
||||||
{
|
{
|
||||||
IsInAutoMode = false;
|
IsInAutoMode = false;
|
||||||
|
|
||||||
|
foreach (var partition in Partitions)
|
||||||
|
{
|
||||||
|
partition.SetManualMode();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ToggleMode()
|
public void ToggleMode()
|
||||||
{
|
{
|
||||||
IsInAutoMode = !IsInAutoMode;
|
if (IsInAutoMode)
|
||||||
|
{
|
||||||
|
SetManualMode();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SetAutoMode();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<IRoomCombinationScenario> RoomCombinationScenarios { get; private set; }
|
public List<IRoomCombinationScenario> RoomCombinationScenarios { get; private set; }
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using PepperDash.Core;
|
using PepperDash.Core;
|
||||||
|
|
||||||
@@ -87,12 +88,12 @@ namespace PepperDash.Essentials.Core
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Activates this room combination scenario
|
/// Activates this room combination scenario
|
||||||
/// </summary>
|
/// </summary>
|
||||||
void Activate();
|
Task Activate();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Deactivates this room combination scenario
|
/// Deactivates this room combination scenario
|
||||||
/// </summary>
|
/// </summary>
|
||||||
void Deactivate();
|
Task Deactivate();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The state of the partitions that would activate this scenario
|
/// The state of the partitions that would activate this scenario
|
||||||
|
|||||||
@@ -1,22 +1,16 @@
|
|||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using Crestron.SimplSharp;
|
|
||||||
|
|
||||||
using PepperDash.Core;
|
using PepperDash.Core;
|
||||||
|
using PepperDash.Core.Logging;
|
||||||
using Newtonsoft.Json;
|
|
||||||
using Serilog.Events;
|
using Serilog.Events;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace PepperDash.Essentials.Core
|
namespace PepperDash.Essentials.Core
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents a room combination scenario
|
/// Represents a room combination scenario
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class RoomCombinationScenario: IRoomCombinationScenario, IKeyName
|
public class RoomCombinationScenario : IRoomCombinationScenario, IKeyName
|
||||||
{
|
{
|
||||||
private RoomCombinationScenarioConfig _config;
|
private RoomCombinationScenarioConfig _config;
|
||||||
|
|
||||||
@@ -40,7 +34,7 @@ namespace PepperDash.Essentials.Core
|
|||||||
get { return _isActive; }
|
get { return _isActive; }
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if(value == _isActive)
|
if (value == _isActive)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -76,33 +70,43 @@ namespace PepperDash.Essentials.Core
|
|||||||
IsActiveFeedback = new BoolFeedback(() => _isActive);
|
IsActiveFeedback = new BoolFeedback(() => _isActive);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Activate()
|
public async Task Activate()
|
||||||
{
|
{
|
||||||
Debug.LogMessage(LogEventLevel.Debug, "Activating Scenario: '{0}' with {1} action(s) defined", Name, activationActions.Count);
|
this.LogInformation("Activating Scenario {name} with {activationActionCount} action(s) defined", Name, activationActions.Count);
|
||||||
|
|
||||||
|
List<Task> tasks = new List<Task>();
|
||||||
|
|
||||||
if (activationActions != null)
|
if (activationActions != null)
|
||||||
{
|
{
|
||||||
foreach (var action in activationActions)
|
foreach (var action in activationActions)
|
||||||
{
|
{
|
||||||
DeviceJsonApi.DoDeviceAction(action);
|
this.LogInformation("Running Activation action {@action}", action);
|
||||||
|
tasks.Add(DeviceJsonApi.DoDeviceActionAsync(action));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await Task.WhenAll(tasks);
|
||||||
|
|
||||||
IsActive = true;
|
IsActive = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Deactivate()
|
public async Task Deactivate()
|
||||||
{
|
{
|
||||||
Debug.LogMessage(LogEventLevel.Debug, "Deactivating Scenario: '{0}' with {1} action(s) defined", Name, deactivationActions.Count);
|
this.LogInformation("Deactivating Scenario {name} with {deactivationActionCount} action(s) defined", Name, deactivationActions.Count);
|
||||||
|
|
||||||
|
List<Task> tasks = new List<Task>();
|
||||||
|
|
||||||
if (deactivationActions != null)
|
if (deactivationActions != null)
|
||||||
{
|
{
|
||||||
foreach (var action in deactivationActions)
|
foreach (var action in deactivationActions)
|
||||||
{
|
{
|
||||||
DeviceJsonApi.DoDeviceAction(action);
|
this.LogInformation("Running deactivation action {actionDeviceKey}:{actionMethod}", action.DeviceKey, action.MethodName);
|
||||||
|
tasks.Add( DeviceJsonApi.DoDeviceActionAsync(action));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await Task.WhenAll(tasks);
|
||||||
|
|
||||||
IsActive = false;
|
IsActive = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -200,6 +200,9 @@ namespace PepperDash.Essentials.Room.Config
|
|||||||
public string DestinationListKey { get; set; }
|
public string DestinationListKey { get; set; }
|
||||||
[JsonProperty("audioControlPointListKey")]
|
[JsonProperty("audioControlPointListKey")]
|
||||||
public string AudioControlPointListKey { get; set; }
|
public string AudioControlPointListKey { get; set; }
|
||||||
|
[JsonProperty("cameraListKey")]
|
||||||
|
public string CameraListKey { get; set; }
|
||||||
|
|
||||||
|
|
||||||
[JsonProperty("defaultSourceItem")]
|
[JsonProperty("defaultSourceItem")]
|
||||||
public string DefaultSourceItem { get; set; }
|
public string DefaultSourceItem { get; set; }
|
||||||
|
|||||||
@@ -133,7 +133,28 @@ namespace PepperDash.Essentials.Core
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private string _cameraListKey;
|
||||||
|
public string CameraListKey
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(_cameraListKey))
|
||||||
|
{
|
||||||
|
return _defaultListKey;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return _cameraListKey;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
protected set
|
||||||
|
{
|
||||||
|
if (value != _cameraListKey)
|
||||||
|
{
|
||||||
|
_cameraListKey = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Timer used for informing the UIs of a shutdown
|
/// Timer used for informing the UIs of a shutdown
|
||||||
|
|||||||
@@ -31,6 +31,8 @@ namespace PepperDash.Essentials.Core
|
|||||||
|
|
||||||
string AudioControlPointListKey { get; }
|
string AudioControlPointListKey { get; }
|
||||||
|
|
||||||
|
string CameraListKey { get; }
|
||||||
|
|
||||||
SecondsCountdownTimer ShutdownPromptTimer { get; }
|
SecondsCountdownTimer ShutdownPromptTimer { get; }
|
||||||
int ShutdownPromptSeconds { get; }
|
int ShutdownPromptSeconds { get; }
|
||||||
int ShutdownVacancySeconds { get; }
|
int ShutdownVacancySeconds { get; }
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
using PepperDash.Core;
|
using Serilog.Events;
|
||||||
using Serilog.Events;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using Debug = PepperDash.Core.Debug;
|
||||||
|
|
||||||
|
|
||||||
namespace PepperDash.Essentials.Core
|
namespace PepperDash.Essentials.Core
|
||||||
@@ -20,21 +21,36 @@ namespace PepperDash.Essentials.Core
|
|||||||
/// Gets any existing RouteDescriptor for a destination, clears it using ReleaseRoute
|
/// Gets any existing RouteDescriptor for a destination, clears it using ReleaseRoute
|
||||||
/// and then attempts a new Route and if sucessful, stores that RouteDescriptor
|
/// and then attempts a new Route and if sucessful, stores that RouteDescriptor
|
||||||
/// in RouteDescriptorCollection.DefaultCollection
|
/// in RouteDescriptorCollection.DefaultCollection
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static void ReleaseAndMakeRoute(this IRoutingInputs destination, IRoutingOutputs source, eRoutingSignalType signalType, string destinationPortKey = "", string sourcePortKey = "")
|
public static void ReleaseAndMakeRoute(this IRoutingInputs destination, IRoutingOutputs source, eRoutingSignalType signalType, string destinationPortKey = "", string sourcePortKey = "")
|
||||||
{
|
{
|
||||||
|
// Remove this line before committing!!!!!
|
||||||
|
var frame = new StackFrame(1, true);
|
||||||
|
Debug.LogMessage(LogEventLevel.Information, "ReleaseAndMakeRoute Called from {method} with params {destinationKey}:{sourceKey}:{signalType}:{destinationPortKey}:{sourcePortKey}", frame.GetMethod().Name, destination.Key, source.Key, signalType.ToString(), destinationPortKey, sourcePortKey);
|
||||||
|
|
||||||
var inputPort = string.IsNullOrEmpty(destinationPortKey) ? null : destination.InputPorts.FirstOrDefault(p => p.Key == destinationPortKey);
|
var inputPort = string.IsNullOrEmpty(destinationPortKey) ? null : destination.InputPorts.FirstOrDefault(p => p.Key == destinationPortKey);
|
||||||
var outputPort = string.IsNullOrEmpty(sourcePortKey) ? null : source.OutputPorts.FirstOrDefault(p => p.Key == sourcePortKey);
|
var outputPort = string.IsNullOrEmpty(sourcePortKey) ? null : source.OutputPorts.FirstOrDefault(p => p.Key == sourcePortKey);
|
||||||
|
|
||||||
ReleaseAndMakeRoute(destination, source, signalType, inputPort, outputPort);
|
ReleaseAndMakeRoute(destination, source, signalType, inputPort, outputPort);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void RemoveRouteRequestForDestination(string destinationKey)
|
||||||
|
{
|
||||||
|
Debug.LogMessage(LogEventLevel.Information, "Removing route request for {destination}", null, destinationKey);
|
||||||
|
|
||||||
|
var result = RouteRequests.Remove(destinationKey);
|
||||||
|
|
||||||
|
var messageTemplate = result ? "Route Request for {destination} removed" : "Route Request for {destination} not found";
|
||||||
|
|
||||||
|
Debug.LogMessage(LogEventLevel.Information, messageTemplate, null, destinationKey);
|
||||||
|
}
|
||||||
|
|
||||||
private static void ReleaseAndMakeRoute(IRoutingInputs destination, IRoutingOutputs source, eRoutingSignalType signalType, RoutingInputPort destinationPort = null, RoutingOutputPort sourcePort = null)
|
private static void ReleaseAndMakeRoute(IRoutingInputs destination, IRoutingOutputs source, eRoutingSignalType signalType, RoutingInputPort destinationPort = null, RoutingOutputPort sourcePort = null)
|
||||||
{
|
{
|
||||||
if (destination == null) throw new ArgumentNullException(nameof(destination));
|
if (destination == null) throw new ArgumentNullException(nameof(destination));
|
||||||
if (source == null) throw new ArgumentNullException(nameof(source));
|
if (source == null) throw new ArgumentNullException(nameof(source));
|
||||||
if (destinationPort == null) Debug.LogMessage(LogEventLevel.Verbose, "Destination port is null");
|
if (destinationPort == null) Debug.LogMessage(LogEventLevel.Information, "Destination port is null");
|
||||||
if (sourcePort == null) Debug.LogMessage(LogEventLevel.Verbose, "Source port is null");
|
if (sourcePort == null) Debug.LogMessage(LogEventLevel.Information, "Source port is null");
|
||||||
|
|
||||||
var routeRequest = new RouteRequest
|
var routeRequest = new RouteRequest
|
||||||
{
|
{
|
||||||
@@ -57,7 +73,7 @@ namespace PepperDash.Essentials.Core
|
|||||||
|
|
||||||
RouteRequests[destination.Key] = routeRequest;
|
RouteRequests[destination.Key] = routeRequest;
|
||||||
|
|
||||||
Debug.LogMessage(LogEventLevel.Verbose, "Device: {0} is cooling down and already has a routing request stored. Storing new route request to route to source key: {1}", null, destination.Key, routeRequest.Source.Key);
|
Debug.LogMessage(LogEventLevel.Information, "Device: {destination} is cooling down and already has a routing request stored. Storing new route request to route to source key: {sourceKey}", null, destination.Key, routeRequest.Source.Key);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -71,17 +87,17 @@ namespace PepperDash.Essentials.Core
|
|||||||
|
|
||||||
RouteRequests.Add(destination.Key, routeRequest);
|
RouteRequests.Add(destination.Key, routeRequest);
|
||||||
|
|
||||||
Debug.LogMessage(LogEventLevel.Verbose, "Device: {0} is cooling down. Storing route request to route to source key: {1}", null, destination.Key, routeRequest.Source.Key);
|
Debug.LogMessage(LogEventLevel.Information, "Device: {destination} is cooling down. Storing route request to route to source key: {sourceKey}", null, destination.Key, routeRequest.Source.Key);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (RouteRequests.ContainsKey(destination.Key) && coolingDevice != null && coolingDevice.IsCoolingDownFeedback.BoolValue == false)
|
if (RouteRequests.ContainsKey(destination.Key) && coolingDevice != null && coolingDevice.IsCoolingDownFeedback.BoolValue == false)
|
||||||
{
|
{
|
||||||
RouteRequests.Remove(destination.Key);
|
RouteRequests.Remove(destination.Key);
|
||||||
Debug.LogMessage(LogEventLevel.Verbose, "Device: {0} is NOT cooling down. Removing stored route request and routing to source key: {1}", null, destination.Key, routeRequest.Source.Key);
|
Debug.LogMessage(LogEventLevel.Information, "Device: {destination} is NOT cooling down. Removing stored route request and routing to source key: {sourceKey}", null, destination.Key, routeRequest.Source.Key);
|
||||||
}
|
}
|
||||||
|
|
||||||
destination.ReleaseRoute();
|
destination.ReleaseRoute(destinationPort?.Key ?? string.Empty);
|
||||||
|
|
||||||
RunRouteRequest(routeRequest);
|
RunRouteRequest(routeRequest);
|
||||||
}
|
}
|
||||||
@@ -109,14 +125,21 @@ namespace PepperDash.Essentials.Core
|
|||||||
videoRoute?.ExecuteRoutes();
|
videoRoute?.ExecuteRoutes();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void ReleaseRoute(this IRoutingInputs destination)
|
||||||
|
{
|
||||||
|
ReleaseRoute(destination, string.Empty);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Will release the existing route on the destination, if it is found in
|
/// Will release the existing route on the destination, if it is found in
|
||||||
/// RouteDescriptorCollection.DefaultCollection
|
/// RouteDescriptorCollection.DefaultCollection
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="destination"></param>
|
/// <param name="destination"></param>
|
||||||
public static void ReleaseRoute(this IRoutingInputs destination)
|
public static void ReleaseRoute(this IRoutingInputs destination, string inputPortKey)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
Debug.LogMessage(LogEventLevel.Information, "Release route for {inputPortKey}", destination, string.IsNullOrEmpty(inputPortKey) ? "auto" : inputPortKey);
|
||||||
|
|
||||||
if (RouteRequests.TryGetValue(destination.Key, out RouteRequest existingRequest) && destination is IWarmingCooling)
|
if (RouteRequests.TryGetValue(destination.Key, out RouteRequest existingRequest) && destination is IWarmingCooling)
|
||||||
{
|
{
|
||||||
var coolingDevice = destination as IWarmingCooling;
|
var coolingDevice = destination as IWarmingCooling;
|
||||||
@@ -126,7 +149,7 @@ namespace PepperDash.Essentials.Core
|
|||||||
|
|
||||||
RouteRequests.Remove(destination.Key);
|
RouteRequests.Remove(destination.Key);
|
||||||
|
|
||||||
var current = RouteDescriptorCollection.DefaultCollection.RemoveRouteDescriptor(destination);
|
var current = RouteDescriptorCollection.DefaultCollection.RemoveRouteDescriptor(destination, inputPortKey);
|
||||||
if (current != null)
|
if (current != null)
|
||||||
{
|
{
|
||||||
Debug.LogMessage(LogEventLevel.Debug, "Releasing current route: {0}", destination, current.Source.Key);
|
Debug.LogMessage(LogEventLevel.Debug, "Releasing current route: {0}", destination, current.Source.Key);
|
||||||
@@ -146,7 +169,7 @@ namespace PepperDash.Essentials.Core
|
|||||||
// if it's a single signal type, find the route
|
// if it's a single signal type, find the route
|
||||||
if (!signalType.HasFlag(eRoutingSignalType.AudioVideo))
|
if (!signalType.HasFlag(eRoutingSignalType.AudioVideo))
|
||||||
{
|
{
|
||||||
var singleTypeRouteDescriptor = new RouteDescriptor(source, destination, signalType);
|
var singleTypeRouteDescriptor = new RouteDescriptor(source, destination, destinationPort, signalType);
|
||||||
Debug.LogMessage(LogEventLevel.Debug, "Attempting to build source route from {sourceKey} of type {type}", destination, source.Key, signalType);
|
Debug.LogMessage(LogEventLevel.Debug, "Attempting to build source route from {sourceKey} of type {type}", destination, source.Key, signalType);
|
||||||
|
|
||||||
if (!destination.GetRouteToSource(source, null, null, signalType, 0, singleTypeRouteDescriptor, destinationPort, sourcePort))
|
if (!destination.GetRouteToSource(source, null, null, signalType, 0, singleTypeRouteDescriptor, destinationPort, sourcePort))
|
||||||
@@ -163,14 +186,14 @@ namespace PepperDash.Essentials.Core
|
|||||||
|
|
||||||
Debug.LogMessage(LogEventLevel.Debug, "Attempting to build source route from {sourceKey} of type {type}", destination, source.Key);
|
Debug.LogMessage(LogEventLevel.Debug, "Attempting to build source route from {sourceKey} of type {type}", destination, source.Key);
|
||||||
|
|
||||||
var audioRouteDescriptor = new RouteDescriptor(source, destination, eRoutingSignalType.Audio);
|
var audioRouteDescriptor = new RouteDescriptor(source, destination, destinationPort, eRoutingSignalType.Audio);
|
||||||
|
|
||||||
var audioSuccess = destination.GetRouteToSource(source, null, null, eRoutingSignalType.Audio, 0, audioRouteDescriptor, destinationPort, sourcePort);
|
var audioSuccess = destination.GetRouteToSource(source, null, null, eRoutingSignalType.Audio, 0, audioRouteDescriptor, destinationPort, sourcePort);
|
||||||
|
|
||||||
if (!audioSuccess)
|
if (!audioSuccess)
|
||||||
Debug.LogMessage(LogEventLevel.Debug, "Cannot find audio route to {0}", destination, source.Key);
|
Debug.LogMessage(LogEventLevel.Debug, "Cannot find audio route to {0}", destination, source.Key);
|
||||||
|
|
||||||
var videoRouteDescriptor = new RouteDescriptor(source, destination, eRoutingSignalType.Video);
|
var videoRouteDescriptor = new RouteDescriptor(source, destination, destinationPort, eRoutingSignalType.Video);
|
||||||
|
|
||||||
var videoSuccess = destination.GetRouteToSource(source, null, null, eRoutingSignalType.Video, 0, videoRouteDescriptor, destinationPort, sourcePort);
|
var videoSuccess = destination.GetRouteToSource(source, null, null, eRoutingSignalType.Video, 0, videoRouteDescriptor, destinationPort, sourcePort);
|
||||||
|
|
||||||
|
|||||||
@@ -14,19 +14,27 @@ namespace PepperDash.Essentials.Core
|
|||||||
public class RouteDescriptor
|
public class RouteDescriptor
|
||||||
{
|
{
|
||||||
public IRoutingInputs Destination { get; private set; }
|
public IRoutingInputs Destination { get; private set; }
|
||||||
|
|
||||||
|
public RoutingInputPort InputPort { get; private set; }
|
||||||
|
|
||||||
public IRoutingOutputs Source { get; private set; }
|
public IRoutingOutputs Source { get; private set; }
|
||||||
public eRoutingSignalType SignalType { get; private set; }
|
public eRoutingSignalType SignalType { get; private set; }
|
||||||
public List<RouteSwitchDescriptor> Routes { get; private set; }
|
public List<RouteSwitchDescriptor> Routes { get; private set; }
|
||||||
|
|
||||||
|
|
||||||
public RouteDescriptor(IRoutingOutputs source, IRoutingInputs destination, eRoutingSignalType signalType)
|
public RouteDescriptor(IRoutingOutputs source, IRoutingInputs destination, eRoutingSignalType signalType):this(source,destination, null, signalType)
|
||||||
{
|
{
|
||||||
Destination = destination;
|
|
||||||
Source = source;
|
|
||||||
SignalType = signalType;
|
|
||||||
Routes = new List<RouteSwitchDescriptor>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public RouteDescriptor(IRoutingOutputs source, IRoutingInputs destination, RoutingInputPort inputPort, eRoutingSignalType signalType)
|
||||||
|
{
|
||||||
|
Destination = destination;
|
||||||
|
Source = source;
|
||||||
|
SignalType = signalType;
|
||||||
|
InputPort = inputPort;
|
||||||
|
Routes = new List<RouteSwitchDescriptor>();
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Executes all routes described in this collection. Typically called via
|
/// Executes all routes described in this collection. Typically called via
|
||||||
/// extension method IRoutingInputs.ReleaseAndMakeRoute()
|
/// extension method IRoutingInputs.ReleaseAndMakeRoute()
|
||||||
@@ -60,10 +68,12 @@ namespace PepperDash.Essentials.Core
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public void ReleaseRoutes()
|
public void ReleaseRoutes()
|
||||||
{
|
{
|
||||||
foreach (var route in Routes)
|
foreach (var route in Routes.Where(r => r.SwitchingDevice is IRouting))
|
||||||
{
|
{
|
||||||
if (route.SwitchingDevice is IRouting)
|
if (route.SwitchingDevice is IRouting switchingDevice)
|
||||||
{
|
{
|
||||||
|
switchingDevice.ExecuteSwitch(null, route.OutputPort.Selector, SignalType);
|
||||||
|
|
||||||
// Pull the route from the port. Whatever is watching the output's in use tracker is
|
// Pull the route from the port. Whatever is watching the output's in use tracker is
|
||||||
// responsible for responding appropriately.
|
// responsible for responding appropriately.
|
||||||
route.OutputPort.InUseTracker.RemoveUser(Destination, "destination-" + SignalType);
|
route.OutputPort.InUseTracker.RemoveUser(Destination, "destination-" + SignalType);
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
using System.Collections.Generic;
|
using PepperDash.Core;
|
||||||
using System.Linq;
|
|
||||||
|
|
||||||
using PepperDash.Core;
|
|
||||||
using Serilog.Events;
|
using Serilog.Events;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
|
||||||
namespace PepperDash.Essentials.Core
|
namespace PepperDash.Essentials.Core
|
||||||
@@ -33,7 +32,13 @@ namespace PepperDash.Essentials.Core
|
|||||||
/// <param name="descriptor"></param>
|
/// <param name="descriptor"></param>
|
||||||
public void AddRouteDescriptor(RouteDescriptor descriptor)
|
public void AddRouteDescriptor(RouteDescriptor descriptor)
|
||||||
{
|
{
|
||||||
if (RouteDescriptors.Any(t => t.Destination == descriptor.Destination))
|
if (descriptor == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (RouteDescriptors.Any(t => t.Destination == descriptor.Destination)
|
||||||
|
&& RouteDescriptors.Any(t => t.Destination == descriptor.Destination && t.InputPort != null && descriptor.InputPort != null && t.InputPort.Key == descriptor.InputPort.Key))
|
||||||
{
|
{
|
||||||
Debug.LogMessage(LogEventLevel.Debug, descriptor.Destination,
|
Debug.LogMessage(LogEventLevel.Debug, descriptor.Destination,
|
||||||
"Route to [{0}] already exists in global routes table", descriptor.Source.Key);
|
"Route to [{0}] already exists in global routes table", descriptor.Source.Key);
|
||||||
@@ -48,18 +53,33 @@ namespace PepperDash.Essentials.Core
|
|||||||
/// <returns>null if no RouteDescriptor for a destination exists</returns>
|
/// <returns>null if no RouteDescriptor for a destination exists</returns>
|
||||||
public RouteDescriptor GetRouteDescriptorForDestination(IRoutingInputs destination)
|
public RouteDescriptor GetRouteDescriptorForDestination(IRoutingInputs destination)
|
||||||
{
|
{
|
||||||
|
Debug.LogMessage(LogEventLevel.Debug, "Getting route descriptor", destination);
|
||||||
|
|
||||||
return RouteDescriptors.FirstOrDefault(rd => rd.Destination == destination);
|
return RouteDescriptors.FirstOrDefault(rd => rd.Destination == destination);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public RouteDescriptor GetRouteDescriptorForDestinationAndInputPort(IRoutingInputs destination, string inputPortKey)
|
||||||
|
{
|
||||||
|
Debug.LogMessage(LogEventLevel.Debug, "Getting route descriptor for {inputPortKey}", destination, string.IsNullOrEmpty(inputPortKey) ? "auto" : inputPortKey);
|
||||||
|
return RouteDescriptors.FirstOrDefault(rd => rd.Destination == destination && rd.InputPort != null && rd.InputPort.Key == inputPortKey);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns the RouteDescriptor for a given destination AND removes it from collection.
|
/// Returns the RouteDescriptor for a given destination AND removes it from collection.
|
||||||
/// Returns null if no route with the provided destination exists.
|
/// Returns null if no route with the provided destination exists.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public RouteDescriptor RemoveRouteDescriptor(IRoutingInputs destination)
|
public RouteDescriptor RemoveRouteDescriptor(IRoutingInputs destination, string inputPortKey = "")
|
||||||
{
|
{
|
||||||
var descr = GetRouteDescriptorForDestination(destination);
|
Debug.LogMessage(LogEventLevel.Debug, "Removing route descriptor for {inputPortKey}", destination, string.IsNullOrEmpty(inputPortKey) ? "auto" : inputPortKey);
|
||||||
|
|
||||||
|
var descr = string.IsNullOrEmpty(inputPortKey)
|
||||||
|
? GetRouteDescriptorForDestination(destination)
|
||||||
|
: GetRouteDescriptorForDestinationAndInputPort(destination, inputPortKey);
|
||||||
if (descr != null)
|
if (descr != null)
|
||||||
RouteDescriptors.Remove(descr);
|
RouteDescriptors.Remove(descr);
|
||||||
|
|
||||||
|
Debug.LogMessage(LogEventLevel.Debug, "Found route descriptor {routeDescriptor}", destination, descr);
|
||||||
|
|
||||||
return descr;
|
return descr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
namespace PepperDash.Essentials.Core
|
using PepperDash.Core;
|
||||||
|
using Serilog.Events;
|
||||||
|
|
||||||
|
namespace PepperDash.Essentials.Core
|
||||||
{
|
{
|
||||||
public class RouteRequest
|
public class RouteRequest
|
||||||
{
|
{
|
||||||
@@ -11,37 +14,21 @@
|
|||||||
|
|
||||||
public void HandleCooldown(object sender, FeedbackEventArgs args)
|
public void HandleCooldown(object sender, FeedbackEventArgs args)
|
||||||
{
|
{
|
||||||
var coolingDevice = sender as IWarmingCooling;
|
Debug.LogMessage(LogEventLevel.Information, "Handling cooldown route request: {destination}:{destinationPort} -> {source}:{sourcePort} {type}", null, Destination.Key, DestinationPort.Key, Source.Key, SourcePort.Key, SignalType.ToString());
|
||||||
|
|
||||||
if (args.BoolValue == false)
|
if (args.BoolValue == true)
|
||||||
{
|
{
|
||||||
Destination.ReleaseAndMakeRoute(Source, SignalType);
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (sender == null) return;
|
Debug.LogMessage(LogEventLevel.Information, "Cooldown complete. Making route from {destination} to {source}", Destination.Key, Source.Key);
|
||||||
|
Destination.ReleaseAndMakeRoute(Source, SignalType, DestinationPort?.Key ?? string.Empty, SourcePort?.Key ?? string.Empty);
|
||||||
|
|
||||||
|
if (sender is IWarmingCooling coolingDevice)
|
||||||
|
{
|
||||||
|
Debug.LogMessage(LogEventLevel.Debug, "Unsubscribing from cooling feedback for {destination}", null, Destination.Key);
|
||||||
coolingDevice.IsCoolingDownFeedback.OutputChange -= HandleCooldown;
|
coolingDevice.IsCoolingDownFeedback.OutputChange -= HandleCooldown;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*public class RouteRequest<TInputSelector, TOutputSelector>
|
|
||||||
{
|
|
||||||
public IRoutingSink<TInputSelector> Destination { get; set; }
|
|
||||||
public IRoutingOutputs<TOutputSelector> Source { get; set; }
|
|
||||||
public eRoutingSignalType SignalType { get; set; }
|
|
||||||
|
|
||||||
public void HandleCooldown(object sender, FeedbackEventArgs args)
|
|
||||||
{
|
|
||||||
var coolingDevice = sender as IWarmingCooling;
|
|
||||||
|
|
||||||
if (args.BoolValue == false)
|
|
||||||
{
|
|
||||||
Destination.ReleaseAndMakeRoute(Source, SignalType);
|
|
||||||
|
|
||||||
if (sender == null) return;
|
|
||||||
|
|
||||||
coolingDevice.IsCoolingDownFeedback.OutputChange -= HandleCooldown;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
using Crestron.SimplSharpPro;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace PepperDash.Essentials.Devices.Common.Codec
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Describes a cisco codec device that can allow configuration of cameras
|
||||||
|
/// </summary>
|
||||||
|
public interface ICiscoCodecCameraConfig
|
||||||
|
{
|
||||||
|
void SetCameraAssignedSerialNumber(uint cameraId, string serialNumber);
|
||||||
|
|
||||||
|
void SetCameraName(uint videoConnectorId, string name);
|
||||||
|
|
||||||
|
void SetInputSourceType(uint videoConnectorId, eCiscoCodecInputSourceType sourceType);
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum eCiscoCodecInputSourceType
|
||||||
|
{
|
||||||
|
PC,
|
||||||
|
camera,
|
||||||
|
document_camera,
|
||||||
|
mediaplayer,
|
||||||
|
other,
|
||||||
|
whiteboard
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user