fix: merge errors that weren't caught on edit

This commit is contained in:
Andrew Welker
2025-03-03 17:15:55 -06:00
parent 3458897057
commit b7fcb94098

View File

@@ -3,6 +3,7 @@ using System.Text;
using System.Threading; using System.Threading;
using Crestron.SimplSharp; using Crestron.SimplSharp;
using Crestron.SimplSharp.CrestronSockets; using Crestron.SimplSharp.CrestronSockets;
using Org.BouncyCastle.Utilities;
using PepperDash.Core.Logging; using PepperDash.Core.Logging;
using Renci.SshNet; using Renci.SshNet;
using Renci.SshNet.Common; using Renci.SshNet.Common;
@@ -364,40 +365,12 @@ namespace PepperDash.Core
Client.Dispose(); Client.Dispose();
Client = null; Client = null;
ClientStatus = status; ClientStatus = status;
Debug.Console(1, this, "Disconnected"); this.LogDebug("Disconnected");
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
Debug.Console(0, this, Debug.ErrorLogLevel.Notice, "Exception in Kill Client:{0}", ex); this.LogException(ex,"Exception in Kill Client");
}
}
/// <summary>
/// Anything to do with reestablishing connection on failures
/// </summary>
void HandleConnectionFailure()
{
KillClient(SocketStatus.SOCKET_STATUS_CONNECT_FAILED);
Debug.Console(1, this, "Client nulled due to connection failure. AutoReconnect: {0}, ConnectEnabled: {1}", AutoReconnect, ConnectEnabled);
if (AutoReconnect && ConnectEnabled)
{
Debug.Console(1, this, "Checking autoreconnect: {0}, {1}ms", AutoReconnect, AutoReconnectIntervalMs);
if (ReconnectTimer == null)
{
ReconnectTimer = new CTimer(o =>
{
Connect();
}, AutoReconnectIntervalMs);
Debug.Console(1, this, "Attempting connection in {0} seconds",
(float) (AutoReconnectIntervalMs/1000));
}
else
{
Debug.Console(1, this, "{0} second reconnect cycle running",
(float) (AutoReconnectIntervalMs/1000));
}
} }
} }
@@ -519,9 +492,8 @@ namespace PepperDash.Core
if (Client != null && TheStream != null && IsConnected) if (Client != null && TheStream != null && IsConnected)
{ {
if (StreamDebugging.TxStreamDebuggingIsEnabled) if (StreamDebugging.TxStreamDebuggingIsEnabled)
Debug.Console(0, this.LogInformation(
this, "Sending {length} characters of text: '{text}'",
"Sending {0} characters of text: '{1}'",
text.Length, text.Length,
ComTextHelper.GetDebugText(text)); ComTextHelper.GetDebugText(text));
@@ -530,13 +502,12 @@ namespace PepperDash.Core
} }
else else
{ {
Debug.Console(1, this, "Client is null or disconnected. Cannot Send Text"); this.LogDebug("Client is null or disconnected. Cannot Send Text");
} }
} }
catch (ObjectDisposedException ex) catch (ObjectDisposedException ex)
{ {
Debug.Console(0, this, Debug.ErrorLogLevel.Notice, "Exception: {0}", ex.Message); this.LogException(ex, "ObjectDisposedException sending {message}", text);
Debug.Console(1, this, Debug.ErrorLogLevel.Notice, "Stack Trace: {0}", ex.StackTrace);
KillClient(SocketStatus.SOCKET_STATUS_CONNECT_FAILED); KillClient(SocketStatus.SOCKET_STATUS_CONNECT_FAILED);
ReconnectTimer.Reset(); ReconnectTimer.Reset();
@@ -579,20 +550,9 @@ namespace PepperDash.Core
{ {
this.LogException(ex, "Exception sending {message}", ComTextHelper.GetEscapedText(bytes)); this.LogException(ex, "Exception sending {message}", ComTextHelper.GetEscapedText(bytes));
} }
KillClient(SocketStatus.SOCKET_STATUS_CONNECT_FAILED);
ReconnectTimer.Reset();
} }
catch (Exception ex)
{
Debug.Console(0, this, Debug.ErrorLogLevel.Notice, "Exception: {0}", ex.Message);
Debug.Console(1, this, Debug.ErrorLogLevel.Notice, "Stack Trace: {0}", ex.StackTrace);
Debug.Console(1, this, Debug.ErrorLogLevel.Error, "Stream write failed");
}
}
#endregion #endregion
} }
//***************************************************************************************************** //*****************************************************************************************************