mirror of
https://github.com/PepperDash/PepperDashCore.git
synced 2026-02-16 21:24:43 +00:00
Changes to unify GenericTcpClient and GenericSshClient under ISocketStatus
This commit is contained in:
@@ -0,0 +1,12 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using Crestron.SimplSharp;
|
||||||
|
using Crestron.SimplSharp.CrestronSockets;
|
||||||
|
|
||||||
|
|
||||||
|
namespace PepperDash.Core
|
||||||
|
{
|
||||||
|
public delegate void GenericSocketStatusChangeEventDelegate(ISocketStatus client);
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using Crestron.SimplSharp;
|
using Crestron.SimplSharp;
|
||||||
|
using Crestron.SimplSharp.CrestronSockets;
|
||||||
using Crestron.SimplSharp.Ssh;
|
using Crestron.SimplSharp.Ssh;
|
||||||
using Crestron.SimplSharp.Ssh.Common;
|
using Crestron.SimplSharp.Ssh.Common;
|
||||||
|
|
||||||
@@ -25,11 +26,13 @@ namespace PepperDash.Core
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Event when the connection status changes.
|
/// Event when the connection status changes.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public event EventHandler<SshConnectionChangeEventArgs> ConnectionChange;
|
//[Obsolete("Use SocketStatusChange instead")]
|
||||||
|
//public event EventHandler<SshConnectionChangeEventArgs> ConnectionChange;
|
||||||
|
|
||||||
public event Crestron.SimplSharp.CrestronSockets.TCPClientSocketStatusChangeEventHandler SocketStatusChange;
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public event GenericSocketStatusChangeEventDelegate SocketStatusChange;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Address of server
|
/// Address of server
|
||||||
@@ -57,16 +60,24 @@ namespace PepperDash.Core
|
|||||||
public bool IsConnected
|
public bool IsConnected
|
||||||
{
|
{
|
||||||
// returns false if no client or not connected
|
// returns false if no client or not connected
|
||||||
get { return UStatus == 2; }
|
get { return ClientStatus == SocketStatus.SOCKET_STATUS_CONNECTED; }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Crestron.SimplSharp.CrestronSockets.SocketStatus ClientStatus
|
public SocketStatus ClientStatus
|
||||||
{
|
{
|
||||||
get { throw new NotImplementedException(); }
|
get { return _ClientStatus; }
|
||||||
|
private set
|
||||||
|
{
|
||||||
|
if (_ClientStatus == value)
|
||||||
|
return;
|
||||||
|
_ClientStatus = value;
|
||||||
|
OnConnectionChange();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
SocketStatus _ClientStatus;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Contains the familiar Simpl analog status values. This drives the ConnectionChange event
|
/// Contains the familiar Simpl analog status values. This drives the ConnectionChange event
|
||||||
@@ -74,17 +85,8 @@ namespace PepperDash.Core
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public ushort UStatus
|
public ushort UStatus
|
||||||
{
|
{
|
||||||
get { return _UStatus; }
|
get { return (ushort)_ClientStatus; }
|
||||||
private set
|
|
||||||
{
|
|
||||||
if (_UStatus == value)
|
|
||||||
return;
|
|
||||||
_UStatus = value;
|
|
||||||
OnConnectionChange();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
ushort _UStatus;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Determines whether client will attempt reconnection on failure. Default is true
|
/// Determines whether client will attempt reconnection on failure. Default is true
|
||||||
@@ -226,7 +228,7 @@ namespace PepperDash.Core
|
|||||||
PreviousUsername = Username;
|
PreviousUsername = Username;
|
||||||
|
|
||||||
//You can do it!
|
//You can do it!
|
||||||
UStatus = 1;
|
ClientStatus = SocketStatus.SOCKET_STATUS_WAITING;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Client.Connect();
|
Client.Connect();
|
||||||
@@ -237,7 +239,7 @@ namespace PepperDash.Core
|
|||||||
TheStream = Client.CreateShellStream("PDTShell", 100, 80, 100, 200, 65534);
|
TheStream = Client.CreateShellStream("PDTShell", 100, 80, 100, 200, 65534);
|
||||||
TheStream.DataReceived += Stream_DataReceived;
|
TheStream.DataReceived += Stream_DataReceived;
|
||||||
Debug.Console(1, this, "Connected");
|
Debug.Console(1, this, "Connected");
|
||||||
UStatus = 2;
|
ClientStatus = SocketStatus.SOCKET_STATUS_CONNECTED;
|
||||||
PreviousHostname = Hostname;
|
PreviousHostname = Hostname;
|
||||||
PreviousPassword = Password;
|
PreviousPassword = Password;
|
||||||
PreviousPort = Port;
|
PreviousPort = Port;
|
||||||
@@ -268,7 +270,7 @@ namespace PepperDash.Core
|
|||||||
|
|
||||||
// Sucess will not make it this far
|
// Sucess will not make it this far
|
||||||
Client.Disconnect();
|
Client.Disconnect();
|
||||||
UStatus = 3;
|
ClientStatus = SocketStatus.SOCKET_STATUS_CONNECT_FAILED;
|
||||||
HandleConnectionFailure();
|
HandleConnectionFailure();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -286,7 +288,7 @@ namespace PepperDash.Core
|
|||||||
if(TheStream != null)
|
if(TheStream != null)
|
||||||
TheStream.DataReceived -= Stream_DataReceived;
|
TheStream.DataReceived -= Stream_DataReceived;
|
||||||
Client.Disconnect();
|
Client.Disconnect();
|
||||||
UStatus = 5;
|
ClientStatus = SocketStatus.SOCKET_STATUS_BROKEN_LOCALLY;
|
||||||
Debug.Console(1, this, "Disconnected");
|
Debug.Console(1, this, "Disconnected");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -386,7 +388,7 @@ namespace PepperDash.Core
|
|||||||
//Client.Dispose();
|
//Client.Dispose();
|
||||||
//Client = null;
|
//Client = null;
|
||||||
}
|
}
|
||||||
UStatus = 4;
|
ClientStatus = SocketStatus.SOCKET_STATUS_BROKEN_REMOTELY;
|
||||||
HandleConnectionFailure();
|
HandleConnectionFailure();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -395,8 +397,12 @@ namespace PepperDash.Core
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
void OnConnectionChange()
|
void OnConnectionChange()
|
||||||
{
|
{
|
||||||
if(ConnectionChange != null)
|
//if(ConnectionChange != null)
|
||||||
ConnectionChange(this, new SshConnectionChangeEventArgs(IsConnected, this));
|
// ConnectionChange(this, new SshConnectionChangeEventArgs(IsConnected, this));
|
||||||
|
|
||||||
|
var handler = SocketStatusChange;
|
||||||
|
if (handler != null)
|
||||||
|
SocketStatusChange(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
#region IBasicCommunication Members
|
#region IBasicCommunication Members
|
||||||
@@ -415,7 +421,7 @@ namespace PepperDash.Core
|
|||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
Debug.Console(1, this, "Stream write failed. Disconnected, closing");
|
Debug.Console(1, this, "Stream write failed. Disconnected, closing");
|
||||||
UStatus = 4;
|
ClientStatus = SocketStatus.SOCKET_STATUS_BROKEN_REMOTELY;
|
||||||
HandleConnectionFailure();
|
HandleConnectionFailure();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -430,7 +436,7 @@ namespace PepperDash.Core
|
|||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
Debug.Console(1, this, "Stream write failed. Disconnected, closing");
|
Debug.Console(1, this, "Stream write failed. Disconnected, closing");
|
||||||
UStatus = 4;
|
ClientStatus = SocketStatus.SOCKET_STATUS_BROKEN_REMOTELY;
|
||||||
HandleConnectionFailure();
|
HandleConnectionFailure();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ namespace PepperDash.Core
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public event TCPClientSocketStatusChangeEventHandler SocketStatusChange;
|
public event GenericSocketStatusChangeEventDelegate SocketStatusChange;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
@@ -107,7 +107,7 @@ namespace PepperDash.Core
|
|||||||
DisconnectCalledByUser = false;
|
DisconnectCalledByUser = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Disconnnect()
|
public void Disconnect()
|
||||||
{
|
{
|
||||||
DisconnectCalledByUser = true;
|
DisconnectCalledByUser = true;
|
||||||
Client.DisconnectFromServer();
|
Client.DisconnectFromServer();
|
||||||
@@ -196,7 +196,7 @@ namespace PepperDash.Core
|
|||||||
// Relay the event
|
// Relay the event
|
||||||
var handler = SocketStatusChange;
|
var handler = SocketStatusChange;
|
||||||
if (handler != null)
|
if (handler != null)
|
||||||
SocketStatusChange(client, clientSocketStatus);
|
SocketStatusChange(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,35 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using Crestron.SimplSharp;
|
|
||||||
|
|
||||||
namespace PepperDash.Core
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// A wrapper class that creates a TCP client and gather for use within S+
|
|
||||||
/// </summary>
|
|
||||||
public class SplusGenericTcpIpClientWithGather
|
|
||||||
{
|
|
||||||
public GenericTcpIpClient Client { get; private set; }
|
|
||||||
public CommunicationGather Gather { get; private set; }
|
|
||||||
|
|
||||||
public SplusGenericTcpIpClientWithGather()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// In place of the useless contstructor, for S+ compatability
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="key"></param>
|
|
||||||
/// <param name="host"></param>
|
|
||||||
/// <param name="port"></param>
|
|
||||||
/// <param name="bufferSize"></param>
|
|
||||||
/// <param name="delimiter"></param>
|
|
||||||
public void Initialize(string key, string host, int port, int bufferSize, char delimiter)
|
|
||||||
{
|
|
||||||
Client = new GenericTcpIpClient(key, host, port, bufferSize);
|
|
||||||
Gather = new CommunicationGather(Client, delimiter);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
//using System;
|
|
||||||
//using System.Collections.Generic;
|
|
||||||
//using System.Linq;
|
|
||||||
//using System.Text;
|
|
||||||
//using Crestron.SimplSharp;
|
|
||||||
|
|
||||||
//using Newtonsoft.Json;
|
|
||||||
|
|
||||||
//namespace PepperDash.Core
|
|
||||||
//{
|
|
||||||
// public class SshConfig : TcpIpConfig
|
|
||||||
// {
|
|
||||||
// public string Username { get; set; }
|
|
||||||
// public string Password { get; set; }
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
@@ -22,6 +22,7 @@ namespace PepperDash.Core
|
|||||||
void SendText(string text);
|
void SendText(string text);
|
||||||
void SendBytes(byte[] bytes);
|
void SendBytes(byte[] bytes);
|
||||||
void Connect();
|
void Connect();
|
||||||
|
void Disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -30,7 +31,7 @@ namespace PepperDash.Core
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public interface ISocketStatus : IBasicCommunication
|
public interface ISocketStatus : IBasicCommunication
|
||||||
{
|
{
|
||||||
event TCPClientSocketStatusChangeEventHandler SocketStatusChange;
|
event GenericSocketStatusChangeEventDelegate SocketStatusChange;
|
||||||
SocketStatus ClientStatus { get; }
|
SocketStatus ClientStatus { get; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -64,9 +64,8 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="CommunicationExtras.cs" />
|
<Compile Include="CommunicationExtras.cs" />
|
||||||
<Compile Include="Comm\CommunicationGather.cs" />
|
<Compile Include="Comm\CommunicationGather.cs" />
|
||||||
|
<Compile Include="Comm\GenericSocketStatusChangeEventArgs.cs" />
|
||||||
<Compile Include="Comm\GenericSshClient.cs" />
|
<Compile Include="Comm\GenericSshClient.cs" />
|
||||||
<Compile Include="Comm\GenericTcpIpClientWithGather.cs" />
|
|
||||||
<Compile Include="Comm\SshConfig.cs" />
|
|
||||||
<Compile Include="CoreInterfaces.cs" />
|
<Compile Include="CoreInterfaces.cs" />
|
||||||
<Compile Include="Debug.cs" />
|
<Compile Include="Debug.cs" />
|
||||||
<Compile Include="Device.cs" />
|
<Compile Include="Device.cs" />
|
||||||
@@ -85,7 +84,7 @@
|
|||||||
<Programmer />
|
<Programmer />
|
||||||
<ArchiveFilename>C:\Users\hvolm\Desktop\working\pepperdash-simplsharp-core\Pepperdash Core\Pepperdash Core\bin\PepperDash_Core.clz</ArchiveFilename>
|
<ArchiveFilename>C:\Users\hvolm\Desktop\working\pepperdash-simplsharp-core\Pepperdash Core\Pepperdash Core\bin\PepperDash_Core.clz</ArchiveFilename>
|
||||||
<MinFirmwareVersion>1.007.0017</MinFirmwareVersion>
|
<MinFirmwareVersion>1.007.0017</MinFirmwareVersion>
|
||||||
<CompiledOn>9/26/2016 9:02:28 AM</CompiledOn>
|
<CompiledOn>9/27/2016 5:17:31 PM</CompiledOn>
|
||||||
<AdditionalInfo />
|
<AdditionalInfo />
|
||||||
<EmbedSourceArchive>False</EmbedSourceArchive>
|
<EmbedSourceArchive>False</EmbedSourceArchive>
|
||||||
<CopyTo />
|
<CopyTo />
|
||||||
|
|||||||
Binary file not shown.
@@ -10,7 +10,7 @@
|
|||||||
<ArchiveName />
|
<ArchiveName />
|
||||||
</RequiredInfo>
|
</RequiredInfo>
|
||||||
<OptionalInfo>
|
<OptionalInfo>
|
||||||
<CompiledOn>9/26/2016 9:02:28 AM</CompiledOn>
|
<CompiledOn>9/27/2016 5:17:31 PM</CompiledOn>
|
||||||
<CompilerRev>1.0.0.14473</CompilerRev>
|
<CompilerRev>1.0.0.29325</CompilerRev>
|
||||||
</OptionalInfo>
|
</OptionalInfo>
|
||||||
</ProgramInfo>
|
</ProgramInfo>
|
||||||
Binary file not shown.
@@ -1,4 +1,4 @@
|
|||||||
MainAssembly=PepperDash_Core.dll:ddd7e6504766069b1c909eac0c499966
|
MainAssembly=PepperDash_Core.dll:945e6c6366e369445585fb8cacdefe8e
|
||||||
MainAssemblyMinFirmwareVersion=1.007.0017
|
MainAssemblyMinFirmwareVersion=1.007.0017
|
||||||
ü
|
ü
|
||||||
DependencySource=Newtonsoft.Json.Compact.dll:ea996aa2ec65aa1878e7c9d09e37a896
|
DependencySource=Newtonsoft.Json.Compact.dll:ea996aa2ec65aa1878e7c9d09e37a896
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user