Files
dotnet-screenlogic/EasyTouchUnit.cs
Parnic e524e394c6 C#-ified
Converted as much ugly code as I could find into appropriate C#-friendly versions. For example, all the manual ByteHelper stuff, buffer index tracking, etc. are now BinaryWriters/BinaryReaders. Also cleaned up a bunch of getter and setter methods to use C# properties.

There's still more to be done here, but this greatly simplifies the code for reading and comprehension.
2018-03-28 15:30:05 -05:00

58 lines
1.9 KiB
C#

using System;
using System.Net;
using System.Net.Sockets;
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)
{
if (BitConverter.ToInt32(result.Buffer, 0) == 2)
{
int i;
byte[] temp = new byte[4];
for (i = 4; i < 8; i++)
{
temp[i - 4] = result.Buffer[i];
}
try
{
this.ipAddress = result.RemoteEndPoint.Address;
port = BitConverter.ToInt16(result.Buffer, 8);
gatewayType = result.Buffer[10];
gatewaySubType = result.Buffer[11];
int nameDataSize = 28;
i = 0;
while (i < nameDataSize)
{
i++;
if (result.Buffer[i + 12] == 0)
{
nameDataSize = i;
}
}
char[] nameData = new char[nameDataSize];
for (i = 0; i < nameDataSize; i++)
{
nameData[i] = (char)result.Buffer[i + 12];
}
gatewayName = new String(nameData);
isValid = true;
}
catch (Exception e)
{
System.Diagnostics.Debug.WriteLine(e.StackTrace);
}
}
}
}
}