Attempting to resolve exception in CotijaSystemController when SystemMonitor tries to notify AppServer of program start before WSClient is *really* connected.

This commit is contained in:
Neil Dorin
2019-03-15 14:42:47 -06:00
parent 6235b44d89
commit e3a3a2cd2d
3 changed files with 12 additions and 3 deletions

View File

@@ -458,10 +458,11 @@ namespace PepperDash.Essentials
var result = WSClient.Send(messageBytes, (uint)messageBytes.Length, WebSocketClient.WEBSOCKET_PACKET_TYPES.LWS_WS_OPCODE_07__TEXT_FRAME); var result = WSClient.Send(messageBytes, (uint)messageBytes.Length, WebSocketClient.WEBSOCKET_PACKET_TYPES.LWS_WS_OPCODE_07__TEXT_FRAME);
if (result != WebSocketClient.WEBSOCKET_RESULT_CODES.WEBSOCKET_CLIENT_SUCCESS) if (result != WebSocketClient.WEBSOCKET_RESULT_CODES.WEBSOCKET_CLIENT_SUCCESS)
{ {
#warning It seems like this debug statement is throwing an exception when called
Debug.Console(1, this, "Socket send result error: {0}", result); Debug.Console(1, this, "Socket send result error: {0}", result);
} }
} }
else if (!WSClient.Connected) else if (WSClient == null)
{ {
Debug.Console(1, this, "Cannot send. Not connected {0}"); Debug.Console(1, this, "Cannot send. Not connected {0}");
} }

View File

@@ -32,16 +32,24 @@ namespace PepperDash.Essentials.AppServer.Messengers
appServerController.AddAction(MessagePath + "/updateConfig", new Action<string>(s => GetConfigFile(s))); appServerController.AddAction(MessagePath + "/updateConfig", new Action<string>(s => GetConfigFile(s)));
} }
/// <summary>
/// Generates or passes the URL to make the request to GET the config from a server
/// </summary>
/// <param name="url"></param>
void GetConfigFile(string url) void GetConfigFile(string url)
{ {
try try
{ {
// Attempt to parse the URL
var parser = new Crestron.SimplSharp.Net.Http.UrlParser(url); var parser = new Crestron.SimplSharp.Net.Http.UrlParser(url);
Debug.Console(0, Debug.ErrorLogLevel.Notice, "Successfully parsed URL from AppServer message: {0}", parser.Url); Debug.Console(0, Debug.ErrorLogLevel.Notice, "Successfully parsed URL from AppServer message: {0}", parser.Url);
} }
catch catch (Exception e)
{ {
// If unable to parse the URL, generate it from config data
Debug.Console(2, "Error parsing URL: {0}", e);
Debug.Console(0, Debug.ErrorLogLevel.Notice, "Unable to parse URL from AppServer message. Generating URL from config data"); Debug.Console(0, Debug.ErrorLogLevel.Notice, "Unable to parse URL from AppServer message. Generating URL from config data");
url = string.Format("http://{0}/api/system/{1}/config", AppServerController.Config.ServerUrl, AppServerController.SystemUuid); url = string.Format("http://{0}/api/system/{1}/config", AppServerController.Config.ServerUrl, AppServerController.SystemUuid);
} }