mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-01-27 19:34:51 +00:00
Compare commits
16 Commits
2.0.0-alph
...
2.0.0-alph
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b80b827217 | ||
|
|
35e9e54564 | ||
|
|
3eefd1ce36 | ||
|
|
1e6e8a044d | ||
|
|
f9d3607072 | ||
|
|
d6b32f48c7 | ||
|
|
8883fc329e | ||
|
|
ab6f1f36f0 | ||
|
|
610fae972d | ||
|
|
876689fdfe | ||
|
|
a2c628145d | ||
|
|
d2877f2cec | ||
|
|
3eaa86905f | ||
|
|
b263c7421b | ||
|
|
1727e81e33 | ||
|
|
5a097e7057 |
@@ -1,6 +1,7 @@
|
||||
<Project>
|
||||
<PropertyGroup>
|
||||
<Version>2.0.0-local</Version>
|
||||
<InformationalVersion>$(Version)</InformationalVersion>
|
||||
<Authors>PepperDash Technologies</Authors>
|
||||
<Company>PepperDash Technologies</Company>
|
||||
<Product>PepperDash Essentials</Product>
|
||||
|
||||
@@ -375,8 +375,7 @@ namespace PepperDash.Essentials.Core.Bridges
|
||||
{
|
||||
try
|
||||
{
|
||||
if (Debug.Level >= 1)
|
||||
Debug.Console(1, this, "EiscApiAdvanced change: {0} {1}={2}", args.Sig.Type, args.Sig.Number, args.Sig.StringValue);
|
||||
Debug.Console(2, this, "EiscApiAdvanced change: {0} {1}={2}", args.Sig.Type, args.Sig.Number, args.Sig.StringValue);
|
||||
var uo = args.Sig.UserObject;
|
||||
|
||||
if (uo == null) return;
|
||||
|
||||
13
src/PepperDash.Essentials.Core/Config/ILoadConfig.cs
Normal file
13
src/PepperDash.Essentials.Core/Config/ILoadConfig.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PepperDash.Essentials.Core
|
||||
{
|
||||
public interface ILoadConfig
|
||||
{
|
||||
void GoWithLoad();
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
using System;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using PepperDash.Core;
|
||||
|
||||
namespace PepperDash.Essentials.Core.DeviceTypeInterfaces
|
||||
@@ -17,8 +19,39 @@ namespace PepperDash.Essentials.Core.DeviceTypeInterfaces
|
||||
/// Describes a MobileSystemController that accepts IEssentialsRoom
|
||||
/// </summary>
|
||||
public interface IMobileControl3 : IMobileControl
|
||||
{
|
||||
void SendMessageObject(IMobileControlMessage o);
|
||||
|
||||
void AddAction(string key, Action<JToken> action);
|
||||
|
||||
void RemoveAction(string key);
|
||||
|
||||
void AddDeviceMessenger(IMobileControlMessenger messenger);
|
||||
|
||||
bool CheckForDeviceMessenger(string key);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Describes a mobile control messenger
|
||||
/// </summary>
|
||||
public interface IMobileControlMessenger: IKeyed
|
||||
{
|
||||
void CreateMobileControlRoomBridge(IEssentialsRoom room, IMobileControl parent);
|
||||
IMobileControl3 AppServerController { get; }
|
||||
string MessagePath { get; }
|
||||
void RegisterWithAppServer(IMobileControl3 appServerController);
|
||||
}
|
||||
|
||||
public interface IMobileControlMessage
|
||||
{
|
||||
[JsonProperty("type")]
|
||||
string Type { get; }
|
||||
|
||||
[JsonProperty("clientId", NullValueHandling = NullValueHandling.Ignore)]
|
||||
string ClientId { get; }
|
||||
|
||||
[JsonProperty("content", NullValueHandling = NullValueHandling.Ignore)]
|
||||
JToken Content { get; }
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -189,7 +189,7 @@ namespace PepperDash.Essentials.Core
|
||||
CrestronConsole.ConsoleCommandResponse(
|
||||
@"Type: '{0}'
|
||||
CType: '{1}'
|
||||
Description: {2}", type.Key, cType, description);
|
||||
Description: {2}{3}", type.Key, cType, description, CrestronEnvironment.NewLine);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,14 +21,9 @@
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Remove="Web\**" />
|
||||
<EmbeddedResource Remove="Web\**" />
|
||||
<None Remove="Web\**" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Crestron.SimplSharp.SDK.ProgramLibrary" Version="2.20.42" />
|
||||
<PackageReference Include="PepperDashCore" Version="2.0.0-beta-383" />
|
||||
<PackageReference Include="PepperDashCore" Version="2.0.0-beta-385" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Crestron\CrestronGenericBaseDevice.cs.orig" />
|
||||
|
||||
@@ -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;
|
||||
|
||||
12
src/PepperDash.Essentials.Core/Room/IRoomEventSchedule.cs
Normal file
12
src/PepperDash.Essentials.Core/Room/IRoomEventSchedule.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using PepperDash.Essentials.Room.Config;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace PepperDash.Essentials.Core
|
||||
{
|
||||
public interface IRoomEventSchedule
|
||||
{
|
||||
void AddOrUpdateScheduledEvent(ScheduledEventConfig eventConfig);
|
||||
|
||||
List<ScheduledEventConfig> GetScheduledEvents();
|
||||
}
|
||||
}
|
||||
@@ -154,8 +154,7 @@ namespace PepperDash.Essentials.Core.UI
|
||||
|
||||
private void Panel_SigChange(object currentDevice, Crestron.SimplSharpPro.SigEventArgs args)
|
||||
{
|
||||
if (Debug.Level == 2)
|
||||
Debug.Console(2, this, "Sig change: {0} {1}={2}", args.Sig.Type, args.Sig.Number, args.Sig.StringValue);
|
||||
Debug.Console(5, this, "Sig change: {0} {1}={2}", args.Sig.Type, args.Sig.Number, args.Sig.StringValue);
|
||||
var uo = args.Sig.UserObject;
|
||||
if (uo is Action<bool>)
|
||||
(uo as Action<bool>)(args.Sig.BoolValue);
|
||||
|
||||
@@ -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,115 @@ 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")
|
||||
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()
|
||||
},
|
||||
new HttpCwsRoute("debugSession")
|
||||
{
|
||||
Name = "ReportVersions",
|
||||
RouteHandler = new ReportVersionsRequestHandler()
|
||||
Name = "DebugSession",
|
||||
RouteHandler = new DebugSessionRequestHandler()
|
||||
},
|
||||
new HttpCwsRoute("appdebug")
|
||||
new HttpCwsRoute("doNotLoadConfigOnNextBoot")
|
||||
{
|
||||
Name = "AppDebug",
|
||||
RouteHandler = new AppDebugRequestHandler()
|
||||
Name = "DoNotLoadConfigOnNextBoot",
|
||||
RouteHandler = new DoNotLoadConfigOnNextBootRequestHandler()
|
||||
},
|
||||
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()
|
||||
}
|
||||
};
|
||||
new HttpCwsRoute("restartProgram")
|
||||
{
|
||||
Name = "Restart Program",
|
||||
RouteHandler = new RestartProgramRequestHandler()
|
||||
},
|
||||
new HttpCwsRoute("loadConfig")
|
||||
{
|
||||
Name = "Load Config",
|
||||
RouteHandler = new LoadConfigRequestHandler()
|
||||
}
|
||||
|
||||
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
|
||||
@@ -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;
|
||||
|
||||
@@ -2,6 +2,9 @@
|
||||
using Newtonsoft.Json;
|
||||
using PepperDash.Core;
|
||||
using PepperDash.Core.Web.RequestHandlers;
|
||||
using System;
|
||||
using Serilog.Events;
|
||||
using Newtonsoft.Json.Converters;
|
||||
|
||||
namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
||||
{
|
||||
@@ -24,7 +27,7 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
||||
/// <param name="context"></param>
|
||||
protected override void HandleGet(HttpCwsContext context)
|
||||
{
|
||||
var appDebug = new AppDebug { Level = Debug.Level };
|
||||
var appDebug = new AppDebug { MinimumLevel = Debug.WebsocketMinimumLogLevel };
|
||||
|
||||
var body = JsonConvert.SerializeObject(appDebug, Formatting.Indented);
|
||||
|
||||
@@ -60,11 +63,11 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
||||
}
|
||||
|
||||
var appDebug = new AppDebug();
|
||||
var requestBody = JsonConvert.DeserializeAnonymousType(data, appDebug);
|
||||
var requestBody = JsonConvert.DeserializeObject<AppDebug>(data);
|
||||
|
||||
Debug.SetDebugLevel(requestBody.Level);
|
||||
Debug.SetWebSocketMinimumDebugLevel(requestBody.MinimumLevel);
|
||||
|
||||
appDebug.Level = Debug.Level;
|
||||
appDebug.MinimumLevel = Debug.WebsocketMinimumLogLevel;
|
||||
var responseBody = JsonConvert.SerializeObject(appDebug, Formatting.Indented);
|
||||
|
||||
context.Response.StatusCode = 200;
|
||||
@@ -76,7 +79,8 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
||||
|
||||
public class AppDebug
|
||||
{
|
||||
[JsonProperty("level", NullValueHandling = NullValueHandling.Ignore)]
|
||||
public int Level { get; set; }
|
||||
[JsonProperty("minimumLevel", NullValueHandling = NullValueHandling.Ignore)]
|
||||
[JsonConverter(typeof(StringEnumConverter))]
|
||||
public LogEventLevel MinimumLevel { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
using Crestron.SimplSharp;
|
||||
using Crestron.SimplSharp.WebScripting;
|
||||
using Crestron.SimplSharpPro.EthernetCommunication;
|
||||
using Newtonsoft.Json;
|
||||
using PepperDash.Core;
|
||||
using PepperDash.Core.Web.RequestHandlers;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
||||
{
|
||||
public class DebugSessionRequestHandler : WebApiBaseRequestHandler
|
||||
{
|
||||
public DebugSessionRequestHandler()
|
||||
: base(true)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets details for a debug session
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
protected override void HandleGet(Crestron.SimplSharp.WebScripting.HttpCwsContext context)
|
||||
{
|
||||
var routeData = context.Request.RouteData;
|
||||
if (routeData == null)
|
||||
{
|
||||
context.Response.StatusCode = 400;
|
||||
context.Response.StatusDescription = "Bad Request";
|
||||
context.Response.End();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var ip = CrestronEthernetHelper.GetEthernetParameter(
|
||||
CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_IP_ADDRESS, 0);
|
||||
|
||||
var port = 0;
|
||||
|
||||
if (!Debug.WebsocketSink.IsRunning)
|
||||
{
|
||||
Debug.Console(0, "Starting WS Server");
|
||||
// Generate a random port within a specified range
|
||||
port = new Random().Next(65435, 65535);
|
||||
// Start the WS Server
|
||||
Debug.WebsocketSink.StartServerAndSetPort(port);
|
||||
Debug.SetWebSocketMinimumDebugLevel(Serilog.Events.LogEventLevel.Verbose);
|
||||
}
|
||||
|
||||
var url = Debug.WebsocketSink.Url;
|
||||
|
||||
object data = new
|
||||
{
|
||||
url = Debug.WebsocketSink.Url
|
||||
};
|
||||
|
||||
Debug.Console(0, "Debug Session URL: {0}", url);
|
||||
|
||||
// Return the port number with the full url of the WS Server
|
||||
var res = JsonConvert.SerializeObject(data);
|
||||
|
||||
context.Response.ContentType = "application/json";
|
||||
context.Response.ContentEncoding = Encoding.UTF8;
|
||||
context.Response.StatusCode = 200;
|
||||
context.Response.StatusDescription = "OK";
|
||||
context.Response.Write(res, false);
|
||||
context.Response.End();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.Console(0, "Error: {0}", e);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stops a debug session
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
protected override void HandlePost(HttpCwsContext context)
|
||||
{
|
||||
Debug.WebsocketSink.StopServer();
|
||||
|
||||
context.Response.StatusCode = 200;
|
||||
context.Response.StatusDescription = "OK";
|
||||
context.Response.End();
|
||||
|
||||
Debug.Console(0, "Websocket Debug Session Stopped");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
using Crestron.SimplSharp.WebScripting;
|
||||
using Newtonsoft.Json;
|
||||
using PepperDash.Core;
|
||||
using PepperDash.Core.Web.RequestHandlers;
|
||||
|
||||
namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
||||
{
|
||||
public class DoNotLoadConfigOnNextBootRequestHandler : WebApiBaseRequestHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// base(true) enables CORS support by default
|
||||
/// </remarks>
|
||||
public DoNotLoadConfigOnNextBootRequestHandler()
|
||||
: base(true)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles GET method requests
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
protected override void HandleGet(HttpCwsContext context)
|
||||
{
|
||||
var data = new Data
|
||||
{
|
||||
DoNotLoadConfigOnNextBoot = Debug.DoNotLoadConfigOnNextBoot
|
||||
};
|
||||
|
||||
var body = JsonConvert.SerializeObject(data, Formatting.Indented);
|
||||
|
||||
context.Response.StatusCode = 200;
|
||||
context.Response.StatusDescription = "OK";
|
||||
context.Response.Write(body, false);
|
||||
context.Response.End();
|
||||
}
|
||||
|
||||
/// <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();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var data = EssentialsWebApiHelpers.GetRequestBody(context.Request);
|
||||
if (string.IsNullOrEmpty(data))
|
||||
{
|
||||
context.Response.StatusCode = 400;
|
||||
context.Response.StatusDescription = "Bad Request";
|
||||
context.Response.End();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var d = new Data();
|
||||
var requestBody = JsonConvert.DeserializeAnonymousType(data, d);
|
||||
|
||||
Debug.SetDoNotLoadConfigOnNextBoot(requestBody.DoNotLoadConfigOnNextBoot);
|
||||
|
||||
var responseBody = JsonConvert.SerializeObject(d, Formatting.Indented);
|
||||
|
||||
context.Response.StatusCode = 200;
|
||||
context.Response.StatusDescription = "OK";
|
||||
context.Response.Write(responseBody, false);
|
||||
context.Response.End();
|
||||
}
|
||||
}
|
||||
|
||||
public class Data
|
||||
{
|
||||
[JsonProperty("doNotLoadConfigOnNextBoot", NullValueHandling = NullValueHandling.Ignore)]
|
||||
public bool DoNotLoadConfigOnNextBoot { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,6 @@
|
||||
extern alias Full
|
||||
|
||||
using System.Linq;
|
||||
using System.Linq;
|
||||
using Crestron.SimplSharp.WebScripting;
|
||||
using Full.Newtonsoft.Json;
|
||||
using Newtonsoft.Json;
|
||||
using PepperDash.Core.Web.RequestHandlers;
|
||||
|
||||
namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
extern alias Full
|
||||
|
||||
using System.Linq;
|
||||
using System.Linq;
|
||||
using Crestron.SimplSharp.WebScripting;
|
||||
using Full.Newtonsoft.Json;
|
||||
using Newtonsoft.Json;
|
||||
using PepperDash.Core.Web.RequestHandlers;
|
||||
|
||||
namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
using Crestron.SimplSharp;
|
||||
using Crestron.SimplSharp.WebScripting;
|
||||
using Newtonsoft.Json;
|
||||
using PepperDash.Core;
|
||||
using PepperDash.Core.Web.RequestHandlers;
|
||||
|
||||
namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
||||
{
|
||||
public class LoadConfigRequestHandler : WebApiBaseRequestHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// base(true) enables CORS support by default
|
||||
/// </remarks>
|
||||
public LoadConfigRequestHandler()
|
||||
: base(true)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles POST method requests
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
protected override void HandlePost(HttpCwsContext context)
|
||||
{
|
||||
var message = "";
|
||||
var cs = Global.ControlSystem as ILoadConfig;
|
||||
if(cs != null)
|
||||
cs.GoWithLoad();
|
||||
|
||||
context.Response.StatusCode = 200;
|
||||
context.Response.StatusDescription = "OK";
|
||||
context.Response.Write(message, false);
|
||||
context.Response.End();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,6 @@
|
||||
extern alias Full
|
||||
|
||||
using System.Linq;
|
||||
using System.Linq;
|
||||
using Crestron.SimplSharp.WebScripting;
|
||||
using Full.Newtonsoft.Json;
|
||||
using Newtonsoft.Json;
|
||||
using PepperDash.Core.Web.RequestHandlers;
|
||||
|
||||
namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
using Crestron.SimplSharp;
|
||||
using Crestron.SimplSharp.WebScripting;
|
||||
using Newtonsoft.Json;
|
||||
using PepperDash.Core;
|
||||
using PepperDash.Core.Web.RequestHandlers;
|
||||
|
||||
namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
||||
{
|
||||
public class RestartProgramRequestHandler : WebApiBaseRequestHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// base(true) enables CORS support by default
|
||||
/// </remarks>
|
||||
public RestartProgramRequestHandler()
|
||||
: base(true)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles POST method requests
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
protected override void HandlePost(HttpCwsContext context)
|
||||
{
|
||||
var message = "";
|
||||
if(CrestronEnvironment.DevicePlatform == eDevicePlatform.Appliance)
|
||||
CrestronConsole.SendControlSystemCommand($"progres -p:{InitialParametersClass.ApplicationNumber}", ref message);
|
||||
|
||||
context.Response.StatusCode = 200;
|
||||
context.Response.StatusDescription = "OK";
|
||||
context.Response.Write(message, false);
|
||||
context.Response.End();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
extern alias Full
|
||||
|
||||
using Crestron.SimplSharp.WebScripting;
|
||||
using Full.Newtonsoft.Json;
|
||||
using Crestron.SimplSharp.WebScripting;
|
||||
using Newtonsoft.Json;
|
||||
using PepperDash.Core.Web.RequestHandlers;
|
||||
using PepperDash.Essentials.Core.Config;
|
||||
|
||||
|
||||
@@ -27,6 +27,6 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Crestron.SimplSharp.SDK.ProgramLibrary" Version="2.20.42" />
|
||||
<PackageReference Include="PepperDashCore" Version="2.0.0-beta-383" />
|
||||
<PackageReference Include="PepperDashCore" Version="2.0.0-beta-385" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -10,12 +10,13 @@ using PepperDash.Essentials.Core;
|
||||
using PepperDash.Essentials.Core.Bridges;
|
||||
using PepperDash.Essentials.Core.Config;
|
||||
using PepperDash.Essentials.Core.DeviceTypeInterfaces;
|
||||
using PepperDash.Essentials.Core.Web;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace PepperDash.Essentials
|
||||
{
|
||||
public class ControlSystem : CrestronControlSystem
|
||||
public class ControlSystem : CrestronControlSystem, ILoadConfig
|
||||
{
|
||||
HttpLogoServer LogoServer;
|
||||
|
||||
@@ -87,7 +88,7 @@ namespace PepperDash.Essentials
|
||||
{
|
||||
DeterminePlatform();
|
||||
|
||||
if (Debug.DoNotLoadOnNextBoot)
|
||||
if (Debug.DoNotLoadConfigOnNextBoot)
|
||||
{
|
||||
CrestronConsole.AddNewConsoleCommand(s => CrestronInvoke.BeginInvoke((o) => GoWithLoad()), "go", "Loads configuration file",
|
||||
ConsoleAccessLevelEnum.AccessOperator);
|
||||
@@ -135,7 +136,9 @@ namespace PepperDash.Essentials
|
||||
CrestronConsole.AddNewConsoleCommand(DeviceManager.GetRoutingPorts,
|
||||
"getroutingports", "Reports all routing ports, if any. Requires a device key", ConsoleAccessLevelEnum.AccessOperator);
|
||||
|
||||
if (!Debug.DoNotLoadOnNextBoot)
|
||||
DeviceManager.AddDevice(new EssentialsWebApi("essentialsWebApi", "Essentials Web API"));
|
||||
|
||||
if (!Debug.DoNotLoadConfigOnNextBoot)
|
||||
{
|
||||
GoWithLoad();
|
||||
return;
|
||||
@@ -170,6 +173,8 @@ namespace PepperDash.Essentials
|
||||
|
||||
Global.SetAssemblyVersion(fullVersion);
|
||||
|
||||
//Global.SetAssemblyVersion(fullVersionAtt.InformationalVersion);
|
||||
|
||||
if (CrestronEnvironment.DevicePlatform != eDevicePlatform.Server) // Handles 3-series running Windows CE OS
|
||||
{
|
||||
string userFolder;
|
||||
@@ -217,7 +222,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);
|
||||
|
||||
@@ -240,7 +245,7 @@ namespace PepperDash.Essentials
|
||||
{
|
||||
try
|
||||
{
|
||||
Debug.SetDoNotLoadOnNextBoot(false);
|
||||
Debug.SetDoNotLoadConfigOnNextBoot(false);
|
||||
|
||||
PluginLoader.AddProgramAssemblies();
|
||||
|
||||
@@ -305,6 +310,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);
|
||||
@@ -373,7 +380,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)
|
||||
@@ -402,51 +408,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;
|
||||
}
|
||||
|
||||
@@ -11,6 +11,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>
|
||||
@@ -46,7 +47,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Crestron.SimplSharp.SDK.Program" Version="2.20.42" />
|
||||
<PackageReference Include="PepperDashCore" Version="2.0.0-beta-383" />
|
||||
<PackageReference Include="PepperDashCore" Version="2.0.0-beta-385" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\PepperDash.Essentials.Core\PepperDash.Essentials.Core.csproj" />
|
||||
|
||||
Reference in New Issue
Block a user