This brings along proper password encryption and validation for the login process (which is still not needed for local connections). You can run the remote connection tests by passing a system name and password as 2 arguments (so the system name needs to be quoted, e.g.: `test "Pentair: xx-xx-xx" 1234`) Also updated to latest .NET Core and C# versions while I was at it.
65 lines
2.0 KiB
C#
65 lines
2.0 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Net;
|
|
using System.Net.Sockets;
|
|
using System.Text;
|
|
|
|
namespace ScreenLogicConnect
|
|
{
|
|
public class EasyTouchUnit
|
|
{
|
|
public String gatewayName { get; private set; }
|
|
public byte gatewaySubType { get; private set; }
|
|
public byte gatewayType { get; private set; }
|
|
public IPAddress ipAddress { get; private set; }
|
|
public bool isValid { get; private set; }
|
|
public short port { get; private set; }
|
|
|
|
public EasyTouchUnit(UdpReceiveResult result)
|
|
{
|
|
try
|
|
{
|
|
ipAddress = result.RemoteEndPoint.Address;
|
|
|
|
using (var ms = new MemoryStream(result.Buffer))
|
|
{
|
|
using (var br = new BinaryReader(ms))
|
|
{
|
|
var unitType = br.ReadInt32();
|
|
if (unitType == 2)
|
|
{
|
|
br.ReadBytes(4);
|
|
port = br.ReadInt16();
|
|
gatewayType = br.ReadByte();
|
|
gatewaySubType = br.ReadByte();
|
|
gatewayName = Encoding.ASCII.GetString(result.Buffer.Skip((int)ms.Position).TakeWhile(x => x != 0).ToArray());
|
|
|
|
isValid = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
System.Diagnostics.Debug.WriteLine(e.StackTrace);
|
|
}
|
|
}
|
|
|
|
public EasyTouchUnit(Messages.GetGatewayData data)
|
|
{
|
|
try
|
|
{
|
|
gatewayName = data.GatewayName;
|
|
ipAddress = IPAddress.Parse(data.IPAddr);
|
|
port = data.Port;
|
|
isValid = data.GatewayFound && data.PortOpen;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
System.Diagnostics.Debug.WriteLine(e.StackTrace);
|
|
}
|
|
}
|
|
}
|
|
}
|