refactor: Changed CWS references to WebApi, re-organized Web folder

This commit is contained in:
jdevito
2023-01-18 15:22:50 -06:00
parent 6221619400
commit a56f66230a
5 changed files with 30 additions and 24 deletions

View File

@@ -93,9 +93,9 @@
<Compile Include="Comm\TcpServerConfigObject.cs" /> <Compile Include="Comm\TcpServerConfigObject.cs" />
<Compile Include="Config\PortalConfigReader.cs" /> <Compile Include="Config\PortalConfigReader.cs" />
<Compile Include="CoreInterfaces.cs" /> <Compile Include="CoreInterfaces.cs" />
<Compile Include="CrestronWebServer\CwsBaseHandler.cs" /> <Compile Include="Web\RequestHandlers\WebApiBaseRequestHandler.cs" />
<Compile Include="CrestronWebServer\GenericCwsBase.cs" /> <Compile Include="Web\WebApiServer.cs" />
<Compile Include="CrestronWebServer\CwsDefaultRequestHandler.cs" /> <Compile Include="Web\RequestHandlers\DefaultRequestRequestHandler.cs" />
<Compile Include="EventArgs.cs" /> <Compile Include="EventArgs.cs" />
<Compile Include="GenericRESTfulCommunications\Constants.cs" /> <Compile Include="GenericRESTfulCommunications\Constants.cs" />
<Compile Include="GenericRESTfulCommunications\GenericRESTfulClient.cs" /> <Compile Include="GenericRESTfulCommunications\GenericRESTfulClient.cs" />

View File

@@ -1,2 +1,3 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> <wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=CrestronWebServer/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary> <s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=CrestronWebServer/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=Web/@EntryIndexedValue">False</s:Boolean></wpf:ResourceDictionary>

View File

@@ -1,8 +1,8 @@
using Crestron.SimplSharp.WebScripting; using Crestron.SimplSharp.WebScripting;
namespace PepperDash.Core namespace PepperDash.Core.Web.RequestHandlers
{ {
public class CwsDefaultRequestHandler : CwsBaseHandler public class DefaultRequestRequestHandler : WebApiBaseRequestHandler
{ {
/// <summary> /// <summary>
/// Handles CONNECT method requests /// Handles CONNECT method requests

View File

@@ -1,21 +1,20 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using Crestron.SimplSharp.WebScripting; using Crestron.SimplSharp.WebScripting;
using Newtonsoft.Json;
namespace PepperDash.Core namespace PepperDash.Core.Web.RequestHandlers
{ {
/// <summary> /// <summary>
/// CWS Base Handler, implements IHttpCwsHandler /// CWS Base Handler, implements IHttpCwsHandler
/// </summary> /// </summary>
public abstract class CwsBaseHandler : IHttpCwsHandler public abstract class WebApiBaseRequestHandler : IHttpCwsHandler
{ {
private readonly Dictionary<string, Action<HttpCwsContext>> _handlers; private readonly Dictionary<string, Action<HttpCwsContext>> _handlers;
/// <summary> /// <summary>
/// Constructor /// Constructor
/// </summary> /// </summary>
protected CwsBaseHandler() protected WebApiBaseRequestHandler()
{ {
_handlers = new Dictionary<string, Action<HttpCwsContext>> _handlers = new Dictionary<string, Action<HttpCwsContext>>
{ {

View File

@@ -1,12 +1,14 @@
using System; using System;
using Crestron.SimplSharp; using Crestron.SimplSharp;
using Crestron.SimplSharp.WebScripting; using Crestron.SimplSharp.WebScripting;
using PepperDash.Core.Web.RequestHandlers;
namespace PepperDash.Core namespace PepperDash.Core.Web
{ {
public class GenericCwsBase : Device public class WebApiServer : IKeyName
{ {
private const string SplusKey = "Uninitialized CWS Server"; private const string SplusKey = "Uninitialized Web API Server";
private const string DefaultName = "Web API Server";
private const string DefaultBasePath = "/api"; private const string DefaultBasePath = "/api";
private const uint DebugTrace = 0; private const uint DebugTrace = 0;
@@ -16,6 +18,9 @@ namespace PepperDash.Core
private HttpCwsServer _server; private HttpCwsServer _server;
private readonly CCriticalSection _serverLock = new CCriticalSection(); private readonly CCriticalSection _serverLock = new CCriticalSection();
public string Key { get; private set; }
public string Name { get; private set; }
/// <summary> /// <summary>
/// CWS base path, will default to "/api" if not set via initialize method /// CWS base path, will default to "/api" if not set via initialize method
/// </summary> /// </summary>
@@ -29,11 +34,9 @@ namespace PepperDash.Core
/// <summary> /// <summary>
/// Constructor for S+. Make sure to set necessary properties using init method /// Constructor for S+. Make sure to set necessary properties using init method
/// </summary> /// </summary>
public GenericCwsBase() public WebApiServer()
: base(SplusKey) : this(SplusKey, DefaultName, null)
{ {
CrestronEnvironment.ProgramStatusEventHandler += CrestronEnvironment_ProgramStatusEventHandler;
CrestronEnvironment.EthernetEventHandler += CrestronEnvironment_EthernetEventHandler;
} }
/// <summary> /// <summary>
@@ -41,10 +44,9 @@ namespace PepperDash.Core
/// </summary> /// </summary>
/// <param name="key"></param> /// <param name="key"></param>
/// <param name="basePath"></param> /// <param name="basePath"></param>
public GenericCwsBase(string key, string basePath) public WebApiServer(string key, string basePath)
: base(key) : this(key, DefaultName, basePath)
{ {
BasePath = string.IsNullOrEmpty(basePath) ? DefaultBasePath : basePath;
} }
/// <summary> /// <summary>
@@ -53,10 +55,14 @@ namespace PepperDash.Core
/// <param name="key"></param> /// <param name="key"></param>
/// <param name="name"></param> /// <param name="name"></param>
/// <param name="basePath"></param> /// <param name="basePath"></param>
public GenericCwsBase(string key, string name, string basePath) public WebApiServer(string key, string name, string basePath)
: base(key, name)
{ {
Key = key;
Name = string.IsNullOrEmpty(name) ? DefaultName : name;
BasePath = string.IsNullOrEmpty(basePath) ? DefaultBasePath : basePath; BasePath = string.IsNullOrEmpty(basePath) ? DefaultBasePath : basePath;
CrestronEnvironment.ProgramStatusEventHandler += CrestronEnvironment_ProgramStatusEventHandler;
CrestronEnvironment.EthernetEventHandler += CrestronEnvironment_EthernetEventHandler;
} }
/// <summary> /// <summary>
@@ -148,7 +154,7 @@ namespace PepperDash.Core
_server = new HttpCwsServer(BasePath) _server = new HttpCwsServer(BasePath)
{ {
HttpRequestHandler = new CwsDefaultRequestHandler() HttpRequestHandler = new DefaultRequestRequestHandler()
}; };
IsRegistered = _server.Register(); IsRegistered = _server.Register();