Pull request and build

This commit is contained in:
Heath Volmer
2018-02-22 15:10:33 -07:00
3 changed files with 23 additions and 12 deletions

View File

@@ -193,13 +193,9 @@ namespace PepperDash.Core
void CrestronEnvironment_ProgramStatusEventHandler(eProgramStatusEventType programEventType) void CrestronEnvironment_ProgramStatusEventHandler(eProgramStatusEventType programEventType)
{ {
if (programEventType == eProgramStatusEventType.Stopping) if (programEventType == eProgramStatusEventType.Stopping)
{
if (Client != null)
{ {
Debug.Console(1, this, "Program stopping. Closing connection"); Debug.Console(1, this, "Program stopping. Closing connection");
Client.DisconnectFromServer(); DisconnectClient();
Client.Dispose();
}
} }
} }
@@ -218,7 +214,7 @@ namespace PepperDash.Core
public void Connect() public void Connect()
{ {
if (IsConnected) if (IsConnected)
return; DisconnectClient();
if (string.IsNullOrEmpty(Hostname)) if (string.IsNullOrEmpty(Hostname))
{ {
@@ -233,8 +229,11 @@ namespace PepperDash.Core
} }
} }
if (Client == null)
{
Client = new TCPClient(Hostname, Port, BufferSize); Client = new TCPClient(Hostname, Port, BufferSize);
Client.SocketStatusChange += Client_SocketStatusChange; Client.SocketStatusChange += Client_SocketStatusChange;
}
Client.ConnectToServerAsync(null); Client.ConnectToServerAsync(null);
DisconnectCalledByUser = false; DisconnectCalledByUser = false;
@@ -243,7 +242,18 @@ namespace PepperDash.Core
public void Disconnect() public void Disconnect()
{ {
DisconnectCalledByUser = true; DisconnectCalledByUser = true;
DisconnectClient();
}
public void DisconnectClient()
{
if (Client != null)
{
Debug.Console(1, this, "Disconnecting client");
//Client.SocketStatusChange -= Client_SocketStatusChange;
if(IsConnected)
Client.DisconnectFromServer(); Client.DisconnectFromServer();
}
} }
void ConnectToServerCallback(TCPClient c) void ConnectToServerCallback(TCPClient c)
@@ -254,7 +264,8 @@ namespace PepperDash.Core
void WaitAndTryReconnect() void WaitAndTryReconnect()
{ {
Client.DisconnectFromServer(); DisconnectClient();
Debug.Console(2, "Attempting reconnect, status={0}", Client.ClientStatus); Debug.Console(2, "Attempting reconnect, status={0}", Client.ClientStatus);
if(!DisconnectCalledByUser) if(!DisconnectCalledByUser)
RetryTimer = new CTimer(o => { Client.ConnectToServerAsync(ConnectToServerCallback); }, AutoReconnectIntervalMs); RetryTimer = new CTimer(o => { Client.ConnectToServerAsync(ConnectToServerCallback); }, AutoReconnectIntervalMs);