mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-02-05 15:55:02 +00:00
fix: Updated showconfig, gettypes, getjoinmap handlers; updated BridgeBase to expose joinmaps; updated DeviceFactory to introduce method for getting dictionary
This commit is contained in:
@@ -109,7 +109,7 @@ namespace PepperDash.Essentials.Core.Bridges
|
||||
{
|
||||
public EiscApiPropertiesConfig PropertiesConfig { get; private set; }
|
||||
|
||||
protected Dictionary<string, JoinMapBaseAdvanced> JoinMaps { get; private set; }
|
||||
public Dictionary<string, JoinMapBaseAdvanced> JoinMaps { get; private set; }
|
||||
|
||||
public BasicTriList Eisc { get; private set; }
|
||||
|
||||
|
||||
@@ -204,5 +204,17 @@ namespace PepperDash.Essentials.Core
|
||||
Description: {2}", type.Key, cType, description);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the device factory dictionary
|
||||
/// </summary>
|
||||
/// <param name="filter"></param>
|
||||
/// <returns></returns>
|
||||
public static Dictionary<string, DeviceFactoryWrapper> GetDeviceFactoryDictionary(string filter)
|
||||
{
|
||||
return !string.IsNullOrEmpty(filter)
|
||||
? FactoryMethods.Where(k => k.Key.Contains(filter)).ToDictionary(k => k.Key, k => k.Value)
|
||||
: FactoryMethods;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -198,6 +198,8 @@
|
||||
<Compile Include="Crestron IO\Relay\ISwitchedOutput.cs" />
|
||||
<Compile Include="Crestron IO\StatusSign\StatusSignController.cs" />
|
||||
<Compile Include="Web\RequestHandlers\AppDebugRequestHandler.cs" />
|
||||
<Compile Include="Web\RequestHandlers\GetTypesByFilterRequestHandler.cs" />
|
||||
<Compile Include="Web\RequestHandlers\GetJoinMapForDeviceKeyRequestHandler.cs" />
|
||||
<Compile Include="Web\RequestHandlers\DefaultRequestHandler.cs" />
|
||||
<Compile Include="Web\RequestHandlers\DevListRequestHandler.cs" />
|
||||
<Compile Include="Web\RequestHandlers\DevPropsRequestHandler.cs" />
|
||||
@@ -206,7 +208,7 @@
|
||||
<Compile Include="Web\RequestHandlers\DisableAllStreamDebugRequestHandler.cs" />
|
||||
<Compile Include="Web\RequestHandlers\ShowConfigRequestHandler.cs" />
|
||||
<Compile Include="Web\RequestHandlers\GetTypesRequestHandler.cs" />
|
||||
<Compile Include="Web\RequestHandlers\GetJoinMapRequestHandler.cs" />
|
||||
<Compile Include="Web\RequestHandlers\GetJoinMapForBridgeKeyRequestHandler.cs" />
|
||||
<Compile Include="Web\EssemtialsWebApi.cs" />
|
||||
<Compile Include="Web\EssentialsWebApiFactory.cs" />
|
||||
<Compile Include="Web\EssentialsWebApiPropertiesConfig.cs" />
|
||||
|
||||
@@ -128,25 +128,25 @@ namespace PepperDash.Essentials.Core.Web
|
||||
Name = "ShowConfig",
|
||||
RouteHandler = new ShowConfigRequestHandler()
|
||||
},
|
||||
new HttpCwsRoute("gettypes/all")
|
||||
new HttpCwsRoute("gettypes")
|
||||
{
|
||||
Name = "GetTypesAll",
|
||||
Name = "GetTypes",
|
||||
RouteHandler = new GetTypesRequestHandler()
|
||||
},
|
||||
new HttpCwsRoute("gettypes/{filter}")
|
||||
{
|
||||
Name = "GetTypesByFilter",
|
||||
RouteHandler = new GetTypesRequestHandler()
|
||||
RouteHandler = new GetTypesByFilterRequestHandler()
|
||||
},
|
||||
new HttpCwsRoute("getjoinmap/{bridgeKey}/all")
|
||||
new HttpCwsRoute("getjoinmap/{bridgeKey}")
|
||||
{
|
||||
Name = "GetJoinMapsByBridgeKey",
|
||||
RouteHandler = new GetJoinMapRequestHandler()
|
||||
Name = "GetJoinMapsForBridgeKey",
|
||||
RouteHandler = new GetJoinMapForBridgeKeyRequestHandler()
|
||||
},
|
||||
new HttpCwsRoute("getjoinmap/{bridgeKey}/{deviceKey}")
|
||||
{
|
||||
Name = "GetJoinMapsForBridgeKeyFilteredByDeviceKey",
|
||||
RouteHandler = new GetJoinMapRequestHandler()
|
||||
Name = "GetJoinMapsForDeviceKey",
|
||||
RouteHandler = new GetJoinMapForDeviceKeyRequestHandler()
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -92,11 +92,20 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
||||
var data = Encoding.UTF8.GetString(bytes, 0, bytes.Length);
|
||||
Debug.Console(Info, "[{0}] Request data:\n{1}", Key.ToLower(), data);
|
||||
|
||||
DeviceJsonApi.DoDeviceActionWithJson(data);
|
||||
try
|
||||
{
|
||||
DeviceJsonApi.DoDeviceActionWithJson(data);
|
||||
|
||||
context.Response.StatusCode = 200;
|
||||
context.Response.StatusDescription = "OK";
|
||||
context.Response.End();
|
||||
context.Response.StatusCode = 200;
|
||||
context.Response.StatusDescription = "OK";
|
||||
context.Response.End();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
context.Response.StatusCode = 400;
|
||||
context.Response.StatusDescription = "Bad Request";
|
||||
context.Response.End();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -0,0 +1,175 @@
|
||||
using Crestron.SimplSharp.WebScripting;
|
||||
using Newtonsoft.Json;
|
||||
using PepperDash.Core;
|
||||
using PepperDash.Core.Web.RequestHandlers;
|
||||
using PepperDash.Essentials.Core.Bridges;
|
||||
|
||||
namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
||||
{
|
||||
public class GetJoinMapForBridgeKeyRequestHandler : WebApiBaseRequestHandler
|
||||
{
|
||||
private const string Key = "GetJoinMapForBridgeKeyRequestHandler";
|
||||
private const uint Trace = 0;
|
||||
private const uint Info = 0;
|
||||
private const uint Verbose = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Handles CONNECT method requests
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
protected override void HandleConnect(HttpCwsContext context)
|
||||
{
|
||||
context.Response.StatusCode = 501;
|
||||
context.Response.StatusDescription = "Not Implemented";
|
||||
context.Response.End();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles DELETE method requests
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
protected override void HandleDelete(HttpCwsContext context)
|
||||
{
|
||||
context.Response.StatusCode = 501;
|
||||
context.Response.StatusDescription = "Not Implemented";
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
var routeDataJson = JsonConvert.SerializeObject(routeData, Formatting.Indented);
|
||||
Debug.Console(Verbose, "routeData:\n{0}", routeDataJson);
|
||||
|
||||
|
||||
object bridgeObj;
|
||||
if (!routeData.Values.TryGetValue("bridgeKey", out bridgeObj))
|
||||
{
|
||||
Debug.Console(Verbose, "TryGetValue bridgeKey failed");
|
||||
|
||||
context.Response.StatusCode = 400;
|
||||
context.Response.StatusDescription = "Bad Request";
|
||||
context.Response.End();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var bridge = DeviceManager.GetDeviceForKey(bridgeObj.ToString()) as EiscApiAdvanced;
|
||||
if (bridge == null)
|
||||
{
|
||||
context.Response.StatusCode = 400;
|
||||
context.Response.StatusDescription = "Bad Request";
|
||||
context.Response.End();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var joinMap = bridge.JoinMaps;
|
||||
if (joinMap == null)
|
||||
{
|
||||
context.Response.StatusCode = 400;
|
||||
context.Response.StatusDescription = "Bad Request";
|
||||
context.Response.End();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var js = JsonConvert.SerializeObject(joinMap, Formatting.Indented, new JsonSerializerSettings
|
||||
{
|
||||
ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
|
||||
NullValueHandling = NullValueHandling.Ignore,
|
||||
MissingMemberHandling = MissingMemberHandling.Ignore,
|
||||
DefaultValueHandling = DefaultValueHandling.Ignore,
|
||||
TypeNameHandling = TypeNameHandling.None
|
||||
});
|
||||
Debug.Console(Verbose, "[{0}] HandleGet: \x0d\x0a{1}", Key.ToLower(), js);
|
||||
|
||||
context.Response.StatusCode = 200;
|
||||
context.Response.StatusDescription = "OK";
|
||||
context.Response.ContentType = "application/json";
|
||||
context.Response.ContentEncoding = System.Text.Encoding.UTF8;
|
||||
context.Response.Write(js, false);
|
||||
context.Response.End();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles HEAD method requests
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
protected override void HandleHead(HttpCwsContext context)
|
||||
{
|
||||
context.Response.StatusCode = 501;
|
||||
context.Response.StatusDescription = "Not Implemented";
|
||||
context.Response.End();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles OPTIONS method requests
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
protected override void HandleOptions(HttpCwsContext context)
|
||||
{
|
||||
context.Response.StatusCode = 501;
|
||||
context.Response.StatusDescription = "Not Implemented";
|
||||
context.Response.End();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles PATCH method requests
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
protected override void HandlePatch(HttpCwsContext context)
|
||||
{
|
||||
context.Response.StatusCode = 501;
|
||||
context.Response.StatusDescription = "Not Implemented";
|
||||
context.Response.End();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles POST method requests
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
protected override void HandlePost(HttpCwsContext context)
|
||||
{
|
||||
context.Response.StatusCode = 501;
|
||||
context.Response.StatusDescription = "Not Implemented";
|
||||
context.Response.End();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles PUT method requests
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
protected override void HandlePut(HttpCwsContext context)
|
||||
{
|
||||
context.Response.StatusCode = 501;
|
||||
context.Response.StatusDescription = "Not Implemented";
|
||||
context.Response.End();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles TRACE method requests
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
protected override void HandleTrace(HttpCwsContext context)
|
||||
{
|
||||
context.Response.StatusCode = 501;
|
||||
context.Response.StatusDescription = "Not Implemented";
|
||||
context.Response.End();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,196 @@
|
||||
using System.Collections.Generic;
|
||||
using Crestron.SimplSharp.WebScripting;
|
||||
using Newtonsoft.Json;
|
||||
using PepperDash.Core;
|
||||
using PepperDash.Core.Web.RequestHandlers;
|
||||
using PepperDash.Essentials.Core.Bridges;
|
||||
|
||||
namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
||||
{
|
||||
public class GetJoinMapForDeviceKeyRequestHandler : WebApiBaseRequestHandler
|
||||
{
|
||||
private const string Key = "GetJoinMapForDeviceKeyRequestHandler";
|
||||
private const uint Trace = 0;
|
||||
private const uint Info = 0;
|
||||
private const uint Verbose = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Handles CONNECT method requests
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
protected override void HandleConnect(HttpCwsContext context)
|
||||
{
|
||||
context.Response.StatusCode = 501;
|
||||
context.Response.StatusDescription = "Not Implemented";
|
||||
context.Response.End();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles DELETE method requests
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
protected override void HandleDelete(HttpCwsContext context)
|
||||
{
|
||||
context.Response.StatusCode = 501;
|
||||
context.Response.StatusDescription = "Not Implemented";
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
var routeDataJson = JsonConvert.SerializeObject(routeData, Formatting.Indented);
|
||||
Debug.Console(Verbose, "routeData:\n{0}", routeDataJson);
|
||||
|
||||
|
||||
object bridgeObj;
|
||||
if (!routeData.Values.TryGetValue("bridgeKey", out bridgeObj))
|
||||
{
|
||||
Debug.Console(Verbose, "TryGetValue bridgeKey failed");
|
||||
|
||||
context.Response.StatusCode = 400;
|
||||
context.Response.StatusDescription = "Bad Request";
|
||||
context.Response.End();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
object deviceObj;
|
||||
if (!routeData.Values.TryGetValue("deviceKey", out deviceObj))
|
||||
{
|
||||
Debug.Console(Verbose, "TryGetValue deviceKey failed");
|
||||
|
||||
context.Response.StatusCode = 400;
|
||||
context.Response.StatusDescription = "Bad Request";
|
||||
context.Response.End();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var bridge = DeviceManager.GetDeviceForKey(bridgeObj.ToString()) as EiscApiAdvanced;
|
||||
if (bridge == null)
|
||||
{
|
||||
context.Response.StatusCode = 400;
|
||||
context.Response.StatusDescription = "Bad Request";
|
||||
context.Response.End();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
JoinMapBaseAdvanced deviceJoinMap;
|
||||
if (!bridge.JoinMaps.TryGetValue(deviceObj.ToString(), out deviceJoinMap))
|
||||
{
|
||||
context.Response.StatusCode = 400;
|
||||
context.Response.StatusDescription = "Bad Request";
|
||||
context.Response.End();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var joinMap = new Dictionary<string, JoinMapBaseAdvanced>
|
||||
{
|
||||
{
|
||||
deviceObj.ToString(),
|
||||
deviceJoinMap
|
||||
}
|
||||
};
|
||||
|
||||
var js = JsonConvert.SerializeObject(joinMap, Formatting.Indented, new JsonSerializerSettings
|
||||
{
|
||||
ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
|
||||
NullValueHandling = NullValueHandling.Ignore,
|
||||
MissingMemberHandling = MissingMemberHandling.Ignore,
|
||||
DefaultValueHandling = DefaultValueHandling.Ignore,
|
||||
TypeNameHandling = TypeNameHandling.None
|
||||
});
|
||||
Debug.Console(Verbose, "[{0}] HandleGet: \x0d\x0a{1}", Key.ToLower(), js);
|
||||
|
||||
context.Response.StatusCode = 200;
|
||||
context.Response.StatusDescription = "OK";
|
||||
context.Response.ContentType = "application/json";
|
||||
context.Response.ContentEncoding = System.Text.Encoding.UTF8;
|
||||
context.Response.Write(js, false);
|
||||
context.Response.End();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles HEAD method requests
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
protected override void HandleHead(HttpCwsContext context)
|
||||
{
|
||||
context.Response.StatusCode = 501;
|
||||
context.Response.StatusDescription = "Not Implemented";
|
||||
context.Response.End();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles OPTIONS method requests
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
protected override void HandleOptions(HttpCwsContext context)
|
||||
{
|
||||
context.Response.StatusCode = 501;
|
||||
context.Response.StatusDescription = "Not Implemented";
|
||||
context.Response.End();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles PATCH method requests
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
protected override void HandlePatch(HttpCwsContext context)
|
||||
{
|
||||
context.Response.StatusCode = 501;
|
||||
context.Response.StatusDescription = "Not Implemented";
|
||||
context.Response.End();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles POST method requests
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
protected override void HandlePost(HttpCwsContext context)
|
||||
{
|
||||
context.Response.StatusCode = 501;
|
||||
context.Response.StatusDescription = "Not Implemented";
|
||||
context.Response.End();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles PUT method requests
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
protected override void HandlePut(HttpCwsContext context)
|
||||
{
|
||||
context.Response.StatusCode = 501;
|
||||
context.Response.StatusDescription = "Not Implemented";
|
||||
context.Response.End();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles TRACE method requests
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
protected override void HandleTrace(HttpCwsContext context)
|
||||
{
|
||||
context.Response.StatusCode = 501;
|
||||
context.Response.StatusDescription = "Not Implemented";
|
||||
context.Response.End();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,18 @@
|
||||
using Crestron.SimplSharp.WebScripting;
|
||||
using Newtonsoft.Json;
|
||||
using PepperDash.Core;
|
||||
using PepperDash.Core.Web.RequestHandlers;
|
||||
using PepperDash.Essentials.Core.Bridges;
|
||||
|
||||
namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
||||
{
|
||||
public class GetJoinMapRequestHandler : WebApiBaseRequestHandler
|
||||
public class GetTypesByFilterRequestHandler : WebApiBaseRequestHandler
|
||||
{
|
||||
private const string Key = "GetTypesByFilterRequestHandler";
|
||||
private const uint Trace = 0;
|
||||
private const uint Info = 0;
|
||||
private const uint Verbose = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Handles CONNECT method requests
|
||||
/// </summary>
|
||||
@@ -33,8 +41,60 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
||||
/// <param name="context"></param>
|
||||
protected override void HandleGet(HttpCwsContext context)
|
||||
{
|
||||
context.Response.StatusCode = 501;
|
||||
context.Response.StatusDescription = "Not Implemented";
|
||||
var routeData = context.Request.RouteData;
|
||||
if (routeData == null)
|
||||
{
|
||||
context.Response.StatusCode = 400;
|
||||
context.Response.StatusDescription = "Bad Request";
|
||||
context.Response.End();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
var routeDataJson = JsonConvert.SerializeObject(routeData, Formatting.Indented);
|
||||
Debug.Console(Verbose, "routeData:\n{0}", routeDataJson);
|
||||
|
||||
|
||||
object filterObj;
|
||||
if (!routeData.Values.TryGetValue("filter", out filterObj))
|
||||
{
|
||||
Debug.Console(Verbose, "TryGetValue filter failed");
|
||||
|
||||
context.Response.StatusCode = 400;
|
||||
context.Response.StatusDescription = "Bad Request";
|
||||
context.Response.End();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var types = DeviceFactory.GetDeviceFactoryDictionary(filterObj.ToString());
|
||||
if (types == null)
|
||||
{
|
||||
Debug.Console(Verbose, "Get device type from dictionary failed");
|
||||
|
||||
context.Response.StatusCode = 400;
|
||||
context.Response.StatusDescription = "Bad Request";
|
||||
context.Response.End();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var js = JsonConvert.SerializeObject(types, Formatting.Indented, new JsonSerializerSettings
|
||||
{
|
||||
ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
|
||||
NullValueHandling = NullValueHandling.Ignore,
|
||||
MissingMemberHandling = MissingMemberHandling.Ignore,
|
||||
DefaultValueHandling = DefaultValueHandling.Ignore,
|
||||
TypeNameHandling = TypeNameHandling.None
|
||||
});
|
||||
Debug.Console(Verbose, "[{0}] HandleGet: \x0d\x0a{1}", Key.ToLower(), js);
|
||||
|
||||
context.Response.StatusCode = 200;
|
||||
context.Response.StatusDescription = "OK";
|
||||
context.Response.ContentType = "application/json";
|
||||
context.Response.ContentEncoding = System.Text.Encoding.UTF8;
|
||||
context.Response.Write(js, false);
|
||||
context.Response.End();
|
||||
}
|
||||
|
||||
@@ -1,10 +1,18 @@
|
||||
using Crestron.SimplSharp.WebScripting;
|
||||
using System.Linq;
|
||||
using Crestron.SimplSharp.WebScripting;
|
||||
using Newtonsoft.Json;
|
||||
using PepperDash.Core;
|
||||
using PepperDash.Core.Web.RequestHandlers;
|
||||
|
||||
namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
||||
{
|
||||
public class GetTypesRequestHandler : WebApiBaseRequestHandler
|
||||
{
|
||||
private const string Key = "GetTypesRequestHandler";
|
||||
private const uint Trace = 0;
|
||||
private const uint Info = 0;
|
||||
private const uint Verbose = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Handles CONNECT method requests
|
||||
/// </summary>
|
||||
@@ -33,8 +41,37 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
||||
/// <param name="context"></param>
|
||||
protected override void HandleGet(HttpCwsContext context)
|
||||
{
|
||||
context.Response.StatusCode = 501;
|
||||
context.Response.StatusDescription = "Not Implemented";
|
||||
// TODO [ ] DeviceFactory.FactoryMethods dictionary is private and the method GetDeviceFactoryTypes has a return type void
|
||||
// added new public method to return the DeviceFactory.FactoryMethod dictionary
|
||||
var types = DeviceFactory.GetDeviceFactoryDictionary(null);
|
||||
if (types == null)
|
||||
{
|
||||
Debug.Console(Verbose, "Get device factory dictionary failed");
|
||||
|
||||
context.Response.StatusCode = 400;
|
||||
context.Response.StatusDescription = "Bad Request";
|
||||
context.Response.End();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
types.OrderBy(t => t.Key);
|
||||
|
||||
var js = JsonConvert.SerializeObject(types, Formatting.Indented, new JsonSerializerSettings
|
||||
{
|
||||
ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
|
||||
NullValueHandling = NullValueHandling.Ignore,
|
||||
MissingMemberHandling = MissingMemberHandling.Ignore,
|
||||
DefaultValueHandling = DefaultValueHandling.Ignore,
|
||||
TypeNameHandling = TypeNameHandling.None
|
||||
});
|
||||
//Debug.Console(Verbose, "[{0}] HandleGet: \x0d\x0a{1}", Key.ToLower(), js);
|
||||
|
||||
context.Response.StatusCode = 200;
|
||||
context.Response.StatusDescription = "OK";
|
||||
context.Response.ContentType = "application/json";
|
||||
context.Response.ContentEncoding = System.Text.Encoding.UTF8;
|
||||
context.Response.Write(js, false);
|
||||
context.Response.End();
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
using System.Text;
|
||||
using Crestron.SimplSharp.WebScripting;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using PepperDash.Core;
|
||||
using PepperDash.Core.Web.RequestHandlers;
|
||||
|
||||
|
||||
@@ -1,10 +1,17 @@
|
||||
using Crestron.SimplSharp.WebScripting;
|
||||
using Newtonsoft.Json;
|
||||
using PepperDash.Core.Web.RequestHandlers;
|
||||
using PepperDash.Essentials.Core.Config;
|
||||
|
||||
namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
||||
{
|
||||
public class ShowConfigRequestHandler : WebApiBaseRequestHandler
|
||||
{
|
||||
private const string Key = "ShowConfigRequestHandler";
|
||||
private const uint Trace = 0;
|
||||
private const uint Info = 0;
|
||||
private const uint Verbose = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Handles CONNECT method requests
|
||||
/// </summary>
|
||||
@@ -33,8 +40,13 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
||||
/// <param name="context"></param>
|
||||
protected override void HandleGet(HttpCwsContext context)
|
||||
{
|
||||
context.Response.StatusCode = 501;
|
||||
context.Response.StatusDescription = "Not Implemented";
|
||||
var config = JsonConvert.SerializeObject(ConfigReader.ConfigObject, Formatting.Indented);
|
||||
|
||||
context.Response.StatusCode = 200;
|
||||
context.Response.StatusDescription = "OK";
|
||||
context.Response.ContentType = "application/json";
|
||||
context.Response.ContentEncoding = System.Text.Encoding.UTF8;
|
||||
context.Response.Write(config, false);
|
||||
context.Response.End();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user