diff --git a/Pepperdash Core/Pepperdash Core/Comm/CommunicationGather.cs b/Pepperdash Core/Pepperdash Core/Comm/CommunicationGather.cs index 5c4ed71..f71a496 100644 --- a/Pepperdash Core/Pepperdash Core/Comm/CommunicationGather.cs +++ b/Pepperdash Core/Pepperdash Core/Comm/CommunicationGather.cs @@ -51,7 +51,7 @@ namespace PepperDash.Core string[] StringDelimiters; /// - /// Fires up a gather, given a IBasicCommunicaion port and char for de + /// Constructor for using a char delimiter /// /// /// @@ -63,7 +63,7 @@ namespace PepperDash.Core } /// - /// + /// Constructor for using a single string delimiter /// /// /// @@ -72,6 +72,11 @@ namespace PepperDash.Core { } + /// + /// Constructor for using an array of string delimiters + /// + /// + /// public CommunicationGather(ICommunicationReceiver port, string[] delimiters) { Port = port; diff --git a/Pepperdash Core/Pepperdash Core/Comm/CommunicationStreamDebugging.cs b/Pepperdash Core/Pepperdash Core/Comm/CommunicationStreamDebugging.cs index 3afbf01..0a38d82 100644 --- a/Pepperdash Core/Pepperdash Core/Comm/CommunicationStreamDebugging.cs +++ b/Pepperdash Core/Pepperdash Core/Comm/CommunicationStreamDebugging.cs @@ -22,6 +22,9 @@ namespace PepperDash.Core /// private CTimer DebugExpiryPeriod; + /// + /// The current debug setting + /// public eStreamDebuggingSetting DebugSetting { get; private set; } private uint _DebugTimeoutInMs; @@ -38,11 +41,20 @@ namespace PepperDash.Core } } + /// + /// Indicates that receive stream debugging is enabled + /// public bool RxStreamDebuggingIsEnabled{ get; private set; } + /// + /// Indicates that transmit stream debugging is enabled + /// public bool TxStreamDebuggingIsEnabled { get; private set; } - + /// + /// Constructor + /// + /// public CommunicationStreamDebugging(string parentDeviceKey) { ParentDeviceKey = parentDeviceKey; @@ -125,9 +137,21 @@ namespace PepperDash.Core [Flags] public enum eStreamDebuggingSetting { + /// + /// Debug off + /// Off = 0, + /// + /// Debug received data + /// Rx = 1, + /// + /// Debug transmitted data + /// Tx = 2, + /// + /// Debug both received and transmitted data + /// Both = Rx | Tx } @@ -137,8 +161,17 @@ namespace PepperDash.Core [Flags] public enum eStreamDebuggingDataTypeSettings { + /// + /// Debug data in byte format + /// Bytes = 0, + /// + /// Debug data in text format + /// Text = 1, + /// + /// Debug data in both byte and text formats + /// Both = Bytes | Text, } } diff --git a/Pepperdash Core/Pepperdash Core/Comm/ControlPropertiesConfig.cs b/Pepperdash Core/Pepperdash Core/Comm/ControlPropertiesConfig.cs index c4e6a07..651dacd 100644 --- a/Pepperdash Core/Pepperdash Core/Comm/ControlPropertiesConfig.cs +++ b/Pepperdash Core/Pepperdash Core/Comm/ControlPropertiesConfig.cs @@ -8,34 +8,56 @@ using Newtonsoft.Json; namespace PepperDash.Core { /// - /// + /// Config properties that indicate how to communicate with a device for control /// public class ControlPropertiesConfig { + /// + /// The method of control + /// public eControlMethod Method { get; set; } + /// + /// The key of the device that contains the control port + /// public string ControlPortDevKey { get; set; } + /// + /// The number of the control port on the device specified by ControlPortDevKey + /// [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] // In case "null" is present in config on this value public uint ControlPortNumber { get; set; } + /// + /// The name of the control port on the device specified by ControlPortDevKey + /// [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] // In case "null" is present in config on this value public string ControlPortName { get; set; } + /// + /// Properties for ethernet based communications + /// public TcpSshPropertiesConfig TcpSshProperties { get; set; } + /// + /// The filename and path for the IR file + /// public string IrFile { get; set; } - //public ComPortConfig ComParams { get; set; } - - //[JsonConverter(typeof(ComSpecJsonConverter))] - //public ComPort.ComPortSpec ComParams { get; set; } - + /// + /// The IpId of a Crestron device + /// public string IpId { get; set; } + /// + /// Readonly uint representation of the IpId + /// [JsonIgnore] public uint IpIdInt { get { return Convert.ToUInt32(IpId, 16); } } + /// + /// Char indicating end of line + /// public char EndOfLineChar { get; set; } /// @@ -43,8 +65,14 @@ namespace PepperDash.Core /// public string EndOfLineString { get; set; } + /// + /// Indicates + /// public string DeviceReadyResponsePattern { get; set; } + /// + /// Constructor + /// public ControlPropertiesConfig() { EndOfLineString = CrestronEnvironment.NewLine; diff --git a/Pepperdash Core/Pepperdash Core/Comm/EventArgs.cs b/Pepperdash Core/Pepperdash Core/Comm/EventArgs.cs index ecf6db8..95dfa99 100644 --- a/Pepperdash Core/Pepperdash Core/Comm/EventArgs.cs +++ b/Pepperdash Core/Pepperdash Core/Comm/EventArgs.cs @@ -18,49 +18,108 @@ using Crestron.SimplSharp.CrestronSockets; namespace PepperDash.Core { + /// + /// Delegate for notifying of socket status changes + /// + /// public delegate void GenericSocketStatusChangeEventDelegate(ISocketStatus client); + + /// + /// EventArgs class for socket status changes + /// public class GenericSocketStatusChageEventArgs : EventArgs { + /// + /// + /// public ISocketStatus Client { get; private set; } + /// + /// + /// + /// public GenericSocketStatusChageEventArgs(ISocketStatus client) { Client = client; } /// - /// Stupid S+ Constructor + /// S+ Constructor /// public GenericSocketStatusChageEventArgs() { } } + /// + /// Delegate for notifying of TCP Server state changes + /// + /// public delegate void GenericTcpServerStateChangedEventDelegate(ServerState state); + + /// + /// EventArgs class for TCP Server state changes + /// public class GenericTcpServerStateChangedEventArgs : EventArgs { + /// + /// + /// public ServerState State { get; private set; } + /// + /// + /// + /// public GenericTcpServerStateChangedEventArgs(ServerState state) { State = state; } /// - /// Stupid S+ Constructor + /// S+ Constructor /// public GenericTcpServerStateChangedEventArgs() { } } + /// + /// Delegate for TCP Server socket status changes + /// + /// + /// + /// public delegate void GenericTcpServerSocketStatusChangeEventDelegate(object socket, uint clientIndex, SocketStatus clientStatus); + /// + /// EventArgs for TCP server socket status changes + /// public class GenericTcpServerSocketStatusChangeEventArgs : EventArgs { + /// + /// + /// public object Socket { get; private set; } + /// + /// + /// public uint ReceivedFromClientIndex { get; private set; } + /// + /// + /// public SocketStatus ClientStatus { get; set; } + /// + /// + /// + /// + /// public GenericTcpServerSocketStatusChangeEventArgs(object socket, SocketStatus clientStatus) { Socket = socket; ClientStatus = clientStatus; } + /// + /// + /// + /// + /// + /// public GenericTcpServerSocketStatusChangeEventArgs(object socket, uint clientIndex, SocketStatus clientStatus) { Socket = socket; @@ -68,14 +127,24 @@ namespace PepperDash.Core ClientStatus = clientStatus; } /// - /// Stupid S+ Constructor + /// S+ Constructor /// public GenericTcpServerSocketStatusChangeEventArgs() { } } + /// + /// EventArgs for TCP server com method receive text + /// public class GenericTcpServerCommMethodReceiveTextArgs : EventArgs { + /// + /// + /// public uint ReceivedFromClientIndex { get; private set; } + + /// + /// + /// public ushort ReceivedFromClientIndexShort { get @@ -84,49 +153,92 @@ namespace PepperDash.Core } } + /// + /// + /// public string Text { get; private set; } + /// + /// + /// + /// public GenericTcpServerCommMethodReceiveTextArgs(string text) { Text = text; } + /// + /// + /// + /// + /// public GenericTcpServerCommMethodReceiveTextArgs(string text, uint clientIndex) { Text = text; ReceivedFromClientIndex = clientIndex; } /// - /// Stupid S+ Constructor + /// S+ Constructor /// public GenericTcpServerCommMethodReceiveTextArgs() { } } + /// + /// EventArgs for TCP server client ready for communication + /// public class GenericTcpServerClientReadyForcommunicationsEventArgs : EventArgs { + /// + /// + /// public bool IsReady; + + /// + /// + /// + /// public GenericTcpServerClientReadyForcommunicationsEventArgs(bool isReady) { IsReady = isReady; } /// - /// Stupid S+ Constructor + /// S+ Constructor /// public GenericTcpServerClientReadyForcommunicationsEventArgs() { } } + /// + /// EventArgs for UDP connected + /// public class GenericUdpConnectedEventArgs : EventArgs { + /// + /// + /// public ushort UConnected; + /// + /// + /// public bool Connected; + /// + /// Constructor + /// public GenericUdpConnectedEventArgs() { } + /// + /// + /// + /// public GenericUdpConnectedEventArgs(ushort uconnected) { UConnected = uconnected; } + /// + /// + /// + /// public GenericUdpConnectedEventArgs(bool connected) { Connected = connected; diff --git a/Pepperdash Core/Pepperdash Core/Comm/GenericHttpSseClient.cs b/Pepperdash Core/Pepperdash Core/Comm/GenericHttpSseClient.cs index 1feac8f..3b941c9 100644 --- a/Pepperdash Core/Pepperdash Core/Comm/GenericHttpSseClient.cs +++ b/Pepperdash Core/Pepperdash Core/Comm/GenericHttpSseClient.cs @@ -8,50 +8,86 @@ using Crestron.SimplSharp.Net.Http; namespace PepperDash.Core { + /// + /// Client for communicating with an HTTP Server Side Event pattern + /// public class GenericHttpSseClient : ICommunicationReceiver { + /// + /// Notifies when bytes have been received + /// public event EventHandler BytesReceived; + /// + /// Notifies when text has been received + /// public event EventHandler TextReceived; + /// + /// Indicates connection status + /// public bool IsConnected { get; private set; } + /// + /// Unique identifier for the instance + /// public string Key { get; private set; } + /// + /// Name for the instance + /// public string Name { get; private set; } + /// + /// URL of the server + /// public string Url { get; set; } HttpClient Client; HttpClientRequest Request; + /// + /// Constructor + /// + /// + /// public GenericHttpSseClient(string key, string name) { Key = key; Name = name; } + /// + /// Connects to the server. Requires Url to be set first. + /// public void Connect() { InitiateConnection(Url); } + /// + /// Disconnects from the server + /// public void Disconnect() { CloseConnection(null); } + /// + /// Initiates connection to the server + /// + /// public void InitiateConnection(string url) { CrestronInvoke.BeginInvoke(o => @@ -84,6 +120,10 @@ namespace PepperDash.Core }); } + /// + /// Closes the connection to the server + /// + /// public void CloseConnection(string s) { if (Client != null) @@ -119,7 +159,7 @@ namespace PepperDash.Core /// /// /// - /// + /// /// /// 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"); } - /// - /// - /// - /// 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 /// public class RequestState { + /// + /// + /// public const int BUFFER_SIZE = 10000; + /// + /// + /// public byte[] BufferRead; + /// + /// + /// public HttpClient HttpClient; + /// + /// + /// public HttpClientRequest Request; + /// + /// + /// public HttpClientResponse Response; + /// + /// + /// public Stream StreamResponse; + /// + /// + /// public bool Done; + /// + /// Constructor + /// public RequestState() { BufferRead = new byte[BUFFER_SIZE]; @@ -246,6 +306,9 @@ namespace PepperDash.Core /// public class StreamAsyncTest { + /// + /// + /// public CEvent wait_for_response = new CEvent(true, false); } } \ No newline at end of file diff --git a/Pepperdash Core/Pepperdash Core/Comm/GenericSecureTcpIpClient.cs b/Pepperdash Core/Pepperdash Core/Comm/GenericSecureTcpIpClient.cs index fcc59b9..ec166f3 100644 --- a/Pepperdash Core/Pepperdash Core/Comm/GenericSecureTcpIpClient.cs +++ b/Pepperdash Core/Pepperdash Core/Comm/GenericSecureTcpIpClient.cs @@ -416,6 +416,10 @@ namespace PepperDash.Core } + /// + /// Deactivate the client + /// + /// public override bool Deactivate() { if (_client != null) @@ -604,30 +608,6 @@ namespace PepperDash.Core ConnectFailTimer.Dispose(); ConnectFailTimer = null; } - - /// - /// Internal call to close up client. ALWAYS use this when disconnecting. - /// - //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 diff --git a/Pepperdash Core/Pepperdash Core/Comm/GenericSecureTcpIpClient_ForServer.cs b/Pepperdash Core/Pepperdash Core/Comm/GenericSecureTcpIpClient_ForServer.cs index 53468a8..143b3cc 100644 --- a/Pepperdash Core/Pepperdash Core/Comm/GenericSecureTcpIpClient_ForServer.cs +++ b/Pepperdash Core/Pepperdash Core/Comm/GenericSecureTcpIpClient_ForServer.cs @@ -20,6 +20,9 @@ using Crestron.SimplSharp.CrestronSockets; namespace PepperDash.Core { + /// + /// Generic secure TCP/IP client for server + /// public class GenericSecureTcpIpClient_ForServer : Device, IAutoReconnect { /// @@ -31,8 +34,14 @@ namespace PepperDash.Core //public event EventHandler BytesReceived; + /// + /// Notifies of text received + /// public event EventHandler TextReceived; + /// + /// Notifies of auto reconnect sequence triggered + /// public event EventHandler AutoReconnectTriggered; /// @@ -41,7 +50,9 @@ namespace PepperDash.Core /// public event EventHandler TextReceivedQueueInvoke; - + /// + /// Notifies of socket status change + /// public event EventHandler ConnectionChange; @@ -212,13 +223,22 @@ namespace PepperDash.Core CTimer RetryTimer; + /// + /// + /// public bool HeartbeatEnabled { get; set; } + /// + /// + /// public ushort UHeartbeatEnabled { get { return (ushort)(HeartbeatEnabled ? 1 : 0); } set { HeartbeatEnabled = value == 1; } } + /// + /// + /// public string HeartbeatString { get; set; } //public int HeartbeatInterval = 50000; @@ -269,7 +289,13 @@ namespace PepperDash.Core #region Constructors - //Base class constructor + /// + /// Constructor + /// + /// + /// + /// + /// public GenericSecureTcpIpClient_ForServer(string key, string address, int port, int bufferSize) : base(key) { @@ -281,7 +307,9 @@ namespace PepperDash.Core } - //base class constructor + /// + /// Constructor for S+ + /// public GenericSecureTcpIpClient_ForServer() : base("Uninitialized Secure Tcp Client For Server") { @@ -293,7 +321,8 @@ namespace PepperDash.Core /// /// Contstructor that sets all properties by calling the initialize method with a config object. /// - /// + /// + /// public GenericSecureTcpIpClient_ForServer(string key, TcpClientConfigObject clientConfigObject) : base(key) { diff --git a/Pepperdash Core/Pepperdash Core/Comm/GenericSecureTcpIpServer.cs b/Pepperdash Core/Pepperdash Core/Comm/GenericSecureTcpIpServer.cs index 74ce8cb..d53a801 100644 --- a/Pepperdash Core/Pepperdash Core/Comm/GenericSecureTcpIpServer.cs +++ b/Pepperdash Core/Pepperdash Core/Comm/GenericSecureTcpIpServer.cs @@ -20,6 +20,9 @@ using Newtonsoft.Json.Linq; namespace PepperDash.Core { + /// + /// Generic secure TCP/IP server + /// public class GenericSecureTcpIpServer : Device { #region Events @@ -55,6 +58,9 @@ namespace PepperDash.Core /// public ServerHasChokedCallbackDelegate ServerHasChoked { get; set; } + /// + /// + /// public delegate void ServerHasChokedCallbackDelegate(); #endregion @@ -265,7 +271,9 @@ namespace PepperDash.Core List ClientReadyAfterKeyExchange = new List(); - //Store the connected client indexes + /// + /// The connected client indexes + /// public List ConnectedClientsIndexes = new List(); /// @@ -354,6 +362,10 @@ namespace PepperDash.Core Key = key; } + /// + /// Initialze the server + /// + /// public void Initialize(TcpServerConfigObject serverConfigObject) { try @@ -618,6 +630,11 @@ namespace PepperDash.Core return received; } + /// + /// Get the IP Address for the client at the specifed index + /// + /// + /// public string GetClientIPAddress(uint clientIndex) { Debug.Console(1, this, Debug.ErrorLogLevel.Notice, "GetClientIPAddress Index: {0}", clientIndex); @@ -675,7 +692,7 @@ namespace PepperDash.Core /// /// Secure Server Socket Status Changed Callback /// - /// + /// /// /// void SecureServer_SocketStatusChange(SecureTCPServer server, uint clientIndex, SocketStatus serverSocketStatus) @@ -723,7 +740,7 @@ namespace PepperDash.Core /// /// Secure TCP Client Connected to Secure Server Callback /// - /// + /// /// void SecureConnectCallback(SecureTCPServer server, uint clientIndex) { diff --git a/Pepperdash Core/Pepperdash Core/Comm/GenericSshClient.cs b/Pepperdash Core/Pepperdash Core/Comm/GenericSshClient.cs index ae38011..b61a39e 100644 --- a/Pepperdash Core/Pepperdash Core/Comm/GenericSshClient.cs +++ b/Pepperdash Core/Pepperdash Core/Comm/GenericSshClient.cs @@ -14,6 +14,9 @@ namespace PepperDash.Core public class GenericSshClient : Device, ISocketStatusWithStreamDebugging, IAutoReconnect { private const string SPlusKey = "Uninitialized SshClient"; + /// + /// Object to enable stream debugging + /// public CommunicationStreamDebugging StreamDebugging { get; private set; } /// @@ -31,10 +34,10 @@ namespace PepperDash.Core /// public event EventHandler ConnectionChange; - /// - /// - /// - //public event GenericSocketStatusChangeEventDelegate SocketStatusChange; + ///// + ///// + ///// + //public event GenericSocketStatusChangeEventDelegate SocketStatusChange; /// /// Address of server diff --git a/Pepperdash Core/Pepperdash Core/Comm/GenericTcpIpClient.cs b/Pepperdash Core/Pepperdash Core/Comm/GenericTcpIpClient.cs index 480e4d1..16013a3 100644 --- a/Pepperdash Core/Pepperdash Core/Comm/GenericTcpIpClient.cs +++ b/Pepperdash Core/Pepperdash Core/Comm/GenericTcpIpClient.cs @@ -17,6 +17,9 @@ namespace PepperDash.Core public class GenericTcpIpClient : Device, ISocketStatusWithStreamDebugging, IAutoReconnect { private const string SplusKey = "Uninitialized TcpIpClient"; + /// + /// Object to enable stream debugging + /// public CommunicationStreamDebugging StreamDebugging { get; private set; } /// @@ -125,10 +128,10 @@ namespace PepperDash.Core /// public string ClientStatusText { get { return ClientStatus.ToString(); } } - [Obsolete] /// /// Ushort representation of client status /// + [Obsolete] public ushort UClientStatus { get { return (ushort)ClientStatus; } } /// @@ -172,7 +175,7 @@ namespace PepperDash.Core /// /// Constructor /// - /// + /// unique string to differentiate between instances /// /// /// @@ -502,6 +505,9 @@ namespace PepperDash.Core /// public int AutoReconnectIntervalMs { get; set; } + /// + /// Default constructor + /// public TcpSshPropertiesConfig() { BufferSize = 32768; diff --git a/Pepperdash Core/Pepperdash Core/Comm/GenericTcpIpClient_ForServer.cs b/Pepperdash Core/Pepperdash Core/Comm/GenericTcpIpClient_ForServer.cs index b00c0a0..1e31c6f 100644 --- a/Pepperdash Core/Pepperdash Core/Comm/GenericTcpIpClient_ForServer.cs +++ b/Pepperdash Core/Pepperdash Core/Comm/GenericTcpIpClient_ForServer.cs @@ -20,6 +20,9 @@ using Crestron.SimplSharp.CrestronSockets; namespace PepperDash.Core { + /// + /// Generic TCP/IP client for server + /// public class GenericTcpIpClient_ForServer : Device, IAutoReconnect { /// @@ -31,8 +34,14 @@ namespace PepperDash.Core //public event EventHandler BytesReceived; + /// + /// Notifies of text received + /// public event EventHandler TextReceived; + /// + /// Notifies of socket status change + /// public event EventHandler ConnectionChange; @@ -203,14 +212,30 @@ namespace PepperDash.Core CTimer RetryTimer; + /// + /// + /// public bool HeartbeatEnabled { get; set; } + + /// + /// + /// public ushort UHeartbeatEnabled { get { return (ushort)(HeartbeatEnabled ? 1 : 0); } set { HeartbeatEnabled = value == 1; } } + + /// + /// + /// public string HeartbeatString = "heartbeat"; + + /// + /// + /// public int HeartbeatInterval = 50000; + CTimer HeartbeatSendTimer; CTimer HeartbeatAckTimer; /// @@ -230,7 +255,13 @@ namespace PepperDash.Core #region Constructors - //Base class constructor + /// + /// Constructor + /// + /// + /// + /// + /// public GenericTcpIpClient_ForServer(string key, string address, int port, int bufferSize) : base(key) { @@ -242,7 +273,9 @@ namespace PepperDash.Core } - //base class constructor + /// + /// Constructor for S+ + /// public GenericTcpIpClient_ForServer() : base("Uninitialized DynamicTcpClient") { diff --git a/Pepperdash Core/Pepperdash Core/Comm/GenericTcpIpServer.cs b/Pepperdash Core/Pepperdash Core/Comm/GenericTcpIpServer.cs index 443a69a..e3a00f2 100644 --- a/Pepperdash Core/Pepperdash Core/Comm/GenericTcpIpServer.cs +++ b/Pepperdash Core/Pepperdash Core/Comm/GenericTcpIpServer.cs @@ -20,6 +20,9 @@ using Newtonsoft.Json.Linq; namespace PepperDash.Core { + /// + /// Generic TCP/IP server device + /// public class GenericTcpIpServer : Device { #region Events @@ -49,6 +52,9 @@ namespace PepperDash.Core /// public ServerHasChokedCallbackDelegate ServerHasChoked { get; set; } + /// + /// + /// 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 + /// + /// The maximum number of clients. + /// Should be set by parameter in SIMPL+ in the MAIN method, Should not ever need to be configurable + /// + public ushort MaxClients { get; set; } + /// /// Number of clients currently connected. /// @@ -241,7 +252,9 @@ namespace PepperDash.Core List ClientReadyAfterKeyExchange = new List(); - //Store the connected client indexes + /// + /// The connected client indexes + /// public List ConnectedClientsIndexes = new List(); /// @@ -330,6 +343,10 @@ namespace PepperDash.Core Key = key; } + /// + /// Initialze with server configuration object + /// + /// public void Initialize(TcpServerConfigObject serverConfigObject) { try @@ -416,7 +433,7 @@ namespace PepperDash.Core } /// - /// Stop Listeneing + /// Stop Listening /// public void StopListening() { @@ -592,6 +609,11 @@ namespace PepperDash.Core return received; } + /// + /// Gets the IP address based on the client index + /// + /// + /// IP address of the client public string GetClientIPAddress(uint clientIndex) { Debug.Console(1, this, Debug.ErrorLogLevel.Notice, "GetClientIPAddress Index: {0}", clientIndex); @@ -649,7 +671,7 @@ namespace PepperDash.Core /// /// Secure Server Socket Status Changed Callback /// - /// + /// /// /// void TcpServer_SocketStatusChange(TCPServer server, uint clientIndex, SocketStatus serverSocketStatus) @@ -687,7 +709,7 @@ namespace PepperDash.Core /// /// Secure TCP Client Connected to Secure Server Callback /// - /// + /// /// void TcpConnectCallback(TCPServer server, uint clientIndex) { @@ -762,7 +784,7 @@ namespace PepperDash.Core /// /// Secure Received Data Async Callback /// - /// + /// /// /// void TcpServerReceivedDataAsyncCallback(TCPServer myTCPServer, uint clientIndex, int numberOfBytesReceived) diff --git a/Pepperdash Core/Pepperdash Core/Comm/GenericUdpServer.cs b/Pepperdash Core/Pepperdash Core/Comm/GenericUdpServer.cs index 36a2657..5bd85b0 100644 --- a/Pepperdash Core/Pepperdash Core/Comm/GenericUdpServer.cs +++ b/Pepperdash Core/Pepperdash Core/Comm/GenericUdpServer.cs @@ -15,9 +15,15 @@ using Newtonsoft.Json.Linq; namespace PepperDash.Core { + /// + /// Generic UDP Server device + /// public class GenericUdpServer : Device, ISocketStatusWithStreamDebugging { private const string SplusKey = "Uninitialized Udp Server"; + /// + /// Object to enable stream debugging + /// public CommunicationStreamDebugging StreamDebugging { get; private set; } /// /// @@ -68,10 +74,6 @@ namespace PepperDash.Core /// public string Hostname { get; set; } - /// - /// IP Address of the sender of the last recieved message - /// - /// /// Port on server @@ -97,6 +99,9 @@ namespace PepperDash.Core private set; } + /// + /// Numeric value indicating + /// public ushort UIsConnected { get { return IsConnected ? (ushort)1 : (ushort)0; } @@ -107,6 +112,9 @@ namespace PepperDash.Core /// public int BufferSize { get; set; } + /// + /// The server + /// public UDPServer Server { get; private set; } /// diff --git a/Pepperdash Core/Pepperdash Core/Comm/QscCoreDoubleTcpIpClient.cs b/Pepperdash Core/Pepperdash Core/Comm/QscCoreDoubleTcpIpClient.cs index 2f61dc8..7011325 100644 --- a/Pepperdash Core/Pepperdash Core/Comm/QscCoreDoubleTcpIpClient.cs +++ b/Pepperdash Core/Pepperdash Core/Comm/QscCoreDoubleTcpIpClient.cs @@ -6,15 +6,36 @@ using Crestron.SimplSharp; namespace PepperDash.Core { + /// + /// Allows for two simultaneous TCP clients to connect to a redundant pair of QSC Core DSPs and manages + /// public class QscCoreDoubleTcpIpClient : IKeyed { + /// + /// Key to uniquely identify the instance of the class + /// public string Key { get; private set; } + /// + /// Fires when a bool value changes to notify the S+ module + /// public event EventHandler BoolChange; + /// + /// Fires when a ushort value changes to notify the S+ module + /// public event EventHandler UshortChange; + /// + /// Fires when a string value changes to notify the S+ module + /// public event EventHandler StringChange; + /// + /// The client for the master DSP unit + /// public GenericTcpIpClient MasterClient { get; private set; } + /// + /// The client for the slave DSP unit + /// public GenericTcpIpClient SlaveClient { get; private set; } string Username; @@ -45,7 +66,7 @@ namespace PepperDash.Core } /// - /// + /// Connects to both DSP units /// /// /// @@ -55,6 +76,7 @@ namespace PepperDash.Core /// /// /// + /// 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)); } - + /// + /// + /// public const ushort MasterIsActiveId = 3; + /// + /// + /// public const ushort SlaveIsActiveId = 4; + /// + /// + /// public const ushort MainModuleInitiailzeId = 5; + /// + /// + /// public const ushort MasterClientStatusId = 101; + /// + /// + /// public const ushort SlaveClientStatusId = 102; + /// + /// + /// public const ushort LineReceivedId = 201; } } \ No newline at end of file diff --git a/Pepperdash Core/Pepperdash Core/Comm/eControlMethods.cs b/Pepperdash Core/Pepperdash Core/Comm/eControlMethods.cs index 4936afd..28a95b1 100644 --- a/Pepperdash Core/Pepperdash Core/Comm/eControlMethods.cs +++ b/Pepperdash Core/Pepperdash Core/Comm/eControlMethods.cs @@ -11,6 +11,69 @@ namespace PepperDash.Core /// public enum eControlMethod { - None = 0, Com, IpId, IpidTcp, IR, Ssh, Tcpip, Telnet, Cresnet, Cec, Udp, Http, Https, Ws, Wss, SecureTcpIp + /// + /// + /// + None = 0, + /// + /// RS232/422/485 + /// + Com, + /// + /// Crestron IpId (most Crestron ethernet devices) + /// + IpId, + /// + /// Crestron IpIdTcp (HD-MD series, etc.) + /// + IpidTcp, + /// + /// Crestron IR control + /// + IR, + /// + /// SSH client + /// + Ssh, + /// + /// TCP/IP client + /// + Tcpip, + /// + /// Telnet + /// + Telnet, + /// + /// Crestnet device + /// + Cresnet, + /// + /// CEC Control, via a DM HDMI port + /// + Cec, + /// + /// UDP Server + /// + Udp, + /// + /// HTTP client + /// + Http, + /// + /// HTTPS client + /// + Https, + /// + /// Websocket client + /// + Ws, + /// + /// Secure Websocket client + /// + Wss, + /// + /// Secure TCP/IP + /// + SecureTcpIp } } \ No newline at end of file diff --git a/Pepperdash Core/Pepperdash Core/CommunicationExtras.cs b/Pepperdash Core/Pepperdash Core/CommunicationExtras.cs index 775fd01..353b14f 100644 --- a/Pepperdash Core/Pepperdash Core/CommunicationExtras.cs +++ b/Pepperdash Core/Pepperdash Core/CommunicationExtras.cs @@ -15,11 +15,26 @@ namespace PepperDash.Core /// public interface ICommunicationReceiver : IKeyed { + /// + /// Notifies of bytes received + /// event EventHandler BytesReceived; + /// + /// Notifies of text received + /// event EventHandler TextReceived; + /// + /// Indicates connection status + /// bool IsConnected { get; } + /// + /// Connect to the device + /// void Connect(); + /// + /// Disconnect from the device + /// void Disconnect(); } @@ -28,7 +43,16 @@ namespace PepperDash.Core /// public interface IBasicCommunication : ICommunicationReceiver { + /// + /// Send text to the device + /// + /// void SendText(string text); + + /// + /// Send bytes to the device + /// + /// void SendBytes(byte[] bytes); } @@ -45,6 +69,9 @@ namespace PepperDash.Core /// public interface IStreamDebugging { + /// + /// Object to enable stream debugging + /// CommunicationStreamDebugging StreamDebugging { get; } } @@ -54,21 +81,37 @@ namespace PepperDash.Core /// public interface ISocketStatus : IBasicCommunication { + /// + /// Notifies of socket status changes + /// event EventHandler ConnectionChange; + + /// + /// The current socket status of the client + /// SocketStatus ClientStatus { get; } } /// - /// Represents a device that implements ISocketStatus and IStreamDebugging + /// Describes a device that implements ISocketStatus and IStreamDebugging /// public interface ISocketStatusWithStreamDebugging : ISocketStatus, IStreamDebugging { } + /// + /// Describes a device that can automatically attempt to reconnect + /// public interface IAutoReconnect { + /// + /// Enable automatic recconnect + /// bool AutoReconnect { get; set; } + /// + /// Interval in ms to attempt automatic recconnections + /// int AutoReconnectIntervalMs { get; set; } } @@ -77,7 +120,14 @@ namespace PepperDash.Core /// public enum eGenericCommMethodStatusChangeType { - Connected, Disconnected + /// + /// Connected + /// + Connected, + /// + /// Disconnected + /// + Disconnected } /// @@ -92,14 +142,22 @@ namespace PepperDash.Core /// public class GenericCommMethodReceiveBytesArgs : EventArgs { + /// + /// + /// public byte[] Bytes { get; private set; } + + /// + /// + /// + /// public GenericCommMethodReceiveBytesArgs(byte[] bytes) { Bytes = bytes; } /// - /// Stupid S+ Constructor + /// S+ Constructor /// public GenericCommMethodReceiveBytesArgs() { } } @@ -109,13 +167,28 @@ namespace PepperDash.Core /// public class GenericCommMethodReceiveTextArgs : EventArgs { + /// + /// + /// public string Text { get; private set; } + /// + /// + /// public string Delimiter { get; private set; } + /// + /// + /// + /// public GenericCommMethodReceiveTextArgs(string text) { Text = text; } + /// + /// + /// + /// + /// public GenericCommMethodReceiveTextArgs(string text, string delimiter) :this(text) { @@ -123,7 +196,7 @@ namespace PepperDash.Core } /// - /// Stupid S+ Constructor + /// S+ Constructor /// public GenericCommMethodReceiveTextArgs() { } } @@ -135,17 +208,32 @@ namespace PepperDash.Core /// public class ComTextHelper { + /// + /// Gets escaped text for a byte array + /// + /// + /// public static string GetEscapedText(byte[] bytes) { return String.Concat(bytes.Select(b => string.Format(@"[{0:X2}]", (int)b)).ToArray()); } + /// + /// Gets escaped text for a string + /// + /// + /// 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()); } + /// + /// Gets debug text for a string + /// + /// + /// public static string GetDebugText(string text) { return Regex.Replace(text, @"[^\u0020-\u007E]", a => GetEscapedText(a.Value)); diff --git a/Pepperdash Core/Pepperdash Core/Config/PortalConfigReader.cs b/Pepperdash Core/Pepperdash Core/Config/PortalConfigReader.cs index 16af795..f2ad746 100644 --- a/Pepperdash Core/Pepperdash Core/Config/PortalConfigReader.cs +++ b/Pepperdash Core/Pepperdash Core/Config/PortalConfigReader.cs @@ -12,6 +12,9 @@ using PepperDash.Core; namespace PepperDash.Core.Config { + /// + /// Reads a Portal formatted config file + /// public class PortalConfigReader { /// @@ -170,8 +173,9 @@ namespace PepperDash.Core.Config /// /// Merge o2 onto o1 /// - /// - /// + /// + /// + /// static JObject Merge(JObject o1, JObject o2, string path) { foreach (var o2Prop in o2) diff --git a/Pepperdash Core/Pepperdash Core/Device.cs b/Pepperdash Core/Pepperdash Core/Device.cs index bfbe359..c889dd3 100644 --- a/Pepperdash Core/Pepperdash Core/Device.cs +++ b/Pepperdash Core/Pepperdash Core/Device.cs @@ -36,6 +36,9 @@ namespace PepperDash.Core List _PreActivationActions; List _PostActivationActions; + /// + /// + /// public static Device DefaultDevice { get { return _DefaultDevice; } } static Device _DefaultDevice = new Device("Default", "Default"); @@ -51,6 +54,11 @@ namespace PepperDash.Core } + /// + /// Constructor with key and name + /// + /// + /// public Device(string key, string name) : this(key) { Name = name; @@ -63,6 +71,10 @@ namespace PepperDash.Core // Config = config; //} + /// + /// Adds a pre activation action + /// + /// public void AddPreActivationAction(Action act) { if (_PreActivationActions == null) @@ -70,6 +82,10 @@ namespace PepperDash.Core _PreActivationActions.Add(act); } + /// + /// Adds a post activation action + /// + /// public void AddPostActivationAction(Action act) { if (_PostActivationActions == null) @@ -77,6 +93,9 @@ namespace PepperDash.Core _PostActivationActions.Add(act); } + /// + /// Executes the preactivation actions + /// public void PreActivate() { if (_PreActivationActions != null) @@ -98,6 +117,9 @@ namespace PepperDash.Core return result; } + /// + /// Executes the postactivation actions + /// public void PostActivate() { if (_PostActivationActions != null) diff --git a/Pepperdash Core/Pepperdash Core/EthernetHelper.cs b/Pepperdash Core/Pepperdash Core/EthernetHelper.cs index be0d5fa..220d386 100644 --- a/Pepperdash Core/Pepperdash Core/EthernetHelper.cs +++ b/Pepperdash Core/Pepperdash Core/EthernetHelper.cs @@ -8,6 +8,9 @@ using Newtonsoft.Json; namespace PepperDash.Core { + /// + /// Class to help with accessing values from the CrestronEthernetHelper class + /// public class EthernetHelper { /// diff --git a/Pepperdash Core/Pepperdash Core/GenericRESTfulCommunications/GenericRESTfulClient.cs b/Pepperdash Core/Pepperdash Core/GenericRESTfulCommunications/GenericRESTfulClient.cs index 7d8df61..c1db1aa 100644 --- a/Pepperdash Core/Pepperdash Core/GenericRESTfulCommunications/GenericRESTfulClient.cs +++ b/Pepperdash Core/Pepperdash Core/GenericRESTfulCommunications/GenericRESTfulClient.cs @@ -42,6 +42,7 @@ namespace PepperDash.Core.GenericRESTfulCommunications /// /// /// + /// 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 /// /// /// + /// /// /// private void SubmitRequestHttp(string url, ushort port, ushort requestType, string contentType, string username, string password) @@ -121,6 +123,7 @@ namespace PepperDash.Core.GenericRESTfulCommunications /// /// /// + /// /// /// private void SubmitRequestHttps(string url, ushort port, ushort requestType, string contentType, string username, string password) diff --git a/Pepperdash Core/Pepperdash Core/JsonStandardObjects/JsonToSimplDeviceConfig.cs b/Pepperdash Core/Pepperdash Core/JsonStandardObjects/JsonToSimplDeviceConfig.cs index 92e9f03..114609e 100644 --- a/Pepperdash Core/Pepperdash Core/JsonStandardObjects/JsonToSimplDeviceConfig.cs +++ b/Pepperdash Core/Pepperdash Core/JsonStandardObjects/JsonToSimplDeviceConfig.cs @@ -52,19 +52,55 @@ namespace PepperDash.Core.JsonStandardObjects /// public class ComParamsConfig { + /// + /// + /// public int baudRate { get; set; } + /// + /// + /// public int dataBits { get; set; } + /// + /// + /// public int stopBits { get; set; } + /// + /// + /// public string parity { get; set; } + /// + /// + /// public string protocol { get; set; } + /// + /// + /// public string hardwareHandshake { get; set; } + /// + /// + /// public string softwareHandshake { get; set; } + /// + /// + /// public int pacing { get; set; } // convert properties for simpl + /// + /// + /// public ushort simplBaudRate { get { return Convert.ToUInt16(baudRate); } } + /// + /// + /// public ushort simplDataBits { get { return Convert.ToUInt16(dataBits); } } + /// + /// + /// public ushort simplStopBits { get { return Convert.ToUInt16(stopBits); } } + /// + /// + /// public ushort simplPacing { get { return Convert.ToUInt16(pacing); } } /// @@ -81,16 +117,43 @@ namespace PepperDash.Core.JsonStandardObjects /// public class TcpSshPropertiesConfig { + /// + /// + /// public string address { get; set; } + /// + /// + /// public int port { get; set; } + /// + /// + /// public string username { get; set; } + /// + /// + /// public string password { get; set; } + /// + /// + /// public bool autoReconnect { get; set; } + /// + /// + /// public int autoReconnectIntervalMs { get; set; } // convert properties for simpl + /// + /// + /// public ushort simplPort { get { return Convert.ToUInt16(port); } } + /// + /// + /// public ushort simplAutoReconnect { get { return (ushort)(autoReconnect ? 1 : 0); } } + /// + /// + /// public ushort simplAutoReconnectIntervalMs { get { return Convert.ToUInt16(autoReconnectIntervalMs); } } /// @@ -107,13 +170,31 @@ namespace PepperDash.Core.JsonStandardObjects /// public class ControlConfig { + /// + /// + /// public string method { get; set; } + /// + /// + /// public string controlPortDevKey { get; set; } + /// + /// + /// public int controlPortNumber { get; set; } + /// + /// + /// public ComParamsConfig comParams { get; set; } + /// + /// + /// public TcpSshPropertiesConfig tcpSshProperties { get; set; } // convert properties for simpl + /// + /// + /// public ushort simplControlPortNumber { get { return Convert.ToUInt16(controlPortNumber); } } /// @@ -131,12 +212,27 @@ namespace PepperDash.Core.JsonStandardObjects /// public class PropertiesConfig { + /// + /// + /// public int deviceId { get; set; } + /// + /// + /// public bool enabled { get; set; } + /// + /// + /// public ControlConfig control { get; set; } // convert properties for simpl + /// + /// + /// public ushort simplDeviceId { get { return Convert.ToUInt16(deviceId); } } + /// + /// + /// public ushort simplEnabled { get { return (ushort)(enabled ? 1 : 0); } } /// @@ -153,6 +249,9 @@ namespace PepperDash.Core.JsonStandardObjects /// public class RootObject { + /// + /// The collection of devices + /// public List devices { get; set; } } } \ No newline at end of file diff --git a/Pepperdash Core/Pepperdash Core/JsonToSimpl/Constants.cs b/Pepperdash Core/Pepperdash Core/JsonToSimpl/Constants.cs index 0838d56..0bf9872 100644 --- a/Pepperdash Core/Pepperdash Core/JsonToSimpl/Constants.cs +++ b/Pepperdash Core/Pepperdash Core/JsonToSimpl/Constants.cs @@ -11,18 +11,71 @@ namespace PepperDash.Core.JsonToSimpl /// public class JsonToSimplConstants { + /// + /// + /// public const ushort BoolValueChange = 1; + /// + /// + /// public const ushort JsonIsValidBoolChange = 2; - public const ushort UshortValueChange = 101; + /// + /// Reports the if the device is 3-series compatible + /// + public const ushort ProgramCompatibility3SeriesChange = 3; + + /// + /// Reports the if the device is 4-series compatible + /// + public const ushort ProgramCompatibility4SeriesChange = 4; + + /// + /// Reports the device platform enum value + /// + public const ushort DevicePlatformValueChange = 5; + + /// + /// + /// + public const ushort UshortValueChange = 101; + /// + /// + /// public const ushort StringValueChange = 201; + /// + /// + /// public const ushort FullPathToArrayChange = 202; + /// + /// + /// public const ushort ActualFilePathChange = 203; - // TODO: pdc-20: Added below constants for passing file path and filename back to S+ + /// + /// + /// public const ushort FilenameResolvedChange = 204; + /// + /// + /// public const ushort FilePathResolvedChange = 205; + + /// + /// Reports the root directory change + /// + public const ushort RootDirectoryChange = 206; + + /// + /// Reports the room ID change + /// + public const ushort RoomIdChange = 207; + + /// + /// Reports the room name change + /// + public const ushort RoomNameChange = 208; } /// @@ -35,13 +88,33 @@ namespace PepperDash.Core.JsonToSimpl /// public class SPlusValueWrapper { + /// + /// + /// public SPlusType ValueType { get; private set; } + /// + /// + /// public ushort Index { get; private set; } + /// + /// + /// public ushort BoolUShortValue { get; set; } + /// + /// + /// public string StringValue { get; set; } - public SPlusValueWrapper() { } + /// + /// + /// + public SPlusValueWrapper() {} + /// + /// + /// + /// + /// public SPlusValueWrapper(SPlusType type, ushort index) { ValueType = type; @@ -54,6 +127,17 @@ namespace PepperDash.Core.JsonToSimpl /// public enum SPlusType { - Digital, Analog, String + /// + /// Digital + /// + Digital, + /// + /// Analog + /// + Analog, + /// + /// String + /// + String } } \ No newline at end of file diff --git a/Pepperdash Core/Pepperdash Core/JsonToSimpl/Global.cs b/Pepperdash Core/Pepperdash Core/JsonToSimpl/Global.cs index c7019d2..be2e795 100644 --- a/Pepperdash Core/Pepperdash Core/JsonToSimpl/Global.cs +++ b/Pepperdash Core/Pepperdash Core/JsonToSimpl/Global.cs @@ -8,6 +8,9 @@ using Crestron.SimplSharp; namespace PepperDash.Core.JsonToSimpl { + /// + /// The global class to manage all the instances of JsonToSimplMaster + /// public class J2SGlobal { static List Masters = new List(); diff --git a/Pepperdash Core/Pepperdash Core/JsonToSimpl/JsonToSimplArrayLookupChild.cs b/Pepperdash Core/Pepperdash Core/JsonToSimpl/JsonToSimplArrayLookupChild.cs index 0ac1bbf..6535308 100644 --- a/Pepperdash Core/Pepperdash Core/JsonToSimpl/JsonToSimplArrayLookupChild.cs +++ b/Pepperdash Core/Pepperdash Core/JsonToSimpl/JsonToSimplArrayLookupChild.cs @@ -8,15 +8,24 @@ using Newtonsoft.Json.Linq; namespace PepperDash.Core.JsonToSimpl { + /// + /// Used to interact with an array of values with the S+ modules + /// public class JsonToSimplArrayLookupChild : JsonToSimplChildObjectBase { + /// + /// + /// public string SearchPropertyName { get; set; } + /// + /// + /// public string SearchPropertyValue { get; set; } int ArrayIndex; /// - /// For <2.4.1 array lookups + /// For gt2.4.1 array lookups /// /// /// @@ -70,6 +79,9 @@ namespace PepperDash.Core.JsonToSimpl PathSuffix == null ? "" : PathSuffix); } + /// + /// Process all values + /// public override void ProcessAll() { if (FindInArray()) diff --git a/Pepperdash Core/Pepperdash Core/JsonToSimpl/JsonToSimplChildObjectBase.cs b/Pepperdash Core/Pepperdash Core/JsonToSimpl/JsonToSimplChildObjectBase.cs index cdd4ccd..e507105 100644 --- a/Pepperdash Core/Pepperdash Core/JsonToSimpl/JsonToSimplChildObjectBase.cs +++ b/Pepperdash Core/Pepperdash Core/JsonToSimpl/JsonToSimplChildObjectBase.cs @@ -8,13 +8,27 @@ using Newtonsoft.Json.Linq; namespace PepperDash.Core.JsonToSimpl { + /// + /// Base class for JSON objects + /// public abstract class JsonToSimplChildObjectBase : IKeyed { - + /// + /// Notifies of bool change + /// public event EventHandler BoolChange; + /// + /// Notifies of ushort change + /// public event EventHandler UShortChange; + /// + /// Notifies of string change + /// public event EventHandler StringChange; + /// + /// Delegate to get all values + /// public SPlusValuesDelegate GetAllValuesDelegate { get; set; } /// @@ -22,6 +36,9 @@ namespace PepperDash.Core.JsonToSimpl /// public SPlusValuesDelegate SetAllPathsDelegate { get; set; } + /// + /// Unique identifier for instance + /// public string Key { get; protected set; } /// @@ -35,19 +52,33 @@ namespace PepperDash.Core.JsonToSimpl /// public string PathSuffix { get; protected set; } + /// + /// Indicates if the instance is linked to an object + /// public bool LinkedToObject { get; protected set; } + /// + /// Reference to Master instance + /// protected JsonToSimplMaster Master; - // The sent-in JPaths for the various types - protected Dictionary BoolPaths = new Dictionary(); + /// + /// Paths to boolean values in JSON structure + /// + protected Dictionary BoolPaths = new Dictionary(); + /// + /// Paths to numeric values in JSON structure + /// protected Dictionary UshortPaths = new Dictionary(); + /// + /// Paths to string values in JSON structure + /// protected Dictionary StringPaths = new Dictionary(); /// /// Call this before doing anything else /// - /// + /// /// /// /// @@ -64,6 +95,10 @@ namespace PepperDash.Core.JsonToSimpl Debug.Console(1, "JSON Child [{0}] cannot link to master {1}", key, masterUniqueId); } + /// + /// Sets the path prefix for the object + /// + /// public void SetPathPrefix(string pathPrefix) { PathPrefix = pathPrefix; @@ -240,29 +275,54 @@ namespace PepperDash.Core.JsonToSimpl GetAllValuesDelegate(); } + /// + /// + /// + /// + /// public void USetBoolValue(ushort key, ushort theValue) { SetBoolValue(key, theValue == 1); } + /// + /// + /// + /// + /// public void SetBoolValue(ushort key, bool theValue) { if (BoolPaths.ContainsKey(key)) SetValueOnMaster(BoolPaths[key], new JValue(theValue)); } + /// + /// + /// + /// + /// public void SetUShortValue(ushort key, ushort theValue) { if (UshortPaths.ContainsKey(key)) SetValueOnMaster(UshortPaths[key], new JValue(theValue)); } + /// + /// + /// + /// + /// public void SetStringValue(ushort key, string theValue) { if (StringPaths.ContainsKey(key)) SetValueOnMaster(StringPaths[key], new JValue(theValue)); } + /// + /// + /// + /// + /// public void SetValueOnMaster(string keyPath, JValue valueToSave) { var path = GetFullPath(keyPath); @@ -292,6 +352,12 @@ namespace PepperDash.Core.JsonToSimpl // Helpers for events //****************************************************************************************** + /// + /// Event helper + /// + /// + /// + /// protected void OnBoolChange(bool state, ushort index, ushort type) { var handler = BoolChange; @@ -304,6 +370,12 @@ namespace PepperDash.Core.JsonToSimpl } //****************************************************************************************** + /// + /// Event helper + /// + /// + /// + /// protected void OnUShortChange(ushort state, ushort index, ushort type) { var handler = UShortChange; @@ -315,6 +387,12 @@ namespace PepperDash.Core.JsonToSimpl } } + /// + /// Event helper + /// + /// + /// + /// protected void OnStringChange(string value, ushort index, ushort type) { var handler = StringChange; diff --git a/Pepperdash Core/Pepperdash Core/JsonToSimpl/JsonToSimplFileMaster.cs b/Pepperdash Core/Pepperdash Core/JsonToSimpl/JsonToSimplFileMaster.cs index 7ddaeb3..c5f50d5 100644 --- a/Pepperdash Core/Pepperdash Core/JsonToSimpl/JsonToSimplFileMaster.cs +++ b/Pepperdash Core/Pepperdash Core/JsonToSimpl/JsonToSimplFileMaster.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; +using System.Text.RegularExpressions; using Crestron.SimplSharp; using Crestron.SimplSharp.CrestronIO; using Newtonsoft.Json; @@ -10,185 +11,281 @@ using Newtonsoft.Json.Linq; namespace PepperDash.Core.JsonToSimpl { - public class JsonToSimplFileMaster : JsonToSimplMaster - { - /// - /// Sets the filepath as well as registers this with the Global.Masters list - /// - public string Filepath { get; private set; } + /// + /// Represents a JSON file that can be read and written to + /// + public class JsonToSimplFileMaster : JsonToSimplMaster + { + /// + /// Sets the filepath as well as registers this with the Global.Masters list + /// + public string Filepath { get; private set; } - public string ActualFilePath { get; private set; } + /// + /// Filepath to the actual file that will be read (Portal or local) + /// + public string ActualFilePath { get; private set; } - // TODO: pdc-20: added to return filename back to SIMPL - public string Filename { get; private set; } - public string FilePathName { get; private set; } + /// + /// + /// + public string Filename { get; private set; } + /// + /// + /// + public string FilePathName { get; private set; } - /*****************************************************************************************/ - /** Privates **/ + /*****************************************************************************************/ + /** Privates **/ - // The JSON file in JObject form - // For gathering the incoming data - object StringBuilderLock = new object(); - // To prevent multiple same-file access - static object FileLock = new object(); + // The JSON file in JObject form + // For gathering the incoming data + object StringBuilderLock = new object(); + // To prevent multiple same-file access + static object FileLock = new object(); - /*****************************************************************************************/ + /*****************************************************************************************/ - /// - /// SIMPL+ default constructor. - /// - public JsonToSimplFileMaster() - { - } + /// + /// SIMPL+ default constructor. + /// + public JsonToSimplFileMaster() + { + } - /// - /// Read, evaluate and udpate status - /// - public void EvaluateFile(string filepath) - { - Filepath = filepath; + /// + /// Read, evaluate and udpate status + /// + public void EvaluateFile(string filepath) + { + try + { + OnBoolChange(false, 0, JsonToSimplConstants.JsonIsValidBoolChange); - OnBoolChange(false, 0, JsonToSimplConstants.JsonIsValidBoolChange); - if (string.IsNullOrEmpty(Filepath)) - { - CrestronConsole.PrintLine("Cannot evaluate file. JSON file path not set"); - return; - } + var dirSeparator = Path.DirectorySeparatorChar; + var dirSeparatorAlt = Path.AltDirectorySeparatorChar; - // Resolve wildcard - var dir = Path.GetDirectoryName(Filepath); - Debug.Console(1, "Checking directory {0}", dir); - var fileName = Path.GetFileName(Filepath); - var directory = new DirectoryInfo(dir); + var series = CrestronEnvironment.ProgramCompatibility; - var actualFile = directory.GetFiles(fileName).FirstOrDefault(); - if (actualFile == null) - { - var msg = string.Format("JSON file not found: {0}", Filepath); - CrestronConsole.PrintLine(msg); - ErrorLog.Error(msg); - return; - } + var is3Series = (eCrestronSeries.Series3 == (series & eCrestronSeries.Series3)); + OnBoolChange(is3Series, 0, + JsonToSimplConstants.ProgramCompatibility3SeriesChange); - // \xSE\xR\PDT000-Template_Main_Config-Combined_DSP_v00.02.json - // \USER\PDT000-Template_Main_Config-Combined_DSP_v00.02.json - ActualFilePath = actualFile.FullName; - OnStringChange(ActualFilePath, 0, JsonToSimplConstants.ActualFilePathChange); - Debug.Console(1, "Actual JSON file is {0}", ActualFilePath); + var is4Series = (eCrestronSeries.Series4 == (series & eCrestronSeries.Series4)); + OnBoolChange(is4Series, 0, + JsonToSimplConstants.ProgramCompatibility4SeriesChange); - Filename = actualFile.Name; - OnStringChange(Filename, 0, JsonToSimplConstants.FilenameResolvedChange); - Debug.Console(1, "JSON Filename is {0}", Filename); + var isServer = CrestronEnvironment.DevicePlatform == eDevicePlatform.Server; + OnBoolChange(isServer, 0, + JsonToSimplConstants.DevicePlatformValueChange); - FilePathName = string.Format(@"{0}\", actualFile.DirectoryName); - OnStringChange(FilePathName, 0, JsonToSimplConstants.FilePathResolvedChange); - Debug.Console(1, "JSON File Path is {0}", FilePathName); + // get the roomID + var roomId = Crestron.SimplSharp.InitialParametersClass.RoomId; + if (!string.IsNullOrEmpty(roomId)) + { + OnStringChange(roomId, 0, JsonToSimplConstants.RoomIdChange); + } - string json = File.ReadToEnd(ActualFilePath, System.Text.Encoding.ASCII); + // get the roomName + var roomName = Crestron.SimplSharp.InitialParametersClass.RoomName; + if (!string.IsNullOrEmpty(roomName)) + { + OnStringChange(roomName, 0, JsonToSimplConstants.RoomNameChange); + } - try - { - JsonObject = JObject.Parse(json); - foreach (var child in Children) - child.ProcessAll(); - OnBoolChange(true, 0, JsonToSimplConstants.JsonIsValidBoolChange); - } - catch (Exception e) - { - var msg = string.Format("JSON parsing failed:\r{0}", e); - CrestronConsole.PrintLine(msg); - ErrorLog.Error(msg); - return; - } - } - public void setDebugLevel(int level) - { - Debug.SetDebugLevel(level); - } + var rootDirectory = Directory.GetApplicationRootDirectory(); + OnStringChange(rootDirectory, 0, JsonToSimplConstants.RootDirectoryChange); + + var splusPath = string.Empty; + if (Regex.IsMatch(filepath, @"user", RegexOptions.IgnoreCase)) + { + if (is4Series) + splusPath = Regex.Replace(filepath, "user", "user", RegexOptions.IgnoreCase); + else if (isServer) + splusPath = Regex.Replace(filepath, "user", "User", RegexOptions.IgnoreCase); + else + splusPath = filepath; + } - public override void Save() - { - // this code is duplicated in the other masters!!!!!!!!!!!!! - UnsavedValues = new Dictionary(); - // Make each child update their values into master object - foreach (var child in Children) - { - Debug.Console(1, "Master [{0}] checking child [{1}] for updates to save", UniqueID, child.Key); - child.UpdateInputsForMaster(); - } + filepath = splusPath.Replace(dirSeparatorAlt, dirSeparator); + + Filepath = string.Format("{1}{0}{2}", dirSeparator, rootDirectory, + filepath.TrimStart(dirSeparator, dirSeparatorAlt)); + + OnStringChange(string.Format("Attempting to evaluate {0}", Filepath), 0, JsonToSimplConstants.StringValueChange); - if (UnsavedValues == null || UnsavedValues.Count == 0) - { - Debug.Console(1, "Master [{0}] No updated values to save. Skipping", UniqueID); - return; - } - lock (FileLock) - { - Debug.Console(1, "Saving"); - foreach (var path in UnsavedValues.Keys) - { - var tokenToReplace = JsonObject.SelectToken(path); - if (tokenToReplace != null) - {// It's found - tokenToReplace.Replace(UnsavedValues[path]); - Debug.Console(1, "JSON Master[{0}] Updating '{1}'", UniqueID, path); - } - else // No token. Let's make one - { - //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); + if (string.IsNullOrEmpty(Filepath)) + { + OnStringChange(string.Format("Cannot evaluate file. JSON file path not set"), 0, JsonToSimplConstants.StringValueChange); + CrestronConsole.PrintLine("Cannot evaluate file. JSON file path not set"); + return; + } - // JContainer jpart = JsonObject; - // // walk down the path and find where it goes - //#warning Does not handle arrays. - // foreach (var part in path.Split('.')) - // { + // get file directory and name to search + var fileDirectory = Path.GetDirectoryName(Filepath); + var fileName = Path.GetFileName(Filepath); - // 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)); + OnStringChange(string.Format("Checking '{0}' for '{1}'", fileDirectory, fileName), 0, JsonToSimplConstants.StringValueChange); + Debug.Console(1, "Checking '{0}' for '{1}'", fileDirectory, fileName); - // // 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()); - // } + if (Directory.Exists(fileDirectory)) + { + // get the directory info + var directoryInfo = new DirectoryInfo(fileDirectory); - // 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)) - { - try - { - sw.Write(JsonObject.ToString()); - sw.Flush(); - } - catch (Exception e) - { - string err = string.Format("Error writing JSON file:\r{0}", e); - Debug.Console(0, err); - ErrorLog.Warn(err); - return; - } - } - } - } - } + // get the file to be read + var actualFile = directoryInfo.GetFiles(fileName).FirstOrDefault(); + if (actualFile == null) + { + var msg = string.Format("JSON file not found: {0}", Filepath); + OnStringChange(msg, 0, JsonToSimplConstants.StringValueChange); + CrestronConsole.PrintLine(msg); + ErrorLog.Error(msg); + return; + } + + // \xSE\xR\PDT000-Template_Main_Config-Combined_DSP_v00.02.json + // \USER\PDT000-Template_Main_Config-Combined_DSP_v00.02.json + ActualFilePath = actualFile.FullName; + OnStringChange(ActualFilePath, 0, JsonToSimplConstants.ActualFilePathChange); + OnStringChange(string.Format("Actual JSON file is {0}", ActualFilePath), 0, JsonToSimplConstants.StringValueChange); + Debug.Console(1, "Actual JSON file is {0}", ActualFilePath); + + Filename = actualFile.Name; + OnStringChange(Filename, 0, JsonToSimplConstants.FilenameResolvedChange); + OnStringChange(string.Format("JSON Filename is {0}", Filename), 0, JsonToSimplConstants.StringValueChange); + Debug.Console(1, "JSON Filename is {0}", Filename); + + + FilePathName = string.Format(@"{0}{1}", actualFile.DirectoryName, dirSeparator); + OnStringChange(string.Format(@"{0}", actualFile.DirectoryName), 0, JsonToSimplConstants.FilePathResolvedChange); + OnStringChange(string.Format(@"JSON File Path is {0}", actualFile.DirectoryName), 0, JsonToSimplConstants.StringValueChange); + Debug.Console(1, "JSON File Path is {0}", FilePathName); + + var json = File.ReadToEnd(ActualFilePath, System.Text.Encoding.ASCII); + + JsonObject = JObject.Parse(json); + foreach (var child in Children) + child.ProcessAll(); + + OnBoolChange(true, 0, JsonToSimplConstants.JsonIsValidBoolChange); + } + else + { + OnStringChange(string.Format("'{0}' not found", fileDirectory), 0, JsonToSimplConstants.StringValueChange); + Debug.Console(1, "'{0}' not found", fileDirectory); + } + } + catch (Exception e) + { + var msg = string.Format("EvaluateFile Exception: Message\r{0}", e.Message); + OnStringChange(msg, 0, JsonToSimplConstants.StringValueChange); + CrestronConsole.PrintLine(msg); + ErrorLog.Error(msg); + + var stackTrace = string.Format("EvaluateFile: Stack Trace\r{0}", e.StackTrace); + OnStringChange(stackTrace, 0, JsonToSimplConstants.StringValueChange); + CrestronConsole.PrintLine(stackTrace); + ErrorLog.Error(stackTrace); + } + } + + + /// + /// Sets the debug level + /// + /// + public void setDebugLevel(int level) + { + Debug.SetDebugLevel(level); + } + + /// + /// Saves the values to the file + /// + public override void Save() + { + // this code is duplicated in the other masters!!!!!!!!!!!!! + UnsavedValues = new Dictionary(); + // Make each child update their values into master object + foreach (var child in Children) + { + Debug.Console(1, "Master [{0}] checking child [{1}] for updates to save", UniqueID, child.Key); + child.UpdateInputsForMaster(); + } + + if (UnsavedValues == null || UnsavedValues.Count == 0) + { + Debug.Console(1, "Master [{0}] No updated values to save. Skipping", UniqueID); + return; + } + lock (FileLock) + { + Debug.Console(1, "Saving"); + foreach (var path in UnsavedValues.Keys) + { + var tokenToReplace = JsonObject.SelectToken(path); + if (tokenToReplace != null) + {// It's found + tokenToReplace.Replace(UnsavedValues[path]); + Debug.Console(1, "JSON Master[{0}] Updating '{1}'", UniqueID, path); + } + else // No token. Let's make one + { + //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)) + { + try + { + sw.Write(JsonObject.ToString()); + sw.Flush(); + } + catch (Exception e) + { + string err = string.Format("Error writing JSON file:\r{0}", e); + Debug.Console(0, err); + ErrorLog.Warn(err); + return; + } + } + } + } + } } diff --git a/Pepperdash Core/Pepperdash Core/JsonToSimpl/JsonToSimplFixedPathObject.cs b/Pepperdash Core/Pepperdash Core/JsonToSimpl/JsonToSimplFixedPathObject.cs index 01fc2ba..4d56772 100644 --- a/Pepperdash Core/Pepperdash Core/JsonToSimpl/JsonToSimplFixedPathObject.cs +++ b/Pepperdash Core/Pepperdash Core/JsonToSimpl/JsonToSimplFixedPathObject.cs @@ -10,9 +10,14 @@ using Newtonsoft.Json.Linq; namespace PepperDash.Core.JsonToSimpl { - + /// + /// + /// public class JsonToSimplFixedPathObject : JsonToSimplChildObjectBase { + /// + /// Constructor + /// public JsonToSimplFixedPathObject() { this.LinkedToObject = true; diff --git a/Pepperdash Core/Pepperdash Core/JsonToSimpl/JsonToSimplGenericMaster.cs b/Pepperdash Core/Pepperdash Core/JsonToSimpl/JsonToSimplGenericMaster.cs index d83748f..e0f42f8 100644 --- a/Pepperdash Core/Pepperdash Core/JsonToSimpl/JsonToSimplGenericMaster.cs +++ b/Pepperdash Core/Pepperdash Core/JsonToSimpl/JsonToSimplGenericMaster.cs @@ -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 { + /// + /// Generic Master + /// public class JsonToSimplGenericMaster : JsonToSimplMaster { /*****************************************************************************************/ @@ -24,6 +20,9 @@ namespace PepperDash.Core.JsonToSimpl // To prevent multiple same-file access static object WriteLock = new object(); + /// + /// Callback action for saving + /// public Action SaveCallback { get; set; } /*****************************************************************************************/ @@ -116,38 +115,4 @@ namespace PepperDash.Core.JsonToSimpl Debug.Console(0, this, "WARNING: No save callback defined."); } } -} - - -// 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]); \ No newline at end of file +} \ No newline at end of file diff --git a/Pepperdash Core/Pepperdash Core/JsonToSimpl/JsonToSimplMaster.cs b/Pepperdash Core/Pepperdash Core/JsonToSimpl/JsonToSimplMaster.cs index bd48fa9..2443c0a 100644 --- a/Pepperdash Core/Pepperdash Core/JsonToSimpl/JsonToSimplMaster.cs +++ b/Pepperdash Core/Pepperdash Core/JsonToSimpl/JsonToSimplMaster.cs @@ -10,15 +10,27 @@ using Newtonsoft.Json.Linq; namespace PepperDash.Core.JsonToSimpl { + /// + /// Abstract base class for JsonToSimpl interactions + /// public abstract class JsonToSimplMaster : IKeyed { - /*****************************************************************************************/ - /** Events **/ - + /// + /// Notifies of bool change + /// public event EventHandler BoolChange; + /// + /// Notifies of ushort change + /// public event EventHandler UshrtChange; + /// + /// Notifies of string change + /// public event EventHandler StringChange; + /// + /// A collection of associated child modules + /// protected List Children = new List(); /*****************************************************************************************/ @@ -28,6 +40,9 @@ namespace PepperDash.Core.JsonToSimpl /// public string Key { get { return UniqueID; } } + /// + /// A unique ID + /// public string UniqueID { get; protected set; } /// @@ -70,6 +85,9 @@ namespace PepperDash.Core.JsonToSimpl } } + /// + /// + /// 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); } + /// + /// Saves the file + /// public abstract void Save(); - //****************************************************************************************** + /// + /// + /// public static class JsonFixes { + /// + /// Deserializes a string into a JObject + /// + /// + /// 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 } } + /// + /// Deserializes a string into a JArray + /// + /// + /// 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 - //****************************************************************************************** + /// + /// Helper event + /// + /// + /// + /// protected void OnBoolChange(bool state, ushort index, ushort type) { if (BoolChange != null) @@ -169,7 +206,12 @@ namespace PepperDash.Core.JsonToSimpl } } - //****************************************************************************************** + /// + /// Helper event + /// + /// + /// + /// protected void OnUshrtChange(ushort state, ushort index, ushort type) { if (UshrtChange != null) @@ -180,6 +222,12 @@ namespace PepperDash.Core.JsonToSimpl } } + /// + /// Helper event + /// + /// + /// + /// protected void OnStringChange(string value, ushort index, ushort type) { if (StringChange != null) diff --git a/Pepperdash Core/Pepperdash Core/JsonToSimpl/JsonToSimplPortalFileMaster.cs b/Pepperdash Core/Pepperdash Core/JsonToSimpl/JsonToSimplPortalFileMaster.cs index 282c717..ca307e5 100644 --- a/Pepperdash Core/Pepperdash Core/JsonToSimpl/JsonToSimplPortalFileMaster.cs +++ b/Pepperdash Core/Pepperdash Core/JsonToSimpl/JsonToSimplPortalFileMaster.cs @@ -1,221 +1,195 @@ -using System; -//using System.IO; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Crestron.SimplSharp; -using Crestron.SimplSharp.CrestronIO; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; - -using PepperDash.Core.Config; - -namespace PepperDash.Core.JsonToSimpl -{ - public class JsonToSimplPortalFileMaster : JsonToSimplMaster - { - /// - /// Sets the filepath as well as registers this with the Global.Masters list - /// +using System; +//using System.IO; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Crestron.SimplSharp; +using Crestron.SimplSharp.CrestronIO; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; + +using PepperDash.Core.Config; + +namespace PepperDash.Core.JsonToSimpl +{ + /// + /// Portal File Master + /// + public class JsonToSimplPortalFileMaster : JsonToSimplMaster + { + /// + /// Sets the filepath as well as registers this with the Global.Masters list + /// public string PortalFilepath { get; private set; } - public string ActualFilePath { get; private set; } - - /*****************************************************************************************/ - /** Privates **/ - - // To prevent multiple same-file access - object StringBuilderLock = new object(); - static object FileLock = new object(); - - /*****************************************************************************************/ - - /// - /// SIMPL+ default constructor. - /// - public JsonToSimplPortalFileMaster() - { - } - - /// - /// Read, evaluate and udpate status - /// - public void EvaluateFile(string portalFilepath) - { - PortalFilepath = portalFilepath; - - OnBoolChange(false, 0, JsonToSimplConstants.JsonIsValidBoolChange); - if (string.IsNullOrEmpty(PortalFilepath)) - { - CrestronConsole.PrintLine("Cannot evaluate file. JSON file path not set"); - return; - } - - // Resolve possible wildcarded filename - - // If the portal file is xyz.json, then - // the file we want to check for first will be called xyz.local.json - var localFilepath = Path.ChangeExtension(PortalFilepath, "local.json"); - Debug.Console(0, this, "Checking for local file {0}", localFilepath); - var actualLocalFile = GetActualFileInfoFromPath(localFilepath); - - if (actualLocalFile != null) - { + /// + /// File path of the actual file being read (Portal or local) + /// + public string ActualFilePath { get; private set; } + + /*****************************************************************************************/ + /** Privates **/ + + // To prevent multiple same-file access + object StringBuilderLock = new object(); + static object FileLock = new object(); + + /*****************************************************************************************/ + + /// + /// SIMPL+ default constructor. + /// + public JsonToSimplPortalFileMaster() + { + } + + /// + /// Read, evaluate and udpate status + /// + public void EvaluateFile(string portalFilepath) + { + PortalFilepath = portalFilepath; + + OnBoolChange(false, 0, JsonToSimplConstants.JsonIsValidBoolChange); + if (string.IsNullOrEmpty(PortalFilepath)) + { + CrestronConsole.PrintLine("Cannot evaluate file. JSON file path not set"); + return; + } + + // Resolve possible wildcarded filename + + // If the portal file is xyz.json, then + // the file we want to check for first will be called xyz.local.json + var localFilepath = Path.ChangeExtension(PortalFilepath, "local.json"); + Debug.Console(0, this, "Checking for local file {0}", localFilepath); + var actualLocalFile = GetActualFileInfoFromPath(localFilepath); + + if (actualLocalFile != null) + { ActualFilePath = actualLocalFile.FullName; - OnStringChange(ActualFilePath, 0, JsonToSimplConstants.ActualFilePathChange); - } - // If the local file does not exist, then read the portal file xyz.json - // and create the local. - else - { - Debug.Console(1, this, "Local JSON file not found {0}\rLoading portal JSON file", localFilepath); - var actualPortalFile = GetActualFileInfoFromPath(portalFilepath); - if (actualPortalFile != null) - { - var newLocalPath = Path.ChangeExtension(actualPortalFile.FullName, "local.json"); - // got the portal file, hand off to the merge / save method - PortalConfigReader.ReadAndMergeFileIfNecessary(actualPortalFile.FullName, newLocalPath); + OnStringChange(ActualFilePath, 0, JsonToSimplConstants.ActualFilePathChange); + } + // If the local file does not exist, then read the portal file xyz.json + // and create the local. + else + { + Debug.Console(1, this, "Local JSON file not found {0}\rLoading portal JSON file", localFilepath); + var actualPortalFile = GetActualFileInfoFromPath(portalFilepath); + if (actualPortalFile != null) + { + var newLocalPath = Path.ChangeExtension(actualPortalFile.FullName, "local.json"); + // got the portal file, hand off to the merge / save method + PortalConfigReader.ReadAndMergeFileIfNecessary(actualPortalFile.FullName, newLocalPath); ActualFilePath = newLocalPath; - OnStringChange(ActualFilePath, 0, JsonToSimplConstants.ActualFilePathChange); - } - else - { - var msg = string.Format("Portal JSON file not found: {0}", PortalFilepath); - Debug.Console(1, this, msg); - ErrorLog.Error(msg); - return; - } - } - - // At this point we should have a local file. Do it. - Debug.Console(1, "Reading local JSON file {0}", ActualFilePath); - - string json = File.ReadToEnd(ActualFilePath, System.Text.Encoding.ASCII); - - try - { - JsonObject = JObject.Parse(json); - foreach (var child in Children) - child.ProcessAll(); - OnBoolChange(true, 0, JsonToSimplConstants.JsonIsValidBoolChange); - } - catch (Exception e) - { - var msg = string.Format("JSON parsing failed:\r{0}", e); - CrestronConsole.PrintLine(msg); - ErrorLog.Error(msg); - return; - } - } - - /// - /// Returns the FileInfo object for a given path, with possible wildcards - /// - /// - /// - FileInfo GetActualFileInfoFromPath(string path) - { - var dir = Path.GetDirectoryName(path); - var localFilename = Path.GetFileName(path); - var directory = new DirectoryInfo(dir); - // search the directory for the file w/ wildcards - return directory.GetFiles(localFilename).FirstOrDefault(); - } - - /// - /// - /// - /// - public void setDebugLevel(int level) - { - Debug.SetDebugLevel(level); - } - - /// - /// - /// - public override void Save() - { - // this code is duplicated in the other masters!!!!!!!!!!!!! - UnsavedValues = new Dictionary(); - // Make each child update their values into master object - foreach (var child in Children) - { - Debug.Console(1, "Master [{0}] checking child [{1}] for updates to save", UniqueID, child.Key); - child.UpdateInputsForMaster(); - } - - if (UnsavedValues == null || UnsavedValues.Count == 0) - { - Debug.Console(1, "Master [{0}] No updated values to save. Skipping", UniqueID); - return; - } - lock (FileLock) - { - Debug.Console(1, "Saving"); - foreach (var path in UnsavedValues.Keys) - { - var tokenToReplace = JsonObject.SelectToken(path); - if (tokenToReplace != null) - {// It's found - tokenToReplace.Replace(UnsavedValues[path]); - Debug.Console(1, "JSON Master[{0}] Updating '{1}'", UniqueID, path); - } - else // No token. Let's make one - { - //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)) - { - try - { - sw.Write(JsonObject.ToString()); - sw.Flush(); - } - catch (Exception e) - { - string err = string.Format("Error writing JSON file:\r{0}", e); - Debug.Console(0, err); - ErrorLog.Warn(err); - return; - } - } - } - } - } -} + OnStringChange(ActualFilePath, 0, JsonToSimplConstants.ActualFilePathChange); + } + else + { + var msg = string.Format("Portal JSON file not found: {0}", PortalFilepath); + Debug.Console(1, this, msg); + ErrorLog.Error(msg); + return; + } + } + + // At this point we should have a local file. Do it. + Debug.Console(1, "Reading local JSON file {0}", ActualFilePath); + + string json = File.ReadToEnd(ActualFilePath, System.Text.Encoding.ASCII); + + try + { + JsonObject = JObject.Parse(json); + foreach (var child in Children) + child.ProcessAll(); + OnBoolChange(true, 0, JsonToSimplConstants.JsonIsValidBoolChange); + } + catch (Exception e) + { + var msg = string.Format("JSON parsing failed:\r{0}", e); + CrestronConsole.PrintLine(msg); + ErrorLog.Error(msg); + return; + } + } + + /// + /// Returns the FileInfo object for a given path, with possible wildcards + /// + /// + /// + FileInfo GetActualFileInfoFromPath(string path) + { + var dir = Path.GetDirectoryName(path); + var localFilename = Path.GetFileName(path); + var directory = new DirectoryInfo(dir); + // search the directory for the file w/ wildcards + return directory.GetFiles(localFilename).FirstOrDefault(); + } + + /// + /// + /// + /// + public void setDebugLevel(int level) + { + Debug.SetDebugLevel(level); + } + + /// + /// + /// + public override void Save() + { + // this code is duplicated in the other masters!!!!!!!!!!!!! + UnsavedValues = new Dictionary(); + // Make each child update their values into master object + foreach (var child in Children) + { + Debug.Console(1, "Master [{0}] checking child [{1}] for updates to save", UniqueID, child.Key); + child.UpdateInputsForMaster(); + } + + if (UnsavedValues == null || UnsavedValues.Count == 0) + { + Debug.Console(1, "Master [{0}] No updated values to save. Skipping", UniqueID); + return; + } + lock (FileLock) + { + Debug.Console(1, "Saving"); + foreach (var path in UnsavedValues.Keys) + { + var tokenToReplace = JsonObject.SelectToken(path); + if (tokenToReplace != null) + {// It's found + tokenToReplace.Replace(UnsavedValues[path]); + Debug.Console(1, "JSON Master[{0}] Updating '{1}'", UniqueID, path); + } + else // No token. Let's make one + { + //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); + + } + } + using (StreamWriter sw = new StreamWriter(ActualFilePath)) + { + try + { + sw.Write(JsonObject.ToString()); + sw.Flush(); + } + catch (Exception e) + { + string err = string.Format("Error writing JSON file:\r{0}", e); + Debug.Console(0, err); + ErrorLog.Warn(err); + return; + } + } + } + } + } +} diff --git a/Pepperdash Core/Pepperdash Core/Logging/Debug.cs b/Pepperdash Core/Pepperdash Core/Logging/Debug.cs index a0e7ed8..fdb3cb4 100644 --- a/Pepperdash Core/Pepperdash Core/Logging/Debug.cs +++ b/Pepperdash Core/Pepperdash Core/Logging/Debug.cs @@ -561,9 +561,27 @@ namespace PepperDash.Core Directory.Delete(@"\nvram\debugSettings"); } + /// + /// Error level to for message to be logged at + /// public enum ErrorLogLevel { - Error, Warning, Notice, None + /// + /// Error + /// + Error, + /// + /// Warning + /// + Warning, + /// + /// Notice + /// + Notice, + /// + /// None + /// + None, } } } \ No newline at end of file diff --git a/Pepperdash Core/Pepperdash Core/Logging/DebugContext.cs b/Pepperdash Core/Pepperdash Core/Logging/DebugContext.cs index 62ed96a..39c47c3 100644 --- a/Pepperdash Core/Pepperdash Core/Logging/DebugContext.cs +++ b/Pepperdash Core/Pepperdash Core/Logging/DebugContext.cs @@ -11,6 +11,9 @@ using PepperDash.Core.DebugThings; namespace PepperDash.Core { + /// + /// Represents a debugging context + /// public class DebugContext { /// @@ -149,6 +152,14 @@ namespace PepperDash.Core Console(level, "[{0}] {1}", dev.Key, string.Format(format, items)); } + /// + /// + /// + /// + /// + /// + /// + /// public void Console(uint level, IKeyed dev, Debug.ErrorLogLevel errorLogLevel, string format, params object[] items) { @@ -160,6 +171,13 @@ namespace PepperDash.Core } } + /// + /// + /// + /// + /// + /// + /// public void Console(uint level, Debug.ErrorLogLevel errorLogLevel, string format, params object[] items) { @@ -171,6 +189,11 @@ namespace PepperDash.Core } } + /// + /// + /// + /// + /// 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 } } + /// + /// + /// public class DebugContextSaveData { + /// + /// + /// public int Level { get; set; } } } \ No newline at end of file diff --git a/Pepperdash Core/Pepperdash Core/Logging/DebugMemory.cs b/Pepperdash Core/Pepperdash Core/Logging/DebugMemory.cs index d9b925e..ab48afe 100644 --- a/Pepperdash Core/Pepperdash Core/Logging/DebugMemory.cs +++ b/Pepperdash Core/Pepperdash Core/Logging/DebugMemory.cs @@ -40,7 +40,6 @@ namespace PepperDash.Core.DebugThings /// /// /// - /// True if level is between 0 & 2 and the conte public void SetLevel(string contextKey, int level) { if (level < 0 || level > 2) diff --git a/Pepperdash Core/Pepperdash Core/PasswordManagement/PasswordClient.cs b/Pepperdash Core/Pepperdash Core/PasswordManagement/PasswordClient.cs index b274842..e286733 100644 --- a/Pepperdash Core/Pepperdash Core/PasswordManagement/PasswordClient.cs +++ b/Pepperdash Core/Pepperdash Core/PasswordManagement/PasswordClient.cs @@ -6,6 +6,9 @@ using Crestron.SimplSharp; namespace PepperDash.Core.PasswordManagement { + /// + /// A class to allow user interaction with the PasswordManager + /// public class PasswordClient { /// diff --git a/Pepperdash Core/Pepperdash Core/PasswordManagement/PasswordManager.cs b/Pepperdash Core/Pepperdash Core/PasswordManagement/PasswordManager.cs index 2ba323d..c9bc06b 100644 --- a/Pepperdash Core/Pepperdash Core/PasswordManagement/PasswordManager.cs +++ b/Pepperdash Core/Pepperdash Core/PasswordManagement/PasswordManager.cs @@ -10,6 +10,9 @@ using PepperDash.Core.JsonStandardObjects; namespace PepperDash.Core.PasswordManagement { + /// + /// Allows passwords to be stored and managed + /// public class PasswordManager { /// @@ -193,7 +196,7 @@ namespace PepperDash.Core.PasswordManagement /// /// Protected ushort change event handler /// - /// + /// /// /// protected void OnUshrtChange(ushort value, ushort index, ushort type) diff --git a/Pepperdash Core/Pepperdash Core/SystemInfo/EventArgs and Constants.cs b/Pepperdash Core/Pepperdash Core/SystemInfo/EventArgs and Constants.cs index 4e6b500..25f8099 100644 --- a/Pepperdash Core/Pepperdash Core/SystemInfo/EventArgs and Constants.cs +++ b/Pepperdash Core/Pepperdash Core/SystemInfo/EventArgs and Constants.cs @@ -11,22 +11,61 @@ namespace PepperDash.Core.SystemInfo /// public class SystemInfoConstants { + /// + /// + /// public const ushort BoolValueChange = 1; - public const ushort CompleteBoolChange = 2; - public const ushort BusyBoolChange = 3; - + /// + /// + /// + public const ushort CompleteBoolChange = 2; + /// + /// + /// + public const ushort BusyBoolChange = 3; + + /// + /// + /// public const ushort UshortValueChange = 101; + /// + /// + /// public const ushort StringValueChange = 201; - public const ushort ConsoleResponseChange = 202; - public const ushort ProcessorUptimeChange = 203; - public const ushort ProgramUptimeChange = 204; + /// + /// + /// + public const ushort ConsoleResponseChange = 202; + /// + /// + /// + public const ushort ProcessorUptimeChange = 203; + /// + /// + /// + public const ushort ProgramUptimeChange = 204; + /// + /// + /// public const ushort ObjectChange = 301; - public const ushort ProcessorConfigChange = 302; - public const ushort EthernetConfigChange = 303; - public const ushort ControlSubnetConfigChange = 304; - public const ushort ProgramConfigChange = 305; + /// + /// + /// + public const ushort ProcessorConfigChange = 302; + /// + /// + /// + public const ushort EthernetConfigChange = 303; + /// + /// + /// + public const ushort ControlSubnetConfigChange = 304; + /// + /// + /// + public const ushort ProgramConfigChange = 305; } /// @@ -34,9 +73,18 @@ namespace PepperDash.Core.SystemInfo /// public class ProcessorChangeEventArgs : EventArgs { + /// + /// + /// public ProcessorInfo Processor { get; set; } - public ushort Type { get; set; } - public ushort Index { get; set; } + /// + /// + /// + public ushort Type { get; set; } + /// + /// + /// + public ushort Index { get; set; } /// /// Constructor @@ -71,9 +119,18 @@ namespace PepperDash.Core.SystemInfo /// public class EthernetChangeEventArgs : EventArgs { + /// + /// + /// public EthernetInfo Adapter { get; set; } - public ushort Type { get; set; } - public ushort Index { get; set; } + /// + /// + /// + public ushort Type { get; set; } + /// + /// + /// + public ushort Index { get; set; } /// /// Constructor @@ -86,7 +143,7 @@ namespace PepperDash.Core.SystemInfo /// /// Constructor overload /// - /// + /// /// public EthernetChangeEventArgs(EthernetInfo ethernet, ushort type) { @@ -97,8 +154,9 @@ namespace PepperDash.Core.SystemInfo /// /// Constructor overload /// - /// + /// /// + /// public EthernetChangeEventArgs(EthernetInfo ethernet, ushort type, ushort index) { Adapter = ethernet; @@ -112,9 +170,18 @@ namespace PepperDash.Core.SystemInfo /// public class ControlSubnetChangeEventArgs : EventArgs { + /// + /// + /// public ControlSubnetInfo Adapter { get; set; } - public ushort Type { get; set; } - public ushort Index { get; set; } + /// + /// + /// + public ushort Type { get; set; } + /// + /// + /// + public ushort Index { get; set; } /// /// Constructor @@ -149,9 +216,18 @@ namespace PepperDash.Core.SystemInfo /// public class ProgramChangeEventArgs : EventArgs { + /// + /// + /// public ProgramInfo Program { get; set; } - public ushort Type { get; set; } - public ushort Index { get; set; } + /// + /// + /// + public ushort Type { get; set; } + /// + /// + /// + public ushort Index { get; set; } /// /// Constructor @@ -164,7 +240,7 @@ namespace PepperDash.Core.SystemInfo /// /// Constructor overload /// - /// + /// /// public ProgramChangeEventArgs(ProgramInfo program, ushort type) { @@ -175,8 +251,9 @@ namespace PepperDash.Core.SystemInfo /// /// Constructor overload /// - /// + /// /// + /// public ProgramChangeEventArgs(ProgramInfo program, ushort type, ushort index) { Program = program; diff --git a/Pepperdash Core/Pepperdash Core/SystemInfo/SystemInfoConfig.cs b/Pepperdash Core/Pepperdash Core/SystemInfo/SystemInfoConfig.cs index cbf5f4b..7b33b47 100644 --- a/Pepperdash Core/Pepperdash Core/SystemInfo/SystemInfoConfig.cs +++ b/Pepperdash Core/Pepperdash Core/SystemInfo/SystemInfoConfig.cs @@ -11,15 +11,45 @@ namespace PepperDash.Core.SystemInfo /// public class ProcessorInfo { + /// + /// + /// public string Model { get; set; } + /// + /// + /// public string SerialNumber { get; set; } + /// + /// + /// public string Firmware { get; set; } + /// + /// + /// public string FirmwareDate { get; set; } + /// + /// + /// public string OsVersion { get; set; } + /// + /// + /// public string RuntimeEnvironment { get; set; } + /// + /// + /// public string DevicePlatform { get; set; } + /// + /// + /// public string ModuleDirectory { get; set; } - public string LocalTimeZone { get; set; } + /// + /// + /// + public string LocalTimeZone { get; set; } + /// + /// + /// public string ProgramIdTag { get; set; } /// @@ -36,15 +66,45 @@ namespace PepperDash.Core.SystemInfo /// public class EthernetInfo { + /// + /// + /// public ushort DhcpIsOn { get; set; } + /// + /// + /// public string Hostname { get; set; } + /// + /// + /// public string MacAddress { get; set; } + /// + /// + /// public string IpAddress { get; set; } + /// + /// + /// public string Subnet { get; set; } + /// + /// + /// public string Gateway { get; set; } + /// + /// + /// public string Dns1 { get; set; } + /// + /// + /// public string Dns2 { get; set; } + /// + /// + /// public string Dns3 { get; set; } + /// + /// + /// public string Domain { get; set; } /// @@ -61,11 +121,29 @@ namespace PepperDash.Core.SystemInfo /// public class ControlSubnetInfo { + /// + /// + /// public ushort Enabled { get; set; } + /// + /// + /// public ushort IsInAutomaticMode { get; set; } + /// + /// + /// public string MacAddress { get; set; } + /// + /// + /// public string IpAddress { get; set; } + /// + /// + /// public string Subnet { get; set; } + /// + /// + /// public string RouterPrefix { get; set; } /// @@ -82,13 +160,37 @@ namespace PepperDash.Core.SystemInfo /// public class ProgramInfo { + /// + /// + /// public string Name { get; set; } + /// + /// + /// public string Header { get; set; } + /// + /// + /// public string System { get; set; } + /// + /// + /// public string ProgramIdTag { get; set; } + /// + /// + /// public string CompileTime { get; set; } + /// + /// + /// public string Database { get; set; } + /// + /// + /// public string Environment { get; set; } + /// + /// + /// public string Programmer { get; set; } /// diff --git a/Pepperdash Core/Pepperdash Core/SystemInfo/SystemInfoToSimpl.cs b/Pepperdash Core/Pepperdash Core/SystemInfo/SystemInfoToSimpl.cs index 1d58a80..d4fe40a 100644 --- a/Pepperdash Core/Pepperdash Core/SystemInfo/SystemInfoToSimpl.cs +++ b/Pepperdash Core/Pepperdash Core/SystemInfo/SystemInfoToSimpl.cs @@ -11,12 +11,30 @@ namespace PepperDash.Core.SystemInfo /// public class SystemInfoToSimpl { + /// + /// Notifies of bool change + /// public event EventHandler BoolChange; + /// + /// Notifies of string change + /// public event EventHandler StringChange; + /// + /// Notifies of processor change + /// public event EventHandler ProcessorChange; + /// + /// Notifies of ethernet change + /// public event EventHandler EthernetChange; + /// + /// Notifies of control subnet change + /// public event EventHandler ControlSubnetChange; + /// + /// Notifies of program change + /// public event EventHandler ProgramChange; /// @@ -309,10 +327,10 @@ namespace PepperDash.Core.SystemInfo /// /// private method to parse console messages /// - /// + /// /// - /// - /// + /// + /// /// private string ParseConsoleResponse(string data, string line, string dataStart, string dataEnd) { diff --git a/Pepperdash Core/Pepperdash Core/WebApi/Presets/Preset.cs b/Pepperdash Core/Pepperdash Core/WebApi/Presets/Preset.cs index 18879a2..804156f 100644 --- a/Pepperdash Core/Pepperdash Core/WebApi/Presets/Preset.cs +++ b/Pepperdash Core/Pepperdash Core/WebApi/Presets/Preset.cs @@ -9,20 +9,44 @@ using Newtonsoft.Json; namespace PepperDash.Core.WebApi.Presets { + /// + /// Represents a preset + /// public class Preset { + /// + /// ID of preset + /// public int Id { get; set; } + /// + /// User ID + /// public int UserId { get; set; } + /// + /// Room Type ID + /// public int RoomTypeId { get; set; } + /// + /// Preset Name + /// public string PresetName { get; set; } + /// + /// Preset Number + /// public int PresetNumber { get; set; } + /// + /// Preset Data + /// public string Data { get; set; } + /// + /// Constructor + /// public Preset() { PresetName = ""; @@ -42,10 +66,13 @@ namespace PepperDash.Core.WebApi.Presets public bool LookupSuccess { get; private set; } /// - /// S+ helper for stupid S+ + /// S+ helper /// public ushort ULookupSuccess { get { return (ushort)(LookupSuccess ? 1 : 0); } } + /// + /// The preset + /// public Preset Preset { get; private set; } /// @@ -53,6 +80,11 @@ namespace PepperDash.Core.WebApi.Presets /// public PresetReceivedEventArgs() { } + /// + /// Constructor + /// + /// + /// public PresetReceivedEventArgs(Preset preset, bool success) { LookupSuccess = success; diff --git a/Pepperdash Core/Pepperdash Core/WebApi/Presets/User.cs b/Pepperdash Core/Pepperdash Core/WebApi/Presets/User.cs index ce119c7..c82824f 100644 --- a/Pepperdash Core/Pepperdash Core/WebApi/Presets/User.cs +++ b/Pepperdash Core/Pepperdash Core/WebApi/Presets/User.cs @@ -11,12 +11,24 @@ namespace PepperDash.Core.WebApi.Presets /// public class User { + /// + /// + /// public int Id { get; set; } + /// + /// + /// public string ExternalId { get; set; } + /// + /// + /// public string FirstName { get; set; } + /// + /// + /// public string LastName { get; set; } } @@ -36,6 +48,9 @@ namespace PepperDash.Core.WebApi.Presets /// public ushort ULookupSuccess { get { return (ushort)(LookupSuccess ? 1 : 0); } } + /// + /// + /// public User User { get; private set; } /// @@ -43,6 +58,11 @@ namespace PepperDash.Core.WebApi.Presets /// public UserReceivedEventArgs() { } + /// + /// Constructor + /// + /// + /// public UserReceivedEventArgs(User user, bool success) { LookupSuccess = success; @@ -55,10 +75,19 @@ namespace PepperDash.Core.WebApi.Presets /// public class UserAndRoomMessage { + /// + /// + /// public int UserId { get; set; } + /// + /// + /// public int RoomTypeId { get; set; } + /// + /// + /// public int PresetNumber { get; set; } } } \ No newline at end of file diff --git a/Pepperdash Core/Pepperdash Core/WebApi/Presets/WebApiPasscodeClient.cs b/Pepperdash Core/Pepperdash Core/WebApi/Presets/WebApiPasscodeClient.cs index d9c8cc0..e7e0efb 100644 --- a/Pepperdash Core/Pepperdash Core/WebApi/Presets/WebApiPasscodeClient.cs +++ b/Pepperdash Core/Pepperdash Core/WebApi/Presets/WebApiPasscodeClient.cs @@ -14,12 +14,24 @@ using PepperDash.Core.JsonToSimpl; namespace PepperDash.Core.WebApi.Presets { + /// + /// Passcode client for the WebApi + /// public class WebApiPasscodeClient : IKeyed { + /// + /// Notifies when user received + /// public event EventHandler UserReceived; + /// + /// Notifies when Preset received + /// public event EventHandler PresetReceived; + /// + /// Unique identifier for this instance + /// public string Key { get; private set; } //string JsonMasterKey; @@ -46,6 +58,13 @@ namespace PepperDash.Core.WebApi.Presets { } + /// + /// Initializes the instance + /// + /// + /// + /// + /// 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); } + /// + /// Gets the user for a passcode + /// + /// public void GetUserForPasscode(string passcode) { // Bullshit duplicate code here... These two cases should be the same diff --git a/Pepperdash Core/Pepperdash Core/XSigUtility/Serialization/IXSigSerialization.cs b/Pepperdash Core/Pepperdash Core/XSigUtility/Serialization/IXSigSerialization.cs index 074d8a5..8303731 100644 --- a/Pepperdash Core/Pepperdash Core/XSigUtility/Serialization/IXSigSerialization.cs +++ b/Pepperdash Core/Pepperdash Core/XSigUtility/Serialization/IXSigSerialization.cs @@ -8,7 +8,18 @@ namespace PepperDash.Core.Intersystem.Serialization /// public interface IXSigSerialization { + /// + /// Serialize the sig data + /// + /// IEnumerable Serialize(); + + /// + /// Deserialize the sig data + /// + /// + /// + /// T Deserialize(IEnumerable tokens) where T : class, IXSigSerialization; } } \ No newline at end of file diff --git a/Pepperdash Core/Pepperdash Core/XSigUtility/Serialization/XSigSerializationException.cs b/Pepperdash Core/Pepperdash Core/XSigUtility/Serialization/XSigSerializationException.cs index f1c50f5..8f3fc04 100644 --- a/Pepperdash Core/Pepperdash Core/XSigUtility/Serialization/XSigSerializationException.cs +++ b/Pepperdash Core/Pepperdash Core/XSigUtility/Serialization/XSigSerializationException.cs @@ -2,10 +2,27 @@ using System; namespace PepperDash.Core.Intersystem.Serialization { + /// + /// Class to handle this specific exception type + /// public class XSigSerializationException : Exception { + /// + /// default constructor + /// public XSigSerializationException() { } + + /// + /// constructor with message + /// + /// public XSigSerializationException(string message) : base(message) { } + + /// + /// constructor with message and innner exception + /// + /// + /// public XSigSerializationException(string message, Exception inner) : base(message, inner) { } } } \ No newline at end of file diff --git a/Pepperdash Core/Pepperdash Core/XSigUtility/Tokens/XSigAnalogToken.cs b/Pepperdash Core/Pepperdash Core/XSigUtility/Tokens/XSigAnalogToken.cs index 6236f3e..5847336 100644 --- a/Pepperdash Core/Pepperdash Core/XSigUtility/Tokens/XSigAnalogToken.cs +++ b/Pepperdash Core/Pepperdash Core/XSigUtility/Tokens/XSigAnalogToken.cs @@ -2,10 +2,18 @@ using System; namespace PepperDash.Core.Intersystem.Tokens { + /// + /// Represents an XSigAnalogToken + /// public sealed class XSigAnalogToken : XSigToken, IFormattable { private readonly ushort _value; + /// + /// Constructor + /// + /// + /// public XSigAnalogToken(int index, ushort value) : base(index) { @@ -16,16 +24,26 @@ namespace PepperDash.Core.Intersystem.Tokens _value = value; } + /// + /// + /// public ushort Value { get { return _value; } } + /// + /// + /// public override XSigTokenType TokenType { get { return XSigTokenType.Analog; } } + /// + /// + /// + /// public override byte[] GetBytes() { return new[] { @@ -36,17 +54,32 @@ namespace PepperDash.Core.Intersystem.Tokens }; } + /// + /// + /// + /// + /// public override XSigToken GetTokenWithOffset(int offset) { if (offset == 0) return this; return new XSigAnalogToken(Index + offset, Value); } + /// + /// + /// + /// public override string ToString() { return Index + " = 0x" + Value.ToString("X4"); } + /// + /// + /// + /// + /// + /// public string ToString(string format, IFormatProvider formatProvider) { return Value.ToString(format, formatProvider); diff --git a/Pepperdash Core/Pepperdash Core/XSigUtility/Tokens/XSigDigitalToken.cs b/Pepperdash Core/Pepperdash Core/XSigUtility/Tokens/XSigDigitalToken.cs index 7840e90..70ccc85 100644 --- a/Pepperdash Core/Pepperdash Core/XSigUtility/Tokens/XSigDigitalToken.cs +++ b/Pepperdash Core/Pepperdash Core/XSigUtility/Tokens/XSigDigitalToken.cs @@ -2,10 +2,18 @@ using System; namespace PepperDash.Core.Intersystem.Tokens { + /// + /// Represents an XSigDigitalToken + /// public sealed class XSigDigitalToken : XSigToken { private readonly bool _value; + /// + /// + /// + /// + /// public XSigDigitalToken(int index, bool value) : base(index) { @@ -16,16 +24,26 @@ namespace PepperDash.Core.Intersystem.Tokens _value = value; } + /// + /// + /// public bool Value { get { return _value; } } + /// + /// + /// public override XSigTokenType TokenType { get { return XSigTokenType.Digital; } } + /// + /// + /// + /// public override byte[] GetBytes() { return new[] { @@ -34,17 +52,31 @@ namespace PepperDash.Core.Intersystem.Tokens }; } + /// + /// + /// + /// + /// public override XSigToken GetTokenWithOffset(int offset) { if (offset == 0) return this; return new XSigDigitalToken(Index + offset, Value); } + /// + /// + /// + /// public override string ToString() { return Index + " = " + (Value ? "High" : "Low"); } + /// + /// + /// + /// + /// public string ToString(IFormatProvider formatProvider) { return Value.ToString(formatProvider); diff --git a/Pepperdash Core/Pepperdash Core/XSigUtility/Tokens/XSigSerialToken.cs b/Pepperdash Core/Pepperdash Core/XSigUtility/Tokens/XSigSerialToken.cs index deb721a..25ee3fd 100644 --- a/Pepperdash Core/Pepperdash Core/XSigUtility/Tokens/XSigSerialToken.cs +++ b/Pepperdash Core/Pepperdash Core/XSigUtility/Tokens/XSigSerialToken.cs @@ -3,10 +3,18 @@ using System.Text; namespace PepperDash.Core.Intersystem.Tokens { + /// + /// Represents an XSigSerialToken + /// public sealed class XSigSerialToken : XSigToken { private readonly string _value; + /// + /// Constructor + /// + /// + /// public XSigSerialToken(int index, string value) : base(index) { @@ -17,16 +25,26 @@ namespace PepperDash.Core.Intersystem.Tokens _value = value; } + /// + /// + /// public string Value { get { return _value; } } + /// + /// + /// public override XSigTokenType TokenType { get { return XSigTokenType.Serial; } } + /// + /// + /// + /// 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; } + /// + /// + /// + /// + /// public override XSigToken GetTokenWithOffset(int offset) { if (offset == 0) return this; return new XSigSerialToken(Index + offset, Value); } + /// + /// + /// + /// public override string ToString() { return Index + " = \"" + Value + "\"";