Compare commits

...

2 Commits

Author SHA1 Message Date
Neil Dorin
5a097e7057 feat: updates for web debugging 2023-11-02 23:31:15 -06:00
Neil Dorin
e1eb432dee Merge pull request #1153 from PepperDash/feature-2.0.0/move-dm-to-library
Move DM Project to library
2023-10-27 10:35:45 -06:00
13 changed files with 240 additions and 203 deletions

View File

@@ -16,11 +16,6 @@
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
</PropertyGroup>
<ItemGroup>
<Compile Remove="Web\**" />
<EmbeddedResource Remove="Web\**" />
<None Remove="Web\**" />
</ItemGroup>
<ItemGroup>
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
@@ -31,7 +26,7 @@
<PackageReference Include="Newtonsoft.Json" Version="13.0.2">
<Aliases>Full</Aliases>
</PackageReference>
<PackageReference Include="PepperDashCore" Version="2.0.0-beta-318" />
<PackageReference Include="PepperDashCore" Version="2.0.0-alpha-344" />
</ItemGroup>
<ItemGroup>
<None Include="Crestron\CrestronGenericBaseDevice.cs.orig" />

View File

@@ -75,11 +75,6 @@ namespace PepperDash.Essentials
version = Global.AssemblyVersion;
break;
}
case ("PepperDash_Essentials_DM.dll"):
{
version = Global.AssemblyVersion;
break;
}
case ("Essentials Devices Common.dll"):
{
version = Global.AssemblyVersion;

View File

@@ -9,7 +9,7 @@ using PepperDash.Essentials.Core.Web.RequestHandlers;
namespace PepperDash.Essentials.Core.Web
{
public class EssemtialsWebApi : EssentialsDevice
public class EssentialsWebApi : EssentialsDevice
{
private readonly WebApiServer _server;
@@ -43,7 +43,7 @@ namespace PepperDash.Essentials.Core.Web
/// </summary>
/// <param name="key"></param>
/// <param name="name"></param>
public EssemtialsWebApi(string key, string name)
public EssentialsWebApi(string key, string name)
: this(key, name, null)
{
}
@@ -54,7 +54,7 @@ namespace PepperDash.Essentials.Core.Web
/// <param name="key"></param>
/// <param name="name"></param>
/// <param name="config"></param>
public EssemtialsWebApi(string key, string name, EssentialsWebApiPropertiesConfig config)
public EssentialsWebApi(string key, string name, EssentialsWebApiPropertiesConfig config)
: base(key, name)
{
Key = key;
@@ -65,91 +65,95 @@ namespace PepperDash.Essentials.Core.Web
BasePath = string.IsNullOrEmpty(config.BasePath) ? _defaultBasePath : config.BasePath;
_server = new WebApiServer(Key, Name, BasePath);
SetupRoutes();
Initialize();
}
/// <summary>
/// Custom activate, add routes
/// </summary>
/// <returns></returns>
public override bool CustomActivate()
private void SetupRoutes()
{
var routes = new List<HttpCwsRoute>
{
new HttpCwsRoute("reportversions")
{
Name = "ReportVersions",
RouteHandler = new ReportVersionsRequestHandler()
},
new HttpCwsRoute("appdebug")
{
Name = "AppDebug",
RouteHandler = new AppDebugRequestHandler()
},
new HttpCwsRoute("devlist")
{
Name = "DevList",
RouteHandler = new DevListRequestHandler()
},
new HttpCwsRoute("devprops")
{
Name = "DevProps",
RouteHandler = new DevPropsRequestHandler()
},
new HttpCwsRoute("devjson")
{
Name = "DevJson",
RouteHandler = new DevJsonRequestHandler()
},
new HttpCwsRoute("setdevicestreamdebug")
{
Name = "SetDeviceStreamDebug",
RouteHandler = new SetDeviceStreamDebugRequestHandler()
},
new HttpCwsRoute("disableallstreamdebug")
{
Name = "DisableAllStreamDebug",
RouteHandler = new DisableAllStreamDebugRequestHandler()
},
new HttpCwsRoute("showconfig")
{
Name = "ShowConfig",
RouteHandler = new ShowConfigRequestHandler()
},
new HttpCwsRoute("gettypes")
{
Name = "GetTypes",
RouteHandler = new GetTypesRequestHandler()
},
new HttpCwsRoute("gettypes/{filter}")
{
Name = "GetTypesByFilter",
RouteHandler = new GetTypesByFilterRequestHandler()
},
new HttpCwsRoute("getjoinmap/{bridgeKey}")
{
Name = "GetJoinMapsForBridgeKey",
RouteHandler = new GetJoinMapForBridgeKeyRequestHandler()
},
new HttpCwsRoute("getjoinmap/{bridgeKey}/{deviceKey}")
{
Name = "GetJoinMapsForDeviceKey",
RouteHandler = new GetJoinMapForDeviceKeyRequestHandler()
},
new HttpCwsRoute("feedbacks/{deviceKey}")
{
Name = "GetFeedbacksForDeviceKey",
RouteHandler = new GetFeedbacksForDeviceRequestHandler()
}
};
var routes = new List<HttpCwsRoute>
{
new HttpCwsRoute("versions")
{
Name = "ReportVersions",
RouteHandler = new ReportVersionsRequestHandler()
},
new HttpCwsRoute("appdebug")
{
Name = "AppDebug",
RouteHandler = new AppDebugRequestHandler()
},
new HttpCwsRoute("devices")
{
Name = "DevList",
RouteHandler = new DevListRequestHandler()
},
new HttpCwsRoute("deviceCommands")
{
Name = "DevJson",
RouteHandler = new DevJsonRequestHandler()
},
new HttpCwsRoute("deviceProperties/{deviceKey}")
{
Name = "DevProps",
RouteHandler = new DevPropsRequestHandler()
},
new HttpCwsRoute("deviceMethods/{deviceKey}")
{
Name = "DevMethods",
RouteHandler = new DevMethodsRequestHandler()
},
new HttpCwsRoute("deviceFeedbacks/{deviceKey}")
{
Name = "GetFeedbacksForDeviceKey",
RouteHandler = new GetFeedbacksForDeviceRequestHandler()
},
new HttpCwsRoute("deviceStreamDebug")
{
Name = "SetDeviceStreamDebug",
RouteHandler = new SetDeviceStreamDebugRequestHandler()
},
new HttpCwsRoute("disableAllStreamDebug")
{
Name = "DisableAllStreamDebug",
RouteHandler = new DisableAllStreamDebugRequestHandler()
},
new HttpCwsRoute("config")
{
Name = "ShowConfig",
RouteHandler = new ShowConfigRequestHandler()
},
new HttpCwsRoute("types")
{
Name = "GetTypes",
RouteHandler = new GetTypesRequestHandler()
},
new HttpCwsRoute("types/{filter}")
{
Name = "GetTypesByFilter",
RouteHandler = new GetTypesByFilterRequestHandler()
},
new HttpCwsRoute("joinMap/{bridgeKey}")
{
Name = "GetJoinMapsForBridgeKey",
RouteHandler = new GetJoinMapForBridgeKeyRequestHandler()
},
new HttpCwsRoute("joinMap/{bridgeKey}/{deviceKey}")
{
Name = "GetJoinMapsForDeviceKey",
RouteHandler = new GetJoinMapForDeviceKeyRequestHandler()
},
foreach (var route in routes.Where(route => route != null))
{
var r = route;
_server.AddRoute(r);
}
};
return base.CustomActivate();
}
foreach (var route in routes.Where(route => route != null))
{
var r = route;
_server.AddRoute(r);
}
}
/// <summary>
/// Initializes the CWS class

View File

@@ -4,7 +4,7 @@ using PepperDash.Essentials.Core.Config;
namespace PepperDash.Essentials.Core.Web
{
public class EssentialsWebApiFactory : EssentialsDeviceFactory<EssemtialsWebApi>
public class EssentialsWebApiFactory : EssentialsDeviceFactory<EssentialsWebApi>
{
public EssentialsWebApiFactory()
{
@@ -16,7 +16,7 @@ namespace PepperDash.Essentials.Core.Web
Debug.Console(1, "Factory Attempting to create new Essentials Web API Server");
var props = dc.Properties.ToObject<EssentialsWebApiPropertiesConfig>();
if (props != null) return new EssemtialsWebApi(dc.Key, dc.Name, props);
if (props != null) return new EssentialsWebApi(dc.Key, dc.Name, props);
Debug.Console(1, "Factory failed to create new Essentials Web API Server");
return null;

View File

@@ -0,0 +1,76 @@
using System.Text;
using Crestron.SimplSharp.WebScripting;
using Newtonsoft.Json;
using PepperDash.Core.Web.RequestHandlers;
namespace PepperDash.Essentials.Core.Web.RequestHandlers
{
public class DevMethodsRequestHandler : WebApiBaseRequestHandler
{
/// <summary>
/// Constructor
/// </summary>
/// <remarks>
/// base(true) enables CORS support by default
/// </remarks>
public DevMethodsRequestHandler()
: base(true)
{
}
/// <summary>
/// Handles GET method requests
/// </summary>
/// <param name="context"></param>
protected override void HandleGet(HttpCwsContext context)
{
var routeData = context.Request.RouteData;
if (routeData == null)
{
context.Response.StatusCode = 400;
context.Response.StatusDescription = "Bad Request";
context.Response.End();
return;
}
object deviceObj;
if (!routeData.Values.TryGetValue("deviceKey", out deviceObj))
{
context.Response.StatusCode = 400;
context.Response.StatusDescription = "Bad Request";
context.Response.End();
return;
}
var device = DeviceManager.GetDeviceForKey(deviceObj.ToString());
if (device == null)
{
context.Response.StatusCode = 404;
context.Response.StatusDescription = "Device Not Found";
context.Response.End();
return;
}
var deviceMethods = DeviceJsonApi.GetMethods(device.Key);
if (deviceMethods == null || deviceMethods.ToLower().Contains("no device"))
{
context.Response.StatusCode = 404;
context.Response.StatusDescription = "Not Found";
context.Response.End();
return;
}
context.Response.StatusCode = 200;
context.Response.StatusDescription = "OK";
context.Response.ContentType = "application/json";
context.Response.ContentEncoding = Encoding.UTF8;
context.Response.Write(deviceMethods, false);
context.Response.End();
}
}
}

View File

@@ -18,59 +18,59 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers
{
}
/// <summary>
/// Handles POST method requests
/// </summary>
/// <param name="context"></param>
protected override void HandlePost(HttpCwsContext context)
{
if (context.Request.ContentLength < 0)
{
context.Response.StatusCode = 400;
context.Response.StatusDescription = "Bad Request";
context.Response.End();
/// <summary>
/// Handles GET method requests
/// </summary>
/// <param name="context"></param>
protected override void HandleGet(HttpCwsContext context)
{
var routeData = context.Request.RouteData;
if (routeData == null)
{
context.Response.StatusCode = 400;
context.Response.StatusDescription = "Bad Request";
context.Response.End();
return;
}
return;
}
var data = EssentialsWebApiHelpers.GetRequestBody(context.Request);
if (string.IsNullOrEmpty(data))
{
context.Response.StatusCode = 400;
context.Response.StatusDescription = "Bad Request";
context.Response.End();
object deviceObj;
if (!routeData.Values.TryGetValue("deviceKey", out deviceObj))
{
context.Response.StatusCode = 400;
context.Response.StatusDescription = "Bad Request";
context.Response.End();
return;
}
return;
}
var o = new DeviceActionWrapper();
var body = JsonConvert.DeserializeAnonymousType(data, o);
if (string.IsNullOrEmpty(body.DeviceKey))
{
context.Response.StatusCode = 400;
context.Response.StatusDescription = "Bad Request";
context.Response.End();
var device = DeviceManager.GetDeviceForKey(deviceObj.ToString());
return;
}
if (device == null)
{
context.Response.StatusCode = 404;
context.Response.StatusDescription = "Device Not Found";
context.Response.End();
var deviceProps = DeviceJsonApi.GetProperties(body.DeviceKey);
if (deviceProps == null || deviceProps.ToLower().Contains("no device"))
{
context.Response.StatusCode = 404;
context.Response.StatusDescription = "Not Found";
context.Response.End();
return;
}
return;
}
var deviceProperties = DeviceJsonApi.GetProperties(device.Key);
if (deviceProperties == null || deviceProperties.ToLower().Contains("no device"))
{
context.Response.StatusCode = 404;
context.Response.StatusDescription = "Not Found";
context.Response.End();
context.Response.StatusCode = 200;
context.Response.StatusDescription = "OK";
context.Response.ContentType = "application/json";
context.Response.ContentEncoding = Encoding.UTF8;
context.Response.Write(deviceProps, false);
context.Response.End();
}
}
return;
}
context.Response.StatusCode = 200;
context.Response.StatusDescription = "OK";
context.Response.ContentType = "application/json";
context.Response.ContentEncoding = Encoding.UTF8;
context.Response.Write(deviceProperties, false);
context.Response.End();
}
}
}

View File

@@ -1,4 +1,4 @@
extern alias Full
extern alias Full;
using System.Linq;
using Crestron.SimplSharp.WebScripting;

View File

@@ -1,4 +1,4 @@
extern alias Full
extern alias Full;
using System.Linq;
using Crestron.SimplSharp.WebScripting;

View File

@@ -1,4 +1,4 @@
extern alias Full
extern alias Full;
using System.Linq;
using Crestron.SimplSharp.WebScripting;

View File

@@ -1,4 +1,4 @@
extern alias Full
extern alias Full;
using Crestron.SimplSharp.WebScripting;
using Full.Newtonsoft.Json;

View File

@@ -31,6 +31,6 @@
<PackageReference Include="Newtonsoft.Json" Version="13.0.2">
<Aliases>Full</Aliases>
</PackageReference>
<PackageReference Include="PepperDashCore" Version="2.0.0-beta-318" />
<PackageReference Include="PepperDashCore" Version="2.0.0-alpha-344" />
</ItemGroup>
</Project>

View File

@@ -5,18 +5,15 @@ using Crestron.SimplSharp.Reflection;
using Crestron.SimplSharpPro;
using Crestron.SimplSharpPro.CrestronThread;
using Crestron.SimplSharpPro.Diagnostics;
using Full.Newtonsoft.Json;
using PepperDash.Core;
using PepperDash.Essentials.Core;
using PepperDash.Essentials.Core.Bridges;
using PepperDash.Essentials.Core.Config;
using PepperDash.Essentials.Core.DeviceTypeInterfaces;
using PepperDash.Essentials.Core.Fusion;
using PepperDash.Essentials.Devices.Common;
using PepperDash.Essentials.Core.Web;
using PepperDash.Essentials.Fusion;
using PepperDash.Essentials.Room.Config;
using System;
using System.Collections.Generic;
using System.Linq;
namespace PepperDash.Essentials
@@ -118,6 +115,8 @@ namespace PepperDash.Essentials
CrestronConsole.AddNewConsoleCommand(DeviceManager.GetRoutingPorts,
"getroutingports", "Reports all routing ports, if any. Requires a device key", ConsoleAccessLevelEnum.AccessOperator);
DeviceManager.AddDevice(new EssentialsWebApi("essentialsWebApi", "Essentials Web API"));
if (!Debug.DoNotLoadOnNextBoot)
{
GoWithLoad();
@@ -149,11 +148,22 @@ namespace PepperDash.Essentials
directoryPrefix = Crestron.SimplSharp.CrestronIO.Directory.GetApplicationRootDirectory();
var fullVersion = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyInformationalVersionAttribute), false);
//var assembly = Assembly.GetExecutingAssembly();
AssemblyInformationalVersionAttribute fullVersionAtt = fullVersion[0] as AssemblyInformationalVersionAttribute;
//Debug.Console(0, "Assembly Name: ", assembly.FullName);
Global.SetAssemblyVersion(fullVersionAtt.InformationalVersion);
//var fullVersion = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyInformationalVersionAttribute), false);
//if (fullVersion.Length == 0)
//{
// Debug.Console(0, "***********************Unable to determine version.***********************");
//}
//AssemblyInformationalVersionAttribute fullVersionAtt = fullVersion[0] as AssemblyInformationalVersionAttribute;
//Debug.Console(0, "Full Version: {0}", fullVersionAtt.InformationalVersion);
//Global.SetAssemblyVersion(fullVersionAtt.InformationalVersion);
if (CrestronEnvironment.DevicePlatform != eDevicePlatform.Server) // Handles 3-series running Windows CE OS
{
@@ -202,7 +212,7 @@ namespace PepperDash.Essentials
}
else // Handles Linux OS (Virtual Control)
{
Debug.SetDebugLevel(2);
//Debug.SetDebugLevel(2);
Debug.Console(0, Debug.ErrorLogLevel.Notice, "Starting Essentials v{0} on Virtual Control Server", Global.AssemblyVersion);
@@ -290,6 +300,8 @@ namespace PepperDash.Essentials
{
Debug.Console(0, "Verifying and/or creating folder structure");
var configDir = Global.FilePathPrefix;
Debug.Console(0, "FilePathPrefix: {0}", configDir);
var configExists = Directory.Exists(configDir);
if (!configExists)
Directory.Create(configDir);
@@ -358,7 +370,6 @@ namespace PepperDash.Essentials
// Build the processor wrapper class
DeviceManager.AddDevice(new PepperDash.Essentials.Core.Devices.CrestronProcessor("processor"));
// DeviceManager.AddDevice(new EssemtialsWebApi("essentialsWebApi","Essentials Web API"));
// Add global System Monitor device
if (CrestronEnvironment.DevicePlatform == eDevicePlatform.Appliance)
@@ -387,51 +398,6 @@ namespace PepperDash.Essentials
"WARNING: Config file defines processor type as '{0}' but actual processor is '{1}'! Some ports may not be available",
devConf.Type.ToUpper(), Global.ControlSystem.ControllerPrompt.ToUpper());
//if (newDev == null)
// newDev = PepperDash.Essentials.Core.ProcessorExtensionDeviceFactory.GetExtensionDevice(devConf);
//if (newDev != null)
//{
// DeviceManager.AddDevice(newDev);
// continue;
//}
// Check if the processor is a DMPS model
//if (this.ControllerPrompt.IndexOf("dmps", StringComparison.OrdinalIgnoreCase) > -1)
//{
// Debug.Console(2, "Adding DmpsRoutingController for {0} to Device Manager.", this.ControllerPrompt);
// var propertiesConfig = JsonConvert.DeserializeObject<DM.Config.DmpsRoutingPropertiesConfig>(devConf.Properties.ToString());
// if(propertiesConfig == null)
// propertiesConfig = new DM.Config.DmpsRoutingPropertiesConfig();
// DeviceManager.AddDevice(DmpsRoutingController.GetDmpsRoutingController("processor-avRouting", this.ControllerPrompt, propertiesConfig));
//}
//else
//if (this.ControllerPrompt.IndexOf("mpc3", StringComparison.OrdinalIgnoreCase) > -1)
//{
// Debug.Console(2, "MPC3 processor type detected. Adding Mpc3TouchpanelController.");
// var butToken = devConf.Properties["buttons"];
// if (butToken != null)
// {
// var buttons = butToken.ToObject<Dictionary<string, Essentials.Core.Touchpanels.KeypadButton>>();
// var tpController = new Essentials.Core.Touchpanels.Mpc3TouchpanelController(devConf.Key, devConf.Name, Global.ControlSystem, buttons);
// DeviceManager.AddDevice(tpController);
// }
// else
// {
// Debug.Console(0, Debug.ErrorLogLevel.Error, "Error: Unable to deserialize buttons collection for device: {0}", devConf.Key);
// }
//}
//else
//{
// Debug.Console(2, "************Processor is not DMPS type***************");
//}
continue;
}

View File

@@ -10,6 +10,7 @@
<OutputPath>bin\$(Configuration)\</OutputPath>
<Title>PepperDash Essentials</Title>
<PackageId>PepperDashEssentials</PackageId>
<AssemblyInformationalVersion>$(Version)</AssemblyInformationalVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugType>full</DebugType>
@@ -50,7 +51,7 @@
<PackageReference Include="Newtonsoft.Json" Version="13.0.2">
<Aliases>Full</Aliases>
</PackageReference>
<PackageReference Include="PepperDashCore" Version="2.0.0-beta-318" />
<PackageReference Include="PepperDashCore" Version="2.0.0-alpha-344" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\PepperDash.Essentials.Core\PepperDash.Essentials.Core.csproj" />