mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-02-01 13:55:05 +00:00
fix: resolved issue with GetTypes request handlers causing a 500 error response; updated debug constants to default levels
This commit is contained in:
@@ -212,9 +212,9 @@ namespace PepperDash.Essentials.Core
|
||||
/// <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;
|
||||
return string.IsNullOrEmpty(filter)
|
||||
? FactoryMethods
|
||||
: FactoryMethods.Where(k => k.Key.Contains(filter)).ToDictionary(k => k.Key, k => k.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,8 +11,8 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
||||
{
|
||||
private const string Key = "AppDebugRequestHandler";
|
||||
private const uint Trace = 0;
|
||||
private const uint Info = 0;
|
||||
private const uint Verbose = 0;
|
||||
private const uint Info = 1;
|
||||
private const uint Verbose = 2;
|
||||
|
||||
/// <summary>
|
||||
/// Handles CONNECT method requests
|
||||
|
||||
@@ -16,8 +16,8 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
||||
/// <param name="context"></param>
|
||||
protected override void HandleConnect(HttpCwsContext context)
|
||||
{
|
||||
context.Response.StatusCode = 501;
|
||||
context.Response.StatusDescription = "Not Implemented";
|
||||
context.Response.StatusCode = 418;
|
||||
context.Response.StatusDescription = "I'm a teapot";
|
||||
context.Response.End();
|
||||
}
|
||||
|
||||
@@ -27,8 +27,8 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
||||
/// <param name="context"></param>
|
||||
protected override void HandleDelete(HttpCwsContext context)
|
||||
{
|
||||
context.Response.StatusCode = 501;
|
||||
context.Response.StatusDescription = "Not Implemented";
|
||||
context.Response.StatusCode = 418;
|
||||
context.Response.StatusDescription = "I'm a teapot";
|
||||
context.Response.End();
|
||||
}
|
||||
|
||||
@@ -38,8 +38,8 @@ 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";
|
||||
context.Response.StatusCode = 418;
|
||||
context.Response.StatusDescription = "I'm a teapot";
|
||||
context.Response.End();
|
||||
}
|
||||
|
||||
@@ -49,8 +49,8 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
||||
/// <param name="context"></param>
|
||||
protected override void HandleHead(HttpCwsContext context)
|
||||
{
|
||||
context.Response.StatusCode = 501;
|
||||
context.Response.StatusDescription = "Not Implemented";
|
||||
context.Response.StatusCode = 418;
|
||||
context.Response.StatusDescription = "I'm a teapot";
|
||||
context.Response.End();
|
||||
}
|
||||
|
||||
@@ -60,8 +60,8 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
||||
/// <param name="context"></param>
|
||||
protected override void HandleOptions(HttpCwsContext context)
|
||||
{
|
||||
context.Response.StatusCode = 501;
|
||||
context.Response.StatusDescription = "Not Implemented";
|
||||
context.Response.StatusCode = 418;
|
||||
context.Response.StatusDescription = "I'm a teapot";
|
||||
context.Response.End();
|
||||
}
|
||||
|
||||
@@ -71,8 +71,8 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
||||
/// <param name="context"></param>
|
||||
protected override void HandlePatch(HttpCwsContext context)
|
||||
{
|
||||
context.Response.StatusCode = 501;
|
||||
context.Response.StatusDescription = "Not Implemented";
|
||||
context.Response.StatusCode = 418;
|
||||
context.Response.StatusDescription = "I'm a teapot";
|
||||
context.Response.End();
|
||||
}
|
||||
|
||||
@@ -82,8 +82,8 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
||||
/// <param name="context"></param>
|
||||
protected override void HandlePost(HttpCwsContext context)
|
||||
{
|
||||
context.Response.StatusCode = 501;
|
||||
context.Response.StatusDescription = "Not Implemented";
|
||||
context.Response.StatusCode = 418;
|
||||
context.Response.StatusDescription = "I'm a teapot";
|
||||
context.Response.End();
|
||||
}
|
||||
|
||||
@@ -93,8 +93,8 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
||||
/// <param name="context"></param>
|
||||
protected override void HandlePut(HttpCwsContext context)
|
||||
{
|
||||
context.Response.StatusCode = 501;
|
||||
context.Response.StatusDescription = "Not Implemented";
|
||||
context.Response.StatusCode = 418;
|
||||
context.Response.StatusDescription = "I'm a teapot";
|
||||
context.Response.End();
|
||||
}
|
||||
|
||||
@@ -104,8 +104,8 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
||||
/// <param name="context"></param>
|
||||
protected override void HandleTrace(HttpCwsContext context)
|
||||
{
|
||||
context.Response.StatusCode = 501;
|
||||
context.Response.StatusDescription = "Not Implemented";
|
||||
context.Response.StatusCode = 418;
|
||||
context.Response.StatusDescription = "I'm a teapot";
|
||||
context.Response.End();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,8 +10,8 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
||||
{
|
||||
private const string Key = "DevJsonRequestHandler";
|
||||
private const uint Trace = 0;
|
||||
private const uint Info = 0;
|
||||
private const uint Verbose = 0;
|
||||
private const uint Info = 1;
|
||||
private const uint Verbose = 2;
|
||||
|
||||
/// <summary>
|
||||
/// Handles CONNECT method requests
|
||||
|
||||
@@ -10,8 +10,8 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
||||
{
|
||||
private const string Key = "DevListRequestHandler";
|
||||
private const uint Trace = 0;
|
||||
private const uint Info = 0;
|
||||
private const uint Verbose = 0;
|
||||
private const uint Info = 1;
|
||||
private const uint Verbose = 2;
|
||||
|
||||
/// <summary>
|
||||
/// Handles CONNECT method requests
|
||||
|
||||
@@ -11,8 +11,8 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
||||
{
|
||||
private const string Key = "DevPropsRequestHandler";
|
||||
private const uint Trace = 0;
|
||||
private const uint Info = 0;
|
||||
private const uint Verbose = 0;
|
||||
private const uint Info = 1;
|
||||
private const uint Verbose = 2;
|
||||
|
||||
/// <summary>
|
||||
/// Handles CONNECT method requests
|
||||
|
||||
@@ -5,6 +5,11 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
||||
{
|
||||
public class DisableAllStreamDebugRequestHandler : WebApiBaseRequestHandler
|
||||
{
|
||||
private const string Key = "DisableAllStreamDebugRequestHandler";
|
||||
private const uint Trace = 0;
|
||||
private const uint Info = 1;
|
||||
private const uint Verbose = 2;
|
||||
|
||||
/// <summary>
|
||||
/// Handles CONNECT method requests
|
||||
/// </summary>
|
||||
|
||||
@@ -10,8 +10,8 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
||||
{
|
||||
private const string Key = "GetJoinMapForBridgeKeyRequestHandler";
|
||||
private const uint Trace = 0;
|
||||
private const uint Info = 0;
|
||||
private const uint Verbose = 0;
|
||||
private const uint Info = 1;
|
||||
private const uint Verbose = 2;
|
||||
|
||||
/// <summary>
|
||||
/// Handles CONNECT method requests
|
||||
|
||||
@@ -11,8 +11,8 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
||||
{
|
||||
private const string Key = "GetJoinMapForDeviceKeyRequestHandler";
|
||||
private const uint Trace = 0;
|
||||
private const uint Info = 0;
|
||||
private const uint Verbose = 0;
|
||||
private const uint Info = 1;
|
||||
private const uint Verbose = 2;
|
||||
|
||||
/// <summary>
|
||||
/// Handles CONNECT method requests
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
using Crestron.SimplSharp.WebScripting;
|
||||
using System;
|
||||
using System.Linq;
|
||||
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
|
||||
{
|
||||
@@ -10,8 +11,8 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
||||
{
|
||||
private const string Key = "GetTypesByFilterRequestHandler";
|
||||
private const uint Trace = 0;
|
||||
private const uint Info = 0;
|
||||
private const uint Verbose = 0;
|
||||
private const uint Info = 1;
|
||||
private const uint Verbose = 2;
|
||||
|
||||
/// <summary>
|
||||
/// Handles CONNECT method requests
|
||||
@@ -51,10 +52,8 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
var routeDataJson = JsonConvert.SerializeObject(routeData, Formatting.Indented);
|
||||
Debug.Console(Verbose, "routeData:\n{0}", routeDataJson);
|
||||
|
||||
Debug.Console(Verbose, "[{0}] routeData:\n{1}", Key.ToLower(), routeDataJson);
|
||||
|
||||
object filterObj;
|
||||
if (!routeData.Values.TryGetValue("filter", out filterObj))
|
||||
@@ -68,11 +67,15 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
||||
return;
|
||||
}
|
||||
|
||||
var types = DeviceFactory.GetDeviceFactoryDictionary(filterObj.ToString());
|
||||
var types = DeviceFactory.GetDeviceFactoryDictionary(filterObj.ToString()).Select(type => new
|
||||
{
|
||||
Type = type.Key,
|
||||
Description = type.Value.Description,
|
||||
CType = type.Value.CType == null ? "---" : type.Value.CType.ToString()
|
||||
}).Cast<object>().ToList();
|
||||
|
||||
if (types == null)
|
||||
{
|
||||
Debug.Console(Verbose, "Get device type from dictionary failed");
|
||||
|
||||
context.Response.StatusCode = 400;
|
||||
context.Response.StatusDescription = "Bad Request";
|
||||
context.Response.End();
|
||||
@@ -80,22 +83,28 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
||||
return;
|
||||
}
|
||||
|
||||
var js = JsonConvert.SerializeObject(types, Formatting.Indented, new JsonSerializerSettings
|
||||
try
|
||||
{
|
||||
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);
|
||||
var js = JsonConvert.SerializeObject(types, Formatting.Indented);
|
||||
//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();
|
||||
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();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.Console(Info, "[{0}] HandleGet Exception Message: {1}", Key.ToLower(), ex.Message);
|
||||
Debug.Console(Verbose, "[{0}] HandleGet Exception StackTrace: {1}", Key.ToLower(), ex.StackTrace);
|
||||
if (ex.InnerException != null) Debug.Console(Verbose, "[{0}] HandleGet Exception InnerException: {1}", Key.ToLower(), ex.InnerException);
|
||||
|
||||
context.Response.StatusCode = 500;
|
||||
context.Response.StatusDescription = "Internal Server Error";
|
||||
context.Response.End();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using System.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Crestron.SimplSharp.WebScripting;
|
||||
using Newtonsoft.Json;
|
||||
using PepperDash.Core;
|
||||
@@ -10,8 +12,8 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
||||
{
|
||||
private const string Key = "GetTypesRequestHandler";
|
||||
private const uint Trace = 0;
|
||||
private const uint Info = 0;
|
||||
private const uint Verbose = 0;
|
||||
private const uint Info = 1;
|
||||
private const uint Verbose = 2;
|
||||
|
||||
/// <summary>
|
||||
/// Handles CONNECT method requests
|
||||
@@ -41,13 +43,9 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
||||
/// <param name="context"></param>
|
||||
protected override void HandleGet(HttpCwsContext context)
|
||||
{
|
||||
// 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)
|
||||
var routeData = context.Request.RouteData;
|
||||
if (routeData == null)
|
||||
{
|
||||
Debug.Console(Verbose, "Get device factory dictionary failed");
|
||||
|
||||
context.Response.StatusCode = 400;
|
||||
context.Response.StatusDescription = "Bad Request";
|
||||
context.Response.End();
|
||||
@@ -55,24 +53,47 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
||||
return;
|
||||
}
|
||||
|
||||
types.OrderBy(t => t.Key);
|
||||
var routeDataJson = JsonConvert.SerializeObject(routeData, Formatting.Indented);
|
||||
Debug.Console(Verbose, "[{0}] routeData:\n{1}", Key.ToLower(), routeDataJson);
|
||||
|
||||
var js = JsonConvert.SerializeObject(types, Formatting.Indented, new JsonSerializerSettings
|
||||
var types = DeviceFactory.GetDeviceFactoryDictionary(string.Empty).Select(type => new
|
||||
{
|
||||
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);
|
||||
Type = type.Key,
|
||||
Description = type.Value.Description,
|
||||
CType = type.Value.CType == null ? "---" : type.Value.CType.ToString()
|
||||
}).Cast<object>().ToList();
|
||||
|
||||
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();
|
||||
if (types == null)
|
||||
{
|
||||
context.Response.StatusCode = 400;
|
||||
context.Response.StatusDescription = "Bad Request";
|
||||
context.Response.End();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var js = JsonConvert.SerializeObject(types, Formatting.Indented);
|
||||
//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();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.Console(Info, "[{0}] HandleGet Exception Message: {1}", Key.ToLower(), ex.Message);
|
||||
Debug.Console(Verbose, "[{0}] HandleGet Exception StackTrace: {1}", Key.ToLower(), ex.StackTrace);
|
||||
if (ex.InnerException != null) Debug.Console(Verbose, "[{0}] HandleGet Exception InnerException: {1}", Key.ToLower(), ex.InnerException);
|
||||
|
||||
context.Response.StatusCode = 500;
|
||||
context.Response.StatusDescription = "Internal Server Error";
|
||||
context.Response.End();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -9,8 +9,8 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
||||
{
|
||||
private const string Key = "ReportVersionsRequestHandler";
|
||||
private const uint Trace = 0;
|
||||
private const uint Info = 0;
|
||||
private const uint Verbose = 0;
|
||||
private const uint Info = 1;
|
||||
private const uint Verbose = 2;
|
||||
|
||||
/// <summary>
|
||||
/// Handles CONNECT method requests
|
||||
|
||||
@@ -11,8 +11,8 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
||||
{
|
||||
private const string Key = "SetDeviceStreamDebugRequestHandler";
|
||||
private const uint Trace = 0;
|
||||
private const uint Info = 0;
|
||||
private const uint Verbose = 0;
|
||||
private const uint Info = 1;
|
||||
private const uint Verbose = 2;
|
||||
|
||||
/// <summary>
|
||||
/// Handles CONNECT method requests
|
||||
|
||||
@@ -9,8 +9,8 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
||||
{
|
||||
private const string Key = "ShowConfigRequestHandler";
|
||||
private const uint Trace = 0;
|
||||
private const uint Info = 0;
|
||||
private const uint Verbose = 0;
|
||||
private const uint Info = 1;
|
||||
private const uint Verbose = 2;
|
||||
|
||||
/// <summary>
|
||||
/// Handles CONNECT method requests
|
||||
|
||||
Reference in New Issue
Block a user