Merge pull request #136 from PepperDash/feature/add-documentation

Feature/add documentation
This commit is contained in:
Andrew Welker
2022-06-08 15:46:19 -05:00
committed by GitHub
46 changed files with 1655 additions and 383 deletions

View File

@@ -51,7 +51,7 @@ namespace PepperDash.Core
string[] StringDelimiters;
/// <summary>
/// Fires up a gather, given a IBasicCommunicaion port and char for de
/// Constructor for using a char delimiter
/// </summary>
/// <param name="port"></param>
/// <param name="delimiter"></param>
@@ -63,7 +63,7 @@ namespace PepperDash.Core
}
/// <summary>
///
/// Constructor for using a single string delimiter
/// </summary>
/// <param name="port"></param>
/// <param name="delimiter"></param>
@@ -72,6 +72,11 @@ namespace PepperDash.Core
{
}
/// <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;

View File

@@ -22,6 +22,9 @@ namespace PepperDash.Core
/// </summary>
private CTimer DebugExpiryPeriod;
/// <summary>
/// The current debug setting
/// </summary>
public eStreamDebuggingSetting DebugSetting { get; private set; }
private uint _DebugTimeoutInMs;
@@ -38,11 +41,20 @@ namespace PepperDash.Core
}
}
/// <summary>
/// Indicates that receive stream debugging is enabled
/// </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;
@@ -125,9 +137,21 @@ namespace PepperDash.Core
[Flags]
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
}
@@ -137,8 +161,17 @@ namespace PepperDash.Core
[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

@@ -8,34 +8,56 @@ using Newtonsoft.Json;
namespace PepperDash.Core
{
/// <summary>
///
/// Config properties that indicate how to communicate with a device for control
/// </summary>
public class ControlPropertiesConfig
{
/// <summary>
/// The method of control
/// </summary>
public eControlMethod Method { get; set; }
/// <summary>
/// The key of the device that contains the control port
/// </summary>
public string ControlPortDevKey { get; set; }
/// <summary>
/// The number of the control port on the device specified by ControlPortDevKey
/// </summary>
[JsonProperty(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(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>
public TcpSshPropertiesConfig TcpSshProperties { get; set; }
/// <summary>
/// The filename and path for the IR file
/// </summary>
public string IrFile { get; set; }
//public ComPortConfig ComParams { get; set; }
//[JsonConverter(typeof(ComSpecJsonConverter))]
//public ComPort.ComPortSpec ComParams { get; set; }
/// <summary>
/// The IpId of a Crestron device
/// </summary>
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>
public char EndOfLineChar { get; set; }
/// <summary>
@@ -43,8 +65,14 @@ namespace PepperDash.Core
/// </summary>
public string EndOfLineString { get; set; }
/// <summary>
/// Indicates
/// </summary>
public string DeviceReadyResponsePattern { get; set; }
/// <summary>
/// Constructor
/// </summary>
public ControlPropertiesConfig()
{
EndOfLineString = CrestronEnvironment.NewLine;

View File

@@ -18,49 +18,108 @@ using Crestron.SimplSharp.CrestronSockets;
namespace PepperDash.Core
{
/// <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>
///
/// </summary>
public ISocketStatus Client { get; private set; }
/// <summary>
///
/// </summary>
/// <param name="client"></param>
public GenericSocketStatusChageEventArgs(ISocketStatus client)
{
Client = client;
}
/// <summary>
/// Stupid S+ Constructor
/// 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>
///
/// </summary>
public ServerState State { get; private set; }
/// <summary>
///
/// </summary>
/// <param name="state"></param>
public GenericTcpServerStateChangedEventArgs(ServerState state)
{
State = state;
}
/// <summary>
/// Stupid S+ Constructor
/// 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;
@@ -68,14 +127,24 @@ namespace PepperDash.Core
ClientStatus = clientStatus;
}
/// <summary>
/// Stupid S+ Constructor
/// 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
@@ -84,49 +153,92 @@ namespace PepperDash.Core
}
}
/// <summary>
///
/// </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>
/// Stupid S+ Constructor
/// 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>
/// Stupid S+ Constructor
/// 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

@@ -8,50 +8,86 @@ using Crestron.SimplSharp.Net.Http;
namespace PepperDash.Core
{
/// <summary>
/// Client for communicating with an HTTP Server Side Event pattern
/// </summary>
public class GenericHttpSseClient : ICommunicationReceiver
{
/// <summary>
/// Notifies when bytes have been received
/// </summary>
public event EventHandler<GenericCommMethodReceiveBytesArgs> BytesReceived;
/// <summary>
/// Notifies when text has been received
/// </summary>
public event EventHandler<GenericCommMethodReceiveTextArgs> TextReceived;
/// <summary>
/// Indicates connection status
/// </summary>
public bool IsConnected
{
get;
private set;
}
/// <summary>
/// Unique identifier for the instance
/// </summary>
public string Key
{
get;
private set;
}
/// <summary>
/// Name for the instance
/// </summary>
public string Name
{
get;
private set;
}
/// <summary>
/// URL of the server
/// </summary>
public string Url { get; set; }
HttpClient Client;
HttpClientRequest Request;
/// <summary>
/// Constructor
/// </summary>
/// <param name="key"></param>
/// <param name="name"></param>
public GenericHttpSseClient(string key, string name)
{
Key = key;
Name = name;
}
/// <summary>
/// Connects to the server. Requires Url to be set first.
/// </summary>
public void Connect()
{
InitiateConnection(Url);
}
/// <summary>
/// Disconnects from the server
/// </summary>
public void Disconnect()
{
CloseConnection(null);
}
/// <summary>
/// Initiates connection to the server
/// </summary>
/// <param name="url"></param>
public void InitiateConnection(string url)
{
CrestronInvoke.BeginInvoke(o =>
@@ -84,6 +120,10 @@ namespace PepperDash.Core
});
}
/// <summary>
/// Closes the connection to the server
/// </summary>
/// <param name="s"></param>
public void CloseConnection(string s)
{
if (Client != null)
@@ -119,7 +159,7 @@ namespace PepperDash.Core
/// <summary>
///
/// </summary>
/// <param name="asynchronousResult"></param>
/// <param name="request"></param>
/// <param name="error"></param>
/// <param name="status"></param>
private void GetResponseStreamCallback(HttpClientRequest request, HTTP_CALLBACK_ERROR error, object status)
@@ -165,10 +205,6 @@ namespace PepperDash.Core
Debug.Console(1, this, "DataConnection OnBytesReceived Fired");
}
/// <summary>
///
/// </summary>
/// <param name="asyncResult"></param>
private void ReadCallBack(Crestron.SimplSharp.CrestronIO.IAsyncResult asyncResult)
{
//we are getting back everything here, so cast the state from the call
@@ -222,14 +258,38 @@ namespace PepperDash.Core
/// </summary>
public class RequestState
{
/// <summary>
///
/// </summary>
public const int BUFFER_SIZE = 10000;
/// <summary>
///
/// </summary>
public byte[] BufferRead;
/// <summary>
///
/// </summary>
public HttpClient HttpClient;
/// <summary>
///
/// </summary>
public HttpClientRequest Request;
/// <summary>
///
/// </summary>
public HttpClientResponse Response;
/// <summary>
///
/// </summary>
public Stream StreamResponse;
/// <summary>
///
/// </summary>
public bool Done;
/// <summary>
/// Constructor
/// </summary>
public RequestState()
{
BufferRead = new byte[BUFFER_SIZE];
@@ -246,6 +306,9 @@ namespace PepperDash.Core
/// </summary>
public class StreamAsyncTest
{
/// <summary>
///
/// </summary>
public CEvent wait_for_response = new CEvent(true, false);
}
}

View File

@@ -416,6 +416,10 @@ namespace PepperDash.Core
}
/// <summary>
/// Deactivate the client
/// </summary>
/// <returns></returns>
public override bool Deactivate()
{
if (_client != null)
@@ -605,30 +609,6 @@ namespace PepperDash.Core
ConnectFailTimer = null;
}
/// <summary>
/// Internal call to close up client. ALWAYS use this when disconnecting.
/// </summary>
//void Cleanup()
//{
// IsTryingToConnect = false;
// if (_client != null)
// {
// //SecureClient.DisconnectFromServer();
// Debug.Console(2, this, "Disconnecting _client {0}", DisconnectCalledByUser ? ", Called by user" : "");
// _client.SocketStatusChange -= Client_SocketStatusChange;
// _client.Dispose();
// _client = null;
// }
// if (ConnectFailTimer != null)
// {
// ConnectFailTimer.Stop();
// ConnectFailTimer.Dispose();
// ConnectFailTimer = null;
// }
//}
#region Methods
/// <summary>

View File

@@ -20,6 +20,9 @@ using Crestron.SimplSharp.CrestronSockets;
namespace PepperDash.Core
{
/// <summary>
/// Generic secure TCP/IP client for server
/// </summary>
public class GenericSecureTcpIpClient_ForServer : Device, IAutoReconnect
{
/// <summary>
@@ -31,8 +34,14 @@ namespace PepperDash.Core
//public event EventHandler<GenericCommMethodReceiveBytesArgs> BytesReceived;
/// <summary>
/// Notifies of text received
/// </summary>
public event EventHandler<GenericTcpServerCommMethodReceiveTextArgs> TextReceived;
/// <summary>
/// Notifies of auto reconnect sequence triggered
/// </summary>
public event EventHandler AutoReconnectTriggered;
/// <summary>
@@ -41,7 +50,9 @@ namespace PepperDash.Core
/// </summary>
public event EventHandler<GenericTcpServerCommMethodReceiveTextArgs> TextReceivedQueueInvoke;
/// <summary>
/// Notifies of socket status change
/// </summary>
public event EventHandler<GenericTcpServerSocketStatusChangeEventArgs> ConnectionChange;
@@ -212,13 +223,22 @@ namespace PepperDash.Core
CTimer RetryTimer;
/// <summary>
///
/// </summary>
public bool HeartbeatEnabled { get; set; }
/// <summary>
///
/// </summary>
public ushort UHeartbeatEnabled
{
get { return (ushort)(HeartbeatEnabled ? 1 : 0); }
set { HeartbeatEnabled = value == 1; }
}
/// <summary>
///
/// </summary>
public string HeartbeatString { get; set; }
//public int HeartbeatInterval = 50000;
@@ -269,7 +289,13 @@ namespace PepperDash.Core
#region Constructors
//Base class constructor
/// <summary>
/// Constructor
/// </summary>
/// <param name="key"></param>
/// <param name="address"></param>
/// <param name="port"></param>
/// <param name="bufferSize"></param>
public GenericSecureTcpIpClient_ForServer(string key, string address, int port, int bufferSize)
: base(key)
{
@@ -281,7 +307,9 @@ namespace PepperDash.Core
}
//base class constructor
/// <summary>
/// Constructor for S+
/// </summary>
public GenericSecureTcpIpClient_ForServer()
: base("Uninitialized Secure Tcp Client For Server")
{
@@ -293,7 +321,8 @@ namespace PepperDash.Core
/// <summary>
/// Contstructor that sets all properties by calling the initialize method with a config object.
/// </summary>
/// <param name="serverConfigObject"></param>
/// <param name="key"></param>
/// <param name="clientConfigObject"></param>
public GenericSecureTcpIpClient_ForServer(string key, TcpClientConfigObject clientConfigObject)
: base(key)
{

View File

@@ -20,6 +20,9 @@ using Newtonsoft.Json.Linq;
namespace PepperDash.Core
{
/// <summary>
/// Generic secure TCP/IP server
/// </summary>
public class GenericSecureTcpIpServer : Device
{
#region Events
@@ -55,6 +58,9 @@ namespace PepperDash.Core
/// </summary>
public ServerHasChokedCallbackDelegate ServerHasChoked { get; set; }
/// <summary>
///
/// </summary>
public delegate void ServerHasChokedCallbackDelegate();
#endregion
@@ -265,7 +271,9 @@ namespace PepperDash.Core
List<uint> ClientReadyAfterKeyExchange = new List<uint>();
//Store the connected client indexes
/// <summary>
/// The connected client indexes
/// </summary>
public List<uint> ConnectedClientsIndexes = new List<uint>();
/// <summary>
@@ -354,6 +362,10 @@ namespace PepperDash.Core
Key = key;
}
/// <summary>
/// Initialze the server
/// </summary>
/// <param name="serverConfigObject"></param>
public void Initialize(TcpServerConfigObject serverConfigObject)
{
try
@@ -618,6 +630,11 @@ namespace PepperDash.Core
return received;
}
/// <summary>
/// Get the IP Address for the client at the specifed index
/// </summary>
/// <param name="clientIndex"></param>
/// <returns></returns>
public string GetClientIPAddress(uint clientIndex)
{
Debug.Console(1, this, Debug.ErrorLogLevel.Notice, "GetClientIPAddress Index: {0}", clientIndex);
@@ -675,7 +692,7 @@ namespace PepperDash.Core
/// <summary>
/// Secure Server Socket Status Changed Callback
/// </summary>
/// <param name="mySecureTCPServer"></param>
/// <param name="server"></param>
/// <param name="clientIndex"></param>
/// <param name="serverSocketStatus"></param>
void SecureServer_SocketStatusChange(SecureTCPServer server, uint clientIndex, SocketStatus serverSocketStatus)
@@ -723,7 +740,7 @@ namespace PepperDash.Core
/// <summary>
/// Secure TCP Client Connected to Secure Server Callback
/// </summary>
/// <param name="mySecureTCPServer"></param>
/// <param name="server"></param>
/// <param name="clientIndex"></param>
void SecureConnectCallback(SecureTCPServer server, uint clientIndex)
{

View File

@@ -14,6 +14,9 @@ namespace PepperDash.Core
public class GenericSshClient : Device, ISocketStatusWithStreamDebugging, IAutoReconnect
{
private const string SPlusKey = "Uninitialized SshClient";
/// <summary>
/// Object to enable stream debugging
/// </summary>
public CommunicationStreamDebugging StreamDebugging { get; private set; }
/// <summary>
@@ -31,9 +34,9 @@ namespace PepperDash.Core
/// </summary>
public event EventHandler<GenericSocketStatusChageEventArgs> ConnectionChange;
/// <summary>
///
/// </summary>
///// <summary>
/////
///// </summary>
//public event GenericSocketStatusChangeEventDelegate SocketStatusChange;
/// <summary>

View File

@@ -17,6 +17,9 @@ namespace PepperDash.Core
public class GenericTcpIpClient : Device, ISocketStatusWithStreamDebugging, IAutoReconnect
{
private const string SplusKey = "Uninitialized TcpIpClient";
/// <summary>
/// Object to enable stream debugging
/// </summary>
public CommunicationStreamDebugging StreamDebugging { get; private set; }
/// <summary>
@@ -125,10 +128,10 @@ namespace PepperDash.Core
/// </summary>
public string ClientStatusText { get { return ClientStatus.ToString(); } }
[Obsolete]
/// <summary>
/// Ushort representation of client status
/// </summary>
[Obsolete]
public ushort UClientStatus { get { return (ushort)ClientStatus; } }
/// <summary>
@@ -172,7 +175,7 @@ namespace PepperDash.Core
/// <summary>
/// Constructor
/// </summary>
/// <param name="key"></param>
/// <param name="key">unique string to differentiate between instances</param>
/// <param name="address"></param>
/// <param name="port"></param>
/// <param name="bufferSize"></param>
@@ -502,6 +505,9 @@ namespace PepperDash.Core
/// </summary>
public int AutoReconnectIntervalMs { get; set; }
/// <summary>
/// Default constructor
/// </summary>
public TcpSshPropertiesConfig()
{
BufferSize = 32768;

View File

@@ -20,6 +20,9 @@ using Crestron.SimplSharp.CrestronSockets;
namespace PepperDash.Core
{
/// <summary>
/// Generic TCP/IP client for server
/// </summary>
public class GenericTcpIpClient_ForServer : Device, IAutoReconnect
{
/// <summary>
@@ -31,8 +34,14 @@ namespace PepperDash.Core
//public event EventHandler<GenericCommMethodReceiveBytesArgs> BytesReceived;
/// <summary>
/// Notifies of text received
/// </summary>
public event EventHandler<GenericTcpServerCommMethodReceiveTextArgs> TextReceived;
/// <summary>
/// Notifies of socket status change
/// </summary>
public event EventHandler<GenericTcpServerSocketStatusChangeEventArgs> ConnectionChange;
@@ -203,14 +212,30 @@ namespace PepperDash.Core
CTimer RetryTimer;
/// <summary>
///
/// </summary>
public bool HeartbeatEnabled { get; set; }
/// <summary>
///
/// </summary>
public ushort UHeartbeatEnabled
{
get { return (ushort)(HeartbeatEnabled ? 1 : 0); }
set { HeartbeatEnabled = value == 1; }
}
/// <summary>
///
/// </summary>
public string HeartbeatString = "heartbeat";
/// <summary>
///
/// </summary>
public int HeartbeatInterval = 50000;
CTimer HeartbeatSendTimer;
CTimer HeartbeatAckTimer;
/// <summary>
@@ -230,7 +255,13 @@ namespace PepperDash.Core
#region Constructors
//Base class constructor
/// <summary>
/// Constructor
/// </summary>
/// <param name="key"></param>
/// <param name="address"></param>
/// <param name="port"></param>
/// <param name="bufferSize"></param>
public GenericTcpIpClient_ForServer(string key, string address, int port, int bufferSize)
: base(key)
{
@@ -242,7 +273,9 @@ namespace PepperDash.Core
}
//base class constructor
/// <summary>
/// Constructor for S+
/// </summary>
public GenericTcpIpClient_ForServer()
: base("Uninitialized DynamicTcpClient")
{

View File

@@ -20,6 +20,9 @@ using Newtonsoft.Json.Linq;
namespace PepperDash.Core
{
/// <summary>
/// Generic TCP/IP server device
/// </summary>
public class GenericTcpIpServer : Device
{
#region Events
@@ -49,6 +52,9 @@ namespace PepperDash.Core
/// </summary>
public ServerHasChokedCallbackDelegate ServerHasChoked { get; set; }
/// <summary>
///
/// </summary>
public delegate void ServerHasChokedCallbackDelegate();
#endregion
@@ -146,7 +152,12 @@ namespace PepperDash.Core
get { return (ushort)(IsListening ? 1 : 0); }
}
public ushort MaxClients { get; set; } // should be set by parameter in SIMPL+ in the MAIN method, Should not ever need to be configurable
/// <summary>
/// The maximum number of clients.
/// Should be set by parameter in SIMPL+ in the MAIN method, Should not ever need to be configurable
/// </summary>
public ushort MaxClients { get; set; }
/// <summary>
/// Number of clients currently connected.
/// </summary>
@@ -241,7 +252,9 @@ namespace PepperDash.Core
List<uint> ClientReadyAfterKeyExchange = new List<uint>();
//Store the connected client indexes
/// <summary>
/// The connected client indexes
/// </summary>
public List<uint> ConnectedClientsIndexes = new List<uint>();
/// <summary>
@@ -330,6 +343,10 @@ namespace PepperDash.Core
Key = key;
}
/// <summary>
/// Initialze with server configuration object
/// </summary>
/// <param name="serverConfigObject"></param>
public void Initialize(TcpServerConfigObject serverConfigObject)
{
try
@@ -416,7 +433,7 @@ namespace PepperDash.Core
}
/// <summary>
/// Stop Listeneing
/// Stop Listening
/// </summary>
public void StopListening()
{
@@ -592,6 +609,11 @@ namespace PepperDash.Core
return received;
}
/// <summary>
/// Gets the IP address based on the client index
/// </summary>
/// <param name="clientIndex"></param>
/// <returns>IP address of the client</returns>
public string GetClientIPAddress(uint clientIndex)
{
Debug.Console(1, this, Debug.ErrorLogLevel.Notice, "GetClientIPAddress Index: {0}", clientIndex);
@@ -649,7 +671,7 @@ namespace PepperDash.Core
/// <summary>
/// Secure Server Socket Status Changed Callback
/// </summary>
/// <param name="mySecureTCPServer"></param>
/// <param name="server"></param>
/// <param name="clientIndex"></param>
/// <param name="serverSocketStatus"></param>
void TcpServer_SocketStatusChange(TCPServer server, uint clientIndex, SocketStatus serverSocketStatus)
@@ -687,7 +709,7 @@ namespace PepperDash.Core
/// <summary>
/// Secure TCP Client Connected to Secure Server Callback
/// </summary>
/// <param name="mySecureTCPServer"></param>
/// <param name="server"></param>
/// <param name="clientIndex"></param>
void TcpConnectCallback(TCPServer server, uint clientIndex)
{
@@ -762,7 +784,7 @@ namespace PepperDash.Core
/// <summary>
/// Secure Received Data Async Callback
/// </summary>
/// <param name="mySecureTCPServer"></param>
/// <param name="myTCPServer"></param>
/// <param name="clientIndex"></param>
/// <param name="numberOfBytesReceived"></param>
void TcpServerReceivedDataAsyncCallback(TCPServer myTCPServer, uint clientIndex, int numberOfBytesReceived)

View File

@@ -15,9 +15,15 @@ using Newtonsoft.Json.Linq;
namespace PepperDash.Core
{
/// <summary>
/// Generic UDP Server device
/// </summary>
public class GenericUdpServer : Device, ISocketStatusWithStreamDebugging
{
private const string SplusKey = "Uninitialized Udp Server";
/// <summary>
/// Object to enable stream debugging
/// </summary>
public CommunicationStreamDebugging StreamDebugging { get; private set; }
/// <summary>
///
@@ -68,10 +74,6 @@ namespace PepperDash.Core
/// </summary>
public string Hostname { get; set; }
/// <summary>
/// IP Address of the sender of the last recieved message
/// </summary>
/// <summary>
/// Port on server
@@ -97,6 +99,9 @@ namespace PepperDash.Core
private set;
}
/// <summary>
/// Numeric value indicating
/// </summary>
public ushort UIsConnected
{
get { return IsConnected ? (ushort)1 : (ushort)0; }
@@ -107,6 +112,9 @@ namespace PepperDash.Core
/// </summary>
public int BufferSize { get; set; }
/// <summary>
/// The server
/// </summary>
public UDPServer Server { get; private set; }
/// <summary>

View File

@@ -6,15 +6,36 @@ using Crestron.SimplSharp;
namespace PepperDash.Core
{
/// <summary>
/// Allows for two simultaneous TCP clients to connect to a redundant pair of QSC Core DSPs and manages
/// </summary>
public class QscCoreDoubleTcpIpClient : IKeyed
{
/// <summary>
/// Key to uniquely identify the instance of the class
/// </summary>
public string Key { get; private set; }
/// <summary>
/// Fires when a bool value changes to notify the S+ module
/// </summary>
public event EventHandler<BoolChangeEventArgs> BoolChange;
/// <summary>
/// Fires when a ushort value changes to notify the S+ module
/// </summary>
public event EventHandler<UshrtChangeEventArgs> UshortChange;
/// <summary>
/// Fires when a string value changes to notify the S+ module
/// </summary>
public event EventHandler<StringChangeEventArgs> StringChange;
/// <summary>
/// The client for the master DSP unit
/// </summary>
public GenericTcpIpClient MasterClient { get; private set; }
/// <summary>
/// The client for the slave DSP unit
/// </summary>
public GenericTcpIpClient SlaveClient { get; private set; }
string Username;
@@ -45,7 +66,7 @@ namespace PepperDash.Core
}
/// <summary>
///
/// Connects to both DSP units
/// </summary>
/// <param name="key"></param>
/// <param name="masterAddress"></param>
@@ -55,6 +76,7 @@ namespace PepperDash.Core
/// <param name="username"></param>
/// <param name="password"></param>
/// <param name="pollingIntervalSeconds"></param>
/// <param name="lineEnding"></param>
public void Connect(string key, string masterAddress, int masterPort,
string slaveAddress, int slavePort, string username, string password,
int pollingIntervalSeconds, string lineEnding)
@@ -299,14 +321,31 @@ namespace PepperDash.Core
handler(this, new StringChangeEventArgs(value, type));
}
/// <summary>
///
/// </summary>
public const ushort MasterIsActiveId = 3;
/// <summary>
///
/// </summary>
public const ushort SlaveIsActiveId = 4;
/// <summary>
///
/// </summary>
public const ushort MainModuleInitiailzeId = 5;
/// <summary>
///
/// </summary>
public const ushort MasterClientStatusId = 101;
/// <summary>
///
/// </summary>
public const ushort SlaveClientStatusId = 102;
/// <summary>
///
/// </summary>
public const ushort LineReceivedId = 201;
}
}

View File

@@ -11,6 +11,69 @@ namespace PepperDash.Core
/// </summary>
public enum eControlMethod
{
None = 0, Com, IpId, IpidTcp, IR, Ssh, Tcpip, Telnet, Cresnet, Cec, Udp, Http, Https, Ws, Wss, SecureTcpIp
/// <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

@@ -15,11 +15,26 @@ namespace PepperDash.Core
/// </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>
bool IsConnected { get; }
/// <summary>
/// Connect to the device
/// </summary>
void Connect();
/// <summary>
/// Disconnect from the device
/// </summary>
void Disconnect();
}
@@ -28,7 +43,16 @@ namespace PepperDash.Core
/// </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);
}
@@ -45,6 +69,9 @@ namespace PepperDash.Core
/// </summary>
public interface IStreamDebugging
{
/// <summary>
/// Object to enable stream debugging
/// </summary>
CommunicationStreamDebugging StreamDebugging { get; }
}
@@ -54,21 +81,37 @@ namespace PepperDash.Core
/// </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>
SocketStatus ClientStatus { get; }
}
/// <summary>
/// Represents a device that implements ISocketStatus and IStreamDebugging
/// Describes a device that implements ISocketStatus and IStreamDebugging
/// </summary>
public interface ISocketStatusWithStreamDebugging : ISocketStatus, IStreamDebugging
{
}
/// <summary>
/// Describes a device that can automatically attempt to reconnect
/// </summary>
public interface IAutoReconnect
{
/// <summary>
/// Enable automatic recconnect
/// </summary>
bool AutoReconnect { get; set; }
/// <summary>
/// Interval in ms to attempt automatic recconnections
/// </summary>
int AutoReconnectIntervalMs { get; set; }
}
@@ -77,7 +120,14 @@ namespace PepperDash.Core
/// </summary>
public enum eGenericCommMethodStatusChangeType
{
Connected, Disconnected
/// <summary>
/// Connected
/// </summary>
Connected,
/// <summary>
/// Disconnected
/// </summary>
Disconnected
}
/// <summary>
@@ -92,14 +142,22 @@ namespace PepperDash.Core
/// </summary>
public class GenericCommMethodReceiveBytesArgs : EventArgs
{
/// <summary>
///
/// </summary>
public byte[] Bytes { get; private set; }
/// <summary>
///
/// </summary>
/// <param name="bytes"></param>
public GenericCommMethodReceiveBytesArgs(byte[] bytes)
{
Bytes = bytes;
}
/// <summary>
/// Stupid S+ Constructor
/// S+ Constructor
/// </summary>
public GenericCommMethodReceiveBytesArgs() { }
}
@@ -109,13 +167,28 @@ namespace PepperDash.Core
/// </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)
{
@@ -123,7 +196,7 @@ namespace PepperDash.Core
}
/// <summary>
/// Stupid S+ Constructor
/// S+ Constructor
/// </summary>
public GenericCommMethodReceiveTextArgs() { }
}
@@ -135,17 +208,32 @@ namespace PepperDash.Core
/// </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>
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>
public static string GetDebugText(string text)
{
return Regex.Replace(text, @"[^\u0020-\u007E]", a => GetEscapedText(a.Value));

View File

@@ -12,6 +12,9 @@ using PepperDash.Core;
namespace PepperDash.Core.Config
{
/// <summary>
/// Reads a Portal formatted config file
/// </summary>
public class PortalConfigReader
{
/// <summary>
@@ -170,8 +173,9 @@ namespace PepperDash.Core.Config
/// <summary>
/// Merge o2 onto o1
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <param name="o1"></param>
/// <param name="o2"></param>
/// <param name="path"></param>
static JObject Merge(JObject o1, JObject o2, string path)
{
foreach (var o2Prop in o2)

View File

@@ -36,6 +36,9 @@ namespace PepperDash.Core
List<Action> _PreActivationActions;
List<Action> _PostActivationActions;
/// <summary>
///
/// </summary>
public static Device DefaultDevice { get { return _DefaultDevice; } }
static Device _DefaultDevice = new Device("Default", "Default");
@@ -51,6 +54,11 @@ namespace PepperDash.Core
}
/// <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;
@@ -63,6 +71,10 @@ namespace PepperDash.Core
// Config = config;
//}
/// <summary>
/// Adds a pre activation action
/// </summary>
/// <param name="act"></param>
public void AddPreActivationAction(Action act)
{
if (_PreActivationActions == null)
@@ -70,6 +82,10 @@ namespace PepperDash.Core
_PreActivationActions.Add(act);
}
/// <summary>
/// Adds a post activation action
/// </summary>
/// <param name="act"></param>
public void AddPostActivationAction(Action act)
{
if (_PostActivationActions == null)
@@ -77,6 +93,9 @@ namespace PepperDash.Core
_PostActivationActions.Add(act);
}
/// <summary>
/// Executes the preactivation actions
/// </summary>
public void PreActivate()
{
if (_PreActivationActions != null)
@@ -98,6 +117,9 @@ namespace PepperDash.Core
return result;
}
/// <summary>
/// Executes the postactivation actions
/// </summary>
public void PostActivate()
{
if (_PostActivationActions != null)

View File

@@ -8,6 +8,9 @@ using Newtonsoft.Json;
namespace PepperDash.Core
{
/// <summary>
/// Class to help with accessing values from the CrestronEthernetHelper class
/// </summary>
public class EthernetHelper
{
/// <summary>

View File

@@ -42,6 +42,7 @@ namespace PepperDash.Core.GenericRESTfulCommunications
/// <param name="requestType"></param>
/// <param name="username"></param>
/// <param name="password"></param>
/// <param name="contentType"></param>
public void SubmitRequest(string url, ushort port, ushort requestType, string contentType, string username, string password)
{
if (url.StartsWith("https:", StringComparison.OrdinalIgnoreCase))
@@ -64,6 +65,7 @@ namespace PepperDash.Core.GenericRESTfulCommunications
/// <param name="url"></param>
/// <param name="port"></param>
/// <param name="requestType"></param>
/// <param name="contentType"></param>
/// <param name="username"></param>
/// <param name="password"></param>
private void SubmitRequestHttp(string url, ushort port, ushort requestType, string contentType, string username, string password)
@@ -121,6 +123,7 @@ namespace PepperDash.Core.GenericRESTfulCommunications
/// <param name="url"></param>
/// <param name="port"></param>
/// <param name="requestType"></param>
/// <param name="contentType"></param>
/// <param name="username"></param>
/// <param name="password"></param>
private void SubmitRequestHttps(string url, ushort port, ushort requestType, string contentType, string username, string password)

View File

@@ -52,19 +52,55 @@ namespace PepperDash.Core.JsonStandardObjects
/// </summary>
public class ComParamsConfig
{
/// <summary>
///
/// </summary>
public int baudRate { get; set; }
/// <summary>
///
/// </summary>
public int dataBits { get; set; }
/// <summary>
///
/// </summary>
public int stopBits { get; set; }
/// <summary>
///
/// </summary>
public string parity { get; set; }
/// <summary>
///
/// </summary>
public string protocol { get; set; }
/// <summary>
///
/// </summary>
public string hardwareHandshake { get; set; }
/// <summary>
///
/// </summary>
public string softwareHandshake { get; set; }
/// <summary>
///
/// </summary>
public int pacing { get; set; }
// convert properties for simpl
/// <summary>
///
/// </summary>
public ushort simplBaudRate { get { return Convert.ToUInt16(baudRate); } }
/// <summary>
///
/// </summary>
public ushort simplDataBits { get { return Convert.ToUInt16(dataBits); } }
/// <summary>
///
/// </summary>
public ushort simplStopBits { get { return Convert.ToUInt16(stopBits); } }
/// <summary>
///
/// </summary>
public ushort simplPacing { get { return Convert.ToUInt16(pacing); } }
/// <summary>
@@ -81,16 +117,43 @@ namespace PepperDash.Core.JsonStandardObjects
/// </summary>
public class TcpSshPropertiesConfig
{
/// <summary>
///
/// </summary>
public string address { get; set; }
/// <summary>
///
/// </summary>
public int port { get; set; }
/// <summary>
///
/// </summary>
public string username { get; set; }
/// <summary>
///
/// </summary>
public string password { get; set; }
/// <summary>
///
/// </summary>
public bool autoReconnect { get; set; }
/// <summary>
///
/// </summary>
public int autoReconnectIntervalMs { get; set; }
// convert properties for simpl
/// <summary>
///
/// </summary>
public ushort simplPort { get { return Convert.ToUInt16(port); } }
/// <summary>
///
/// </summary>
public ushort simplAutoReconnect { get { return (ushort)(autoReconnect ? 1 : 0); } }
/// <summary>
///
/// </summary>
public ushort simplAutoReconnectIntervalMs { get { return Convert.ToUInt16(autoReconnectIntervalMs); } }
/// <summary>
@@ -107,13 +170,31 @@ namespace PepperDash.Core.JsonStandardObjects
/// </summary>
public class ControlConfig
{
/// <summary>
///
/// </summary>
public string method { get; set; }
/// <summary>
///
/// </summary>
public string controlPortDevKey { get; set; }
/// <summary>
///
/// </summary>
public int controlPortNumber { get; set; }
/// <summary>
///
/// </summary>
public ComParamsConfig comParams { get; set; }
/// <summary>
///
/// </summary>
public TcpSshPropertiesConfig tcpSshProperties { get; set; }
// convert properties for simpl
/// <summary>
///
/// </summary>
public ushort simplControlPortNumber { get { return Convert.ToUInt16(controlPortNumber); } }
/// <summary>
@@ -131,12 +212,27 @@ namespace PepperDash.Core.JsonStandardObjects
/// </summary>
public class PropertiesConfig
{
/// <summary>
///
/// </summary>
public int deviceId { get; set; }
/// <summary>
///
/// </summary>
public bool enabled { get; set; }
/// <summary>
///
/// </summary>
public ControlConfig control { get; set; }
// convert properties for simpl
/// <summary>
///
/// </summary>
public ushort simplDeviceId { get { return Convert.ToUInt16(deviceId); } }
/// <summary>
///
/// </summary>
public ushort simplEnabled { get { return (ushort)(enabled ? 1 : 0); } }
/// <summary>
@@ -153,6 +249,9 @@ namespace PepperDash.Core.JsonStandardObjects
/// </summary>
public class RootObject
{
/// <summary>
/// The collection of devices
/// </summary>
public List<DeviceConfig> devices { get; set; }
}
}

View File

@@ -11,17 +11,40 @@ namespace PepperDash.Core.JsonToSimpl
/// </summary>
public class JsonToSimplConstants
{
/// <summary>
///
/// </summary>
public const ushort BoolValueChange = 1;
/// <summary>
///
/// </summary>
public const ushort JsonIsValidBoolChange = 2;
/// <summary>
///
/// </summary>
public const ushort UshortValueChange = 101;
/// <summary>
///
/// </summary>
public const ushort StringValueChange = 201;
/// <summary>
///
/// </summary>
public const ushort FullPathToArrayChange = 202;
/// <summary>
///
/// </summary>
public const ushort ActualFilePathChange = 203;
// TODO: pdc-20: Added below constants for passing file path and filename back to S+
/// <summary>
///
/// </summary>
public const ushort FilenameResolvedChange = 204;
/// <summary>
///
/// </summary>
public const ushort FilePathResolvedChange = 205;
}
@@ -35,13 +58,33 @@ namespace PepperDash.Core.JsonToSimpl
/// </summary>
public class SPlusValueWrapper
{
/// <summary>
///
/// </summary>
public SPlusType ValueType { get; private set; }
/// <summary>
///
/// </summary>
public ushort Index { get; private set; }
/// <summary>
///
/// </summary>
public ushort BoolUShortValue { get; set; }
/// <summary>
///
/// </summary>
public string StringValue { get; set; }
public SPlusValueWrapper() { }
/// <summary>
///
/// </summary>
public SPlusValueWrapper() {}
/// <summary>
///
/// </summary>
/// <param name="type"></param>
/// <param name="index"></param>
public SPlusValueWrapper(SPlusType type, ushort index)
{
ValueType = type;
@@ -54,6 +97,17 @@ namespace PepperDash.Core.JsonToSimpl
/// </summary>
public enum SPlusType
{
Digital, Analog, String
/// <summary>
/// Digital
/// </summary>
Digital,
/// <summary>
/// Analog
/// </summary>
Analog,
/// <summary>
/// String
/// </summary>
String
}
}

View File

@@ -8,6 +8,9 @@ using Crestron.SimplSharp;
namespace PepperDash.Core.JsonToSimpl
{
/// <summary>
/// The global class to manage all the instances of JsonToSimplMaster
/// </summary>
public class J2SGlobal
{
static List<JsonToSimplMaster> Masters = new List<JsonToSimplMaster>();

View File

@@ -8,15 +8,24 @@ using Newtonsoft.Json.Linq;
namespace PepperDash.Core.JsonToSimpl
{
/// <summary>
/// Used to interact with an array of values with the S+ modules
/// </summary>
public class JsonToSimplArrayLookupChild : JsonToSimplChildObjectBase
{
/// <summary>
///
/// </summary>
public string SearchPropertyName { get; set; }
/// <summary>
///
/// </summary>
public string SearchPropertyValue { get; set; }
int ArrayIndex;
/// <summary>
/// For <2.4.1 array lookups
/// For gt2.4.1 array lookups
/// </summary>
/// <param name="file"></param>
/// <param name="key"></param>
@@ -70,6 +79,9 @@ namespace PepperDash.Core.JsonToSimpl
PathSuffix == null ? "" : PathSuffix);
}
/// <summary>
/// Process all values
/// </summary>
public override void ProcessAll()
{
if (FindInArray())

View File

@@ -8,13 +8,27 @@ using Newtonsoft.Json.Linq;
namespace PepperDash.Core.JsonToSimpl
{
/// <summary>
/// Base class for JSON objects
/// </summary>
public abstract class JsonToSimplChildObjectBase : IKeyed
{
/// <summary>
/// Notifies of bool change
/// </summary>
public event EventHandler<BoolChangeEventArgs> BoolChange;
/// <summary>
/// Notifies of ushort change
/// </summary>
public event EventHandler<UshrtChangeEventArgs> UShortChange;
/// <summary>
/// Notifies of string change
/// </summary>
public event EventHandler<StringChangeEventArgs> StringChange;
/// <summary>
/// Delegate to get all values
/// </summary>
public SPlusValuesDelegate GetAllValuesDelegate { get; set; }
/// <summary>
@@ -22,6 +36,9 @@ namespace PepperDash.Core.JsonToSimpl
/// </summary>
public SPlusValuesDelegate SetAllPathsDelegate { get; set; }
/// <summary>
/// Unique identifier for instance
/// </summary>
public string Key { get; protected set; }
/// <summary>
@@ -35,19 +52,33 @@ namespace PepperDash.Core.JsonToSimpl
/// </summary>
public string PathSuffix { get; protected set; }
/// <summary>
/// Indicates if the instance is linked to an object
/// </summary>
public bool LinkedToObject { get; protected set; }
/// <summary>
/// Reference to Master instance
/// </summary>
protected JsonToSimplMaster Master;
// The sent-in JPaths for the various types
/// <summary>
/// Paths to boolean values in JSON structure
/// </summary>
protected Dictionary<ushort, string> BoolPaths = new Dictionary<ushort, string>();
/// <summary>
/// Paths to numeric values in JSON structure
/// </summary>
protected Dictionary<ushort, string> UshortPaths = new Dictionary<ushort, string>();
/// <summary>
/// Paths to string values in JSON structure
/// </summary>
protected Dictionary<ushort, string> StringPaths = new Dictionary<ushort, string>();
/// <summary>
/// Call this before doing anything else
/// </summary>
/// <param name="file"></param>
/// <param name="masterUniqueId"></param>
/// <param name="key"></param>
/// <param name="pathPrefix"></param>
/// <param name="pathSuffix"></param>
@@ -64,6 +95,10 @@ namespace PepperDash.Core.JsonToSimpl
Debug.Console(1, "JSON Child [{0}] cannot link to master {1}", key, masterUniqueId);
}
/// <summary>
/// Sets the path prefix for the object
/// </summary>
/// <param name="pathPrefix"></param>
public void SetPathPrefix(string pathPrefix)
{
PathPrefix = pathPrefix;
@@ -240,29 +275,54 @@ namespace PepperDash.Core.JsonToSimpl
GetAllValuesDelegate();
}
/// <summary>
///
/// </summary>
/// <param name="key"></param>
/// <param name="theValue"></param>
public void USetBoolValue(ushort key, ushort theValue)
{
SetBoolValue(key, theValue == 1);
}
/// <summary>
///
/// </summary>
/// <param name="key"></param>
/// <param name="theValue"></param>
public void SetBoolValue(ushort key, bool theValue)
{
if (BoolPaths.ContainsKey(key))
SetValueOnMaster(BoolPaths[key], new JValue(theValue));
}
/// <summary>
///
/// </summary>
/// <param name="key"></param>
/// <param name="theValue"></param>
public void SetUShortValue(ushort key, ushort theValue)
{
if (UshortPaths.ContainsKey(key))
SetValueOnMaster(UshortPaths[key], new JValue(theValue));
}
/// <summary>
///
/// </summary>
/// <param name="key"></param>
/// <param name="theValue"></param>
public void SetStringValue(ushort key, string theValue)
{
if (StringPaths.ContainsKey(key))
SetValueOnMaster(StringPaths[key], new JValue(theValue));
}
/// <summary>
///
/// </summary>
/// <param name="keyPath"></param>
/// <param name="valueToSave"></param>
public void SetValueOnMaster(string keyPath, JValue valueToSave)
{
var path = GetFullPath(keyPath);
@@ -292,6 +352,12 @@ namespace PepperDash.Core.JsonToSimpl
// Helpers for events
//******************************************************************************************
/// <summary>
/// Event helper
/// </summary>
/// <param name="state"></param>
/// <param name="index"></param>
/// <param name="type"></param>
protected void OnBoolChange(bool state, ushort index, ushort type)
{
var handler = BoolChange;
@@ -304,6 +370,12 @@ namespace PepperDash.Core.JsonToSimpl
}
//******************************************************************************************
/// <summary>
/// Event helper
/// </summary>
/// <param name="state"></param>
/// <param name="index"></param>
/// <param name="type"></param>
protected void OnUShortChange(ushort state, ushort index, ushort type)
{
var handler = UShortChange;
@@ -315,6 +387,12 @@ namespace PepperDash.Core.JsonToSimpl
}
}
/// <summary>
/// Event helper
/// </summary>
/// <param name="value"></param>
/// <param name="index"></param>
/// <param name="type"></param>
protected void OnStringChange(string value, ushort index, ushort type)
{
var handler = StringChange;

View File

@@ -10,6 +10,9 @@ using Newtonsoft.Json.Linq;
namespace PepperDash.Core.JsonToSimpl
{
/// <summary>
/// Represents a JSON file that can be read and written to
/// </summary>
public class JsonToSimplFileMaster : JsonToSimplMaster
{
/// <summary>
@@ -17,10 +20,18 @@ namespace PepperDash.Core.JsonToSimpl
/// </summary>
public string Filepath { get; private set; }
/// <summary>
/// Filepath to the actual file that will be read (Portal or local)
/// </summary>
public string ActualFilePath { get; private set; }
// TODO: pdc-20: added to return filename back to SIMPL
/// <summary>
///
/// </summary>
public string Filename { get; private set; }
/// <summary>
///
/// </summary>
public string FilePathName { get; private set; }
/*****************************************************************************************/
@@ -102,11 +113,20 @@ namespace PepperDash.Core.JsonToSimpl
return;
}
}
/// <summary>
/// Sets the debug level
/// </summary>
/// <param name="level"></param>
public void setDebugLevel(int level)
{
Debug.SetDebugLevel(level);
}
/// <summary>
/// Saves the values to the file
/// </summary>
public override void Save()
{
// this code is duplicated in the other masters!!!!!!!!!!!!!

View File

@@ -10,9 +10,14 @@ using Newtonsoft.Json.Linq;
namespace PepperDash.Core.JsonToSimpl
{
/// <summary>
///
/// </summary>
public class JsonToSimplFixedPathObject : JsonToSimplChildObjectBase
{
/// <summary>
/// Constructor
/// </summary>
public JsonToSimplFixedPathObject()
{
this.LinkedToObject = true;

View File

@@ -1,17 +1,13 @@
using System;
//using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Crestron.SimplSharp;
using Crestron.SimplSharp.CrestronIO;
using Crestron.SimplSharp.Net.Http;
using Crestron.SimplSharp.Net.Https;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace PepperDash.Core.JsonToSimpl
{
/// <summary>
/// Generic Master
/// </summary>
public class JsonToSimplGenericMaster : JsonToSimplMaster
{
/*****************************************************************************************/
@@ -24,6 +20,9 @@ namespace PepperDash.Core.JsonToSimpl
// To prevent multiple same-file access
static object WriteLock = new object();
/// <summary>
/// Callback action for saving
/// </summary>
public Action<string> SaveCallback { get; set; }
/*****************************************************************************************/
@@ -117,37 +116,3 @@ namespace PepperDash.Core.JsonToSimpl
}
}
}
// JContainer jpart = JsonObject;
// // walk down the path and find where it goes
//#warning Does not handle arrays.
// foreach (var part in path.Split('.'))
// {
// var openPos = part.IndexOf('[');
// if (openPos > -1)
// {
// openPos++; // move to number
// var closePos = part.IndexOf(']');
// var arrayName = part.Substring(0, openPos - 1); // get the name
// var index = Convert.ToInt32(part.Substring(openPos, closePos - openPos));
// // Check if the array itself exists and add the item if so
// if (jpart[arrayName] != null)
// {
// var arrayObj = jpart[arrayName] as JArray;
// var item = arrayObj[index];
// if (item == null)
// arrayObj.Add(new JObject());
// }
// Debug.Console(0, "IGNORING MISSING ARRAY VALUE FOR NOW");
// continue;
// }
// // Build the
// if (jpart[part] == null)
// jpart.Add(new JProperty(part, new JObject()));
// jpart = jpart[part] as JContainer;
// }
// jpart.Replace(UnsavedValues[path]);

View File

@@ -10,15 +10,27 @@ using Newtonsoft.Json.Linq;
namespace PepperDash.Core.JsonToSimpl
{
/// <summary>
/// Abstract base class for JsonToSimpl interactions
/// </summary>
public abstract class JsonToSimplMaster : IKeyed
{
/*****************************************************************************************/
/** Events **/
/// <summary>
/// Notifies of bool change
/// </summary>
public event EventHandler<BoolChangeEventArgs> BoolChange;
/// <summary>
/// Notifies of ushort change
/// </summary>
public event EventHandler<UshrtChangeEventArgs> UshrtChange;
/// <summary>
/// Notifies of string change
/// </summary>
public event EventHandler<StringChangeEventArgs> StringChange;
/// <summary>
/// A collection of associated child modules
/// </summary>
protected List<JsonToSimplChildObjectBase> Children = new List<JsonToSimplChildObjectBase>();
/*****************************************************************************************/
@@ -28,6 +40,9 @@ namespace PepperDash.Core.JsonToSimpl
/// </summary>
public string Key { get { return UniqueID; } }
/// <summary>
/// A unique ID
/// </summary>
public string UniqueID { get; protected set; }
/// <summary>
@@ -70,6 +85,9 @@ namespace PepperDash.Core.JsonToSimpl
}
}
/// <summary>
///
/// </summary>
public JObject JsonObject { get; protected set; }
/*****************************************************************************************/
@@ -126,12 +144,22 @@ namespace PepperDash.Core.JsonToSimpl
//Debug.Console(0, "Master[{0}] Unsaved size={1}", UniqueID, UnsavedValues.Count);
}
/// <summary>
/// Saves the file
/// </summary>
public abstract void Save();
//******************************************************************************************
/// <summary>
///
/// </summary>
public static class JsonFixes
{
/// <summary>
/// Deserializes a string into a JObject
/// </summary>
/// <param name="json"></param>
/// <returns></returns>
public static JObject ParseObject(string json)
{
using (var reader = new JsonTextReader(new Crestron.SimplSharp.CrestronIO.StringReader(json)))
@@ -144,6 +172,11 @@ namespace PepperDash.Core.JsonToSimpl
}
}
/// <summary>
/// Deserializes a string into a JArray
/// </summary>
/// <param name="json"></param>
/// <returns></returns>
public static JArray ParseArray(string json)
{
using (var reader = new JsonTextReader(new Crestron.SimplSharp.CrestronIO.StringReader(json)))
@@ -157,8 +190,12 @@ namespace PepperDash.Core.JsonToSimpl
}
}
// Helpers for events
//******************************************************************************************
/// <summary>
/// Helper event
/// </summary>
/// <param name="state"></param>
/// <param name="index"></param>
/// <param name="type"></param>
protected void OnBoolChange(bool state, ushort index, ushort type)
{
if (BoolChange != null)
@@ -169,7 +206,12 @@ namespace PepperDash.Core.JsonToSimpl
}
}
//******************************************************************************************
/// <summary>
/// Helper event
/// </summary>
/// <param name="state"></param>
/// <param name="index"></param>
/// <param name="type"></param>
protected void OnUshrtChange(ushort state, ushort index, ushort type)
{
if (UshrtChange != null)
@@ -180,6 +222,12 @@ namespace PepperDash.Core.JsonToSimpl
}
}
/// <summary>
/// Helper event
/// </summary>
/// <param name="value"></param>
/// <param name="index"></param>
/// <param name="type"></param>
protected void OnStringChange(string value, ushort index, ushort type)
{
if (StringChange != null)

View File

@@ -12,6 +12,9 @@ using PepperDash.Core.Config;
namespace PepperDash.Core.JsonToSimpl
{
/// <summary>
/// Portal File Master
/// </summary>
public class JsonToSimplPortalFileMaster : JsonToSimplMaster
{
/// <summary>
@@ -19,6 +22,9 @@ namespace PepperDash.Core.JsonToSimpl
/// </summary>
public string PortalFilepath { get; private set; }
/// <summary>
/// File path of the actual file being read (Portal or local)
/// </summary>
public string ActualFilePath { get; private set; }
/*****************************************************************************************/
@@ -166,38 +172,6 @@ namespace PepperDash.Core.JsonToSimpl
//http://stackoverflow.com/questions/17455052/how-to-set-the-value-of-a-json-path-using-json-net
Debug.Console(1, "JSON Master[{0}] Cannot write value onto missing property: '{1}'", UniqueID, path);
// JContainer jpart = JsonObject;
// // walk down the path and find where it goes
//#warning Does not handle arrays.
// foreach (var part in path.Split('.'))
// {
// var openPos = part.IndexOf('[');
// if (openPos > -1)
// {
// openPos++; // move to number
// var closePos = part.IndexOf(']');
// var arrayName = part.Substring(0, openPos - 1); // get the name
// var index = Convert.ToInt32(part.Substring(openPos, closePos - openPos));
// // Check if the array itself exists and add the item if so
// if (jpart[arrayName] != null)
// {
// var arrayObj = jpart[arrayName] as JArray;
// var item = arrayObj[index];
// if (item == null)
// arrayObj.Add(new JObject());
// }
// Debug.Console(0, "IGNORING MISSING ARRAY VALUE FOR NOW");
// continue;
// }
// // Build the
// if (jpart[part] == null)
// jpart.Add(new JProperty(part, new JObject()));
// jpart = jpart[part] as JContainer;
// }
// jpart.Replace(UnsavedValues[path]);
}
}
using (StreamWriter sw = new StreamWriter(ActualFilePath))

View File

@@ -561,9 +561,27 @@ namespace PepperDash.Core
Directory.Delete(@"\nvram\debugSettings");
}
/// <summary>
/// Error level to for message to be logged at
/// </summary>
public enum ErrorLogLevel
{
Error, Warning, Notice, None
/// <summary>
/// Error
/// </summary>
Error,
/// <summary>
/// Warning
/// </summary>
Warning,
/// <summary>
/// Notice
/// </summary>
Notice,
/// <summary>
/// None
/// </summary>
None,
}
}
}

View File

@@ -11,6 +11,9 @@ using PepperDash.Core.DebugThings;
namespace PepperDash.Core
{
/// <summary>
/// Represents a debugging context
/// </summary>
public class DebugContext
{
/// <summary>
@@ -149,6 +152,14 @@ namespace PepperDash.Core
Console(level, "[{0}] {1}", dev.Key, string.Format(format, items));
}
/// <summary>
///
/// </summary>
/// <param name="level"></param>
/// <param name="dev"></param>
/// <param name="errorLogLevel"></param>
/// <param name="format"></param>
/// <param name="items"></param>
public void Console(uint level, IKeyed dev, Debug.ErrorLogLevel errorLogLevel,
string format, params object[] items)
{
@@ -160,6 +171,13 @@ namespace PepperDash.Core
}
}
/// <summary>
///
/// </summary>
/// <param name="level"></param>
/// <param name="errorLogLevel"></param>
/// <param name="format"></param>
/// <param name="items"></param>
public void Console(uint level, Debug.ErrorLogLevel errorLogLevel,
string format, params object[] items)
{
@@ -171,6 +189,11 @@ namespace PepperDash.Core
}
}
/// <summary>
///
/// </summary>
/// <param name="errorLogLevel"></param>
/// <param name="str"></param>
public void LogError(Debug.ErrorLogLevel errorLogLevel, string str)
{
string msg = string.Format("App {0}:{1}", InitialParametersClass.ApplicationNumber, str);
@@ -248,8 +271,14 @@ namespace PepperDash.Core
}
}
/// <summary>
///
/// </summary>
public class DebugContextSaveData
{
/// <summary>
///
/// </summary>
public int Level { get; set; }
}
}

View File

@@ -40,7 +40,6 @@ namespace PepperDash.Core.DebugThings
/// </summary>
/// <param name="contextKey"></param>
/// <param name="level"></param>
/// <returns>True if level is between 0 & 2 and the conte </returns>
public void SetLevel(string contextKey, int level)
{
if (level < 0 || level > 2)

View File

@@ -6,6 +6,9 @@ using Crestron.SimplSharp;
namespace PepperDash.Core.PasswordManagement
{
/// <summary>
/// A class to allow user interaction with the PasswordManager
/// </summary>
public class PasswordClient
{
/// <summary>

View File

@@ -10,6 +10,9 @@ using PepperDash.Core.JsonStandardObjects;
namespace PepperDash.Core.PasswordManagement
{
/// <summary>
/// Allows passwords to be stored and managed
/// </summary>
public class PasswordManager
{
/// <summary>
@@ -193,7 +196,7 @@ namespace PepperDash.Core.PasswordManagement
/// <summary>
/// Protected ushort change event handler
/// </summary>
/// <param name="state"></param>
/// <param name="value"></param>
/// <param name="index"></param>
/// <param name="type"></param>
protected void OnUshrtChange(ushort value, ushort index, ushort type)

View File

@@ -11,21 +11,60 @@ namespace PepperDash.Core.SystemInfo
/// </summary>
public class SystemInfoConstants
{
/// <summary>
///
/// </summary>
public const ushort BoolValueChange = 1;
/// <summary>
///
/// </summary>
public const ushort CompleteBoolChange = 2;
/// <summary>
///
/// </summary>
public const ushort BusyBoolChange = 3;
/// <summary>
///
/// </summary>
public const ushort UshortValueChange = 101;
/// <summary>
///
/// </summary>
public const ushort StringValueChange = 201;
/// <summary>
///
/// </summary>
public const ushort ConsoleResponseChange = 202;
/// <summary>
///
/// </summary>
public const ushort ProcessorUptimeChange = 203;
/// <summary>
///
/// </summary>
public const ushort ProgramUptimeChange = 204;
/// <summary>
///
/// </summary>
public const ushort ObjectChange = 301;
/// <summary>
///
/// </summary>
public const ushort ProcessorConfigChange = 302;
/// <summary>
///
/// </summary>
public const ushort EthernetConfigChange = 303;
/// <summary>
///
/// </summary>
public const ushort ControlSubnetConfigChange = 304;
/// <summary>
///
/// </summary>
public const ushort ProgramConfigChange = 305;
}
@@ -34,8 +73,17 @@ namespace PepperDash.Core.SystemInfo
/// </summary>
public class ProcessorChangeEventArgs : EventArgs
{
/// <summary>
///
/// </summary>
public ProcessorInfo Processor { get; set; }
/// <summary>
///
/// </summary>
public ushort Type { get; set; }
/// <summary>
///
/// </summary>
public ushort Index { get; set; }
/// <summary>
@@ -71,8 +119,17 @@ namespace PepperDash.Core.SystemInfo
/// </summary>
public class EthernetChangeEventArgs : EventArgs
{
/// <summary>
///
/// </summary>
public EthernetInfo Adapter { get; set; }
/// <summary>
///
/// </summary>
public ushort Type { get; set; }
/// <summary>
///
/// </summary>
public ushort Index { get; set; }
/// <summary>
@@ -86,7 +143,7 @@ namespace PepperDash.Core.SystemInfo
/// <summary>
/// Constructor overload
/// </summary>
/// <param name="Ethernet"></param>
/// <param name="ethernet"></param>
/// <param name="type"></param>
public EthernetChangeEventArgs(EthernetInfo ethernet, ushort type)
{
@@ -97,8 +154,9 @@ namespace PepperDash.Core.SystemInfo
/// <summary>
/// Constructor overload
/// </summary>
/// <param name="Ethernet"></param>
/// <param name="ethernet"></param>
/// <param name="type"></param>
/// <param name="index"></param>
public EthernetChangeEventArgs(EthernetInfo ethernet, ushort type, ushort index)
{
Adapter = ethernet;
@@ -112,8 +170,17 @@ namespace PepperDash.Core.SystemInfo
/// </summary>
public class ControlSubnetChangeEventArgs : EventArgs
{
/// <summary>
///
/// </summary>
public ControlSubnetInfo Adapter { get; set; }
/// <summary>
///
/// </summary>
public ushort Type { get; set; }
/// <summary>
///
/// </summary>
public ushort Index { get; set; }
/// <summary>
@@ -149,8 +216,17 @@ namespace PepperDash.Core.SystemInfo
/// </summary>
public class ProgramChangeEventArgs : EventArgs
{
/// <summary>
///
/// </summary>
public ProgramInfo Program { get; set; }
/// <summary>
///
/// </summary>
public ushort Type { get; set; }
/// <summary>
///
/// </summary>
public ushort Index { get; set; }
/// <summary>
@@ -164,7 +240,7 @@ namespace PepperDash.Core.SystemInfo
/// <summary>
/// Constructor overload
/// </summary>
/// <param name="Program"></param>
/// <param name="program"></param>
/// <param name="type"></param>
public ProgramChangeEventArgs(ProgramInfo program, ushort type)
{
@@ -175,8 +251,9 @@ namespace PepperDash.Core.SystemInfo
/// <summary>
/// Constructor overload
/// </summary>
/// <param name="Program"></param>
/// <param name="program"></param>
/// <param name="type"></param>
/// <param name="index"></param>
public ProgramChangeEventArgs(ProgramInfo program, ushort type, ushort index)
{
Program = program;

View File

@@ -11,15 +11,45 @@ namespace PepperDash.Core.SystemInfo
/// </summary>
public class ProcessorInfo
{
/// <summary>
///
/// </summary>
public string Model { get; set; }
/// <summary>
///
/// </summary>
public string SerialNumber { get; set; }
/// <summary>
///
/// </summary>
public string Firmware { get; set; }
/// <summary>
///
/// </summary>
public string FirmwareDate { get; set; }
/// <summary>
///
/// </summary>
public string OsVersion { get; set; }
/// <summary>
///
/// </summary>
public string RuntimeEnvironment { get; set; }
/// <summary>
///
/// </summary>
public string DevicePlatform { get; set; }
/// <summary>
///
/// </summary>
public string ModuleDirectory { get; set; }
/// <summary>
///
/// </summary>
public string LocalTimeZone { get; set; }
/// <summary>
///
/// </summary>
public string ProgramIdTag { get; set; }
/// <summary>
@@ -36,15 +66,45 @@ namespace PepperDash.Core.SystemInfo
/// </summary>
public class EthernetInfo
{
/// <summary>
///
/// </summary>
public ushort DhcpIsOn { get; set; }
/// <summary>
///
/// </summary>
public string Hostname { get; set; }
/// <summary>
///
/// </summary>
public string MacAddress { get; set; }
/// <summary>
///
/// </summary>
public string IpAddress { get; set; }
/// <summary>
///
/// </summary>
public string Subnet { get; set; }
/// <summary>
///
/// </summary>
public string Gateway { get; set; }
/// <summary>
///
/// </summary>
public string Dns1 { get; set; }
/// <summary>
///
/// </summary>
public string Dns2 { get; set; }
/// <summary>
///
/// </summary>
public string Dns3 { get; set; }
/// <summary>
///
/// </summary>
public string Domain { get; set; }
/// <summary>
@@ -61,11 +121,29 @@ namespace PepperDash.Core.SystemInfo
/// </summary>
public class ControlSubnetInfo
{
/// <summary>
///
/// </summary>
public ushort Enabled { get; set; }
/// <summary>
///
/// </summary>
public ushort IsInAutomaticMode { get; set; }
/// <summary>
///
/// </summary>
public string MacAddress { get; set; }
/// <summary>
///
/// </summary>
public string IpAddress { get; set; }
/// <summary>
///
/// </summary>
public string Subnet { get; set; }
/// <summary>
///
/// </summary>
public string RouterPrefix { get; set; }
/// <summary>
@@ -82,13 +160,37 @@ namespace PepperDash.Core.SystemInfo
/// </summary>
public class ProgramInfo
{
/// <summary>
///
/// </summary>
public string Name { get; set; }
/// <summary>
///
/// </summary>
public string Header { get; set; }
/// <summary>
///
/// </summary>
public string System { get; set; }
/// <summary>
///
/// </summary>
public string ProgramIdTag { get; set; }
/// <summary>
///
/// </summary>
public string CompileTime { get; set; }
/// <summary>
///
/// </summary>
public string Database { get; set; }
/// <summary>
///
/// </summary>
public string Environment { get; set; }
/// <summary>
///
/// </summary>
public string Programmer { get; set; }
/// <summary>

View File

@@ -11,12 +11,30 @@ namespace PepperDash.Core.SystemInfo
/// </summary>
public class SystemInfoToSimpl
{
/// <summary>
/// Notifies of bool change
/// </summary>
public event EventHandler<BoolChangeEventArgs> BoolChange;
/// <summary>
/// Notifies of string change
/// </summary>
public event EventHandler<StringChangeEventArgs> StringChange;
/// <summary>
/// Notifies of processor change
/// </summary>
public event EventHandler<ProcessorChangeEventArgs> ProcessorChange;
/// <summary>
/// Notifies of ethernet change
/// </summary>
public event EventHandler<EthernetChangeEventArgs> EthernetChange;
/// <summary>
/// Notifies of control subnet change
/// </summary>
public event EventHandler<ControlSubnetChangeEventArgs> ControlSubnetChange;
/// <summary>
/// Notifies of program change
/// </summary>
public event EventHandler<ProgramChangeEventArgs> ProgramChange;
/// <summary>
@@ -309,10 +327,10 @@ namespace PepperDash.Core.SystemInfo
/// <summary>
/// private method to parse console messages
/// </summary>
/// <param name="response"></param>
/// <param name="data"></param>
/// <param name="line"></param>
/// <param name="start"></param>
/// <param name="end"></param>
/// <param name="dataStart"></param>
/// <param name="dataEnd"></param>
/// <returns></returns>
private string ParseConsoleResponse(string data, string line, string dataStart, string dataEnd)
{

View File

@@ -9,20 +9,44 @@ using Newtonsoft.Json;
namespace PepperDash.Core.WebApi.Presets
{
/// <summary>
/// Represents a preset
/// </summary>
public class Preset
{
/// <summary>
/// ID of preset
/// </summary>
public int Id { get; set; }
/// <summary>
/// User ID
/// </summary>
public int UserId { get; set; }
/// <summary>
/// Room Type ID
/// </summary>
public int RoomTypeId { get; set; }
/// <summary>
/// Preset Name
/// </summary>
public string PresetName { get; set; }
/// <summary>
/// Preset Number
/// </summary>
public int PresetNumber { get; set; }
/// <summary>
/// Preset Data
/// </summary>
public string Data { get; set; }
/// <summary>
/// Constructor
/// </summary>
public Preset()
{
PresetName = "";
@@ -42,10 +66,13 @@ namespace PepperDash.Core.WebApi.Presets
public bool LookupSuccess { get; private set; }
/// <summary>
/// S+ helper for stupid S+
/// S+ helper
/// </summary>
public ushort ULookupSuccess { get { return (ushort)(LookupSuccess ? 1 : 0); } }
/// <summary>
/// The preset
/// </summary>
public Preset Preset { get; private set; }
/// <summary>
@@ -53,6 +80,11 @@ namespace PepperDash.Core.WebApi.Presets
/// </summary>
public PresetReceivedEventArgs() { }
/// <summary>
/// Constructor
/// </summary>
/// <param name="preset"></param>
/// <param name="success"></param>
public PresetReceivedEventArgs(Preset preset, bool success)
{
LookupSuccess = success;

View File

@@ -11,12 +11,24 @@ namespace PepperDash.Core.WebApi.Presets
/// </summary>
public class User
{
/// <summary>
///
/// </summary>
public int Id { get; set; }
/// <summary>
///
/// </summary>
public string ExternalId { get; set; }
/// <summary>
///
/// </summary>
public string FirstName { get; set; }
/// <summary>
///
/// </summary>
public string LastName { get; set; }
}
@@ -36,6 +48,9 @@ namespace PepperDash.Core.WebApi.Presets
/// </summary>
public ushort ULookupSuccess { get { return (ushort)(LookupSuccess ? 1 : 0); } }
/// <summary>
///
/// </summary>
public User User { get; private set; }
/// <summary>
@@ -43,6 +58,11 @@ namespace PepperDash.Core.WebApi.Presets
/// </summary>
public UserReceivedEventArgs() { }
/// <summary>
/// Constructor
/// </summary>
/// <param name="user"></param>
/// <param name="success"></param>
public UserReceivedEventArgs(User user, bool success)
{
LookupSuccess = success;
@@ -55,10 +75,19 @@ namespace PepperDash.Core.WebApi.Presets
/// </summary>
public class UserAndRoomMessage
{
/// <summary>
///
/// </summary>
public int UserId { get; set; }
/// <summary>
///
/// </summary>
public int RoomTypeId { get; set; }
/// <summary>
///
/// </summary>
public int PresetNumber { get; set; }
}
}

View File

@@ -14,12 +14,24 @@ using PepperDash.Core.JsonToSimpl;
namespace PepperDash.Core.WebApi.Presets
{
/// <summary>
/// Passcode client for the WebApi
/// </summary>
public class WebApiPasscodeClient : IKeyed
{
/// <summary>
/// Notifies when user received
/// </summary>
public event EventHandler<UserReceivedEventArgs> UserReceived;
/// <summary>
/// Notifies when Preset received
/// </summary>
public event EventHandler<PresetReceivedEventArgs> PresetReceived;
/// <summary>
/// Unique identifier for this instance
/// </summary>
public string Key { get; private set; }
//string JsonMasterKey;
@@ -46,6 +58,13 @@ namespace PepperDash.Core.WebApi.Presets
{
}
/// <summary>
/// Initializes the instance
/// </summary>
/// <param name="key"></param>
/// <param name="jsonMasterKey"></param>
/// <param name="urlBase"></param>
/// <param name="defaultPresetJsonFilePath"></param>
public void Initialize(string key, string jsonMasterKey, string urlBase, string defaultPresetJsonFilePath)
{
Key = key;
@@ -58,6 +77,10 @@ namespace PepperDash.Core.WebApi.Presets
J2SMaster.Initialize(jsonMasterKey);
}
/// <summary>
/// Gets the user for a passcode
/// </summary>
/// <param name="passcode"></param>
public void GetUserForPasscode(string passcode)
{
// Bullshit duplicate code here... These two cases should be the same

View File

@@ -8,7 +8,18 @@ namespace PepperDash.Core.Intersystem.Serialization
/// </summary>
public interface IXSigSerialization
{
/// <summary>
/// Serialize the sig data
/// </summary>
/// <returns></returns>
IEnumerable<XSigToken> Serialize();
/// <summary>
/// Deserialize the sig data
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="tokens"></param>
/// <returns></returns>
T Deserialize<T>(IEnumerable<XSigToken> tokens) where T : class, IXSigSerialization;
}
}

View File

@@ -2,10 +2,27 @@ using System;
namespace PepperDash.Core.Intersystem.Serialization
{
/// <summary>
/// Class to handle this specific exception type
/// </summary>
public class XSigSerializationException : Exception
{
/// <summary>
/// default constructor
/// </summary>
public XSigSerializationException() { }
/// <summary>
/// constructor with message
/// </summary>
/// <param name="message"></param>
public XSigSerializationException(string message) : base(message) { }
/// <summary>
/// constructor with message and innner exception
/// </summary>
/// <param name="message"></param>
/// <param name="inner"></param>
public XSigSerializationException(string message, Exception inner) : base(message, inner) { }
}
}

View File

@@ -2,10 +2,18 @@ using System;
namespace PepperDash.Core.Intersystem.Tokens
{
/// <summary>
/// Represents an XSigAnalogToken
/// </summary>
public sealed class XSigAnalogToken : XSigToken, IFormattable
{
private readonly ushort _value;
/// <summary>
/// Constructor
/// </summary>
/// <param name="index"></param>
/// <param name="value"></param>
public XSigAnalogToken(int index, ushort value)
: base(index)
{
@@ -16,16 +24,26 @@ namespace PepperDash.Core.Intersystem.Tokens
_value = value;
}
/// <summary>
///
/// </summary>
public ushort Value
{
get { return _value; }
}
/// <summary>
///
/// </summary>
public override XSigTokenType TokenType
{
get { return XSigTokenType.Analog; }
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public override byte[] GetBytes()
{
return new[] {
@@ -36,17 +54,32 @@ namespace PepperDash.Core.Intersystem.Tokens
};
}
/// <summary>
///
/// </summary>
/// <param name="offset"></param>
/// <returns></returns>
public override XSigToken GetTokenWithOffset(int offset)
{
if (offset == 0) return this;
return new XSigAnalogToken(Index + offset, Value);
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public override string ToString()
{
return Index + " = 0x" + Value.ToString("X4");
}
/// <summary>
///
/// </summary>
/// <param name="format"></param>
/// <param name="formatProvider"></param>
/// <returns></returns>
public string ToString(string format, IFormatProvider formatProvider)
{
return Value.ToString(format, formatProvider);

View File

@@ -2,10 +2,18 @@ using System;
namespace PepperDash.Core.Intersystem.Tokens
{
/// <summary>
/// Represents an XSigDigitalToken
/// </summary>
public sealed class XSigDigitalToken : XSigToken
{
private readonly bool _value;
/// <summary>
///
/// </summary>
/// <param name="index"></param>
/// <param name="value"></param>
public XSigDigitalToken(int index, bool value)
: base(index)
{
@@ -16,16 +24,26 @@ namespace PepperDash.Core.Intersystem.Tokens
_value = value;
}
/// <summary>
///
/// </summary>
public bool Value
{
get { return _value; }
}
/// <summary>
///
/// </summary>
public override XSigTokenType TokenType
{
get { return XSigTokenType.Digital; }
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public override byte[] GetBytes()
{
return new[] {
@@ -34,17 +52,31 @@ namespace PepperDash.Core.Intersystem.Tokens
};
}
/// <summary>
///
/// </summary>
/// <param name="offset"></param>
/// <returns></returns>
public override XSigToken GetTokenWithOffset(int offset)
{
if (offset == 0) return this;
return new XSigDigitalToken(Index + offset, Value);
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public override string ToString()
{
return Index + " = " + (Value ? "High" : "Low");
}
/// <summary>
///
/// </summary>
/// <param name="formatProvider"></param>
/// <returns></returns>
public string ToString(IFormatProvider formatProvider)
{
return Value.ToString(formatProvider);

View File

@@ -3,10 +3,18 @@ using System.Text;
namespace PepperDash.Core.Intersystem.Tokens
{
/// <summary>
/// Represents an XSigSerialToken
/// </summary>
public sealed class XSigSerialToken : XSigToken
{
private readonly string _value;
/// <summary>
/// Constructor
/// </summary>
/// <param name="index"></param>
/// <param name="value"></param>
public XSigSerialToken(int index, string value)
: base(index)
{
@@ -17,16 +25,26 @@ namespace PepperDash.Core.Intersystem.Tokens
_value = value;
}
/// <summary>
///
/// </summary>
public string Value
{
get { return _value; }
}
/// <summary>
///
/// </summary>
public override XSigTokenType TokenType
{
get { return XSigTokenType.Serial; }
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public override byte[] GetBytes()
{
var serialBytes = String.IsNullOrEmpty(Value) ? new byte[0] : Encoding.GetEncoding(28591).GetBytes(Value);
@@ -40,12 +58,21 @@ namespace PepperDash.Core.Intersystem.Tokens
return xsig;
}
/// <summary>
///
/// </summary>
/// <param name="offset"></param>
/// <returns></returns>
public override XSigToken GetTokenWithOffset(int offset)
{
if (offset == 0) return this;
return new XSigSerialToken(Index + offset, Value);
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public override string ToString()
{
return Index + " = \"" + Value + "\"";