feat: wip commit prior to removing the crestron library

This commit is contained in:
Nick Genovese
2025-07-27 21:35:43 -04:00
parent 903236d6d9
commit 473c6d4590
472 changed files with 3075 additions and 1528 deletions

View File

@@ -1,14 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using Crestron.SimplSharp;
using PepperDash.Core;
namespace PepperDash.Core
namespace PepperDash.Essentials.Core.Communications
{
/// <summary>
/// Defines the string event handler for line events on the gather

View File

@@ -3,7 +3,6 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using Crestron.SimplSharp;
using PepperDash.Core;
namespace PepperDash.Core
{

View File

@@ -1,9 +1,8 @@
using System;
using Crestron.SimplSharp;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
namespace PepperDash.Core
namespace PepperDash.Essentials.Core.Communications
{
/// <summary>
/// Represents a ControlPropertiesConfig

View File

@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Crestron.SimplSharp;
namespace PepperDash.Core
namespace PepperDash.Essentials.Core.Communications
{
/// <summary>
/// Crestron Control Methods for a comm object

View File

@@ -8,9 +8,11 @@ using Crestron.SimplSharpPro.DeviceSupport;
using Crestron.SimplSharpPro.EthernetCommunication;
using Newtonsoft.Json;
using PepperDash.Core;
using PepperDash.Essentials.Core.Communications;
using PepperDash.Essentials.Core.Config;
using PepperDash.Essentials.Core.Devices;
using PepperDash.Essentials.Core.JoinMaps;
using PepperDash.Essentials.Core.Monitoring;
using Serilog.Events;
//using PepperDash.Essentials.Devices.Common.Cameras;

View File

@@ -1,4 +1,4 @@
using PepperDash.Core;
using PepperDash.Essentials.Core.Devices;
using Serilog.Events;
//using PepperDash.Essentials.Devices.Common.Cameras;

View File

@@ -1,6 +1,7 @@
using PepperDash.Essentials.Core.JoinMaps;
using System;
namespace PepperDash.Essentials.Core.Bridges
namespace PepperDash.Essentials.Core.Bridges.JoinMaps
{
/// <summary>
/// Represents a AirMediaControllerJoinMap

View File

@@ -1,6 +1,7 @@
using System;
using PepperDash.Essentials.Core.JoinMaps;
using System;
namespace PepperDash.Essentials.Core.Bridges
namespace PepperDash.Essentials.Core.Bridges.JoinMaps
{
/// <summary>
/// Represents a AppleTvJoinMap

View File

@@ -1,6 +1,7 @@
using System;
using PepperDash.Essentials.Core.JoinMaps;
using System;
namespace PepperDash.Essentials.Core.Bridges
namespace PepperDash.Essentials.Core.Bridges.JoinMaps
{
/// <summary>
/// Represents a C2nRthsControllerJoinMap

View File

@@ -1,6 +1,7 @@
using System;
using PepperDash.Essentials.Core.JoinMaps;
using System;
namespace PepperDash.Essentials.Core.Bridges
namespace PepperDash.Essentials.Core.Bridges.JoinMaps
{
/// <summary>
/// Represents a CameraControllerJoinMap

View File

@@ -1,6 +1,7 @@
using System;
using PepperDash.Essentials.Core.JoinMaps;
using System;
namespace PepperDash.Essentials.Core.Bridges
namespace PepperDash.Essentials.Core.Bridges.JoinMaps
{
/// <summary>
/// Represents a CenOdtOccupancySensorBaseJoinMap

View File

@@ -1,6 +1,7 @@
using System;
using PepperDash.Essentials.Core.JoinMaps;
using System;
namespace PepperDash.Essentials.Core.Bridges
namespace PepperDash.Essentials.Core.Bridges.JoinMaps
{
/// <summary>
/// Represents a DisplayControllerJoinMap

View File

@@ -1,6 +1,8 @@
using System;
using PepperDash.Essentials.Core.JoinMaps;
using System;
namespace PepperDash.Essentials.Core.Bridges {
namespace PepperDash.Essentials.Core.Bridges.JoinMaps
{
/// <summary>
/// Represents a DmBladeChassisControllerJoinMap
/// </summary>

View File

@@ -1,6 +1,7 @@
using PepperDash.Essentials.Core.JoinMaps;
using System;
namespace PepperDash.Essentials.Core.Bridges
namespace PepperDash.Essentials.Core.Bridges.JoinMaps
{
/// <summary>
/// Represents a DmChassisControllerJoinMap

View File

@@ -1,6 +1,7 @@
using PepperDash.Essentials.Core.JoinMaps;
using System;
namespace PepperDash.Essentials.Core.Bridges
namespace PepperDash.Essentials.Core.Bridges.JoinMaps
{
/// <summary>
/// Represents a DmRmcControllerJoinMap

View File

@@ -1,6 +1,7 @@
using System;
using PepperDash.Essentials.Core.JoinMaps;
using System;
namespace PepperDash.Essentials.Core.Bridges
namespace PepperDash.Essentials.Core.Bridges.JoinMaps
{
/// <summary>
/// Represents a DmTxControllerJoinMap

View File

@@ -1,6 +1,7 @@
using System;
using PepperDash.Essentials.Core.JoinMaps;
using System;
namespace PepperDash.Essentials.Core.Bridges
namespace PepperDash.Essentials.Core.Bridges.JoinMaps
{
/// <summary>
/// Represents a DmpsAudioOutputControllerJoinMap

View File

@@ -1,6 +1,7 @@
using System;
using PepperDash.Essentials.Core.JoinMaps;
using System;
namespace PepperDash.Essentials.Core.Bridges
namespace PepperDash.Essentials.Core.Bridges.JoinMaps
{
/// <summary>
/// Represents a DmpsMicrophoneControllerJoinMap

View File

@@ -1,6 +1,7 @@
using System;
using PepperDash.Essentials.Core.JoinMaps;
using System;
namespace PepperDash.Essentials.Core.Bridges
namespace PepperDash.Essentials.Core.Bridges.JoinMaps
{
/// <summary>
/// Represents a DmpsRoutingControllerJoinMap

View File

@@ -1,4 +1,6 @@
namespace PepperDash.Essentials.Core.Bridges.JoinMaps
using PepperDash.Essentials.Core.JoinMaps;
namespace PepperDash.Essentials.Core.Bridges.JoinMaps
{
public sealed class GenericIrControllerJoinMap : JoinMapBaseAdvanced
{

View File

@@ -1,7 +1,8 @@
using System;
using PepperDash.Essentials.Core.JoinMaps;
using System;
namespace PepperDash.Essentials.Core.Bridges
namespace PepperDash.Essentials.Core.Bridges.JoinMaps
{
/// <summary>
/// Represents a GenericLightingJoinMap

View File

@@ -1,6 +1,7 @@
using System;
using PepperDash.Essentials.Core.JoinMaps;
using System;
namespace PepperDash.Essentials.Core.Bridges
namespace PepperDash.Essentials.Core.Bridges.JoinMaps
{
/// <summary>
/// Represents a GenericRelayControllerJoinMap

View File

@@ -1,6 +1,7 @@
using System;
using PepperDash.Essentials.Core.JoinMaps;
using System;
namespace PepperDash.Essentials.Core.Bridges
namespace PepperDash.Essentials.Core.Bridges.JoinMaps
{
/// <summary>
/// Represents a GlsOccupancySensorBaseJoinMap

View File

@@ -1,4 +1,5 @@
using System;
using PepperDash.Essentials.Core.JoinMaps;
using System;
namespace PepperDash.Essentials.Core.Bridges.JoinMaps
{

View File

@@ -1,6 +1,7 @@
using System;
using PepperDash.Essentials.Core.JoinMaps;
using System;
namespace PepperDash.Essentials.Core.Bridges
namespace PepperDash.Essentials.Core.Bridges.JoinMaps
{
/// <summary>
/// Represents a HdMdNxM4kEControllerJoinMap

View File

@@ -1,6 +1,7 @@
using System;
using PepperDash.Essentials.Core.JoinMaps;
using System;
namespace PepperDash.Essentials.Core.Bridges
namespace PepperDash.Essentials.Core.Bridges.JoinMaps
{
/// <summary>
/// Represents a HdMdxxxCEControllerJoinMap

View File

@@ -1,6 +1,7 @@
using System;
using PepperDash.Essentials.Core.JoinMaps;
using System;
namespace PepperDash.Essentials.Core.Bridges
namespace PepperDash.Essentials.Core.Bridges.JoinMaps
{
/// <summary>
/// Represents a HdPsXxxControllerJoinMap

View File

@@ -1,6 +1,7 @@
using System;
using PepperDash.Essentials.Core.JoinMaps;
using System;
namespace PepperDash.Essentials.Core.Bridges
namespace PepperDash.Essentials.Core.Bridges.JoinMaps
{
/// <summary>
/// Represents a Hrxxx0WirelessRemoteControllerJoinMap

View File

@@ -1,6 +1,7 @@
using System;
using PepperDash.Essentials.Core.JoinMaps;
using System;
namespace PepperDash.Essentials.Core.Bridges
namespace PepperDash.Essentials.Core.Bridges.JoinMaps
{
/// <summary>
/// Represents a IAnalogInputJoinMap

View File

@@ -1,6 +1,7 @@
using System;
using PepperDash.Essentials.Core.JoinMaps;
using System;
namespace PepperDash.Essentials.Core.Bridges
namespace PepperDash.Essentials.Core.Bridges.JoinMaps
{
/// <summary>
/// Represents a IBasicCommunicationJoinMap

View File

@@ -1,6 +1,7 @@
using System;
using PepperDash.Essentials.Core.JoinMaps;
using System;
namespace PepperDash.Essentials.Core.Bridges
namespace PepperDash.Essentials.Core.Bridges.JoinMaps
{
/// <summary>
/// Represents a IDigitalInputJoinMap

View File

@@ -1,6 +1,7 @@
using System;
using PepperDash.Essentials.Core.JoinMaps;
using System;
namespace PepperDash.Essentials.Core.Bridges
namespace PepperDash.Essentials.Core.Bridges.JoinMaps
{
/// <summary>
/// Represents a IDigitalOutputJoinMap

View File

@@ -1,6 +1,7 @@
using System;
using PepperDash.Essentials.Core.JoinMaps;
using System;
namespace PepperDash.Essentials.Core.Bridges
namespace PepperDash.Essentials.Core.Bridges.JoinMaps
{
/// <summary>
/// Join map for IRBlurayBase devices

View File

@@ -1,6 +1,7 @@
using System;
using PepperDash.Essentials.Core.JoinMaps;
using System;
namespace PepperDash.Essentials.Core.Bridges
namespace PepperDash.Essentials.Core.Bridges.JoinMaps
{
/// <summary>
/// Represents a PduJoinMapBase

View File

@@ -1,7 +1,8 @@
using System;
using PepperDash.Essentials.Core.JoinMaps;
using System;
namespace PepperDash.Essentials.Core.Bridges
namespace PepperDash.Essentials.Core.Bridges.JoinMaps
{
/// <summary>
/// Represents a SetTopBoxControllerJoinMap

View File

@@ -1,6 +1,7 @@
using System;
using PepperDash.Essentials.Core.JoinMaps;
using System;
namespace PepperDash.Essentials.Core.Bridges
namespace PepperDash.Essentials.Core.Bridges.JoinMaps
{
/// <summary>
/// Represents a StatusSignControllerJoinMap

View File

@@ -1,6 +1,7 @@
using System;
using PepperDash.Essentials.Core.JoinMaps;
using System;
namespace PepperDash.Essentials.Core.Bridges
namespace PepperDash.Essentials.Core.Bridges.JoinMaps
{
/// <summary>
/// Represents a SystemMonitorJoinMap

View File

@@ -1,3 +1,4 @@
using PepperDash.Essentials.Core.JoinMaps;
using System;
namespace PepperDash.Essentials.Core.Bridges.JoinMaps
{

View File

@@ -0,0 +1,72 @@
using System;
using Crestron.SimplSharpPro;
namespace PepperDash.Essentials.Core.Bridges
{
/// <summary>
/// Helper class for various Sig events
/// </summary>
public class SigHelper
{
/// <summary>
/// Runs action when Sig is pressed
/// </summary>
/// <param name="sig"></param>
public static void Pressed(Sig sig, Action act) { if (sig.BoolValue) act(); }
/// <summary>
/// Runs action when Sig is released
/// </summary>
public static void Released(Sig sig, Action act) { if (!sig.BoolValue) act(); }
/// <summary>
/// SetBoolOutAction method
/// </summary>
public static void SetBoolOutAction(BoolOutputSig sig, Action<bool> a)
{
if (sig != null)
sig.UserObject = a;
}
/// <summary>
/// Safely clears action of non-null sig.
/// </summary>
public static void ClearBoolOutAction(BoolOutputSig sig)
{
if (sig != null)
sig.UserObject = null;
}
/// <summary>
/// Does a timed ramp, where the time is scaled proportional to the
/// remaining range to cover
/// </summary>
/// <param name="sig">Ushort sig to scale</param>
/// <param name="newLevel">Level to go to</param>
/// <param name="time">In ms (not hundredths like Crestron Sig ramp function)</param>
/// <summary>
/// RampTimeScaled method
/// </summary>
public static void RampTimeScaled(Sig sig, ushort newLevel, uint time)
{
var level = sig.UShortValue;
var diff = Math.Abs(level - newLevel);
var scaledTime = (uint)(diff * time / 65535);
Ramp(sig, newLevel, scaledTime);
}
/// <summary>
/// Ramps signal
/// </summary>
/// <param name="sig"></param>
/// <param name="level"></param>
/// <param name="time">In ms (not hundredths like Crestron Sig ramp function)</param>
/// <summary>
/// Ramp method
/// </summary>
public static void Ramp(Sig sig, ushort level, uint time)
{
sig.CreateRamp(level, time / 10);
}
}
}

View File

@@ -2,11 +2,9 @@
using System.Text;
using System.Text.RegularExpressions;
using Crestron.SimplSharpPro.DM;
using PepperDash.Core;
using Serilog.Events;
namespace PepperDash.Essentials.Core
namespace PepperDash.Essentials.Core.Communications
{
/// <summary>
/// Represents a CecPortController
@@ -135,7 +133,7 @@ namespace PepperDash.Essentials.Core
foreach (var t in split)
{
if (t.StartsWith(@"\") && t.Length == 4)
b.Append((char)(Convert.ToByte(t.Substring(2, 2), 16)));
b.Append((char)Convert.ToByte(t.Substring(2, 2), 16));
else
b.Append(t);
}

View File

@@ -2,12 +2,10 @@
using System.Text;
using System.Text.RegularExpressions;
using Crestron.SimplSharpPro;
using PepperDash.Core;
using Serilog.Events;
namespace PepperDash.Essentials.Core
namespace PepperDash.Essentials.Core.Communications
{
/// <summary>
/// Represents a ComPortController
@@ -187,11 +185,11 @@ namespace PepperDash.Essentials.Core
{
// split out hex chars and build string
var split = Regex.Split(s, @"(\\[Xx][0-9a-fA-F][0-9a-fA-F])");
StringBuilder b = new StringBuilder();
var b = new StringBuilder();
foreach (var t in split)
{
if (t.StartsWith(@"\") && t.Length == 4)
b.Append((char)(Convert.ToByte(t.Substring(2, 2), 16)));
b.Append((char)Convert.ToByte(t.Substring(2, 2), 16));
else
b.Append(t);
}

View File

@@ -6,7 +6,7 @@ using Crestron.SimplSharpPro;
using Newtonsoft.Json;
namespace PepperDash.Essentials.Core
namespace PepperDash.Essentials.Core.Communications
{
/// <summary>
/// This converter creates a proper ComPort.ComPortSpec struct from more-friendly JSON values. It uses

View File

@@ -0,0 +1,49 @@
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace PepperDash.Essentials.Core.Communications
{
/// <summary>
///
/// </summary>
public class ComTextHelper
{
/// <summary>
/// Gets escaped text for a byte array
/// </summary>
/// <param name="bytes"></param>
/// <returns></returns>
public static string GetEscapedText(byte[] bytes)
{
return string.Concat(bytes.Select(b => string.Format(@"[{0:X2}]", (int)b)).ToArray());
}
/// <summary>
/// Gets escaped text for a string
/// </summary>
/// <param name="text"></param>
/// <returns></returns>
/// <summary>
/// GetEscapedText method
/// </summary>
public static string GetEscapedText(string text)
{
var bytes = Encoding.GetEncoding(28591).GetBytes(text);
return string.Concat(bytes.Select(b => string.Format(@"[{0:X2}]", (int)b)).ToArray());
}
/// <summary>
/// Gets debug text for a string
/// </summary>
/// <param name="text"></param>
/// <returns></returns>
/// <summary>
/// GetDebugText method
/// </summary>
public static string GetDebugText(string text)
{
return Regex.Replace(text, @"[^\u0020-\u007E]", a => GetEscapedText(a.Value));
}
}
}

View File

@@ -4,11 +4,12 @@ using System;
using Crestron.SimplSharpPro;
using Crestron.SimplSharpPro.DM;
using Newtonsoft.Json;
using PepperDash.Core;
using PepperDash.Essentials.Core.Config;
using PepperDash.Essentials.Core.Devices;
using PepperDash.Essentials.Core.Routing;
using Serilog.Events;
namespace PepperDash.Essentials.Core
namespace PepperDash.Essentials.Core.Communications
{
/// <summary>
///
@@ -145,7 +146,7 @@ namespace PepperDash.Essentials.Core
if (dev == null)
return null;
if (String.IsNullOrEmpty(config.ControlPortName))
if (string.IsNullOrEmpty(config.ControlPortName))
{
Debug.LogMessage(LogEventLevel.Information, "GetCecPort: '{0}' - Configuration missing 'ControlPortName'", config.ControlPortDevKey);
return null;
@@ -194,8 +195,8 @@ namespace PepperDash.Essentials.Core
/// </summary>
public static IComPorts GetIComPortsDeviceFromManagedDevice(string ComPortDevKey)
{
if ((ComPortDevKey.Equals("controlSystem", System.StringComparison.OrdinalIgnoreCase)
|| ComPortDevKey.Equals("processor", System.StringComparison.OrdinalIgnoreCase))
if ((ComPortDevKey.Equals("controlSystem", StringComparison.OrdinalIgnoreCase)
|| ComPortDevKey.Equals("processor", StringComparison.OrdinalIgnoreCase))
&& Global.ControlSystem is IComPorts)
return Global.ControlSystem;
else

View File

@@ -0,0 +1,91 @@
using System;
namespace PepperDash.Essentials.Core.Communications
{
/// <summary>
///
/// </summary>
public enum eGenericCommMethodStatusChangeType
{
/// <summary>
/// Connected
/// </summary>
Connected,
/// <summary>
/// Disconnected
/// </summary>
Disconnected
}
/// <summary>
/// This delegate defines handler for IBasicCommunication status changes
/// </summary>
/// <param name="comm">Device firing the status change</param>
/// <param name="status"></param>
public delegate void GenericCommMethodStatusHandler(IBasicCommunication comm, eGenericCommMethodStatusChangeType status);
/// <summary>
///
/// </summary>
public class GenericCommMethodReceiveBytesArgs : EventArgs
{
/// <summary>
/// Gets or sets the Bytes
/// </summary>
public byte[] Bytes { get; private set; }
/// <summary>
///
/// </summary>
/// <param name="bytes"></param>
public GenericCommMethodReceiveBytesArgs(byte[] bytes)
{
Bytes = bytes;
}
/// <summary>
/// S+ Constructor
/// </summary>
public GenericCommMethodReceiveBytesArgs() { }
}
/// <summary>
///
/// </summary>
public class GenericCommMethodReceiveTextArgs : EventArgs
{
/// <summary>
///
/// </summary>
public string Text { get; private set; }
/// <summary>
///
/// </summary>
public string Delimiter { get; private set; }
/// <summary>
///
/// </summary>
/// <param name="text"></param>
public GenericCommMethodReceiveTextArgs(string text)
{
Text = text;
}
/// <summary>
///
/// </summary>
/// <param name="text"></param>
/// <param name="delimiter"></param>
public GenericCommMethodReceiveTextArgs(string text, string delimiter)
:this(text)
{
Delimiter = delimiter;
}
/// <summary>
/// S+ Constructor
/// </summary>
public GenericCommMethodReceiveTextArgs() { }
}
}

View File

@@ -0,0 +1,173 @@
using System;
using System.Text;
using System.Text.RegularExpressions;
namespace PepperDash.Essentials.Core.Communications
{
/// <summary>
/// Defines the string event handler for line events on the gather
/// </summary>
/// <param name="text"></param>
public delegate void LineReceivedHandler(string text);
/// <summary>
/// Attaches to IBasicCommunication as a text gather
/// </summary>
public class CommunicationGather
{
/// <summary>
/// Event that fires when a line is received from the IBasicCommunication source.
/// The event merely contains the text, not an EventArgs type class.
/// </summary>
public event EventHandler<GenericCommMethodReceiveTextArgs> LineReceived;
/// <summary>
/// The communication port that this gathers on
/// </summary>
public ICommunicationReceiver Port { get; private set; }
/// <summary>
/// Default false. If true, the delimiter will be included in the line output
/// events
/// </summary>
public bool IncludeDelimiter { get; set; }
/// <summary>
/// For receive buffer
/// </summary>
StringBuilder ReceiveBuffer = new StringBuilder();
/// <summary>
/// Delimiter, like it says!
/// </summary>
char Delimiter;
string[] StringDelimiters;
/// <summary>
/// Constructor for using a char delimiter
/// </summary>
/// <param name="port"></param>
/// <param name="delimiter"></param>
public CommunicationGather(ICommunicationReceiver port, char delimiter)
{
Port = port;
Delimiter = delimiter;
port.TextReceived += new EventHandler<GenericCommMethodReceiveTextArgs>(Port_TextReceived);
}
/// <summary>
/// Constructor for using a single string delimiter
/// </summary>
/// <param name="port"></param>
/// <param name="delimiter"></param>
public CommunicationGather(ICommunicationReceiver port, string delimiter)
:this(port, new string[] { delimiter} )
{
}
/// <summary>
/// Constructor for using an array of string delimiters
/// </summary>
/// <param name="port"></param>
/// <param name="delimiters"></param>
public CommunicationGather(ICommunicationReceiver port, string[] delimiters)
{
Port = port;
StringDelimiters = delimiters;
port.TextReceived += Port_TextReceivedStringDelimiter;
}
/// <summary>
/// Stop method
/// </summary>
public void Stop()
{
Port.TextReceived -= Port_TextReceived;
Port.TextReceived -= Port_TextReceivedStringDelimiter;
}
/// <summary>
/// Handler for raw data coming from port
/// </summary>
void Port_TextReceived(object sender, GenericCommMethodReceiveTextArgs args)
{
var handler = LineReceived;
if (handler != null)
{
ReceiveBuffer.Append(args.Text);
var str = ReceiveBuffer.ToString();
var lines = str.Split(Delimiter);
if (lines.Length > 0)
{
for (int i = 0; i < lines.Length - 1; i++)
{
string strToSend = null;
if (IncludeDelimiter)
strToSend = lines[i] + Delimiter;
else
strToSend = lines[i];
handler(this, new GenericCommMethodReceiveTextArgs(strToSend));
}
ReceiveBuffer = new StringBuilder(lines[lines.Length - 1]);
}
}
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="args"></param>
void Port_TextReceivedStringDelimiter(object sender, GenericCommMethodReceiveTextArgs args)
{
var handler = LineReceived;
if (handler != null)
{
// Receive buffer should either be empty or not contain the delimiter
// If the line does not have a delimiter, append the
ReceiveBuffer.Append(args.Text);
var str = ReceiveBuffer.ToString();
// Case: Receiving DEVICE get version\x0d\0x0a+OK "value":"1234"\x0d\x0a
// RX: DEV
// Split: (1) "DEV"
// RX: I
// Split: (1) "DEVI"
// RX: CE get version
// Split: (1) "DEVICE get version"
// RX: \x0d\x0a+OK "value":"1234"\x0d\x0a
// Split: (2) DEVICE get version, +OK "value":"1234"
// Iterate the delimiters and fire an event for any matching delimiter
foreach (var delimiter in StringDelimiters)
{
var lines = Regex.Split(str, delimiter);
if (lines.Length == 1)
continue;
for (int i = 0; i < lines.Length - 1; i++)
{
string strToSend = null;
if (IncludeDelimiter)
strToSend = lines[i] + delimiter;
else
strToSend = lines[i];
handler(this, new GenericCommMethodReceiveTextArgs(strToSend, delimiter));
}
ReceiveBuffer = new StringBuilder(lines[lines.Length - 1]);
}
}
}
/// <summary>
/// Deconstructor. Disconnects from port TextReceived events.
/// </summary>
~CommunicationGather()
{
Stop();
}
}
}

View File

@@ -0,0 +1,182 @@
using System;
using Crestron.SimplSharp;
namespace PepperDash.Essentials.Core.Communications
{
/// <summary>
/// Controls the ability to disable/enable debugging of TX/RX data sent to/from a device with a built in timer to disable
/// </summary>
public class CommunicationStreamDebugging
{
/// <summary>
/// Device Key that this instance configures
/// </summary>
public string ParentDeviceKey { get; private set; }
/// <summary>
/// Timer to disable automatically if not manually disabled
/// </summary>
private CTimer DebugExpiryPeriod;
/// <summary>
/// Gets or sets the DebugSetting
/// </summary>
public eStreamDebuggingSetting DebugSetting { get; private set; }
private uint _DebugTimeoutInMs;
private const uint _DefaultDebugTimeoutMin = 30;
/// <summary>
/// Timeout in Minutes
/// </summary>
public uint DebugTimeoutMinutes
{
get
{
return _DebugTimeoutInMs/60000;
}
}
/// <summary>
/// Gets or sets the RxStreamDebuggingIsEnabled
/// </summary>
public bool RxStreamDebuggingIsEnabled{ get; private set; }
/// <summary>
/// Indicates that transmit stream debugging is enabled
/// </summary>
public bool TxStreamDebuggingIsEnabled { get; private set; }
/// <summary>
/// Constructor
/// </summary>
/// <param name="parentDeviceKey"></param>
public CommunicationStreamDebugging(string parentDeviceKey)
{
ParentDeviceKey = parentDeviceKey;
}
/// <summary>
/// Sets the debugging setting and if not setting to off, assumes the default of 30 mintues
/// </summary>
/// <param name="setting"></param>
/// <summary>
/// SetDebuggingWithDefaultTimeout method
/// </summary>
public void SetDebuggingWithDefaultTimeout(eStreamDebuggingSetting setting)
{
if (setting == eStreamDebuggingSetting.Off)
{
DisableDebugging();
return;
}
SetDebuggingWithSpecificTimeout(setting, _DefaultDebugTimeoutMin);
}
/// <summary>
/// Sets the debugging setting for the specified number of minutes
/// </summary>
/// <param name="setting"></param>
/// <param name="minutes"></param>
/// <summary>
/// SetDebuggingWithSpecificTimeout method
/// </summary>
public void SetDebuggingWithSpecificTimeout(eStreamDebuggingSetting setting, uint minutes)
{
if (setting == eStreamDebuggingSetting.Off)
{
DisableDebugging();
return;
}
_DebugTimeoutInMs = minutes * 60000;
StopDebugTimer();
DebugExpiryPeriod = new CTimer((o) => DisableDebugging(), _DebugTimeoutInMs);
if ((setting & eStreamDebuggingSetting.Rx) == eStreamDebuggingSetting.Rx)
RxStreamDebuggingIsEnabled = true;
if ((setting & eStreamDebuggingSetting.Tx) == eStreamDebuggingSetting.Tx)
TxStreamDebuggingIsEnabled = true;
Debug.SetDeviceDebugSettings(ParentDeviceKey, setting);
}
/// <summary>
/// Disabled debugging
/// </summary>
private void DisableDebugging()
{
StopDebugTimer();
Debug.SetDeviceDebugSettings(ParentDeviceKey, eStreamDebuggingSetting.Off);
}
private void StopDebugTimer()
{
RxStreamDebuggingIsEnabled = false;
TxStreamDebuggingIsEnabled = false;
if (DebugExpiryPeriod == null)
{
return;
}
DebugExpiryPeriod.Stop();
DebugExpiryPeriod.Dispose();
DebugExpiryPeriod = null;
}
}
/// <summary>
/// The available settings for stream debugging
/// </summary>
[Flags]
/// <summary>
/// Enumeration of eStreamDebuggingSetting values
/// </summary>
public enum eStreamDebuggingSetting
{
/// <summary>
/// Debug off
/// </summary>
Off = 0,
/// <summary>
/// Debug received data
/// </summary>
Rx = 1,
/// <summary>
/// Debug transmitted data
/// </summary>
Tx = 2,
/// <summary>
/// Debug both received and transmitted data
/// </summary>
Both = Rx | Tx
}
/// <summary>
/// The available settings for stream debugging response types
/// </summary>
[Flags]
public enum eStreamDebuggingDataTypeSettings
{
/// <summary>
/// Debug data in byte format
/// </summary>
Bytes = 0,
/// <summary>
/// Debug data in text format
/// </summary>
Text = 1,
/// <summary>
/// Debug data in both byte and text formats
/// </summary>
Both = Bytes | Text,
}
}

View File

@@ -1,12 +1,12 @@
using System.Collections.Generic;
using Crestron.SimplSharp;
using PepperDash.Core;
using PepperDash.Essentials.Core.Config;
using PepperDash.Essentials.Core.Devices;
using PepperDash.Essentials.Core.Monitoring;
using Serilog.Events;
namespace PepperDash.Essentials.Core
namespace PepperDash.Essentials.Core.Communications
{
/// <summary>
/// Represents a ConsoleCommMockDevice

View File

@@ -0,0 +1,92 @@
using System;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
namespace PepperDash.Essentials.Core.Communications
{
/// <summary>
/// Represents a ControlPropertiesConfig
/// </summary>
public class ControlPropertiesConfig
{
/// <summary>
/// The method of control
/// </summary>
[JsonProperty("method")]
[JsonConverter(typeof(StringEnumConverter))]
public eControlMethod Method { get; set; }
/// <summary>
/// The key of the device that contains the control port
/// </summary>
[JsonProperty("controlPortDevKey", NullValueHandling = NullValueHandling.Ignore)]
public string ControlPortDevKey { get; set; }
/// <summary>
/// The number of the control port on the device specified by ControlPortDevKey
/// </summary>
[JsonProperty("controlPortNumber", NullValueHandling = NullValueHandling.Ignore)] // In case "null" is present in config on this value
public uint? ControlPortNumber { get; set; }
/// <summary>
/// The name of the control port on the device specified by ControlPortDevKey
/// </summary>
[JsonProperty("controlPortName", NullValueHandling = NullValueHandling.Ignore)] // In case "null" is present in config on this value
public string ControlPortName { get; set; }
/// <summary>
/// Properties for ethernet based communications
/// </summary>
[JsonProperty("tcpSshProperties", NullValueHandling = NullValueHandling.Ignore)]
public TcpSshPropertiesConfig TcpSshProperties { get; set; }
/// <summary>
/// The filename and path for the IR file
/// </summary>
[JsonProperty("irFile", NullValueHandling = NullValueHandling.Ignore)]
public string IrFile { get; set; }
/// <summary>
/// The IpId of a Crestron device
/// </summary>
[JsonProperty("ipId", NullValueHandling = NullValueHandling.Ignore)]
public string IpId { get; set; }
/// <summary>
/// Readonly uint representation of the IpId
/// </summary>
[JsonIgnore]
public uint IpIdInt { get { return Convert.ToUInt32(IpId, 16); } }
/// <summary>
/// Char indicating end of line
/// </summary>
[JsonProperty("endOfLineChar", NullValueHandling = NullValueHandling.Ignore)]
public char EndOfLineChar { get; set; }
/// <summary>
/// Defaults to Environment.NewLine;
/// </summary>
[JsonProperty("endOfLineString", NullValueHandling = NullValueHandling.Ignore)]
public string EndOfLineString { get; set; }
/// <summary>
/// Indicates
/// </summary>
[JsonProperty("deviceReadyResponsePattern", NullValueHandling = NullValueHandling.Ignore)]
public string DeviceReadyResponsePattern { get; set; }
/// <summary>
/// Used when communcating to programs running in VC-4
/// </summary>
[JsonProperty("roomId", NullValueHandling = NullValueHandling.Ignore)]
public string RoomId { get; set; }
/// <summary>
/// Constructor
/// </summary>
public ControlPropertiesConfig()
{
}
}
}

View File

@@ -0,0 +1,247 @@
/*PepperDash Technology Corp.
Copyright: 2017
------------------------------------
***Notice of Ownership and Copyright***
The material in which this notice appears is the property of PepperDash Technology Corporation,
which claims copyright under the laws of the United States of America in the entire body of material
and in all parts thereof, regardless of the use to which it is being put. Any use, in whole or in part,
of this material by another party without the express written permission of PepperDash Technology Corporation is prohibited.
PepperDash Technology Corporation reserves all rights under applicable laws.
------------------------------------ */
using System;
using Crestron.SimplSharp.CrestronSockets;
namespace PepperDash.Essentials.Core.Communications
{
/// <summary>
/// Delegate for notifying of socket status changes
/// </summary>
/// <param name="client"></param>
public delegate void GenericSocketStatusChangeEventDelegate(ISocketStatus client);
/// <summary>
/// EventArgs class for socket status changes
/// </summary>
public class GenericSocketStatusChageEventArgs : EventArgs
{
/// <summary>
/// Gets or sets the Client
/// </summary>
public ISocketStatus Client { get; private set; }
/// <summary>
///
/// </summary>
/// <param name="client"></param>
public GenericSocketStatusChageEventArgs(ISocketStatus client)
{
Client = client;
}
/// <summary>
/// S+ Constructor
/// </summary>
public GenericSocketStatusChageEventArgs() { }
}
/// <summary>
/// Delegate for notifying of TCP Server state changes
/// </summary>
/// <param name="state"></param>
public delegate void GenericTcpServerStateChangedEventDelegate(ServerState state);
/// <summary>
/// EventArgs class for TCP Server state changes
/// </summary>
public class GenericTcpServerStateChangedEventArgs : EventArgs
{
/// <summary>
/// Gets or sets the State
/// </summary>
public ServerState State { get; private set; }
/// <summary>
///
/// </summary>
/// <param name="state"></param>
public GenericTcpServerStateChangedEventArgs(ServerState state)
{
State = state;
}
/// <summary>
/// S+ Constructor
/// </summary>
public GenericTcpServerStateChangedEventArgs() { }
}
/// <summary>
/// Delegate for TCP Server socket status changes
/// </summary>
/// <param name="socket"></param>
/// <param name="clientIndex"></param>
/// <param name="clientStatus"></param>
public delegate void GenericTcpServerSocketStatusChangeEventDelegate(object socket, uint clientIndex, SocketStatus clientStatus);
/// <summary>
/// EventArgs for TCP server socket status changes
/// </summary>
public class GenericTcpServerSocketStatusChangeEventArgs : EventArgs
{
/// <summary>
///
/// </summary>
public object Socket { get; private set; }
/// <summary>
///
/// </summary>
public uint ReceivedFromClientIndex { get; private set; }
/// <summary>
///
/// </summary>
public SocketStatus ClientStatus { get; set; }
/// <summary>
///
/// </summary>
/// <param name="socket"></param>
/// <param name="clientStatus"></param>
public GenericTcpServerSocketStatusChangeEventArgs(object socket, SocketStatus clientStatus)
{
Socket = socket;
ClientStatus = clientStatus;
}
/// <summary>
///
/// </summary>
/// <param name="socket"></param>
/// <param name="clientIndex"></param>
/// <param name="clientStatus"></param>
public GenericTcpServerSocketStatusChangeEventArgs(object socket, uint clientIndex, SocketStatus clientStatus)
{
Socket = socket;
ReceivedFromClientIndex = clientIndex;
ClientStatus = clientStatus;
}
/// <summary>
/// S+ Constructor
/// </summary>
public GenericTcpServerSocketStatusChangeEventArgs() { }
}
/// <summary>
/// EventArgs for TCP server com method receive text
/// </summary>
public class GenericTcpServerCommMethodReceiveTextArgs : EventArgs
{
/// <summary>
///
/// </summary>
public uint ReceivedFromClientIndex { get; private set; }
/// <summary>
///
/// </summary>
public ushort ReceivedFromClientIndexShort
{
get
{
return (ushort)ReceivedFromClientIndex;
}
}
/// <summary>
/// Gets or sets the Text
/// </summary>
public string Text { get; private set; }
/// <summary>
///
/// </summary>
/// <param name="text"></param>
public GenericTcpServerCommMethodReceiveTextArgs(string text)
{
Text = text;
}
/// <summary>
///
/// </summary>
/// <param name="text"></param>
/// <param name="clientIndex"></param>
public GenericTcpServerCommMethodReceiveTextArgs(string text, uint clientIndex)
{
Text = text;
ReceivedFromClientIndex = clientIndex;
}
/// <summary>
/// S+ Constructor
/// </summary>
public GenericTcpServerCommMethodReceiveTextArgs() { }
}
/// <summary>
/// EventArgs for TCP server client ready for communication
/// </summary>
public class GenericTcpServerClientReadyForcommunicationsEventArgs : EventArgs
{
/// <summary>
///
/// </summary>
public bool IsReady;
/// <summary>
///
/// </summary>
/// <param name="isReady"></param>
public GenericTcpServerClientReadyForcommunicationsEventArgs(bool isReady)
{
IsReady = isReady;
}
/// <summary>
/// S+ Constructor
/// </summary>
public GenericTcpServerClientReadyForcommunicationsEventArgs() { }
}
/// <summary>
/// EventArgs for UDP connected
/// </summary>
public class GenericUdpConnectedEventArgs : EventArgs
{
/// <summary>
///
/// </summary>
public ushort UConnected;
/// <summary>
///
/// </summary>
public bool Connected;
/// <summary>
/// Constructor
/// </summary>
public GenericUdpConnectedEventArgs() { }
/// <summary>
///
/// </summary>
/// <param name="uconnected"></param>
public GenericUdpConnectedEventArgs(ushort uconnected)
{
UConnected = uconnected;
}
/// <summary>
///
/// </summary>
/// <param name="connected"></param>
public GenericUdpConnectedEventArgs(bool connected)
{
Connected = connected;
}
}
}

View File

@@ -1,19 +1,19 @@

using System;
using System;
using System.Collections.Generic;
using Crestron.SimplSharp.CrestronSockets;
using Crestron.SimplSharpPro.DeviceSupport;
using Newtonsoft.Json;
using PepperDash.Core;
using PepperDash.Essentials.Core.Bridges;
using PepperDash.Essentials.Core.Devices;
using PepperDash.Essentials.Core.Config;
using Serilog.Events;
using PepperDash.Essentials.Core.Bridges.JoinMaps;
using PepperDash.Essentials.Core.JoinMaps;
using PepperDash.Essentials.Core.Config.Essentials;
using PepperDash.Essentials.Core.Touchpanels;
namespace PepperDash.Essentials.Core
namespace PepperDash.Essentials.Core.Communications
{
/// <summary>
/// Serves as a generic wrapper class for all styles of IBasicCommuncation ports
@@ -120,7 +120,7 @@ namespace PepperDash.Essentials.Core
if (sComm == null) return;
sComm.ConnectionChange += (s, a) =>
{
trilist.SetUshort(joinMap.Status.JoinNumber, (ushort)(a.Client.ClientStatus));
trilist.SetUshort(joinMap.Status.JoinNumber, (ushort)a.Client.ClientStatus);
trilist.SetBool(joinMap.Connected.JoinNumber, a.Client.ClientStatus ==
SocketStatus.SOCKET_STATUS_CONNECTED);
};

View File

@@ -1,8 +1,7 @@
using Crestron.SimplSharp.Net.Http;
using PepperDash.Core;
using System;
namespace PepperDash.Essentials.Core
namespace PepperDash.Essentials.Core.Communications
{
[Obsolete("Please use the builtin HttpClient class instead: https://learn.microsoft.com/en-us/dotnet/fundamentals/networking/http/httpclient-guidelines")]
/// <summary>
@@ -33,17 +32,17 @@ namespace PepperDash.Essentials.Core
/// </summary>
public void SendText(string path)
{
HttpClientRequest request = new HttpClientRequest();
string url = string.Format("http://{0}/{1}", Client.HostName, path);
var request = new HttpClientRequest();
var url = string.Format("http://{0}/{1}", Client.HostName, path);
request.Url = new UrlParser(url);
HttpClient.DISPATCHASYNC_ERROR error = Client.DispatchAsyncEx(request, Response, request);
var error = Client.DispatchAsyncEx(request, Response, request);
}
public void SendText(string format, params object[] items)
{
HttpClientRequest request = new HttpClientRequest();
string url = string.Format("http://{0}/{1}", Client.HostName, string.Format(format, items));
var request = new HttpClientRequest();
var url = string.Format("http://{0}/{1}", Client.HostName, string.Format(format, items));
request.Url = new UrlParser(url);
HttpClient.DISPATCHASYNC_ERROR error = Client.DispatchAsyncEx(request, Response, request);
var error = Client.DispatchAsyncEx(request, Response, request);
}
/// <summary>
@@ -51,8 +50,8 @@ namespace PepperDash.Essentials.Core
/// </summary>
public void SendTextNoResponse(string format, params object[] items)
{
HttpClientRequest request = new HttpClientRequest();
string url = string.Format("http://{0}/{1}", Client.HostName, string.Format(format, items));
var request = new HttpClientRequest();
var url = string.Format("http://{0}/{1}", Client.HostName, string.Format(format, items));
request.Url = new UrlParser(url);
Client.Dispatch(request);
}

View File

@@ -0,0 +1,21 @@
using Newtonsoft.Json;
namespace PepperDash.Essentials.Core.Communications
{
/// <summary>
/// Describes a device that can automatically attempt to reconnect
/// </summary>
public interface IAutoReconnect
{
/// <summary>
/// Enable automatic recconnect
/// </summary>
[JsonProperty("autoReconnect")]
bool AutoReconnect { get; set; }
/// <summary>
/// Interval in ms to attempt automatic recconnections
/// </summary>
[JsonProperty("autoReconnectIntervalMs")]
int AutoReconnectIntervalMs { get; set; }
}
}

View File

@@ -0,0 +1,20 @@
namespace PepperDash.Essentials.Core.Communications
{
/// <summary>
/// Defines the contract for IBasicCommunication
/// </summary>
public interface IBasicCommunication : ICommunicationReceiver
{
/// <summary>
/// Send text to the device
/// </summary>
/// <param name="text"></param>
void SendText(string text);
/// <summary>
/// Send bytes to the device
/// </summary>
/// <param name="bytes"></param>
void SendBytes(byte[] bytes);
}
}

View File

@@ -0,0 +1,10 @@
namespace PepperDash.Essentials.Core.Communications
{
/// <summary>
/// Represents a device that implements IBasicCommunication and IStreamDebugging
/// </summary>
public interface IBasicCommunicationWithStreamDebugging : IBasicCommunication, IStreamDebugging
{
}
}

View File

@@ -1,7 +1,7 @@
using Crestron.SimplSharpPro;
namespace PepperDash.Essentials.Core
namespace PepperDash.Essentials.Core.Communications
{
/// <summary>
///

View File

@@ -0,0 +1,34 @@
using System;
using Newtonsoft.Json;
namespace PepperDash.Essentials.Core.Communications
{
/// <summary>
/// An incoming communication stream
/// </summary>
public interface ICommunicationReceiver : IKeyed
{
/// <summary>
/// Notifies of bytes received
/// </summary>
event EventHandler<GenericCommMethodReceiveBytesArgs> BytesReceived;
/// <summary>
/// Notifies of text received
/// </summary>
event EventHandler<GenericCommMethodReceiveTextArgs> TextReceived;
/// <summary>
/// Indicates connection status
/// </summary>
[JsonProperty("isConnected")]
bool IsConnected { get; }
/// <summary>
/// Connect to the device
/// </summary>
void Connect();
/// <summary>
/// Disconnect from the device
/// </summary>
void Disconnect();
}
}

View File

@@ -5,11 +5,11 @@ using Crestron.SimplSharpPro;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using PepperDash.Core;
using PepperDash.Essentials.Core.Config;
using PepperDash.Essentials.Core.Devices;
using Serilog.Events;
namespace PepperDash.Essentials.Core
namespace PepperDash.Essentials.Core.Communications
{
/// <summary>
///

View File

@@ -0,0 +1,25 @@
using System;
using Crestron.SimplSharp.CrestronSockets;
using Newtonsoft.Json;
namespace PepperDash.Essentials.Core.Communications
{
/// <summary>
/// For IBasicCommunication classes that have SocketStatus. GenericSshClient,
/// GenericTcpIpClient
/// </summary>
public interface ISocketStatus : IBasicCommunication
{
/// <summary>
/// Notifies of socket status changes
/// </summary>
event EventHandler<GenericSocketStatusChageEventArgs> ConnectionChange;
/// <summary>
/// The current socket status of the client
/// </summary>
[JsonProperty("clientStatus")]
[JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))]
SocketStatus ClientStatus { get; }
}
}

View File

@@ -0,0 +1,10 @@
namespace PepperDash.Essentials.Core.Communications
{
/// <summary>
/// Describes a device that implements ISocketStatus and IStreamDebugging
/// </summary>
public interface ISocketStatusWithStreamDebugging : ISocketStatus, IStreamDebugging
{
}
}

View File

@@ -0,0 +1,16 @@
using Newtonsoft.Json;
namespace PepperDash.Essentials.Core.Communications
{
/// <summary>
/// Represents a device with stream debugging capablities
/// </summary>
public interface IStreamDebugging
{
/// <summary>
/// Object to enable stream debugging
/// </summary>
[JsonProperty("streamDebugging")]
CommunicationStreamDebugging StreamDebugging { get; }
}
}

View File

@@ -0,0 +1,59 @@
using Newtonsoft.Json;
namespace PepperDash.Essentials.Core.Communications
{
/// <summary>
/// Represents a TcpClientConfigObject
/// </summary>
public class TcpClientConfigObject
{
/// <summary>
/// TcpSsh Properties
/// </summary>
[JsonProperty("control")]
public ControlPropertiesConfig Control { get; set; }
/// <summary>
/// Bool value for secure. Currently not implemented in TCP sockets as they are not dynamic
/// </summary>
[JsonProperty("secure")]
public bool Secure { get; set; }
/// <summary>
/// Require a shared key that both server and client negotiate. If negotiation fails server disconnects the client
/// </summary>
[JsonProperty("sharedKeyRequired")]
public bool SharedKeyRequired { get; set; }
/// <summary>
/// The shared key that must match on the server and client
/// </summary>
[JsonProperty("sharedKey")]
public string SharedKey { get; set; }
/// <summary>
/// Require a heartbeat on the client/server connection that will cause the server/client to disconnect if the heartbeat is not received.
/// heartbeats do not raise received events.
/// </summary>
[JsonProperty("heartbeatRequired")]
public bool HeartbeatRequired { get; set; }
/// <summary>
/// The interval in seconds for the heartbeat from the client. If not received client is disconnected
/// </summary>
[JsonProperty("heartbeatRequiredIntervalInSeconds")]
public ushort HeartbeatRequiredIntervalInSeconds { get; set; }
/// <summary>
/// HeartbeatString that will be checked against the message received. defaults to heartbeat if no string is provided.
/// </summary>
[JsonProperty("heartbeatStringToMatch")]
public string HeartbeatStringToMatch { get; set; }
/// <summary>
/// Receive Queue size must be greater than 20 or defaults to 20
/// </summary>
[JsonProperty("receiveQueueSize")]
public int ReceiveQueueSize { get; set; }
}
}

View File

@@ -0,0 +1,54 @@
namespace PepperDash.Essentials.Core.Communications
{
/// <summary>
/// Tcp Server Config object with properties for a tcp server with shared key and heartbeat capabilities
/// </summary>
public class TcpServerConfigObject
{
/// <summary>
/// Uique key
/// </summary>
public string Key { get; set; }
/// <summary>
/// Max Clients that the server will allow to connect.
/// </summary>
public ushort MaxClients { get; set; }
/// <summary>
/// Bool value for secure. Currently not implemented in TCP sockets as they are not dynamic
/// </summary>
public bool Secure { get; set; }
/// <summary>
/// Port for the server to listen on
/// </summary>
public int Port { get; set; }
/// <summary>
/// Require a shared key that both server and client negotiate. If negotiation fails server disconnects the client
/// </summary>
public bool SharedKeyRequired { get; set; }
/// <summary>
/// The shared key that must match on the server and client
/// </summary>
public string SharedKey { get; set; }
/// <summary>
/// Require a heartbeat on the client/server connection that will cause the server/client to disconnect if the heartbeat is not received.
/// heartbeats do not raise received events.
/// </summary>
public bool HeartbeatRequired { get; set; }
/// <summary>
/// The interval in seconds for the heartbeat from the client. If not received client is disconnected
/// </summary>
public ushort HeartbeatRequiredIntervalInSeconds { get; set; }
/// <summary>
/// HeartbeatString that will be checked against the message received. defaults to heartbeat if no string is provided.
/// </summary>
public string HeartbeatStringToMatch { get; set; }
/// <summary>
/// Client buffer size. See Crestron help. defaults to 2000 if not greater than 2000
/// </summary>
public int BufferSize { get; set; }
/// <summary>
/// Receive Queue size must be greater than 20 or defaults to 20
/// </summary>
public int ReceiveQueueSize { get; set; }
}
}

View File

@@ -0,0 +1,59 @@
using Newtonsoft.Json;
namespace PepperDash.Essentials.Core.Communications
{
/// <summary>
/// Represents a TcpSshPropertiesConfig
/// </summary>
public class TcpSshPropertiesConfig
{
/// <summary>
/// Address to connect to
/// </summary>
[JsonProperty(Required = Required.Always)]
public string Address { get; set; }
/// <summary>
/// Port to connect to
/// </summary>
[JsonProperty(Required = Required.Always)]
public int Port { get; set; }
/// <summary>
/// Username credential
/// </summary>
public string Username { get; set; }
/// <summary>
/// Gets or sets the Password
/// </summary>
public string Password { get; set; }
/// <summary>
/// Defaults to 32768
/// </summary>
public int BufferSize { get; set; }
/// <summary>
/// Gets or sets the AutoReconnect
/// </summary>
public bool AutoReconnect { get; set; }
/// <summary>
/// Gets or sets the AutoReconnectIntervalMs
/// </summary>
public int AutoReconnectIntervalMs { get; set; }
/// <summary>
/// Default constructor
/// </summary>
public TcpSshPropertiesConfig()
{
BufferSize = 32768;
AutoReconnect = true;
AutoReconnectIntervalMs = 5000;
Username = "";
Password = "";
}
}
}

View File

@@ -0,0 +1,73 @@
namespace PepperDash.Essentials.Core.Communications
{
/// <summary>
/// Crestron Control Methods for a comm object
/// </summary>
public enum eControlMethod
{
/// <summary>
///
/// </summary>
None = 0,
/// <summary>
/// RS232/422/485
/// </summary>
Com,
/// <summary>
/// Crestron IpId (most Crestron ethernet devices)
/// </summary>
IpId,
/// <summary>
/// Crestron IpIdTcp (HD-MD series, etc.)
/// </summary>
IpidTcp,
/// <summary>
/// Crestron IR control
/// </summary>
IR,
/// <summary>
/// SSH client
/// </summary>
Ssh,
/// <summary>
/// TCP/IP client
/// </summary>
Tcpip,
/// <summary>
/// Telnet
/// </summary>
Telnet,
/// <summary>
/// Crestnet device
/// </summary>
Cresnet,
/// <summary>
/// CEC Control, via a DM HDMI port
/// </summary>
Cec,
/// <summary>
/// UDP Server
/// </summary>
Udp,
/// <summary>
/// HTTP client
/// </summary>
Http,
/// <summary>
/// HTTPS client
/// </summary>
Https,
/// <summary>
/// Websocket client
/// </summary>
Ws,
/// <summary>
/// Secure Websocket client
/// </summary>
Wss,
/// <summary>
/// Secure TCP/IP
/// </summary>
SecureTcpIp
}
}

View File

@@ -1,4 +1,5 @@
using Newtonsoft.Json;
using PepperDash.Essentials.Core.Devices;
using System.Collections.Generic;
namespace PepperDash.Essentials.Core.Config

View File

@@ -5,6 +5,8 @@ using System.Linq;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using PepperDash.Essentials.Core.Devices;
using PepperDash.Essentials.Core.Routing;
namespace PepperDash.Essentials.Core.Config
{

View File

@@ -6,11 +6,9 @@ using System.Text;
using Crestron.SimplSharp;
using Crestron.SimplSharp.CrestronIO;
using Newtonsoft.Json.Linq;
using PepperDash.Core;
using PepperDash.Core.Config;
using Serilog.Events;
namespace PepperDash.Essentials.Core.Config
namespace PepperDash.Essentials.Core.Config.Essentials
{
/// <summary>
/// Loads the ConfigObject from the file
@@ -36,7 +34,7 @@ namespace PepperDash.Essentials.Core.Config
// Check for local config file first
var filePath = Global.FilePathPrefix + ConfigWriter.LocalConfigFolder + Global.DirectorySeparator + Global.ConfigFileName;
bool localConfigFound = false;
var localConfigFound = false;
Debug.LogMessage(LogEventLevel.Information, "Attempting to load Local config file: '{0}'", filePath);
@@ -112,7 +110,7 @@ namespace PepperDash.Essentials.Core.Config
}
// Read the file
using (StreamReader fs = new StreamReader(filePath))
using (var fs = new StreamReader(filePath))
{
Debug.LogMessage(LogEventLevel.Information, "Loading config file: '{0}'", filePath);
@@ -212,7 +210,7 @@ namespace PepperDash.Essentials.Core.Config
{
debugStringWidth = 51;
}
var qualifier = (filePathLength % 2 != 0)
var qualifier = filePathLength % 2 != 0
? " Using Local Config File "
: " Using Local Config File ";
var bookend1 = (debugStringWidth - qualifier.Length) / 2;

View File

@@ -5,11 +5,9 @@ using Crestron.SimplSharp;
using Crestron.SimplSharp.CrestronIO;
using Newtonsoft.Json.Linq;
using Crestron.SimplSharp.Net.Http;
using PepperDash.Core;
using Serilog.Events;
namespace PepperDash.Essentials.Core.Config
namespace PepperDash.Essentials.Core.Config.Essentials
{
public static class ConfigUpdater
{
@@ -141,7 +139,7 @@ namespace PepperDash.Essentials.Core.Config
{
Debug.LogMessage(LogEventLevel.Information, "{0} Existing files found in archive folder. Deleting.", archivedConfigFiles.Length);
for (int i = 0; i < archivedConfigFiles.Length; i++ )
for (var i = 0; i < archivedConfigFiles.Length; i++ )
{
var file = archivedConfigFiles[i];
Debug.LogMessage(LogEventLevel.Information, "Deleting archived file: '{0}'", file.FullName);
@@ -191,7 +189,7 @@ namespace PepperDash.Essentials.Core.Config
OnStatusUpdate(eUpdateStatus.RestartingProgram);
string response = string.Empty;
var response = string.Empty;
CrestronConsole.SendControlSystemCommand(string.Format("progreset -p:{0}", InitialParametersClass.ApplicationNumber), ref response);

View File

@@ -6,10 +6,9 @@ using Crestron.SimplSharp;
using Crestron.SimplSharp.CrestronIO;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using PepperDash.Core;
using Serilog.Events;
namespace PepperDash.Essentials.Core.Config
namespace PepperDash.Essentials.Core.Config.Essentials
{
/// <summary>
/// Responsible for updating config at runtime, and writing the updates out to a local file
@@ -34,7 +33,7 @@ namespace PepperDash.Essentials.Core.Config
/// </summary>
public static bool UpdateDeviceProperties(string deviceKey, JToken properties)
{
bool success = false;
var success = false;
// Get the current device config
var deviceConfig = ConfigReader.ConfigObject.Devices.FirstOrDefault(d => d.Key.Equals(deviceKey));
@@ -59,7 +58,7 @@ namespace PepperDash.Essentials.Core.Config
/// </summary>
public static bool UpdateDeviceConfig(DeviceConfig config)
{
bool success = false;
var success = false;
var deviceConfigIndex = ConfigReader.ConfigObject.Devices.FindIndex(d => d.Key.Equals(config.Key));
@@ -82,7 +81,7 @@ namespace PepperDash.Essentials.Core.Config
/// </summary>
public static bool UpdateRoomConfig(DeviceConfig config)
{
bool success = false;
var success = false;
var roomConfigIndex = ConfigReader.ConfigObject.Rooms.FindIndex(d => d.Key.Equals(config.Key));
@@ -147,7 +146,7 @@ namespace PepperDash.Essentials.Core.Config
{
if (fileLock.TryEnter())
{
using (StreamWriter sw = new StreamWriter(filePath))
using (var sw = new StreamWriter(filePath))
{
sw.Write(configData);
sw.Flush();

View File

@@ -2,7 +2,7 @@
using System.Text.RegularExpressions;
using Newtonsoft.Json;
namespace PepperDash.Essentials.Core.Config
namespace PepperDash.Essentials.Core.Config.Essentials
{
/// <summary>
/// Loads the ConfigObject from the file
@@ -27,12 +27,12 @@ namespace PepperDash.Essentials.Core.Config
if (SystemUrl.Contains("#"))
{
var result = Regex.Match(SystemUrl, @"https?:\/\/.*\/systems\/(.*)\/#.*");
string uuid = result.Groups[1].Value;
var uuid = result.Groups[1].Value;
return uuid;
} else
{
var result = Regex.Match(SystemUrl, @"https?:\/\/.*\/systems\/(.*)\/.*");
string uuid = result.Groups[1].Value;
var uuid = result.Groups[1].Value;
return uuid;
}
}
@@ -49,12 +49,12 @@ namespace PepperDash.Essentials.Core.Config
if (TemplateUrl.Contains("#"))
{
var result = Regex.Match(TemplateUrl, @"https?:\/\/.*\/templates\/(.*)\/#.*");
string uuid = result.Groups[1].Value;
var uuid = result.Groups[1].Value;
return uuid;
} else
{
var result = Regex.Match(TemplateUrl, @"https?:\/\/.*\/system-templates\/(.*)\/system-template-versions\/(.*)\/.*");
string uuid = result.Groups[2].Value;
var uuid = result.Groups[2].Value;
return uuid;
}
}

View File

@@ -1,4 +1,4 @@
namespace PepperDash.Essentials.Core
namespace PepperDash.Essentials.Core.Config
{
/// <summary>
/// Defines the contract for ILoadConfig

View File

@@ -2,6 +2,7 @@
using Crestron.SimplSharp;
using Newtonsoft.Json;
using PepperDash.Essentials.Core.Global;
using System;
using System.Collections.Generic;
@@ -112,7 +113,7 @@ namespace PepperDash.Essentials.Core.Config
/// The information gathered by the processor at runtime about it's NICs and their IP addresses.
/// </summary>
[JsonProperty("ipInfo")]
public Dictionary<short, EthernetAdapterInfo> IpInfo
public Dictionary<short, Core.Global.EthernetAdapterInfo> IpInfo
{
get
{

View File

@@ -1,11 +1,13 @@
using System.Linq;
using Crestron.SimplSharpPro;
using Crestron.SimplSharpPro.DeviceSupport;
using PepperDash.Core;
using PepperDash.Essentials.Core.Bridges;
using PepperDash.Essentials.Core.Devices;
using PepperDash.Essentials.Core.Feedbacks;
using PepperDash.Essentials.Core.Monitoring;
using Serilog.Events;
namespace PepperDash.Essentials.Core
namespace PepperDash.Essentials.Core.Crestron
{
public abstract class CrestronGenericBaseDevice : EssentialsDevice, IOnline, IHasFeedback, ICommunicationMonitor, IUsageTracking
{
@@ -14,7 +16,7 @@ namespace PepperDash.Essentials.Core
/// <summary>
/// Gets or sets the Feedbacks
/// </summary>
public FeedbackCollection<Feedback> Feedbacks { get; private set; }
public FeedbackCollection<Feedbacks.Feedback> Feedbacks { get; private set; }
/// <summary>
/// Gets or sets the IsOnline
@@ -37,7 +39,7 @@ namespace PepperDash.Essentials.Core
protected CrestronGenericBaseDevice(string key, string name, GenericBase hardware)
: base(key, name)
{
Feedbacks = new FeedbackCollection<Feedback>();
Feedbacks = new FeedbackCollection<Feedbacks.Feedback>();
Hardware = hardware;
IsOnline = new BoolFeedback("IsOnlineFeedback", () => Hardware.IsOnline);
@@ -51,7 +53,7 @@ namespace PepperDash.Essentials.Core
protected CrestronGenericBaseDevice(string key, string name)
: base(key, name)
{
Feedbacks = new FeedbackCollection<Feedback>();
Feedbacks = new FeedbackCollection<Feedbacks.Feedback>();
}
@@ -140,7 +142,7 @@ namespace PepperDash.Essentials.Core
/// <summary>
/// AddToFeedbackList method
/// </summary>
public void AddToFeedbackList(params Feedback[] newFbs)
public void AddToFeedbackList(params Feedbacks.Feedback[] newFbs)
{
foreach (var f in newFbs)
{
@@ -184,8 +186,10 @@ namespace PepperDash.Essentials.Core
/// </summary>
public UsageTracking UsageTracker { get; set; }
FeedbackCollection<Feedbacks.Feedback> IHasFeedback.Feedbacks => throw new System.NotImplementedException();
#endregion
}
}
public abstract class CrestronGenericBridgeableBaseDevice : CrestronGenericBaseDevice, IBridgeAdvanced
{

View File

@@ -1,128 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Crestron.SimplSharp;
using Crestron.SimplSharpPro;
using Crestron.SimplSharpPro.DeviceSupport;
using PepperDash.Core;
namespace PepperDash.Essentials.Core
{
/// <summary>
/// A bridge class to cover the basic features of GenericBase hardware
/// </summary>
public class CrestronGenericBaseDevice : Device, IOnline, IHasFeedback, ICommunicationMonitor, IUsageTracking
{
public virtual GenericBase Hardware { get; protected set; }
public BoolFeedback IsOnline { get; private set; }
public BoolFeedback IsRegistered { get; private set; }
public StringFeedback IpConnectionsText { get; private set; }
public CrestronGenericBaseDevice(string key, string name, GenericBase hardware)
: base(key, name)
{
Hardware = hardware;
IsOnline = new BoolFeedback(CommonBoolCue.IsOnlineFeedback, () => Hardware.IsOnline);
IsRegistered = new BoolFeedback(new Cue("IsRegistered", 0, eCueType.Bool), () => Hardware.Registered);
IpConnectionsText = new StringFeedback(CommonStringCue.IpConnectionsText, () =>
string.Join(",", Hardware.ConnectedIpList.Select(cip => cip.DeviceIpAddress).ToArray()));
CommunicationMonitor = new CrestronGenericBaseCommunicationMonitor(this, hardware, 120000, 300000);
}
/// <summary>
/// Make sure that overriding classes call this!
/// Registers the Crestron device, connects up to the base events, starts communication monitor
/// </summary>
public override bool CustomActivate()
{
Debug.LogMessage(LogEventLevel.Information, this, "Activating");
var response = Hardware.RegisterWithLogging(Key);
if (response != eDeviceRegistrationUnRegistrationResponse.Success)
{
<<<<<<< HEAD
Debug.LogMessage(LogEventLevel.Information, this, "ERROR: Cannot register Crestron device: {0}", response);
return false;
}
=======
Debug.LogMessage(LogEventLevel.Information, this, "ERROR: Cannot register Crestron device: {0}", response);
return false;
}
>>>>>>> origin/feature/ecs-342-neil
Hardware.OnlineStatusChange += new OnlineStatusChangeEventHandler(Hardware_OnlineStatusChange);
CommunicationMonitor.Start();
return true;
}
/// <summary>
/// This disconnects events and unregisters the base hardware device.
/// </summary>
/// <returns></returns>
public override bool Deactivate()
{
CommunicationMonitor.Stop();
Hardware.OnlineStatusChange -= Hardware_OnlineStatusChange;
return Hardware.UnRegister() == eDeviceRegistrationUnRegistrationResponse.Success;
}
/// <summary>
/// Returns a list containing the Outputs that we want to expose.
/// </summary>
public virtual List<Feedback> Feedbacks
{
get
{
return new List<Feedback>
{
IsOnline,
IsRegistered,
IpConnectionsText
};
}
}
void Hardware_OnlineStatusChange(GenericBase currentDevice, OnlineOfflineEventArgs args)
{
IsOnline.FireUpdate();
}
#region IStatusMonitor Members
public StatusMonitorBase CommunicationMonitor { get; private set; }
#endregion
#region IUsageTracking Members
public UsageTracking UsageTracker { get; set; }
#endregion
}
//***********************************************************************************
public class CrestronGenericBaseDeviceEventIds
{
public const uint IsOnline = 1;
public const uint IpConnectionsText =2;
}
/// <summary>
/// Adds logging to Register() failure
/// </summary>
public static class GenericBaseExtensions
{
public static eDeviceRegistrationUnRegistrationResponse RegisterWithLogging(this GenericBase device, string key)
{
var result = device.Register();
if (result != eDeviceRegistrationUnRegistrationResponse.Success)
{
Debug.LogMessage(LogEventLevel.Information, "Cannot register device '{0}': {1}", key, result);
}
return result;
}
}
}

View File

@@ -5,9 +5,12 @@ using System.Collections.Generic;
using Crestron.SimplSharpPro;
using Crestron.SimplSharpPro.DeviceSupport;
using Newtonsoft.Json;
using PepperDash.Core;
using PepperDash.Essentials.Core.Bridges;
using PepperDash.Essentials.Core.Bridges.JoinMaps;
using PepperDash.Essentials.Core.Config;
using PepperDash.Essentials.Core.Devices;
using PepperDash.Essentials.Core.Feedbacks;
using PepperDash.Essentials.Core.JoinMaps;
using Serilog.Events;

View File

@@ -5,9 +5,13 @@ using System.Collections.Generic;
using Crestron.SimplSharpPro;
using Crestron.SimplSharpPro.DeviceSupport;
using Newtonsoft.Json;
using PepperDash.Core;
using PepperDash.Essentials.Core.Bridges;
using PepperDash.Essentials.Core.Bridges.JoinMaps;
using PepperDash.Essentials.Core.Config;
using PepperDash.Essentials.Core.Devices;
using PepperDash.Essentials.Core.Feedbacks;
using PepperDash.Essentials.Core.JoinMaps;
using PepperDash.Essentials.Core.Touchpanels;
using Serilog.Events;
namespace PepperDash.Essentials.Core.CrestronIO

View File

@@ -4,14 +4,17 @@ using System;
using System.Collections.Generic;
using Crestron.SimplSharpPro;
using Crestron.SimplSharpPro.DeviceSupport;
using PepperDash.Core;
using PepperDash.Essentials.Core.Config;
using PepperDash.Essentials.Core.Bridges;
using Newtonsoft.Json;
using Serilog.Events;
using PepperDash.Essentials.Core.JoinMaps;
using PepperDash.Essentials.Core.Devices;
using PepperDash.Essentials.Core.Bridges.JoinMaps;
using PepperDash.Essentials.Core.Feedbacks;
using PepperDash.Essentials.Core.Touchpanels;
namespace PepperDash.Essentials.Core.CrestronIO
{

View File

@@ -4,14 +4,17 @@ using System;
using System.Collections.Generic;
using Crestron.SimplSharpPro;
using Crestron.SimplSharpPro.DeviceSupport;
using PepperDash.Core;
using PepperDash.Essentials.Core.Config;
using PepperDash.Essentials.Core.Bridges;
using Newtonsoft.Json;
using Serilog.Events;
using PepperDash.Essentials.Core.Feedbacks;
using PepperDash.Essentials.Core.PartitionSensor;
using PepperDash.Essentials.Core.Bridges.JoinMaps;
using PepperDash.Essentials.Core.JoinMaps;
using PepperDash.Essentials.Core.Devices;
namespace PepperDash.Essentials.Core.CrestronIO
{

View File

@@ -4,14 +4,17 @@ using System;
using System.Collections.Generic;
using Crestron.SimplSharpPro;
using Crestron.SimplSharpPro.DeviceSupport;
using PepperDash.Core;
using PepperDash.Essentials.Core.Config;
using PepperDash.Essentials.Core.Bridges;
using Newtonsoft.Json;
using Serilog.Events;
using PepperDash.Essentials.Core.Bridges.JoinMaps;
using PepperDash.Essentials.Core.Feedbacks;
using PepperDash.Essentials.Core.JoinMaps;
using PepperDash.Essentials.Core.Devices;
using PepperDash.Essentials.Core.Touchpanels;
namespace PepperDash.Essentials.Core.CrestronIO
{

View File

@@ -1,4 +1,6 @@
namespace PepperDash.Essentials.Core.CrestronIO
using PepperDash.Essentials.Core.Feedbacks;
namespace PepperDash.Essentials.Core.CrestronIO
{
/// <summary>
/// Defines the contract for IAnalogInput

View File

@@ -1,4 +1,6 @@
namespace PepperDash.Essentials.Core.CrestronIO
using PepperDash.Essentials.Core.Feedbacks;
namespace PepperDash.Essentials.Core.CrestronIO
{
/// <summary>
/// Represents a device that provides digital input

View File

@@ -1,4 +1,6 @@
namespace PepperDash.Essentials.Core.CrestronIO
using PepperDash.Essentials.Core.Feedbacks;
namespace PepperDash.Essentials.Core.CrestronIO
{
/// <summary>
/// Represents a device that provides digital input

View File

@@ -1,7 +1,7 @@
using Crestron.SimplSharpPro;
using Crestron.SimplSharpPro.DeviceSupport;
namespace PepperDash.Essentials.Core
namespace PepperDash.Essentials.Core.CrestronIO
{
/// <summary>
/// Defines the contract for IHasCresnetBranches

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic;
using PepperDash.Essentials.Core.Feedbacks;
using System.Collections.Generic;
namespace PepperDash.Essentials.Core.CrestronIO
{

View File

@@ -0,0 +1,306 @@
using Crestron.SimplSharp;
using Crestron.SimplSharp.CrestronIO;
using Newtonsoft.Json;
using Serilog;
using Serilog.Context;
using Serilog.Events;
using System;
using System.Collections.Generic;
using static Crestron.SimplSharpPro.Lighting.ZumWired.ZumNetBridgeRoom.ZumWiredRoomInterface;
namespace PepperDash.Essentials.Core
{
/// <summary>
/// Contains debug commands for use in various situations
/// </summary>
public static class Debug
{
private static readonly Dictionary<uint, LogEventLevel> _logLevels = new Dictionary<uint, LogEventLevel>()
{
{0, LogEventLevel.Information },
{3, LogEventLevel.Warning },
{4, LogEventLevel.Error },
{5, LogEventLevel.Fatal },
{1, LogEventLevel.Debug },
{2, LogEventLevel.Verbose },
};
public static void LogMessage(LogEventLevel level, string message, params object[] args)
{
Log.Write(level, message, args);
}
/// <summary>
/// LogMessage method
/// </summary>
public static void LogMessage(LogEventLevel level, Exception ex, string message, params object[] args)
{
Log.Write(level, ex, message, args);
}
/// <summary>
/// LogMessage method
/// </summary>
public static void LogMessage(LogEventLevel level, IKeyed keyed, string message, params object[] args)
{
using (LogContext.PushProperty("Key", keyed.Key))
{
Log.Write(level, message, args);
}
}
/// <summary>
/// LogMessage method
/// </summary>
public static void LogMessage(LogEventLevel level, IKeyed keyed, Exception ex, string message, params object[] args)
{
using (LogContext.PushProperty("Key", keyed.Key))
{
Log.Write(level, ex, message, args);
}
}
#region Explicit methods for logging levels
/// <summary>
/// LogVerbose method
/// </summary>
public static void LogVerbose(IKeyed keyed, string message, params object[] args)
{
using (LogContext.PushProperty("Key", keyed?.Key))
{
Log.Write(LogEventLevel.Verbose, message, args);
}
}
/// <summary>
/// LogVerbose method
/// </summary>
public static void LogVerbose(IKeyed keyed, Exception ex, string message, params object[] args)
{
using (LogContext.PushProperty("Key", keyed?.Key))
{
Log.Write(LogEventLevel.Verbose, ex, message, args);
}
}
/// <summary>
/// LogVerbose method
/// </summary>
public static void LogVerbose(string message, params object[] args)
{
Log.Write(LogEventLevel.Verbose, message, args);
}
/// <summary>
/// LogVerbose method
/// </summary>
public static void LogVerbose(Exception ex, string message, params object[] args)
{
Log.Write(LogEventLevel.Verbose, ex, message, args);
}
/// <summary>
/// LogDebug method
/// </summary>
public static void LogDebug(IKeyed keyed, string message, params object[] args)
{
LogMessage(LogEventLevel.Debug, keyed, message, args);
}
/// <summary>
/// LogDebug method
/// </summary>
public static void LogDebug(IKeyed keyed, Exception ex, string message, params object[] args)
{
LogMessage(LogEventLevel.Debug, keyed, ex, message, args);
}
/// <summary>
/// LogDebug method
/// </summary>
public static void LogDebug(string message, params object[] args)
{
Log.Debug(message, args);
}
/// <summary>
/// LogDebug method
/// </summary>
public static void LogDebug(Exception ex, string message, params object[] args)
{
Log.Debug(ex, message, args);
}
/// <summary>
/// LogInformation method
/// </summary>
public static void LogInformation(IKeyed keyed, string message, params object[] args)
{
LogMessage(LogEventLevel.Information, keyed, message, args);
}
/// <summary>
/// LogInformation method
/// </summary>
public static void LogInformation(IKeyed keyed, Exception ex, string message, params object[] args)
{
LogMessage(LogEventLevel.Information, keyed, ex, message, args);
}
/// <summary>
/// LogInformation method
/// </summary>
public static void LogInformation(string message, params object[] args)
{
Log.Information(message, args);
}
/// <summary>
/// LogInformation method
/// </summary>
public static void LogInformation(Exception ex, string message, params object[] args)
{
Log.Information(ex, message, args);
}
/// <summary>
/// LogWarning method
/// </summary>
public static void LogWarning(IKeyed keyed, string message, params object[] args)
{
LogMessage(LogEventLevel.Warning, keyed, message, args);
}
/// <summary>
/// LogWarning method
/// </summary>
public static void LogWarning(Exception ex, IKeyed keyed, string message, params object[] args)
{
LogMessage(LogEventLevel.Warning, keyed, ex, message, args);
}
/// <summary>
/// LogWarning method
/// </summary>
public static void LogWarning(string message, params object[] args)
{
LogMessage(LogEventLevel.Warning, message, args);
}
/// <summary>
/// LogWarning method
/// </summary>
public static void LogWarning(Exception ex, string message, params object[] args)
{
LogMessage(LogEventLevel.Warning, ex, message, args);
}
/// <summary>
/// LogError method
/// </summary>
public static void LogError(IKeyed keyed, string message, params object[] args)
{
LogMessage(LogEventLevel.Error, keyed, message, args);
}
/// <summary>
/// LogError method
/// </summary>
public static void LogError(IKeyed keyed, Exception ex, string message, params object[] args)
{
LogMessage(LogEventLevel.Error, keyed, ex, message, args);
}
/// <summary>
/// LogError method
/// </summary>
public static void LogError(string message, params object[] args)
{
LogMessage(LogEventLevel.Error, message, args);
}
/// <summary>
/// LogError method
/// </summary>
public static void LogError(Exception ex, string message, params object[] args)
{
LogMessage(LogEventLevel.Error, ex, message, args);
}
/// <summary>
/// LogFatal method
/// </summary>
public static void LogFatal(IKeyed keyed, string message, params object[] args)
{
LogMessage(LogEventLevel.Fatal, keyed, message, args);
}
/// <summary>
/// LogFatal method
/// </summary>
public static void LogFatal(IKeyed keyed, Exception ex, string message, params object[] args)
{
LogMessage(LogEventLevel.Fatal, keyed, ex, message, args);
}
/// <summary>
/// LogFatal method
/// </summary>
public static void LogFatal(string message, params object[] args)
{
LogMessage(LogEventLevel.Fatal, message, args);
}
/// <summary>
/// LogFatal method
/// </summary>
public static void LogFatal(Exception ex, string message, params object[] args)
{
LogMessage(LogEventLevel.Fatal, ex, message, args);
}
#endregion
private static void LogMessage(uint level, string format, params object[] items)
{
if (!_logLevels.ContainsKey(level)) return;
var logLevel = _logLevels[level];
LogMessage(logLevel, format, items);
}
private static void LogMessage(uint level, IKeyed keyed, string format, params object[] items)
{
if (!_logLevels.ContainsKey(level)) return;
var logLevel = _logLevels[level];
LogMessage(logLevel, keyed, format, items);
}
/// <summary>
/// Enumeration of ErrorLogLevel values
/// </summary>
public enum ErrorLogLevel
{
/// <summary>
/// Error
/// </summary>
Error,
/// <summary>
/// Warning
/// </summary>
Warning,
/// <summary>
/// Notice
/// </summary>
Notice,
/// <summary>
/// None
/// </summary>
None,
}
}
}

View File

@@ -1,6 +1,4 @@
using PepperDash.Core;
namespace PepperDash.Essentials.Core.DeviceInfo
namespace PepperDash.Essentials.Core.DeviceInfo
{
/// <summary>
/// Defines the contract for IDeviceInfoProvider

View File

@@ -1,8 +1,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using PepperDash.Core;
using Crestron.SimplSharp;
using PepperDash.Essentials.Core.Extensions;
using Serilog.Events;
namespace PepperDash.Essentials.Core.DeviceInfo

View File

@@ -0,0 +1,199 @@
using System;
using System.Collections.Generic;
using Serilog.Events;
namespace PepperDash.Essentials.Core
{
//*********************************************************************************************************
/// <summary>
/// Represents a Device
/// </summary>
public class Device : IKeyName
{
/// <summary>
/// Unique Key
/// </summary>
public string Key { get; protected set; }
/// <summary>
/// Gets or sets the Name
/// </summary>
public string Name { get; protected set; }
/// <summary>
///
/// </summary>
public bool Enabled { get; protected set; }
/// <summary>
/// A place to store reference to the original config object, if any. These values should
/// NOT be used as properties on the device as they are all publicly-settable values.
/// </summary>
//public DeviceConfig Config { get; private set; }
/// <summary>
/// Helper method to check if Config exists
/// </summary>
//public bool HasConfig { get { return Config != null; } }
List<Action> _PreActivationActions;
List<Action> _PostActivationActions;
/// <summary>
///
/// </summary>
public static Device DefaultDevice { get { return _DefaultDevice; } }
static Device _DefaultDevice = new Device("Default", "Default");
/// <summary>
/// Base constructor for all Devices.
/// </summary>
/// <param name="key"></param>
public Device(string key)
{
Key = key;
if (key.Contains(".")) Debug.LogMessage(LogEventLevel.Information, "WARNING: Device key should not include '.'", this);
Name = "";
}
/// <summary>
/// Constructor with key and name
/// </summary>
/// <param name="key"></param>
/// <param name="name"></param>
public Device(string key, string name) : this(key)
{
Name = name;
}
//public Device(DeviceConfig config)
// : this(config.Key, config.Name)
//{
// Config = config;
//}
/// <summary>
/// Adds a pre activation action
/// </summary>
/// <param name="act"></param>
public void AddPreActivationAction(Action act)
{
if (_PreActivationActions == null)
_PreActivationActions = new List<Action>();
_PreActivationActions.Add(act);
}
/// <summary>
/// Adds a post activation action
/// </summary>
/// <param name="act"></param>
/// <summary>
/// AddPostActivationAction method
/// </summary>
public void AddPostActivationAction(Action act)
{
if (_PostActivationActions == null)
_PostActivationActions = new List<Action>();
_PostActivationActions.Add(act);
}
/// <summary>
/// PreActivate method
/// </summary>
public void PreActivate()
{
if (_PreActivationActions != null)
_PreActivationActions.ForEach(a =>
{
try
{
a.Invoke();
}
catch (Exception e)
{
Debug.LogMessage(e, "Error in PreActivationAction: " + e.Message, this);
}
});
}
/// <summary>
/// Activate method
/// </summary>
public bool Activate()
{
//if (_PreActivationActions != null)
// _PreActivationActions.ForEach(a => a.Invoke());
var result = CustomActivate();
//if(result && _PostActivationActions != null)
// _PostActivationActions.ForEach(a => a.Invoke());
return result;
}
/// <summary>
/// PostActivate method
/// </summary>
public void PostActivate()
{
if (_PostActivationActions != null)
_PostActivationActions.ForEach(a =>
{
try
{
a.Invoke();
}
catch (Exception e)
{
Debug.LogMessage(e, "Error in PostActivationAction: " + e.Message, this);
}
});
}
/// <summary>
/// Called in between Pre and PostActivationActions when Activate() is called.
/// Override to provide addtitional setup when calling activation. Overriding classes
/// do not need to call base.CustomActivate()
/// </summary>
/// <returns>true if device activated successfully.</returns>
/// <summary>
/// CustomActivate method
/// </summary>
public virtual bool CustomActivate() { return true; }
/// <summary>
/// Call to deactivate device - unlink events, etc. Overriding classes do not
/// need to call base.Deactivate()
/// </summary>
/// <returns></returns>
public virtual bool Deactivate() { return true; }
/// <summary>
/// Call this method to start communications with a device. Overriding classes do not need to call base.Initialize()
/// </summary>
public virtual void Initialize()
{
}
/// <summary>
/// Helper method to check object for bool value false and fire an Action method
/// </summary>
/// <param name="o">Should be of type bool, others will be ignored</param>
/// <param name="a">Action to be run when o is false</param>
public void OnFalse(object o, Action a)
{
if (o is bool && !(bool)o) a();
}
/// <summary>
/// Returns a string representation of the object, including its key and name.
/// </summary>
/// <remarks>The returned string is formatted as "{Key} - {Name}". If the <c>Name</c> property is
/// null or empty, "---" is used in place of the name.</remarks>
/// <returns>A string that represents the object, containing the key and name in the format "{Key} - {Name}".</returns>
/// <summary>
/// ToString method
/// </summary>
public override string ToString()
{
return string.Format("{0} - {1}", Key, string.IsNullOrEmpty(Name) ? "---" : Name);
}
}
}

View File

@@ -1,19 +0,0 @@
//using System;
//using System.Collections.Generic;
//using Crestron.SimplSharpPro;
//using Crestron.SimplSharpPro.DeviceSupport;
//using PepperDash.Core;
//namespace PepperDash.Essentials.Core
//{
// public interface IPresentationSource : IKeyed
// {
// string Name { get; }
// PresentationSourceType Type { get; }
// string IconName { get; set; }
// BoolFeedback HasPowerOnFeedback { get; }
// }
//}

View File

@@ -1,6 +1,7 @@
using Crestron.SimplSharpPro.DeviceSupport;
using PepperDash.Essentials.Core.Touchpanels;
namespace PepperDash.Essentials.Core
namespace PepperDash.Essentials.Core.DeviceTypeInterfaces
{
/// <summary>
///

View File

@@ -1,6 +1,7 @@
using Crestron.SimplSharpPro.DeviceSupport;
using PepperDash.Essentials.Core.Touchpanels;
namespace PepperDash.Essentials.Core
namespace PepperDash.Essentials.Core.DeviceTypeInterfaces
{
/// <summary>
///

View File

@@ -1,7 +1,7 @@
using Crestron.SimplSharpPro.DeviceSupport;
using PepperDash.Core;
using PepperDash.Essentials.Core.Touchpanels;
namespace PepperDash.Essentials.Core
namespace PepperDash.Essentials.Core.DeviceTypeInterfaces
{
/// <summary>
///

View File

@@ -1,4 +1,4 @@
namespace PepperDash.Essentials.Core
namespace PepperDash.Essentials.Core.DeviceTypeInterfaces
{
/// <summary>

View File

@@ -1,4 +1,5 @@
using PepperDash.Core;
using PepperDash.Essentials.Core.Devices;
using PepperDash.Essentials.Core.Routing;
namespace PepperDash.Essentials.Core.DeviceTypeInterfaces
{

View File

@@ -1,4 +1,4 @@
namespace PepperDash.Essentials.Core.Devices.DeviceTypeInterfaces
namespace PepperDash.Essentials.Core.DeviceTypeInterfaces
{
/// <summary>
/// Defines the contract for IDisplayBasic

View File

@@ -1,4 +1,4 @@
namespace PepperDash.Essentials.Core
namespace PepperDash.Essentials.Core.DeviceTypeInterfaces
{
/// <summary>
/// Defines the contract for IDumbSource

View File

@@ -1,6 +1,7 @@
using Crestron.SimplSharpPro.DeviceSupport;
using PepperDash.Essentials.Core.Touchpanels;
namespace PepperDash.Essentials.Core
namespace PepperDash.Essentials.Core.DeviceTypeInterfaces
{
/// <summary>
///

View File

@@ -1,4 +1,6 @@
namespace PepperDash.Essentials.Core.DeviceTypeInterfaces
using PepperDash.Essentials.Core.Feedbacks;
namespace PepperDash.Essentials.Core.DeviceTypeInterfaces
{
/// <summary>
/// Defines the contract for IHasFarEndContentStatus

View File

@@ -1,6 +1,4 @@
using PepperDash.Core;
namespace PepperDash.Essentials.Core.DeviceTypeInterfaces
namespace PepperDash.Essentials.Core.DeviceTypeInterfaces
{
/// <summary>
/// Describes a device that has selectable inputs

Some files were not shown because too many files have changed in this diff Show More