mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-02-16 21:24:54 +00:00
Merge pull request #1190 from PepperDash/feature-2.0.0/routing-updates
Updates after testing
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
|
|
||||||
using Crestron.SimplSharp;
|
using Crestron.SimplSharp;
|
||||||
using Crestron.SimplSharp.Reflection;
|
using System.Reflection;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
using PepperDash.Core;
|
using PepperDash.Core;
|
||||||
using PepperDash.Essentials.Core.Config;
|
using PepperDash.Essentials.Core.Config;
|
||||||
@@ -14,7 +14,7 @@ namespace PepperDash.Essentials.Core
|
|||||||
{
|
{
|
||||||
public class DeviceFactoryWrapper
|
public class DeviceFactoryWrapper
|
||||||
{
|
{
|
||||||
public CType CType { get; set; }
|
public Type CType { get; set; }
|
||||||
public string Description { get; set; }
|
public string Description { get; set; }
|
||||||
public Func<DeviceConfig, IKeyed> FactoryMethod { get; set; }
|
public Func<DeviceConfig, IKeyed> FactoryMethod { get; set; }
|
||||||
|
|
||||||
@@ -69,7 +69,7 @@ namespace PepperDash.Essentials.Core
|
|||||||
DeviceFactory.FactoryMethods.Add(typeName, new DeviceFactoryWrapper() { FactoryMethod = method});
|
DeviceFactory.FactoryMethods.Add(typeName, new DeviceFactoryWrapper() { FactoryMethod = method});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void AddFactoryForType(string typeName, string description, CType cType, Func<DeviceConfig, IKeyed> method)
|
public static void AddFactoryForType(string typeName, string description, Type cType, Func<DeviceConfig, IKeyed> method)
|
||||||
{
|
{
|
||||||
//Debug.LogMessage(LogEventLevel.Debug, "Adding factory method for type '{0}'", typeName);
|
//Debug.LogMessage(LogEventLevel.Debug, "Adding factory method for type '{0}'", typeName);
|
||||||
|
|
||||||
@@ -149,18 +149,7 @@ namespace PepperDash.Essentials.Core
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Debug.LogMessage(LogEventLevel.Error, "Exception occurred while creating device {0}: {1}", dc.Key, ex.Message);
|
Debug.LogMessage(ex, "Exception occurred while creating device {0}: {1}", null, dc.Key, ex.Message);
|
||||||
|
|
||||||
Debug.LogMessage(LogEventLevel.Verbose, "{0}", ex.StackTrace);
|
|
||||||
|
|
||||||
if (ex.InnerException == null)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
Debug.LogMessage(LogEventLevel.Error, "Inner exception while creating device {0}: {1}", dc.Key,
|
|
||||||
ex.InnerException.Message);
|
|
||||||
Debug.LogMessage(LogEventLevel.Verbose, "{0}", ex.InnerException.StackTrace);
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
|
|
||||||
using Crestron.SimplSharp.Reflection;
|
using System.Reflection;
|
||||||
using PepperDash.Core;
|
using PepperDash.Core;
|
||||||
using PepperDash.Essentials.Core.Config;
|
using PepperDash.Essentials.Core.Config;
|
||||||
using Serilog.Events;
|
using Serilog.Events;
|
||||||
@@ -55,7 +55,7 @@ namespace PepperDash.Essentials.Core
|
|||||||
ProcessorExtensionDeviceFactory.ProcessorExtensionFactoryMethods.Add(extensionName, new DeviceFactoryWrapper() { FactoryMethod = method });
|
ProcessorExtensionDeviceFactory.ProcessorExtensionFactoryMethods.Add(extensionName, new DeviceFactoryWrapper() { FactoryMethod = method });
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void AddFactoryForType(string extensionName, string description, CType cType, Func<DeviceConfig, IKeyed> method)
|
public static void AddFactoryForType(string extensionName, string description, Type cType, Func<DeviceConfig, IKeyed> method)
|
||||||
{
|
{
|
||||||
//Debug.LogMessage(LogEventLevel.Debug, "Adding factory method for type '{0}'", typeName);
|
//Debug.LogMessage(LogEventLevel.Debug, "Adding factory method for type '{0}'", typeName);
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using Crestron.SimplSharp;
|
using Crestron.SimplSharp;
|
||||||
using Crestron.SimplSharp.CrestronIO;
|
using Crestron.SimplSharp.CrestronIO;
|
||||||
using Crestron.SimplSharp.Reflection;
|
using System.Reflection;
|
||||||
|
|
||||||
using PepperDash.Core;
|
using PepperDash.Core;
|
||||||
using PepperDash.Essentials.Core;
|
using PepperDash.Essentials.Core;
|
||||||
@@ -118,6 +118,8 @@ namespace PepperDash.Essentials
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="fileName"></param>
|
/// <param name="fileName"></param>
|
||||||
static LoadedAssembly LoadAssembly(string filePath)
|
static LoadedAssembly LoadAssembly(string filePath)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
//Debug.LogMessage(LogEventLevel.Verbose, "Attempting to load {0}", filePath);
|
//Debug.LogMessage(LogEventLevel.Verbose, "Attempting to load {0}", filePath);
|
||||||
var assembly = Assembly.LoadFrom(filePath);
|
var assembly = Assembly.LoadFrom(filePath);
|
||||||
@@ -136,6 +138,11 @@ namespace PepperDash.Essentials
|
|||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
} catch(Exception ex)
|
||||||
|
{
|
||||||
|
Debug.LogMessage(ex, "Error loading assembly from {path}", null, filePath);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -354,7 +361,7 @@ namespace PepperDash.Essentials
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
var assy = loadedAssembly.Assembly;
|
var assy = loadedAssembly.Assembly;
|
||||||
CType[] types = {};
|
Type[] types = {};
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
types = assy.GetTypes();
|
types = assy.GetTypes();
|
||||||
@@ -439,7 +446,7 @@ namespace PepperDash.Essentials
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="type"></param>
|
/// <param name="type"></param>
|
||||||
/// <param name="loadPlugin"></param>
|
/// <param name="loadPlugin"></param>
|
||||||
static void LoadCustomLegacyPlugin(CType type, MethodInfo loadPlugin, LoadedAssembly loadedAssembly)
|
static void LoadCustomLegacyPlugin(Type type, MethodInfo loadPlugin, LoadedAssembly loadedAssembly)
|
||||||
{
|
{
|
||||||
Debug.LogMessage(LogEventLevel.Verbose, "LoadPlugin method found in {0}", type.Name);
|
Debug.LogMessage(LogEventLevel.Verbose, "LoadPlugin method found in {0}", type.Name);
|
||||||
|
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ namespace PepperDash.Essentials.Core.Web
|
|||||||
Name = "DevList",
|
Name = "DevList",
|
||||||
RouteHandler = new DevListRequestHandler()
|
RouteHandler = new DevListRequestHandler()
|
||||||
},
|
},
|
||||||
new HttpCwsRoute("deviceCommands")
|
new HttpCwsRoute("deviceCommands/{deviceKey}")
|
||||||
{
|
{
|
||||||
Name = "DevJson",
|
Name = "DevJson",
|
||||||
RouteHandler = new DevJsonRequestHandler()
|
RouteHandler = new DevJsonRequestHandler()
|
||||||
|
|||||||
@@ -7,11 +7,11 @@ using PepperDash.Core;
|
|||||||
|
|
||||||
namespace PepperDash.Essentials.Core.Web
|
namespace PepperDash.Essentials.Core.Web
|
||||||
{
|
{
|
||||||
public class EssentialsWebApiHelpers
|
public static class EssentialsWebApiHelpers
|
||||||
{
|
{
|
||||||
public static string GetRequestBody(HttpCwsRequest request)
|
public static string GetRequestBody(this HttpCwsRequest request)
|
||||||
{
|
{
|
||||||
var bytes = new Byte[request.ContentLength];
|
var bytes = new byte[request.ContentLength];
|
||||||
|
|
||||||
request.InputStream.Read(bytes, 0, request.ContentLength);
|
request.InputStream.Read(bytes, 0, request.ContentLength);
|
||||||
|
|
||||||
@@ -22,8 +22,8 @@ namespace PepperDash.Essentials.Core.Web
|
|||||||
{
|
{
|
||||||
return new
|
return new
|
||||||
{
|
{
|
||||||
Name = assembly.Name,
|
assembly.Name,
|
||||||
Version = assembly.Version
|
assembly.Version
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -31,7 +31,7 @@ namespace PepperDash.Essentials.Core.Web
|
|||||||
{
|
{
|
||||||
return new
|
return new
|
||||||
{
|
{
|
||||||
Key = device.Key,
|
device.Key,
|
||||||
Name = (device is IKeyName)
|
Name = (device is IKeyName)
|
||||||
? (device as IKeyName).Name
|
? (device as IKeyName).Name
|
||||||
: "---"
|
: "---"
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var data = EssentialsWebApiHelpers.GetRequestBody(context.Request);
|
var data = context.Request.GetRequestBody();
|
||||||
if (string.IsNullOrEmpty(data))
|
if (string.IsNullOrEmpty(data))
|
||||||
{
|
{
|
||||||
context.Response.StatusCode = 400;
|
context.Response.StatusCode = 400;
|
||||||
|
|||||||
@@ -26,6 +26,26 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
|||||||
/// <param name="context"></param>
|
/// <param name="context"></param>
|
||||||
protected override void HandlePost(HttpCwsContext context)
|
protected override void HandlePost(HttpCwsContext context)
|
||||||
{
|
{
|
||||||
|
var routeData = context.Request.RouteData;
|
||||||
|
|
||||||
|
if(routeData == null)
|
||||||
|
{
|
||||||
|
context.Response.StatusCode = 400;
|
||||||
|
context.Response.StatusDescription = "Bad Request";
|
||||||
|
context.Response.End();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!routeData.Values.TryGetValue("deviceKey", out var deviceKey))
|
||||||
|
{
|
||||||
|
context.Response.StatusCode = 400;
|
||||||
|
context.Response.StatusDescription = "Bad Request";
|
||||||
|
context.Response.End();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (context.Request.ContentLength < 0)
|
if (context.Request.ContentLength < 0)
|
||||||
{
|
{
|
||||||
context.Response.StatusCode = 400;
|
context.Response.StatusCode = 400;
|
||||||
@@ -35,7 +55,8 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var data = EssentialsWebApiHelpers.GetRequestBody(context.Request);
|
var data = context.Request.GetRequestBody();
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(data))
|
if (string.IsNullOrEmpty(data))
|
||||||
{
|
{
|
||||||
context.Response.StatusCode = 400;
|
context.Response.StatusCode = 400;
|
||||||
@@ -47,8 +68,13 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var daw = JsonConvert.DeserializeObject<DeviceActionWrapper>(data);
|
var daw = new DeviceActionWrapper { DeviceKey = (string) deviceKey};
|
||||||
DeviceJsonApi.DoDeviceActionWithJson(data);
|
|
||||||
|
JsonConvert.PopulateObject(data, daw);
|
||||||
|
|
||||||
|
Debug.LogMessage(LogEventLevel.Verbose, "Device Action Wrapper: {@wrapper}", null, daw);
|
||||||
|
|
||||||
|
DeviceJsonApi.DoDeviceAction(daw);
|
||||||
|
|
||||||
context.Response.StatusCode = 200;
|
context.Response.StatusCode = 200;
|
||||||
context.Response.StatusDescription = "OK";
|
context.Response.StatusDescription = "OK";
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
allDevices.Sort((a, b) => System.String.Compare(a.Key, b.Key, System.StringComparison.Ordinal));
|
allDevices.Sort((a, b) => string.Compare(a.Key, b.Key, System.StringComparison.Ordinal));
|
||||||
|
|
||||||
var deviceList = allDevices.Select(d => EssentialsWebApiHelpers.MapToDeviceListObject(d)).ToList();
|
var deviceList = allDevices.Select(d => EssentialsWebApiHelpers.MapToDeviceListObject(d)).ToList();
|
||||||
|
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var data = EssentialsWebApiHelpers.GetRequestBody(context.Request);
|
var data = context.Request.GetRequestBody();
|
||||||
if (string.IsNullOrEmpty(data))
|
if (string.IsNullOrEmpty(data))
|
||||||
{
|
{
|
||||||
context.Response.StatusCode = 400;
|
context.Response.StatusCode = 400;
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var data = EssentialsWebApiHelpers.GetRequestBody(context.Request);
|
var data = context.Request.GetRequestBody();
|
||||||
if (data == null)
|
if (data == null)
|
||||||
{
|
{
|
||||||
context.Response.StatusCode = 500;
|
context.Response.StatusCode = 500;
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Crestron.SimplSharp.Reflection;
|
using System.Reflection;
|
||||||
using PepperDash.Core;
|
using PepperDash.Core;
|
||||||
using PepperDash.Essentials.Core;
|
using PepperDash.Essentials.Core;
|
||||||
using Serilog.Events;
|
using Serilog.Events;
|
||||||
|
|||||||
@@ -29,6 +29,8 @@ namespace PepperDash.Essentials.Devices.Common.Displays
|
|||||||
|
|
||||||
protected set
|
protected set
|
||||||
{
|
{
|
||||||
|
if (_currentInputPort == value) return;
|
||||||
|
|
||||||
_currentInputPort = value;
|
_currentInputPort = value;
|
||||||
|
|
||||||
InputChanged?.Invoke(this, _currentInputPort);
|
InputChanged?.Invoke(this, _currentInputPort);
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ using Serilog.Events;
|
|||||||
|
|
||||||
namespace PepperDash.Essentials.Devices.Common.Displays
|
namespace PepperDash.Essentials.Devices.Common.Displays
|
||||||
{
|
{
|
||||||
public class MockDisplay : TwoWayDisplayBase, IBasicVolumeWithFeedback, IBridgeAdvanced, IHasInputs<string, string>
|
public class MockDisplay : TwoWayDisplayBase, IBasicVolumeWithFeedback, IBridgeAdvanced, IHasInputs<string, string>, IRoutingSinkWithSwitchingWithInputPort, IHasPowerControlWithFeedback
|
||||||
{
|
{
|
||||||
public ISelectableItems<string> Inputs { get; private set; }
|
public ISelectableItems<string> Inputs { get; private set; }
|
||||||
|
|
||||||
@@ -79,7 +79,7 @@ namespace PepperDash.Essentials.Devices.Common.Displays
|
|||||||
eRoutingPortConnectionType.Hdmi, "HDMI2", this);
|
eRoutingPortConnectionType.Hdmi, "HDMI2", this);
|
||||||
var hdmiIn3 = new RoutingInputPort(RoutingPortNames.HdmiIn3, eRoutingSignalType.AudioVideo,
|
var hdmiIn3 = new RoutingInputPort(RoutingPortNames.HdmiIn3, eRoutingSignalType.AudioVideo,
|
||||||
eRoutingPortConnectionType.Hdmi, "HDMI3", this);
|
eRoutingPortConnectionType.Hdmi, "HDMI3", this);
|
||||||
var hdmiIn4 = new RoutingInputPort(RoutingPortNames.ComponentIn, eRoutingSignalType.AudioVideo,
|
var hdmiIn4 = new RoutingInputPort(RoutingPortNames.HdmiIn4, eRoutingSignalType.AudioVideo,
|
||||||
eRoutingPortConnectionType.Hdmi, "HDMI4", this);
|
eRoutingPortConnectionType.Hdmi, "HDMI4", this);
|
||||||
var dpIn = new RoutingInputPort(RoutingPortNames.DisplayPortIn, eRoutingSignalType.AudioVideo,
|
var dpIn = new RoutingInputPort(RoutingPortNames.DisplayPortIn, eRoutingSignalType.AudioVideo,
|
||||||
eRoutingPortConnectionType.DisplayPort, "DP", this);
|
eRoutingPortConnectionType.DisplayPort, "DP", this);
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ using System.Linq;
|
|||||||
using Crestron.SimplSharp;
|
using Crestron.SimplSharp;
|
||||||
using Crestron.SimplSharp.CrestronIO;
|
using Crestron.SimplSharp.CrestronIO;
|
||||||
using Crestron.SimplSharpPro;
|
using Crestron.SimplSharpPro;
|
||||||
using Crestron.SimplSharp.Reflection;
|
using System.Reflection;
|
||||||
|
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
|
|||||||
Reference in New Issue
Block a user