diff --git a/Pepperdash Core/Pepperdash Core/Comm/GenericSshClient.cs b/Pepperdash Core/Pepperdash Core/Comm/GenericSshClient.cs
index e5e40d1..4fc6401 100644
--- a/Pepperdash Core/Pepperdash Core/Comm/GenericSshClient.cs
+++ b/Pepperdash Core/Pepperdash Core/Comm/GenericSshClient.cs
@@ -7,28 +7,9 @@ using Crestron.SimplSharp.Ssh.Common;
namespace PepperDash.Core
{
- public class ConnectionChangeEventArgs : EventArgs
- {
- public bool IsConnected { get; private set; }
-
- public ushort UIsConnected { get { return (ushort)(Client.IsConnected ? 1 : 0); } }
-
- public GenericSshClient Client { get; private set; }
- public ushort Status { get { return Client.UStatus; } }
-
- // S+ Constructor
- public ConnectionChangeEventArgs() { }
-
- public ConnectionChangeEventArgs(bool isConnected, GenericSshClient client)
- {
- IsConnected = isConnected;
- Client = client;
- }
- }
-
- //*****************************************************************************************************
- //*****************************************************************************************************
-
+ ///
+ ///
+ ///
public class GenericSshClient : Device, IBasicCommunication, IAutoReconnect
{
///
@@ -44,24 +25,39 @@ namespace PepperDash.Core
///
/// Event when the connection status changes.
///
- public event EventHandler ConnectionChange;
-
+ public event EventHandler ConnectionChange;
+ ///
+ /// Address of server
+ ///
public string Hostname { get; set; }
+
///
/// Port on server
///
public int Port { get; set; }
+
+ ///
+ /// Username for server
+ ///
public string Username { get; set; }
+
+ ///
+ /// And... Password for server. That was worth documenting!
+ ///
public string Password { get; set; }
+ ///
+ /// True when the server is connected - when status == 2.
+ ///
public bool IsConnected
{
// returns false if no client or not connected
get { return UStatus == 2; }
}
///
- /// Contains the familiar Simpl analog status values
+ /// Contains the familiar Simpl analog status values. This drives the ConnectionChange event
+ /// and IsConnected with be true when this == 2.
///
public ushort UStatus
{
@@ -101,6 +97,11 @@ namespace PepperDash.Core
ShellStream TheStream;
CTimer ReconnectTimer;
+ string PreviousHostname;
+ int PreviousPort;
+ string PreviousUsername;
+ string PreviousPassword;
+
///
/// Typical constructor.
///
@@ -143,7 +144,7 @@ namespace PepperDash.Core
{
if (Client != null)
{
- Debug.Console(2, this, "Program stopping. Closing connection");
+ Debug.Console(1, this, "Program stopping. Closing connection");
Client.Disconnect();
Client.Dispose();
}
@@ -176,26 +177,43 @@ namespace PepperDash.Core
return;
}
- //You can do it!
- UStatus = 1;
- //IsConnected = false;
-
// This handles both password and keyboard-interactive (like on OS-X, 'nixes)
KeyboardInteractiveAuthenticationMethod kauth = new KeyboardInteractiveAuthenticationMethod(Username);
kauth.AuthenticationPrompt += new EventHandler(kauth_AuthenticationPrompt);
PasswordAuthenticationMethod pauth = new PasswordAuthenticationMethod(Username, Password);
- ConnectionInfo connectionInfo = new ConnectionInfo(Hostname, Port, Username, pauth, kauth);
// always spin up new client in case parameters have changed
// **** MAY WANT TO CHANGE THIS BECAUSE OF SOCKET LEAKS ****
- if (Client != null)
+ //if (Client != null)
+ //{
+ // Client.Disconnect();
+ // Client = null;
+ //}
+
+ // Make a new client if we need it or things have changed
+ if (Client == null || PropertiesHaveChanged())
{
- Client.Disconnect();
- Client = null;
- }
- Client = new SshClient(connectionInfo);
-
- Client.ErrorOccurred += Client_ErrorOccurred;
+ if (Client != null)
+ {
+ Debug.Console(2, this, "Cleaning up disconnected client");
+ Client.ErrorOccurred -= Client_ErrorOccurred;
+ if(TheStream != null)
+ TheStream.DataReceived -= Stream_DataReceived;
+ TheStream = null;
+ }
+
+ Debug.Console(2, this, "Creating new SshClient");
+ ConnectionInfo connectionInfo = new ConnectionInfo(Hostname, Port, Username, pauth, kauth);
+ Client = new SshClient(connectionInfo);
+ Client.ErrorOccurred += Client_ErrorOccurred;
+ }
+ PreviousHostname = Hostname;
+ PreviousPassword = Password;
+ PreviousPort = Port;
+ PreviousUsername = Username;
+
+ //You can do it!
+ UStatus = 1;
try
{
Client.Connect();
@@ -207,7 +225,10 @@ namespace PepperDash.Core
TheStream.DataReceived += Stream_DataReceived;
Debug.Console(1, this, "Connected");
UStatus = 2;
- //IsConnected = true;
+ PreviousHostname = Hostname;
+ PreviousPassword = Password;
+ PreviousPort = Port;
+ PreviousUsername = Username;
}
return;
}
@@ -232,10 +253,9 @@ namespace PepperDash.Core
Debug.Console(0, this, "Unhandled exception on connect:\r({0})", e);
}
-
// Sucess will not make it this far
+ Client.Disconnect();
UStatus = 3;
- //IsConnected = false;
HandleConnectionFailure();
}
@@ -250,34 +270,34 @@ namespace PepperDash.Core
ReconnectTimer.Stop();
ReconnectTimer = null;
}
- DiscoAndCleanup();
+ if(TheStream != null)
+ TheStream.DataReceived -= Stream_DataReceived;
+ Client.Disconnect();
UStatus = 5;
- //IsConnected = false;
+ Debug.Console(1, this, "Disconnected");
}
///
///
///
- void DiscoAndCleanup()
- {
- if (Client != null)
- {
- Client.ErrorOccurred -= Client_ErrorOccurred;
- TheStream.DataReceived -= Stream_DataReceived;
- Debug.Console(2, this, "Cleaning up disconnected client");
- Client.Disconnect();
- Client.Dispose();
- Client = null;
- }
- }
+ //void DiscoAndCleanup()
+ //{
+ // if (Client != null)
+ // {
+ // Client.ErrorOccurred -= Client_ErrorOccurred;
+ // TheStream.DataReceived -= Stream_DataReceived;
+ // Debug.Console(2, this, "Cleaning up disconnected client");
+ // Client.Disconnect();
+ // Client.Dispose();
+ // Client = null;
+ // }
+ //}
///
/// Anything to do with reestablishing connection on failures
///
void HandleConnectionFailure()
{
- DiscoAndCleanup();
-
Debug.Console(2, this, "Checking autoreconnect: {0}, {1}ms",
AutoReconnect, AutoReconnectIntervalMs);
if (AutoReconnect)
@@ -300,6 +320,12 @@ namespace PepperDash.Core
}
}
+ bool PropertiesHaveChanged()
+ {
+ return Hostname != PreviousHostname || Port != PreviousPort
+ || Username != PreviousUsername || Password != PreviousPassword;
+ }
+
///
/// Handles the keyboard interactive authentication, should it be required.
///
@@ -344,11 +370,10 @@ namespace PepperDash.Core
if (Client != null)
{
Client.Disconnect();
- Client.Dispose();
- Client = null;
+ //Client.Dispose();
+ //Client = null;
}
UStatus = 4;
- //IsConnected = false;
HandleConnectionFailure();
}
@@ -358,7 +383,7 @@ namespace PepperDash.Core
void OnConnectionChange()
{
if(ConnectionChange != null)
- ConnectionChange(this, new ConnectionChangeEventArgs(IsConnected, this));
+ ConnectionChange(this, new SshConnectionChangeEventArgs(IsConnected, this));
}
#region IBasicCommunication Members
@@ -378,7 +403,6 @@ namespace PepperDash.Core
{
Debug.Console(1, this, "Stream write failed. Disconnected, closing");
UStatus = 4;
- //IsConnected = false;
HandleConnectionFailure();
}
}
@@ -394,11 +418,34 @@ namespace PepperDash.Core
{
Debug.Console(1, this, "Stream write failed. Disconnected, closing");
UStatus = 4;
- //IsConnected = false;
HandleConnectionFailure();
}
}
#endregion
}
+
+ //*****************************************************************************************************
+ //*****************************************************************************************************
+ ///
+ /// Fired when connection changes
+ ///
+ public class SshConnectionChangeEventArgs : EventArgs
+ {
+ public bool IsConnected { get; private set; }
+
+ public ushort UIsConnected { get { return (ushort)(Client.IsConnected ? 1 : 0); } }
+
+ public GenericSshClient Client { get; private set; }
+ public ushort Status { get { return Client.UStatus; } }
+
+ // S+ Constructor
+ public SshConnectionChangeEventArgs() { }
+
+ public SshConnectionChangeEventArgs(bool isConnected, GenericSshClient client)
+ {
+ IsConnected = isConnected;
+ Client = client;
+ }
+ }
}
diff --git a/Pepperdash Core/Pepperdash Core/PepperDash_Core.csproj b/Pepperdash Core/Pepperdash Core/PepperDash_Core.csproj
index 71d09a4..ddc9b86 100644
--- a/Pepperdash Core/Pepperdash Core/PepperDash_Core.csproj
+++ b/Pepperdash Core/Pepperdash Core/PepperDash_Core.csproj
@@ -85,7 +85,7 @@
C:\Users\hvolm\Desktop\working\pepperdash-simplsharp-core\Pepperdash Core\Pepperdash Core\bin\PepperDash_Core.clz
1.007.0017
- 9/22/2016 9:42:40 PM
+ 9/23/2016 9:37:04 AM
False
diff --git a/Pepperdash Core/Pepperdash Core/Properties/ControlSystem.cfg b/Pepperdash Core/Pepperdash Core/Properties/ControlSystem.cfg
index e69de29..5dff7ae 100644
--- a/Pepperdash Core/Pepperdash Core/Properties/ControlSystem.cfg
+++ b/Pepperdash Core/Pepperdash Core/Properties/ControlSystem.cfg
@@ -0,0 +1,7 @@
+
+
+ MC3 SSH
+ ssh 10.0.0.15
+
+
+
\ No newline at end of file
diff --git a/Pepperdash Core/Pepperdash Core/bin/PepperDash_Core.clz b/Pepperdash Core/Pepperdash Core/bin/PepperDash_Core.clz
index 2f42194..619db53 100644
Binary files a/Pepperdash Core/Pepperdash Core/bin/PepperDash_Core.clz and b/Pepperdash Core/Pepperdash Core/bin/PepperDash_Core.clz differ
diff --git a/Pepperdash Core/Pepperdash Core/bin/PepperDash_Core.config b/Pepperdash Core/Pepperdash Core/bin/PepperDash_Core.config
index 7b07906..ecb3a9e 100644
--- a/Pepperdash Core/Pepperdash Core/bin/PepperDash_Core.config
+++ b/Pepperdash Core/Pepperdash Core/bin/PepperDash_Core.config
@@ -10,7 +10,7 @@
- 9/22/2016 9:42:40 PM
- 1.0.0.37279
+ 9/23/2016 9:37:04 AM
+ 1.0.0.15511
\ No newline at end of file
diff --git a/Pepperdash Core/Pepperdash Core/bin/PepperDash_Core.dll b/Pepperdash Core/Pepperdash Core/bin/PepperDash_Core.dll
index 3216370..b799be7 100644
Binary files a/Pepperdash Core/Pepperdash Core/bin/PepperDash_Core.dll and b/Pepperdash Core/Pepperdash Core/bin/PepperDash_Core.dll differ
diff --git a/Pepperdash Core/Pepperdash Core/bin/manifest.info b/Pepperdash Core/Pepperdash Core/bin/manifest.info
index 523e5f6..f9a7c6c 100644
--- a/Pepperdash Core/Pepperdash Core/bin/manifest.info
+++ b/Pepperdash Core/Pepperdash Core/bin/manifest.info
@@ -1,4 +1,4 @@
-MainAssembly=PepperDash_Core.dll:022f5296f4c24102c3cb64cd3a10fa41
+MainAssembly=PepperDash_Core.dll:ebb9549e48b1f82bec0efdb69443c915
MainAssemblyMinFirmwareVersion=1.007.0017
ü
DependencySource=Newtonsoft.Json.Compact.dll:ea996aa2ec65aa1878e7c9d09e37a896
diff --git a/Pepperdash Core/Pepperdash Core/bin/manifest.ser b/Pepperdash Core/Pepperdash Core/bin/manifest.ser
index 245249e..929be60 100644
Binary files a/Pepperdash Core/Pepperdash Core/bin/manifest.ser and b/Pepperdash Core/Pepperdash Core/bin/manifest.ser differ