mirror of
https://github.com/PepperDash/PepperDashCore.git
synced 2026-02-16 13:14:49 +00:00
fix: moved instantiation of server to resolve null ref exception
This commit is contained in:
@@ -46,7 +46,7 @@ namespace PepperDash.Core.Web
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public WebApiServer()
|
public WebApiServer()
|
||||||
: this(SplusKey, DefaultName, null)
|
: this(SplusKey, DefaultName, null)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -71,6 +71,8 @@ namespace PepperDash.Core.Web
|
|||||||
Name = string.IsNullOrEmpty(name) ? DefaultName : name;
|
Name = string.IsNullOrEmpty(name) ? DefaultName : name;
|
||||||
BasePath = string.IsNullOrEmpty(basePath) ? DefaultBasePath : basePath;
|
BasePath = string.IsNullOrEmpty(basePath) ? DefaultBasePath : basePath;
|
||||||
|
|
||||||
|
if (_server == null) _server = new HttpCwsServer(BasePath);
|
||||||
|
|
||||||
CrestronEnvironment.ProgramStatusEventHandler += CrestronEnvironment_ProgramStatusEventHandler;
|
CrestronEnvironment.ProgramStatusEventHandler += CrestronEnvironment_ProgramStatusEventHandler;
|
||||||
CrestronEnvironment.EthernetEventHandler += CrestronEnvironment_EthernetEventHandler;
|
CrestronEnvironment.EthernetEventHandler += CrestronEnvironment_EthernetEventHandler;
|
||||||
}
|
}
|
||||||
@@ -112,7 +114,7 @@ namespace PepperDash.Core.Web
|
|||||||
public void Initialize(string key, string basePath)
|
public void Initialize(string key, string basePath)
|
||||||
{
|
{
|
||||||
Key = key;
|
Key = key;
|
||||||
BasePath = string.IsNullOrEmpty(basePath) ? DefaultBasePath : basePath;
|
BasePath = string.IsNullOrEmpty(basePath) ? DefaultBasePath : basePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -127,7 +129,7 @@ namespace PepperDash.Core.Web
|
|||||||
}
|
}
|
||||||
|
|
||||||
_server.Routes.Add(route);
|
_server.Routes.Add(route);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -154,18 +156,19 @@ namespace PepperDash.Core.Web
|
|||||||
{
|
{
|
||||||
_serverLock.Enter();
|
_serverLock.Enter();
|
||||||
|
|
||||||
if (_server != null)
|
if (_server == null)
|
||||||
|
{
|
||||||
|
Debug.Console(DebugInfo, this, "Server is null, unable to start");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (IsRegistered)
|
||||||
{
|
{
|
||||||
Debug.Console(DebugInfo, this, "Server has already been started");
|
Debug.Console(DebugInfo, this, "Server has already been started");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Debug.Console(DebugInfo, this, "Starting server");
|
Debug.Console(DebugInfo, this, "Starting server");
|
||||||
|
|
||||||
_server = new HttpCwsServer(BasePath)
|
|
||||||
{
|
|
||||||
HttpRequestHandler = new DefaultRequestRequestHandler()
|
|
||||||
};
|
|
||||||
|
|
||||||
IsRegistered = _server.Register();
|
IsRegistered = _server.Register();
|
||||||
}
|
}
|
||||||
@@ -193,13 +196,13 @@ namespace PepperDash.Core.Web
|
|||||||
|
|
||||||
if (_server == null)
|
if (_server == null)
|
||||||
{
|
{
|
||||||
Debug.Console(DebugInfo, this, "Server has already been stopped");
|
Debug.Console(DebugInfo, this, "Server is null or has already been stopped");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
IsRegistered = _server.Unregister() == false;
|
IsRegistered = _server.Unregister() == false;
|
||||||
_server.Dispose();
|
_server.Dispose();
|
||||||
_server = null;
|
_server = null;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@@ -212,7 +215,7 @@ namespace PepperDash.Core.Web
|
|||||||
{
|
{
|
||||||
_serverLock.Leave();
|
_serverLock.Leave();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Received request handler
|
/// Received request handler
|
||||||
@@ -255,6 +258,6 @@ UserHostName: {9}",
|
|||||||
if (ex.InnerException != null)
|
if (ex.InnerException != null)
|
||||||
Debug.Console(DebugVerbose, this, "ReceivedRequestEventHandler Exception InnerException: {0}", ex.InnerException);
|
Debug.Console(DebugVerbose, this, "ReceivedRequestEventHandler Exception InnerException: {0}", ex.InnerException);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user