Add TcpService
This commit is contained in:
@@ -93,7 +93,7 @@
|
|||||||
</Reference>
|
</Reference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="MQTTService.cs" />
|
<Compile Include="TcpService.cs" />
|
||||||
<Compile Include="Views\EditUserDisplay.cs" />
|
<Compile Include="Views\EditUserDisplay.cs" />
|
||||||
<Compile Include="Views\EntryDialog.cs" />
|
<Compile Include="Views\EntryDialog.cs" />
|
||||||
<Compile Include="Views\FingerprintDialog.cs" />
|
<Compile Include="Views\FingerprintDialog.cs" />
|
||||||
|
|||||||
@@ -1,25 +1,33 @@
|
|||||||
using Akari.Provider.WaveshareUART.Users;
|
using Akari.Provider.WaveshareUART.Users;
|
||||||
using System;
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Net;
|
||||||
|
using System.Net.Sockets;
|
||||||
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using WaveshareUARTFingerprintSensor;
|
using WaveshareUARTFingerprintSensor;
|
||||||
|
|
||||||
namespace Akari.Provider.WaveshareUART
|
namespace Akari.Provider.WaveshareUART
|
||||||
{
|
{
|
||||||
public class MQTTService
|
public class TcpService
|
||||||
{
|
{
|
||||||
public FingerprintSensor FingerprintSensor => WaveshareUARTProvider.Instance.FingerprintSensor;
|
public FingerprintSensor FingerprintSensor => WaveshareUARTProvider.Instance.FingerprintSensor;
|
||||||
public UsersManager UsersManager => WaveshareUARTProvider.Instance.UsersManager;
|
public UsersManager UsersManager => WaveshareUARTProvider.Instance.UsersManager;
|
||||||
|
|
||||||
public MQTTService()
|
private string _ip;
|
||||||
|
private int _port;
|
||||||
|
|
||||||
|
public TcpService()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Start()
|
public void Start()
|
||||||
{
|
{
|
||||||
Console.WriteLine("Starting MQTT service...");
|
Console.WriteLine("Starting Tcp service...");
|
||||||
|
|
||||||
InitMQTT();
|
InitTcp();
|
||||||
|
|
||||||
Console.WriteLine($"There is {UsersManager.Count} users registered");
|
Console.WriteLine($"There is {UsersManager.Count} users registered");
|
||||||
|
|
||||||
@@ -34,14 +42,36 @@ namespace Akari.Provider.WaveshareUART
|
|||||||
FingerprintSensor.Waked -= FingerprintSensor_Waked;
|
FingerprintSensor.Waked -= FingerprintSensor_Waked;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void InitMQTT()
|
private void InitTcp()
|
||||||
{
|
{
|
||||||
// TODO
|
try
|
||||||
|
{
|
||||||
|
_ip = File.ReadAllText(WaveshareUARTProvider.ServerIPFilePath);
|
||||||
|
_port = int.Parse(File.ReadAllText(WaveshareUARTProvider.ServerPortFilePath));
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Console.ForegroundColor = ConsoleColor.Red;
|
||||||
|
Console.WriteLine(e);
|
||||||
|
|
||||||
|
Console.WriteLine();
|
||||||
|
Console.WriteLine($"Couldn't read setting files");
|
||||||
|
Console.WriteLine($"Launch the program with '-c' to config the provider");
|
||||||
|
|
||||||
|
Environment.Exit(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SendAuth(User user)
|
private void SendAuth(User user)
|
||||||
{
|
{
|
||||||
// TODO
|
using (var client = new TcpClient(_ip, _port))
|
||||||
|
{
|
||||||
|
var stream = client.GetStream();
|
||||||
|
|
||||||
|
var data = Convert.FromBase64String(user.Token);
|
||||||
|
|
||||||
|
stream.Write(data, 0, data.Length);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void FingerprintSensor_Waked(FingerprintSensor sender)
|
private void FingerprintSensor_Waked(FingerprintSensor sender)
|
||||||
@@ -54,8 +84,23 @@ namespace Akari.Provider.WaveshareUART
|
|||||||
{
|
{
|
||||||
Console.WriteLine($"{user.Name} fingerprint recognized");
|
Console.WriteLine($"{user.Name} fingerprint recognized");
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
SendAuth(user);
|
SendAuth(user);
|
||||||
}
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
var oldColor = Console.ForegroundColor;
|
||||||
|
Console.ForegroundColor = ConsoleColor.Red;
|
||||||
|
|
||||||
|
Console.WriteLine("Tried to send an auth packet but an error occured.");
|
||||||
|
Console.WriteLine();
|
||||||
|
|
||||||
|
Console.WriteLine(e);
|
||||||
|
|
||||||
|
Console.ForegroundColor = oldColor;
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Console.WriteLine($"Found unknown fingerprint with id {userInfo.userID}");
|
Console.WriteLine($"Found unknown fingerprint with id {userInfo.userID}");
|
||||||
@@ -51,7 +51,7 @@ namespace Akari.Provider.WaveshareUART
|
|||||||
{
|
{
|
||||||
InitSensor();
|
InitSensor();
|
||||||
|
|
||||||
new MQTTService().Start();
|
new TcpService().Start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user