diff --git a/src/PepperDash.Core/Web/WebApiServer.cs b/src/PepperDash.Core/Web/WebApiServer.cs
index cd113c15..62e577ca 100644
--- a/src/PepperDash.Core/Web/WebApiServer.cs
+++ b/src/PepperDash.Core/Web/WebApiServer.cs
@@ -5,6 +5,7 @@ using Crestron.SimplSharp;
using Crestron.SimplSharp.WebScripting;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
+using PepperDash.Core.Logging;
using PepperDash.Core.Web.RequestHandlers;
namespace PepperDash.Core.Web
@@ -25,29 +26,26 @@ namespace PepperDash.Core.Web
private readonly CCriticalSection _serverLock = new CCriticalSection();
private HttpCwsServer _server;
- ///
- /// Gets or sets the Key
- ///
+ ///
+ /// Gets or sets the Key
+ ///
public string Key { get; private set; }
- ///
- /// Gets or sets the Name
- ///
+ ///
+ /// Gets or sets the Name
+ ///
public string Name { get; private set; }
- ///
- /// Gets or sets the BasePath
- ///
+ ///
+ /// Gets or sets the BasePath
+ ///
public string BasePath { get; private set; }
- ///
- /// Gets or sets the IsRegistered
- ///
+ ///
+ /// Gets or sets the IsRegistered
+ ///
public bool IsRegistered { get; private set; }
- ///
- /// Http request handler
- ///
//public IHttpCwsHandler HttpRequestHandler
//{
// get { return _server.HttpRequestHandler; }
@@ -58,9 +56,6 @@ namespace PepperDash.Core.Web
// }
//}
- ///
- /// Received request event handler
- ///
//public event EventHandler ReceivedRequestEvent
//{
// add { _server.ReceivedRequestEvent += new HttpCwsRequestEventHandler(value); }
@@ -91,7 +86,7 @@ namespace PepperDash.Core.Web
///
///
///
- public WebApiServer(string key, string name, string basePath)
+ public WebApiServer(string key, string name, string basePath)
{
Key = key;
Name = string.IsNullOrEmpty(name) ? DefaultName : name;
@@ -116,7 +111,7 @@ namespace PepperDash.Core.Web
{
if (programEventType != eProgramStatusEventType.Stopping) return;
- Debug.Console(DebugInfo, this, "Program stopping. stopping server");
+ this.LogInformation("Program stopping. stopping server");
Stop();
}
@@ -130,18 +125,18 @@ namespace PepperDash.Core.Web
// Re-enable the server if the link comes back up and the status should be connected
if (ethernetEventArgs.EthernetEventType == eEthernetEventType.LinkUp && IsRegistered)
{
- Debug.Console(DebugInfo, this, "Ethernet link up. Server is alreedy registered.");
+ this.LogInformation("Ethernet link up. Server is alreedy registered.");
return;
}
- Debug.Console(DebugInfo, this, "Ethernet link up. Starting server");
+ this.LogInformation("Ethernet link up. Starting server");
Start();
}
- ///
- /// Initialize method
- ///
+ ///
+ /// Initialize method
+ ///
public void Initialize(string key, string basePath)
{
Key = key;
@@ -155,7 +150,7 @@ namespace PepperDash.Core.Web
{
if (route == null)
{
- Debug.Console(DebugInfo, this, "Failed to add route, route parameter is null");
+ this.LogWarning("Failed to add route, route parameter is null");
return;
}
@@ -167,23 +162,20 @@ namespace PepperDash.Core.Web
/// Removes a route from CWS
///
///
- ///
- /// RemoveRoute method
- ///
public void RemoveRoute(HttpCwsRoute route)
{
if (route == null)
{
- Debug.Console(DebugInfo, this, "Failed to remote route, orute parameter is null");
+ this.LogWarning("Failed to remove route, route parameter is null");
return;
}
_server.Routes.Remove(route);
}
- ///
- /// GetRouteCollection method
- ///
+ ///
+ /// GetRouteCollection method
+ ///
public HttpCwsRouteCollection GetRouteCollection()
{
return _server.Routes;
@@ -200,26 +192,24 @@ namespace PepperDash.Core.Web
if (_server == null)
{
- Debug.Console(DebugInfo, this, "Server is null, unable to start");
+ this.LogWarning("Server is null, unable to start");
return;
}
if (IsRegistered)
{
- Debug.Console(DebugInfo, this, "Server has already been started");
+ this.LogWarning("Server has already been started");
return;
}
IsRegistered = _server.Register();
- Debug.Console(DebugInfo, this, "Starting server, registration {0}", IsRegistered ? "was successful" : "failed");
+ this.LogInformation("Starting server, registration {registrationResult}", IsRegistered ? "was successful" : "failed");
}
catch (Exception ex)
{
- Debug.Console(DebugInfo, this, "Start Exception Message: {0}", ex.Message);
- Debug.Console(DebugVerbose, this, "Start Exception StackTrace: {0}", ex.StackTrace);
- if (ex.InnerException != null)
- Debug.Console(DebugVerbose, this, "Start Exception InnerException: {0}", ex.InnerException);
+ this.LogError("Start Exception Message: {message}", ex.Message);
+ this.LogDebug(ex, "Start Exception StackTrace");
}
finally
{
@@ -227,9 +217,9 @@ namespace PepperDash.Core.Web
}
}
- ///
- /// Stop method
- ///
+ ///
+ /// Stop method
+ ///
public void Stop()
{
try
@@ -238,23 +228,21 @@ namespace PepperDash.Core.Web
if (_server == null)
{
- Debug.Console(DebugInfo, this, "Server is null or has already been stopped");
+ this.LogWarning("Server is null or has already been stopped");
return;
}
IsRegistered = _server.Unregister() == false;
- Debug.Console(DebugInfo, this, "Stopping server, unregistration {0}", IsRegistered ? "failed" : "was successful");
+ this.LogInformation("Stopping server, unregistration {unregistrationResult}", IsRegistered ? "failed" : "was successful");
_server.Dispose();
_server = null;
}
catch (Exception ex)
{
- Debug.Console(DebugInfo, this, "Server Stop Exception Message: {0}", ex.Message);
- Debug.Console(DebugVerbose, this, "Server Stop Exception StackTrace: {0}", ex.StackTrace);
- if (ex.InnerException != null)
- Debug.Console(DebugVerbose, this, "Server Stop Exception InnerException: {0}", ex.InnerException);
+ this.LogError("Server Stop Exception Message: {message}", ex.Message);
+ this.LogDebug(ex, "Server Stop Exception StackTrace");
}
finally
{
@@ -275,14 +263,12 @@ namespace PepperDash.Core.Web
try
{
var j = JsonConvert.SerializeObject(args.Context, Formatting.Indented);
- Debug.Console(DebugVerbose, this, "RecieveRequestEventHandler Context:\x0d\x0a{0}", j);
+ this.LogVerbose("RecieveRequestEventHandler Context:\x0d\x0a{0}", j);
}
catch (Exception ex)
{
- Debug.Console(DebugInfo, this, "ReceivedRequestEventHandler Exception Message: {0}", ex.Message);
- Debug.Console(DebugVerbose, this, "ReceivedRequestEventHandler Exception StackTrace: {0}", ex.StackTrace);
- if (ex.InnerException != null)
- Debug.Console(DebugVerbose, this, "ReceivedRequestEventHandler Exception InnerException: {0}", ex.InnerException);
+ this.LogError("ReceivedRequestEventHandler Exception Message: {message}", ex.Message);
+ this.LogDebug(ex, "ReceivedRequestEventHandler Exception StackTrace: {stackTrace}", ex.StackTrace);
}
}
}