Correct commands in IrDaemonCommunicator to add in the missing '#' character and missing StartNewRace command.

Implement the irDaemon shutdown method, with logging. (IrDaemonController, IrDaemonControllerProviderFactory)
Implement using correct commands for StartNewRace and RaceFinished in IrDaemonNotifier.
Move PluginDetails to their own class as used by many classes/extensions.
This commit is contained in:
chris.watts90@outlook.com 2018-02-28 19:30:33 +00:00
parent d207d9448b
commit 27a6ae4631
6 changed files with 46 additions and 10 deletions

View File

@ -10,7 +10,7 @@ namespace IrDaemonNotifier
private const int IRDAEMON_PORT_NO = 3006;
private const int IRDAEMON_PROPERTY_PORT_NO = 3007;
private ILoggerService _logger;
private readonly ILoggerService _logger;
public IrDaemonCommunicator(ILoggerService logger)
{
@ -24,7 +24,7 @@ namespace IrDaemonNotifier
//TODO: convert to use an enum value perhaps? "supported command" style?
public void SendCommand(string command)
{
var formattedCommand = FormatCommand(command);
var formattedCommand = command;//FormatCommand(command); //seems we may not actually need any formatting..
//---create a TCPClient object at the IP and port no.---
var client = new TcpClient(IRDAEMON_SERVER_IP, IRDAEMON_PORT_NO);
@ -131,7 +131,8 @@ namespace IrDaemonNotifier
public const string GetLastToken = "LAST_SCANNED_TOKEN";
}
public const string Shutdown = "SHUTDOWN";
public const string Reset = "RESET";
public const string Shutdown = "SHUTDOWN#";
public const string Reset = "RESET#";
public const string StartNewRace = "START_NEW_RACE#";
}
}

View File

@ -1,13 +1,30 @@
using System.Diagnostics;
using System;
using System.Diagnostics;
using Interfaces;
namespace IrDaemonNotifier
{
public class IrDaemonController:ISystemControlProvider
{
private readonly ILoggerService _logger;
public IrDaemonController(ILoggerService logger)
{
_logger = logger;
}
public void Shutdown()
{
Debug.WriteLine("test");
Debug.WriteLine("Shutdown controller");
try
{
var communicator = new IrDaemonCommunicator(_logger);
communicator.SendCommand(Commands.Shutdown);
}
catch (Exception ex)
{
_logger.Error(ex, "IrDaemonController Shutdown Error");
}
}
public PluginDetails GetPluginDetails()

View File

@ -4,9 +4,16 @@ namespace IrDaemonNotifier
{
public class IrDaemonControllerProviderFactory : ISystemControlProviderFactory
{
private readonly ILoggerService _logger;
public IrDaemonControllerProviderFactory(ILoggerService logger)
{
_logger = logger;
}
public ISystemControlProvider GetProvider()
{
return new IrDaemonController();
return new IrDaemonController(_logger);
}
}
}

View File

@ -27,11 +27,11 @@ namespace IrDaemonNotifier
try
{
var communicator = new IrDaemonCommunicator(_logger);
communicator.SendCommand(Commands.Reset);
communicator.SendCommand(Commands.StartNewRace);
}
catch (Exception ex)
{
_logger.Error(ex, "IrDaemonNotifier Error");
_logger.Error(ex, "IrDaemonNotifier NotifyRaceStarted Error");
}
}
@ -49,6 +49,15 @@ namespace IrDaemonNotifier
public void NotifyRaceFinished(NotificationEventArgs args)
{
try
{
var communicator = new IrDaemonCommunicator(_logger);
communicator.SendCommand(Commands.Reset);
}
catch (Exception ex)
{
_logger.Error(ex, "IrDaemonNotifier NotifyRaceFinished Error");
}
}
}

View File

@ -5,6 +5,8 @@ using Interfaces;
namespace IrDaemonNotifier
{
// TODO: The irDaemon will support tcp connections so that it will publish tokens
// TODO: as they get received rather than need to request them.
public class IrDaemonTransponderUtilities : ITransponderUtilityProvider
{
private readonly ILoggerService _logger;

View File

@ -4,6 +4,6 @@ namespace IrDaemonNotifier
{
public static class Resources
{
public static readonly PluginDetails Details = new PluginDetails("IrDaemonNotifier", "Chris Watts", "IR Daemon Interface", "1.0.0.0");
public static readonly PluginDetails Details = new PluginDetails("IrDaemonNotifier", "Chris Watts", "IR Daemon Interface", "1.0.0.0", "IR Daemon Notifier");
}
}