diff --git a/README.md b/README.md index fcea24e..d4ab98f 100644 --- a/README.md +++ b/README.md @@ -1 +1,68 @@ -# epi-epiphan-pearl \ No newline at end of file +# epi-epiphan-pearl + +### Minimum Essentials Framework Versions + +- 1.12.8 + + + + + +### Join Maps + +#### Digitals + +| Join | Type (RW) | Description | +| --- | --- | --- | +| 1 | R | Recorder Online | +| 2 | R | Start Recording | +| 3 | R | Stop Recording | +| 4 | R | Pause Recording | +| 5 | R | Resume Recording | +| 6 | R | Extend Recording | +| 5 | R | Recording Is Paused | +| 6 | R | Recording Is In Progress | +| 20 | R | Next Recording Exists | + +#### Serials + +| Join | Type (RW) | Description | +| --- | --- | --- | +| 1 | R | Set Hostname | +| 11 | R | CurrentRecordingId | +| 12 | R | Recorder Name | +| 13 | R | CurrentRecordingStartTime | +| 14 | R | CurrentRecordingEndTime | +| 15 | R | CurrentRecordingLength | +| 16 | R | CurrentRecordingTimeRemaining | +| 21 | R | NextRecordingId | +| 22 | R | Recorder Name | +| 23 | R | NextRecordingStartTime | +| 24 | R | NextRecordingEndTime | +| 25 | R | NextRecordingLength | + + +### Interfaces Implemented + +- IEpiphanPearlClient +- ICommunicationMonitor + + +### Base Classes + +- ReconfigurableBridgableDevice +- DateTimeConverterBase +- JoinMapBaseAdvanced +- StatusMonitorBase + + +### Public Methods + +- public string Delete(string path) +- public void setHost(string host) +- public void SetIpAddress(string hostname) +- public string Delete(string path) +- public void setHost(string host) +- public void SetOnlineStatus(bool isOnline) +- public void UpdateTimers() + diff --git a/src/EpiphanPearl/EpiphanPearlClient.cs b/src/EpiphanPearl/EpiphanPearlClient.cs index 926085e..2532661 100644 --- a/src/EpiphanPearl/EpiphanPearlClient.cs +++ b/src/EpiphanPearl/EpiphanPearlClient.cs @@ -1,205 +1,214 @@ -using System; -using Crestron.SimplSharp.Net.Http; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; -using PepperDash.Core; -using PepperDash.Essentials.EpiphanPearl.Interfaces; -using PepperDash.Essentials.EpiphanPearl.Utilities; -using System.Text; - -namespace PepperDash.Essentials.EpiphanPearl -{ - public class EpiphanPearlClient : IEpiphanPearlClient - { - private readonly HttpClient _client; - - private readonly HttpHeader _authHeader; - - private string _basePath; - - public EpiphanPearlClient(string host, string username, string password) - { - _client = new HttpClient(); - - _basePath = string.Format("http://{0}/api", host); - - _authHeader = HttpHelpers.GetAuthorizationHeader(username, password); - } - - public T Get(string path) where T:class - { - var request = CreateRequest(path, RequestType.Get); - - var response = SendRequest(request); - - if (response == null || response.Length <= 0) - { - Debug.Console(2, "[T Get] Response to {0} is null", request.Url, response); - return null; - } - - try - { - Debug.Console(2, "[T Get] Response to {0}: {1}", request.Url, response); - return JsonConvert.DeserializeObject(response); - } - catch (Exception ex) - { - Debug.Console(0, "[T Get] Exception sending to {0}: {1}", request.Url, ex.Message); - Debug.Console(2, "Stack Trace: {0}", ex.StackTrace); - - if (ex.InnerException == null) return null; - - Debug.Console(0, "[T Get] Exception sending to {0}: {1}", request.Url, ex.InnerException.Message); - Debug.Console(2, "Stack Trace: {0}", ex.InnerException.StackTrace); - - return null; - } - } - - public TResponse Post (string path, TBody body) where TBody: class where TResponse: class - { - var request = CreateRequest(path, RequestType.Post); - - request.Header.ContentType = "application/json"; - request.ContentString = body != null ? JsonConvert.SerializeObject(body) : string.Empty; - - Debug.Console(2, "Post request: {0} - {1}", request.Url, request.ContentString); - - var response = SendRequest(request); - - if (response == null) - { - return null; - } - - try - { - return JsonConvert.DeserializeObject(response); - } - catch (Exception ex) - { - Debug.Console(0, "[TResponse Post] Exception sending to {0}: {1}", request.Url, ex.Message); - Debug.Console(2, "Stack Trace: {0}", ex.StackTrace); - - if (ex.InnerException == null) return null; - - Debug.Console(0, "[TResponse Post] Exception sending to {0}: {1}", request.Url, ex.InnerException.Message); - Debug.Console(2, "Stack Trace: {0}", ex.InnerException.StackTrace); - - return null; - } - } - - public TResponse Post(string path) - where TResponse : class - { - var request = CreateRequest(path, RequestType.Post); - - request.Header.ContentType = "application/json"; - - var response = SendRequest(request); - - if (response == null) - { - return null; - } - - try - { - return JsonConvert.DeserializeObject(response); - } - catch (Exception ex) - { - Debug.Console(0, "[TResponse Post] Exception sending to {0}: {1}", request.Url, ex.Message); - Debug.Console(2, "Stack Trace: {0}", ex.StackTrace); - - if (ex.InnerException == null) return null; - - Debug.Console(0, "[TResponse Post] Exception sending to {0}: {1}", request.Url, ex.InnerException.Message); - Debug.Console(2, "Stack Trace: {0}", ex.InnerException.StackTrace); - - return null; - } - } - - public string Delete(string path) - { - var request = CreateRequest(path, RequestType.Delete); - - return SendRequest(request); - } - - public void setHost(string host) - { - _basePath = string.Format("http://{0}/api", host); - } - - private string SendRequest(HttpClientRequest request) - { - if (request == null) - { - Debug.Console(2, "[SendRequest] Request is null"); - return null; - } - - if (_client == null) - { - Debug.Console(2, "[SendRequest] HttpClient is null"); - return null; - } - - try - { - Debug.Console(2, "[SendRequest] Dispatching request to {0}", request.Url); // Log before dispatch - var response = _client.Dispatch(request); - - if (response == null) - { - Debug.Console(2, "[SendRequest] Response is null after dispatching request to {0}", request.Url); - return null; - } - - //Debug.Console(0, "Raw response bytes: {0}", BitConverter.ToString(response.ContentBytes)); - - try - { - // Attempt to parse the response content as a string - var contentString = response.ContentString; - return contentString; - } - catch (Exception ex) - { - Debug.Console(2, "[SendRequest] Error converting response to string for URL {0}: {1}", request.Url, ex.Message); - return null; - } - } - catch (Exception ex) - { - Debug.Console(0, "[SendRequest] Exception sending to {0}: {1}", request.Url, ex.Message); - Debug.Console(2, "Stack Trace: {0}", ex.StackTrace); - - if (ex.InnerException != null) - { - Debug.Console(0, "[SendRequest] Inner Exception: {1}", request.Url, ex.InnerException.Message); - Debug.Console(2, "Inner Stack Trace: {0}", ex.InnerException.StackTrace); - } - - return null; - } - } - - private HttpClientRequest CreateRequest(string path, RequestType requestType) - { - var request = new HttpClientRequest - { - Url = new UrlParser(string.Format("{0}{1}", _basePath, path)), - RequestType = requestType - }; - - request.Header.AddHeader(_authHeader); - - return request; - } - } +using System; +using Crestron.SimplSharp.Net.Http; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using PepperDash.Core; +using PepperDash.Essentials.EpiphanPearl.Interfaces; +using PepperDash.Essentials.EpiphanPearl.Utilities; +using System.Text; + +namespace PepperDash.Essentials.EpiphanPearl +{ + public class EpiphanPearlClient : IEpiphanPearlClient + { + private readonly HttpClient _client; + + private readonly HttpHeader _authHeader; + + private string _basePath; + + public EpiphanPearlClient(string host, string username, string password) + { + _client = new HttpClient(); + + _basePath = string.Format("http://{0}/api", host); + + _authHeader = HttpHelpers.GetAuthorizationHeader(username, password); + } + + public T Get(string path) where T:class + { + var request = CreateRequest(path, RequestType.Get); + + var response = SendRequest(request); + + if (response == null || response.Length <= 0) + { + Debug.Console(2, "[T Get] Response to {0} is null", request.Url, response); + return null; + } + + try + { + Debug.Console(2, "[T Get] Response to {0}: {1}", request.Url, response); + return JsonConvert.DeserializeObject(response); + } + catch (Exception ex) + { + Debug.Console(0, "[T Get] Exception sending to {0}: {1}", request.Url, ex.Message); + Debug.Console(2, "Stack Trace: {0}", ex.StackTrace); + + if (ex.InnerException == null) return null; + + Debug.Console(0, "[T Get] Exception sending to {0}: {1}", request.Url, ex.InnerException.Message); + Debug.Console(2, "Stack Trace: {0}", ex.InnerException.StackTrace); + + return null; + } + finally + { + + } + } + + public TResponse Post (string path, TBody body) where TBody: class where TResponse: class + { + var request = CreateRequest(path, RequestType.Post); + + request.Header.ContentType = "application/json"; + request.ContentString = body != null ? JsonConvert.SerializeObject(body) : string.Empty; + + Debug.Console(2, "Post request: {0} - {1}", request.Url, request.ContentString); + + var response = SendRequest(request); + + if (response == null) + { + return null; + } + + try + { + return JsonConvert.DeserializeObject(response); + } + catch (Exception ex) + { + Debug.Console(0, "[TResponse Post] Exception sending to {0}: {1}", request.Url, ex.Message); + Debug.Console(2, "Stack Trace: {0}", ex.StackTrace); + + if (ex.InnerException == null) return null; + + Debug.Console(0, "[TResponse Post] Exception sending to {0}: {1}", request.Url, ex.InnerException.Message); + Debug.Console(2, "Stack Trace: {0}", ex.InnerException.StackTrace); + + return null; + } + } + + public TResponse Post(string path) + where TResponse : class + { + var request = CreateRequest(path, RequestType.Post); + + request.Header.ContentType = "application/json"; + + var response = SendRequest(request); + + if (response == null) + { + return null; + } + + try + { + return JsonConvert.DeserializeObject(response); + } + catch (Exception ex) + { + Debug.Console(0, "[TResponse Post] Exception sending to {0}: {1}", request.Url, ex.Message); + Debug.Console(2, "Stack Trace: {0}", ex.StackTrace); + + if (ex.InnerException == null) return null; + + Debug.Console(0, "[TResponse Post] Exception sending to {0}: {1}", request.Url, ex.InnerException.Message); + Debug.Console(2, "Stack Trace: {0}", ex.InnerException.StackTrace); + + return null; + } + } + + public string Delete(string path) + { + var request = CreateRequest(path, RequestType.Delete); + + return SendRequest(request); + } + + public void setHost(string host) + { + _basePath = string.Format("http://{0}/api", host); + } + + private string SendRequest(HttpClientRequest request) + { + if (request == null) + { + Debug.Console(2, "[SendRequest] Request is null"); + return null; + } + + if (_client == null) + { + Debug.Console(2, "[SendRequest] HttpClient is null"); + return null; + } + + try + { + Debug.Console(2, "[SendRequest] Dispatching request to {0}", request.Url); // Log before dispatch + var response = _client.Dispatch(request); + + if (response == null) + { + Debug.Console(2, "[SendRequest] Response is null after dispatching request to {0}", request.Url); + return null; + } + + //Debug.Console(0, "Raw response bytes: {0}", BitConverter.ToString(response.ContentBytes)); + + try + { + // Attempt to parse the response content as a string + var contentString = response.ContentString; + return contentString; + } + catch (Exception ex) + { + Debug.Console(2, "[SendRequest] Error converting response to string for URL {0}: {1}", request.Url, ex.Message); + return null; + } + finally + { + response.Dispose(); + } + } + catch (Exception ex) + { + Debug.Console(0, "[SendRequest] Exception sending to {0}: {1}", request.Url, ex.Message); + Debug.Console(2, "Stack Trace: {0}", ex.StackTrace); + + if (ex.InnerException != null) + { + Debug.Console(0, "[SendRequest] Inner Exception: {1}", request.Url, ex.InnerException.Message); + Debug.Console(2, "Inner Stack Trace: {0}", ex.InnerException.StackTrace); + } + + return null; + } + + } + + private HttpClientRequest CreateRequest(string path, RequestType requestType) + { + var request = new HttpClientRequest + { + Url = new UrlParser(string.Format("{0}{1}", _basePath, path)), + RequestType = requestType + }; + + request.Header.AddHeader(_authHeader); + + return request; + } + } } \ No newline at end of file diff --git a/src/epi-epiphan-pearl.csproj b/src/epi-epiphan-pearl.csproj index 6780ee6..c048ef1 100644 --- a/src/epi-epiphan-pearl.csproj +++ b/src/epi-epiphan-pearl.csproj @@ -1,106 +1,106 @@ - - - Release - AnyCPU - 9.0.30729 - 2.0 - {29B51836-D58A-4C57-8305-CD3B6398A851} - Library - Properties - PepperDash.Essentials.EpiphanPearl - EpiphanPearlEpi - {0B4745B0-194B-4BB6-8E21-E9057CA92300};{4D628B5B-2FBC-4AA6-8C16-197242AEB884};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - WindowsCE - E2BECB1F-8C8C-41ba-B736-9BE7D946A398 - 5.0 - SmartDeviceProject1 - v3.5 - Windows CE - - - - - .allowedReferenceRelatedFileExtensions - true - full - false - bin\Debug\ - DEBUG;TRACE; - prompt - 4 - 512 - true - true - off - - - .allowedReferenceRelatedFileExtensions - none - true - bin\Release\ - prompt - 4 - 512 - true - true - off - - - - - False - ..\packages\PepperDashEssentials\lib\net35\PepperDash_Core.dll - - - False - ..\packages\PepperDashEssentials\lib\net35\PepperDash_Essentials_Core.dll - - - False - ..\..\..\..\..\..\..\ProgramData\Crestron\SDK\SimplSharpCustomAttributesInterface.dll - False - - - False - ..\..\..\..\..\..\..\ProgramData\Crestron\SDK\SimplSharpHelperInterface.dll - False - - - False - ..\..\..\..\..\..\..\ProgramData\Crestron\SDK\SimplSharpNewtonsoft.dll - - - False - ..\..\..\..\..\..\..\ProgramData\Crestron\SDK\SimplSharpPro.exe - False - - - False - ..\..\..\..\..\..\..\ProgramData\Crestron\SDK\SimplSharpReflectionInterface.dll - - - - - - - - - - - - - - - - - - - - - - - - - rem S# Pro preparation will execute after these operations - + + + Release + AnyCPU + 9.0.30729 + 2.0 + {29B51836-D58A-4C57-8305-CD3B6398A851} + Library + Properties + PepperDash.Essentials.EpiphanPearl + EpiphanPearlEpi + {0B4745B0-194B-4BB6-8E21-E9057CA92300};{4D628B5B-2FBC-4AA6-8C16-197242AEB884};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + WindowsCE + E2BECB1F-8C8C-41ba-B736-9BE7D946A398 + 5.0 + SmartDeviceProject1 + v3.5 + Windows CE + + + + + .allowedReferenceRelatedFileExtensions + true + full + false + bin\Debug\ + DEBUG;TRACE; + prompt + 4 + 512 + true + true + off + + + .allowedReferenceRelatedFileExtensions + none + true + bin\Release\ + prompt + 4 + 512 + true + true + off + + + + + False + ..\packages\PepperDashEssentials\lib\net35\PepperDash_Core.dll + + + False + ..\packages\PepperDashEssentials\lib\net35\PepperDash_Essentials_Core.dll + + + False + ..\..\..\..\..\..\..\ProgramData\Crestron\SDK\SimplSharpCustomAttributesInterface.dll + False + + + False + ..\..\..\..\..\..\..\ProgramData\Crestron\SDK\SimplSharpHelperInterface.dll + False + + + False + ..\..\..\..\..\..\..\ProgramData\Crestron\SDK\SimplSharpNewtonsoft.dll + + + False + ..\..\..\..\..\..\..\ProgramData\Crestron\SDK\SimplSharpPro.exe + False + + + False + ..\..\..\..\..\..\..\ProgramData\Crestron\SDK\SimplSharpReflectionInterface.dll + + + + + + + + + + + + + + + + + + + + + + + + + rem S# Pro preparation will execute after these operations + \ No newline at end of file