From 2b9fe57a0d2be46950eb1a73e6c5699dfda3221c Mon Sep 17 00:00:00 2001 From: Dave Walker Date: Fri, 16 Aug 2024 10:42:38 +0100 Subject: [PATCH 1/2] Added command line help --- .../BaseStationReader.Data.csproj | 22 ++--- .../BaseStationReader.Entities.csproj | 14 ++-- .../Config/CommandLineOptionType.cs | 1 + .../Exceptions/DuplicateOptionException.cs | 11 --- .../MalformedCommandLineException.cs | 10 --- .../MissingMandatoryOptionException.cs | 10 --- .../Exceptions/TooFewValuesException.cs | 10 --- .../Exceptions/TooManyValuesException.cs | 17 +--- .../UnrecognisedCommandLineOptionException.cs | 10 --- .../Interfaces/ICommandLineParser.cs | 13 +++ .../Interfaces/IHelpGenerator.cs | 9 ++ .../Interfaces/ISimulatorSettingsBuilder.cs | 10 +++ .../Interfaces/ITrackerSettingsBuilder.cs | 2 +- .../BaseStationReader.Logic.csproj | 14 ++-- .../Configuration/CommandLineParser.cs | 25 +++++- .../SimulatorCommandLineParser.cs | 19 +++++ .../Configuration/SimulatorSettingsBuilder.cs | 17 +--- .../Configuration/TrackerCommandLineParser.cs | 31 +++++++ .../Configuration/TrackerSettingsBuilder.cs | 28 +------ .../BaseStationReader.Simulator.csproj | 12 ++- .../Logic/HelpTabulator.cs | 42 ++++++++++ src/BaseStationReader.Simulator/Program.cs | 76 ++++++++++------- .../BaseStationReader.Terminal.csproj | 12 +-- .../Logic/HelpTabulator.cs | 42 ++++++++++ src/BaseStationReader.Terminal/Program.cs | 84 +++++++++++-------- .../appsettings.json | 2 +- .../BaseStationReader.Tests.csproj | 12 +-- .../SimulatorSettingsBuilderTest.cs | 34 ++++++-- .../TrackerSettingsBuilderTest.cs | 70 +++++++++++----- .../BaseStationReader.UI.csproj | 22 ++--- src/BaseStationReader.UI/appsettings.json | 2 +- 31 files changed, 424 insertions(+), 259 deletions(-) create mode 100644 src/BaseStationReader.Entities/Interfaces/ICommandLineParser.cs create mode 100644 src/BaseStationReader.Entities/Interfaces/IHelpGenerator.cs create mode 100644 src/BaseStationReader.Entities/Interfaces/ISimulatorSettingsBuilder.cs create mode 100644 src/BaseStationReader.Logic/Configuration/SimulatorCommandLineParser.cs create mode 100644 src/BaseStationReader.Logic/Configuration/TrackerCommandLineParser.cs create mode 100644 src/BaseStationReader.Simulator/Logic/HelpTabulator.cs create mode 100644 src/BaseStationReader.Terminal/Logic/HelpTabulator.cs diff --git a/src/BaseStationReader.Data/BaseStationReader.Data.csproj b/src/BaseStationReader.Data/BaseStationReader.Data.csproj index 68c2317..1323519 100644 --- a/src/BaseStationReader.Data/BaseStationReader.Data.csproj +++ b/src/BaseStationReader.Data/BaseStationReader.Data.csproj @@ -1,13 +1,13 @@  - net7.0 + net8.0 enable enable BaseStationReader.Data - 1.31.0.0 + 1.32.0.0 Dave Walker - Copyright (c) Dave Walker 2023 + Copyright (c) 2023, 2024 Dave Walker Dave Walker Base Station Reader EF Core Database Layer BaseStationReader database @@ -17,20 +17,20 @@ https://github.com/davewalker5/ADS-B-BaseStationReader MIT false - 1.31.0.0 + 1.32.0.0 - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - + + + + + diff --git a/src/BaseStationReader.Entities/BaseStationReader.Entities.csproj b/src/BaseStationReader.Entities/BaseStationReader.Entities.csproj index aaf843a..cf79861 100644 --- a/src/BaseStationReader.Entities/BaseStationReader.Entities.csproj +++ b/src/BaseStationReader.Entities/BaseStationReader.Entities.csproj @@ -1,13 +1,13 @@  - net7.0 + net8.0 enable enable BaseStationReader.Entities - 1.31.0.0 + 1.32.0.0 Dave Walker - Copyright (c) Dave Walker 2023 + Copyright (c) 2023, 2024 Dave Walker Dave Walker Base Station Reader Domain Models BaseStationReader domain models entities @@ -17,13 +17,13 @@ https://github.com/davewalker5/ADS-B-BaseStationReader MIT false - 1.31.0.0 + 1.32.0.0 - - - + + + diff --git a/src/BaseStationReader.Entities/Config/CommandLineOptionType.cs b/src/BaseStationReader.Entities/Config/CommandLineOptionType.cs index b5a6ec1..0e410ad 100644 --- a/src/BaseStationReader.Entities/Config/CommandLineOptionType.cs +++ b/src/BaseStationReader.Entities/Config/CommandLineOptionType.cs @@ -2,6 +2,7 @@ { public enum CommandLineOptionType { + Help, MinimumLogLevel, Host, Port, diff --git a/src/BaseStationReader.Entities/Exceptions/DuplicateOptionException.cs b/src/BaseStationReader.Entities/Exceptions/DuplicateOptionException.cs index 31d0a95..7288a3f 100644 --- a/src/BaseStationReader.Entities/Exceptions/DuplicateOptionException.cs +++ b/src/BaseStationReader.Entities/Exceptions/DuplicateOptionException.cs @@ -1,9 +1,7 @@ using System.Diagnostics.CodeAnalysis; -using System.Runtime.Serialization; namespace BaseStationReader.Entities.Exceptions { - [Serializable] [ExcludeFromCodeCoverage] public class DuplicateOptionException : Exception @@ -19,14 +17,5 @@ public DuplicateOptionException(string message) : base(message) public DuplicateOptionException(string message, Exception inner) : base(message, inner) { } - - protected DuplicateOptionException(SerializationInfo serializationInfo, StreamingContext streamingContext) : base(serializationInfo, streamingContext) - { - } - - public override void GetObjectData(SerializationInfo info, StreamingContext context) - { - base.GetObjectData(info, context); - } } } \ No newline at end of file diff --git a/src/BaseStationReader.Entities/Exceptions/MalformedCommandLineException.cs b/src/BaseStationReader.Entities/Exceptions/MalformedCommandLineException.cs index e310056..ca6ab8d 100644 --- a/src/BaseStationReader.Entities/Exceptions/MalformedCommandLineException.cs +++ b/src/BaseStationReader.Entities/Exceptions/MalformedCommandLineException.cs @@ -1,5 +1,4 @@ using System.Diagnostics.CodeAnalysis; -using System.Runtime.Serialization; namespace BaseStationReader.Entities.Exceptions { @@ -18,14 +17,5 @@ public MalformedCommandLineException(string message) : base(message) public MalformedCommandLineException(string message, Exception inner) : base(message, inner) { } - - protected MalformedCommandLineException(SerializationInfo serializationInfo, StreamingContext streamingContext) : base(serializationInfo, streamingContext) - { - } - - public override void GetObjectData(SerializationInfo info, StreamingContext context) - { - base.GetObjectData(info, context); - } } } \ No newline at end of file diff --git a/src/BaseStationReader.Entities/Exceptions/MissingMandatoryOptionException.cs b/src/BaseStationReader.Entities/Exceptions/MissingMandatoryOptionException.cs index 372305f..0c0c1ca 100644 --- a/src/BaseStationReader.Entities/Exceptions/MissingMandatoryOptionException.cs +++ b/src/BaseStationReader.Entities/Exceptions/MissingMandatoryOptionException.cs @@ -1,5 +1,4 @@ using System.Diagnostics.CodeAnalysis; -using System.Runtime.Serialization; namespace BaseStationReader.Entities.Exceptions { @@ -18,14 +17,5 @@ public MissingMandatoryOptionException(string message) : base(message) public MissingMandatoryOptionException(string message, Exception inner) : base(message, inner) { } - - protected MissingMandatoryOptionException(SerializationInfo serializationInfo, StreamingContext streamingContext) : base(serializationInfo, streamingContext) - { - } - - public override void GetObjectData(SerializationInfo info, StreamingContext context) - { - base.GetObjectData(info, context); - } } } \ No newline at end of file diff --git a/src/BaseStationReader.Entities/Exceptions/TooFewValuesException.cs b/src/BaseStationReader.Entities/Exceptions/TooFewValuesException.cs index 04e4895..8309410 100644 --- a/src/BaseStationReader.Entities/Exceptions/TooFewValuesException.cs +++ b/src/BaseStationReader.Entities/Exceptions/TooFewValuesException.cs @@ -1,5 +1,4 @@ using System.Diagnostics.CodeAnalysis; -using System.Runtime.Serialization; namespace BaseStationReader.Entities.Exceptions { @@ -18,14 +17,5 @@ public TooFewValuesException(string message) : base(message) public TooFewValuesException(string message, Exception inner) : base(message, inner) { } - - protected TooFewValuesException(SerializationInfo serializationInfo, StreamingContext streamingContext) : base(serializationInfo, streamingContext) - { - } - - public override void GetObjectData(SerializationInfo info, StreamingContext context) - { - base.GetObjectData(info, context); - } } } \ No newline at end of file diff --git a/src/BaseStationReader.Entities/Exceptions/TooManyValuesException.cs b/src/BaseStationReader.Entities/Exceptions/TooManyValuesException.cs index 48f6646..cde0b59 100644 --- a/src/BaseStationReader.Entities/Exceptions/TooManyValuesException.cs +++ b/src/BaseStationReader.Entities/Exceptions/TooManyValuesException.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using System.Linq; -using System.Runtime.Serialization; -using System.Text; -using System.Threading.Tasks; +using System.Diagnostics.CodeAnalysis; namespace BaseStationReader.Entities.Exceptions { @@ -23,14 +17,5 @@ public TooManyValuesException(string message) : base(message) public TooManyValuesException(string message, Exception inner) : base(message, inner) { } - - protected TooManyValuesException(SerializationInfo serializationInfo, StreamingContext streamingContext) : base(serializationInfo, streamingContext) - { - } - - public override void GetObjectData(SerializationInfo info, StreamingContext context) - { - base.GetObjectData(info, context); - } } } \ No newline at end of file diff --git a/src/BaseStationReader.Entities/Exceptions/UnrecognisedCommandLineOptionException.cs b/src/BaseStationReader.Entities/Exceptions/UnrecognisedCommandLineOptionException.cs index 9c7b800..f561f85 100644 --- a/src/BaseStationReader.Entities/Exceptions/UnrecognisedCommandLineOptionException.cs +++ b/src/BaseStationReader.Entities/Exceptions/UnrecognisedCommandLineOptionException.cs @@ -1,5 +1,4 @@ using System.Diagnostics.CodeAnalysis; -using System.Runtime.Serialization; namespace BaseStationReader.Entities.Exceptions { @@ -18,14 +17,5 @@ public UnrecognisedCommandLineOptionException(string message) : base(message) public UnrecognisedCommandLineOptionException(string message, Exception inner) : base(message, inner) { } - - protected UnrecognisedCommandLineOptionException(SerializationInfo serializationInfo, StreamingContext streamingContext) : base(serializationInfo, streamingContext) - { - } - - public override void GetObjectData(SerializationInfo info, StreamingContext context) - { - base.GetObjectData(info, context); - } } } diff --git a/src/BaseStationReader.Entities/Interfaces/ICommandLineParser.cs b/src/BaseStationReader.Entities/Interfaces/ICommandLineParser.cs new file mode 100644 index 0000000..30e5e48 --- /dev/null +++ b/src/BaseStationReader.Entities/Interfaces/ICommandLineParser.cs @@ -0,0 +1,13 @@ +using BaseStationReader.Entities.Config; + +namespace BaseStationReader.Entities.Interfaces +{ + public interface ICommandLineParser + { + void Add(CommandLineOptionType optionType, bool mandatory, string name, string shortName, string description, int minimumNumberOfValues, int maximumNumberOfValues); + List? GetValues(CommandLineOptionType optionType); + void Help(); + bool IsPresent(CommandLineOptionType optionType); + void Parse(IEnumerable args); + } +} \ No newline at end of file diff --git a/src/BaseStationReader.Entities/Interfaces/IHelpGenerator.cs b/src/BaseStationReader.Entities/Interfaces/IHelpGenerator.cs new file mode 100644 index 0000000..b0f96ce --- /dev/null +++ b/src/BaseStationReader.Entities/Interfaces/IHelpGenerator.cs @@ -0,0 +1,9 @@ +using BaseStationReader.Entities.Config; + +namespace BaseStationReader.Entities.Interfaces +{ + public interface IHelpGenerator + { + void Generate(IEnumerable options); + } +} diff --git a/src/BaseStationReader.Entities/Interfaces/ISimulatorSettingsBuilder.cs b/src/BaseStationReader.Entities/Interfaces/ISimulatorSettingsBuilder.cs new file mode 100644 index 0000000..11226c0 --- /dev/null +++ b/src/BaseStationReader.Entities/Interfaces/ISimulatorSettingsBuilder.cs @@ -0,0 +1,10 @@ +using BaseStationReader.Entities.Config; +using BaseStationReader.Entities.Interfaces; + +namespace BaseStationReader.Entities.Interfaces +{ + public interface ISimulatorSettingsBuilder + { + SimulatorApplicationSettings? BuildSettings(ICommandLineParser parser, string configJsonPath); + } +} \ No newline at end of file diff --git a/src/BaseStationReader.Entities/Interfaces/ITrackerSettingsBuilder.cs b/src/BaseStationReader.Entities/Interfaces/ITrackerSettingsBuilder.cs index ddc8eaa..5ccac54 100644 --- a/src/BaseStationReader.Entities/Interfaces/ITrackerSettingsBuilder.cs +++ b/src/BaseStationReader.Entities/Interfaces/ITrackerSettingsBuilder.cs @@ -4,6 +4,6 @@ namespace BaseStationReader.Entities.Interfaces { public interface ITrackerSettingsBuilder { - TrackerApplicationSettings? BuildSettings(IEnumerable args, string configJsonPath); + TrackerApplicationSettings? BuildSettings(ICommandLineParser parser, string configJsonPath); } } \ No newline at end of file diff --git a/src/BaseStationReader.Logic/BaseStationReader.Logic.csproj b/src/BaseStationReader.Logic/BaseStationReader.Logic.csproj index 21186fc..edf1ed8 100644 --- a/src/BaseStationReader.Logic/BaseStationReader.Logic.csproj +++ b/src/BaseStationReader.Logic/BaseStationReader.Logic.csproj @@ -1,13 +1,13 @@  - net7.0 + net8.0 enable enable BaseStationReader.Logic - 1.31.0.0 + 1.32.0.0 Dave Walker - Copyright (c) Dave Walker 2023 + Copyright (c) 2023, 2024 Dave Walker Dave Walker Base Station Reader Business Logic BaseStationReader logic @@ -17,13 +17,13 @@ https://github.com/davewalker5/ADS-B-BaseStationReader MIT false - 1.31.0.0 + 1.32.0.0 - - - + + + diff --git a/src/BaseStationReader.Logic/Configuration/CommandLineParser.cs b/src/BaseStationReader.Logic/Configuration/CommandLineParser.cs index b1666b9..e85258c 100644 --- a/src/BaseStationReader.Logic/Configuration/CommandLineParser.cs +++ b/src/BaseStationReader.Logic/Configuration/CommandLineParser.cs @@ -1,12 +1,19 @@ using BaseStationReader.Entities.Config; using BaseStationReader.Entities.Exceptions; +using BaseStationReader.Entities.Interfaces; namespace BaseStationReader.Logic.Configuration { - public class CommandLineParser + public class CommandLineParser : ICommandLineParser { private readonly List _options = new List(); private readonly Dictionary _values = new Dictionary(); + private readonly IHelpGenerator? _helpGenerator = null; + + public CommandLineParser() { } + + public CommandLineParser(IHelpGenerator? generator) + => _helpGenerator = generator; /// /// Add an option to the available command line options @@ -68,6 +75,14 @@ public void Parse(IEnumerable args) CheckForMandatoryOptions(); } + /// + /// Return true if a command line option has been specified + /// + /// + /// + public bool IsPresent(CommandLineOptionType optionType) + => _values.ContainsKey(optionType); + /// /// Return the valus for the specified option type /// @@ -77,7 +92,7 @@ public void Parse(IEnumerable args) { List? values = null; - if (_values.ContainsKey(optionType)) + if (IsPresent(optionType)) { values = _values[optionType].Values; } @@ -85,6 +100,12 @@ public void Parse(IEnumerable args) return values; } + /// + /// Generate help + /// + public void Help() + => _helpGenerator?.Generate(_options); + /// /// Check that all mandatory options have been specified /// diff --git a/src/BaseStationReader.Logic/Configuration/SimulatorCommandLineParser.cs b/src/BaseStationReader.Logic/Configuration/SimulatorCommandLineParser.cs new file mode 100644 index 0000000..1aea641 --- /dev/null +++ b/src/BaseStationReader.Logic/Configuration/SimulatorCommandLineParser.cs @@ -0,0 +1,19 @@ +using BaseStationReader.Entities.Config; +using BaseStationReader.Entities.Interfaces; + +namespace BaseStationReader.Logic.Configuration +{ + public class SimulatorCommandLineParser : CommandLineParser + { + public SimulatorCommandLineParser(IHelpGenerator? generator) : base(generator) + { + Add(CommandLineOptionType.Help, false, "--help", "-h", "Show command line help",0, 0); + Add(CommandLineOptionType.Port, false, "--port", "-p", "Port to send data on", 1, 1); + Add(CommandLineOptionType.SendInterval, false, "--send-interval", "-s", "Message send interval (ms)", 1, 1); + Add(CommandLineOptionType.NumberOfAircraft, false, "--number", "-n", "Number of concurrent simulated aircraft", 1, 1); + Add(CommandLineOptionType.Lifespan, false, "--lifespan", "-ls", "Simulated aircraft lifespan (ms)", 1, 1); + Add(CommandLineOptionType.LogFile, false, "--log-file", "-l", "Log file path and name", 1, 1); + Add(CommandLineOptionType.MinimumLogLevel, false, "--log-level", "-ll", "Minimum logging level (Debug, Info, Warning or Error)", 1, 1); + } + } +} diff --git a/src/BaseStationReader.Logic/Configuration/SimulatorSettingsBuilder.cs b/src/BaseStationReader.Logic/Configuration/SimulatorSettingsBuilder.cs index 8a84217..64ad655 100644 --- a/src/BaseStationReader.Logic/Configuration/SimulatorSettingsBuilder.cs +++ b/src/BaseStationReader.Logic/Configuration/SimulatorSettingsBuilder.cs @@ -1,32 +1,23 @@ using BaseStationReader.Entities.Config; +using BaseStationReader.Entities.Interfaces; using BaseStationReader.Entities.Logging; namespace BaseStationReader.Logic.Configuration { - public class SimulatorSettingsBuilder + public class SimulatorSettingsBuilder : ISimulatorSettingsBuilder { /// /// Construct the application settings from the configuration file and any command line arguments /// - /// + /// /// /// #pragma warning disable S3776 - public SimulatorApplicationSettings? BuildSettings(IEnumerable args, string configJsonPath) + public SimulatorApplicationSettings? BuildSettings(ICommandLineParser parser, string configJsonPath) { // Read the config file to provide default settings var settings = new ConfigReader().Read(configJsonPath); - // Parse the command line - var parser = new CommandLineParser(); - parser.Add(CommandLineOptionType.Port, false, "--port", "-p", "Port to send data on", 1, 1); - parser.Add(CommandLineOptionType.SendInterval, false, "--send-interval", "-s", "Message send interval (ms)", 1, 1); - parser.Add(CommandLineOptionType.NumberOfAircraft, false, "--number", "-n", "Number of concurrent simulated aircraft", 1, 1); - parser.Add(CommandLineOptionType.Lifespan, false, "--lifespan", "-ls", "Simulated aircraft lifespan (ms)", 1, 1); - parser.Add(CommandLineOptionType.LogFile, false, "--log-file", "-l", "Log file path and name", 1, 1); - parser.Add(CommandLineOptionType.MinimumLogLevel, false, "--log-level", "-ll", "Minimum logging level (Debug, Info, Warning or Error)", 1, 1); - parser.Parse(args); - // Apply the command line values over the defaults var values = parser.GetValues(CommandLineOptionType.Port); if (values != null) settings!.Port = int.Parse(values[0]); diff --git a/src/BaseStationReader.Logic/Configuration/TrackerCommandLineParser.cs b/src/BaseStationReader.Logic/Configuration/TrackerCommandLineParser.cs new file mode 100644 index 0000000..f76a347 --- /dev/null +++ b/src/BaseStationReader.Logic/Configuration/TrackerCommandLineParser.cs @@ -0,0 +1,31 @@ +using BaseStationReader.Entities.Config; +using BaseStationReader.Entities.Interfaces; + +namespace BaseStationReader.Logic.Configuration +{ + public class TrackerCommandLineParser : CommandLineParser + { + public TrackerCommandLineParser(IHelpGenerator? generator) : base(generator) + { + Add(CommandLineOptionType.Help, false, "--help", "-h", "Show command line help", 0, 0); + Add(CommandLineOptionType.Host, false, "--host", "-ho", "Host to connect to for data stream", 1, 1); + Add(CommandLineOptionType.Port, false, "--port", "-p", "Port to connect to for data stream", 1, 1); + Add(CommandLineOptionType.SocketReadTimeout, false, "--read-timeout", "-t", "Timeout (ms) for socket read operations", 1, 1); + Add(CommandLineOptionType.ApplicationTimeout, false, "--app-timeout", "-a", "Timeout (ms) after which the application will quit of no messages are recieved", 1, 1); + Add(CommandLineOptionType.RestartOnTimeout, false, "--auto-restart", "-ar", "Automatically restart the tracker after a timeout", 1, 1); + Add(CommandLineOptionType.TimeToRecent, false, "--recent", "-r", "Time (ms) to 'recent' staleness", 1, 1); + Add(CommandLineOptionType.TimeToStale, false, "--stale", "-s", "Time (ms) to 'stale' staleness", 1, 1); + Add(CommandLineOptionType.TimeToRemoval, false, "--remove", "-x", "Time (ms) to removal of stale records", 1, 1); + Add(CommandLineOptionType.TimeToLock, false, "--lock", "-k", "Time (ms) to locking of active database records", 1, 1); + Add(CommandLineOptionType.LogFile, false, "--log-file", "-l", "Log file path and name", 1, 1); + Add(CommandLineOptionType.MinimumLogLevel, false, "--log-level", "-ll", "Minimum logging level (Debug, Info, Warning or Error)", 1, 1); + Add(CommandLineOptionType.EnableSqlWriter, false, "--enable-sql-writer", "-w", "Log file path and name", 1, 1); + Add(CommandLineOptionType.WriterInterval, false, "--writer-interval", "-i", "SQL write interval (ms)", 1, 1); + Add(CommandLineOptionType.WriterBatchSize, false, "--writer-batch-size", "-b", "SQL write batch size", 1, 1); + Add(CommandLineOptionType.RefreshInterval, false, "--ui-interval", "-ui", "Interval (ms) at which live UI's should update", 1, 1); + Add(CommandLineOptionType.MaximumRows, false, "--max-rows", "-m", "Maximum number of rows displayed", 1, 1); + Add(CommandLineOptionType.ReceiverLatitude, false, "--latitude", "-la", "Receiver latitude", 1, 1); + Add(CommandLineOptionType.ReceiverLongitude, false, "--longitude", "-lo", "Receiver latitude", 1, 1); + } + } +} diff --git a/src/BaseStationReader.Logic/Configuration/TrackerSettingsBuilder.cs b/src/BaseStationReader.Logic/Configuration/TrackerSettingsBuilder.cs index 51c240e..b2d728f 100644 --- a/src/BaseStationReader.Logic/Configuration/TrackerSettingsBuilder.cs +++ b/src/BaseStationReader.Logic/Configuration/TrackerSettingsBuilder.cs @@ -9,37 +9,15 @@ public class TrackerSettingsBuilder : ITrackerSettingsBuilder /// /// Construct the application settings from the configuration file and any command line arguments /// - /// + /// /// /// -# pragma warning disable S3776 - public TrackerApplicationSettings? BuildSettings(IEnumerable args, string configJsonPath) +#pragma warning disable S3776 + public TrackerApplicationSettings? BuildSettings(ICommandLineParser parser, string configJsonPath) { // Read the config file to provide default settings var settings = new TrackerConfigReader().Read(configJsonPath); - // Parse the command line - var parser = new CommandLineParser(); - parser.Add(CommandLineOptionType.Host, false, "--host", "-h", "Host to connect to for data stream", 1, 1); - parser.Add(CommandLineOptionType.Port, false, "--port", "-p", "Port to connect to for data stream", 1, 1); - parser.Add(CommandLineOptionType.SocketReadTimeout, false, "--read-timeout", "-t", "Timeout (ms) for socket read operations", 1, 1); - parser.Add(CommandLineOptionType.ApplicationTimeout, false, "--app-timeout", "-a", "Timeout (ms) after which the application will quit of no messages are recieved", 1, 1); - parser.Add(CommandLineOptionType.RestartOnTimeout, false, "--auto-restart", "-ar", "Automatically restart the tracker after a timeout", 1, 1); - parser.Add(CommandLineOptionType.TimeToRecent, false, "--recent", "-r", "Time (ms) to 'recent' staleness", 1, 1); - parser.Add(CommandLineOptionType.TimeToStale, false, "--stale", "-s", "Time (ms) to 'stale' staleness", 1, 1); - parser.Add(CommandLineOptionType.TimeToRemoval, false, "--remove", "-x", "Time (ms) to removal of stale records", 1, 1); - parser.Add(CommandLineOptionType.TimeToLock, false, "--lock", "-k", "Time (ms) to locking of active database records", 1, 1); - parser.Add(CommandLineOptionType.LogFile, false, "--log-file", "-l", "Log file path and name", 1, 1); - parser.Add(CommandLineOptionType.MinimumLogLevel, false, "--log-level", "-ll", "Minimum logging level (Debug, Info, Warning or Error)", 1, 1); - parser.Add(CommandLineOptionType.EnableSqlWriter, false, "--enable-sql-writer", "-w", "Log file path and name", 1, 1); - parser.Add(CommandLineOptionType.WriterInterval, false, "--writer-interval", "-i", "SQL write interval (ms)", 1, 1); - parser.Add(CommandLineOptionType.WriterBatchSize, false, "--writer-batch-size", "-b", "SQL write batch size", 1, 1); - parser.Add(CommandLineOptionType.RefreshInterval, false, "--ui-interval", "-ui", "Interval (ms) at which live UI's should update", 1, 1); - parser.Add(CommandLineOptionType.MaximumRows, false, "--max-rows", "-m", "Maximum number of rows displayed", 1, 1); - parser.Add(CommandLineOptionType.ReceiverLatitude, false, "--latitude", "-la", "Receiver latitude", 1, 1); - parser.Add(CommandLineOptionType.ReceiverLongitude, false, "--longitude", "-lo", "Receiver latitude", 1, 1); - parser.Parse(args); - // Apply the command line values over the defaults var values = parser.GetValues(CommandLineOptionType.Host); if (values != null) settings!.Host = values[0]; diff --git a/src/BaseStationReader.Simulator/BaseStationReader.Simulator.csproj b/src/BaseStationReader.Simulator/BaseStationReader.Simulator.csproj index 4780025..b226b80 100644 --- a/src/BaseStationReader.Simulator/BaseStationReader.Simulator.csproj +++ b/src/BaseStationReader.Simulator/BaseStationReader.Simulator.csproj @@ -2,10 +2,10 @@ Exe - net7.0 - 1.31.0.0 - 1.31.0.0 - 1.31.0 + net8.0 + 1.32.0.0 + 1.32.0.0 + 1.32.0 enable enable @@ -20,6 +20,10 @@ + + + + diff --git a/src/BaseStationReader.Simulator/Logic/HelpTabulator.cs b/src/BaseStationReader.Simulator/Logic/HelpTabulator.cs new file mode 100644 index 0000000..0fdcb40 --- /dev/null +++ b/src/BaseStationReader.Simulator/Logic/HelpTabulator.cs @@ -0,0 +1,42 @@ +using BaseStationReader.Entities.Config; +using BaseStationReader.Entities.Interfaces; +using Spectre.Console; + +namespace BaseStationReader.Simulator.Logic +{ + public class HelpTabulator : IHelpGenerator + { + /// + /// Tabulate a collection of available command line options + /// + /// + public void Generate(IEnumerable options) + { + var table = new Table(); + + table.AddColumn("Option"); + table.AddColumn("Short Form"); + table.AddColumn("Min Values"); + table.AddColumn("Max Values"); + table.AddColumn("Description"); + + foreach (var option in options) + { + var rowData = new string[] { + GetCellData(option.Name), + GetCellData(option.ShortName), + GetCellData(option.MinimumNumberOfValues.ToString()), + GetCellData(option.MaximumNumberOfValues.ToString()), + GetCellData(option.Description) + }; + + table.AddRow(rowData); + } + + AnsiConsole.Write(table); + } + + private string GetCellData(string value) + => $"[white]{value}[/]"; + } +} diff --git a/src/BaseStationReader.Simulator/Program.cs b/src/BaseStationReader.Simulator/Program.cs index 2392d6b..b1978fc 100644 --- a/src/BaseStationReader.Simulator/Program.cs +++ b/src/BaseStationReader.Simulator/Program.cs @@ -1,9 +1,11 @@ -using BaseStationReader.Entities.Interfaces; +using BaseStationReader.Entities.Config; +using BaseStationReader.Entities.Interfaces; using BaseStationReader.Entities.Logging; using BaseStationReader.Logic.Configuration; using BaseStationReader.Logic.Logging; using BaseStationReader.Logic.Simulator; using BaseStationReader.Logic.Tracking; +using BaseStationReader.Simulator.Logic; using System.Diagnostics; using System.Reflection; @@ -13,31 +15,40 @@ internal static class Program { static void Main(string[] args) { - // Read the application config file - var settings = new SimulatorSettingsBuilder().BuildSettings(args, "appsettings.json"); + // Process the command line arguments. If help's been requested, show help and exit + var parser = new SimulatorCommandLineParser(new HelpTabulator()); + parser.Parse(args); + if (parser.IsPresent(CommandLineOptionType.Help)) + { + parser.Help(); + } + else + { + // Read the application config file + var settings = new SimulatorSettingsBuilder().BuildSettings(parser, "appsettings.json"); - // Configure the log file - ITrackerLogger logger = new FileLogger(); - logger.Initialise(settings!.LogFile, settings.MinimumLogLevel); + // Configure the log file + ITrackerLogger logger = new FileLogger(); + logger.Initialise(settings!.LogFile, settings.MinimumLogLevel); - // Get the version number and application title - Assembly assembly = Assembly.GetExecutingAssembly(); - FileVersionInfo info = FileVersionInfo.GetVersionInfo(assembly.Location); + // Get the version number and application title + Assembly assembly = Assembly.GetExecutingAssembly(); + FileVersionInfo info = FileVersionInfo.GetVersionInfo(assembly.Location); #pragma warning disable S2589 - var title = $"Receiver Simulator v{info.FileVersion}: Port: {settings!.Port}"; + var title = $"Receiver Simulator v{info.FileVersion}: Port: {settings!.Port}"; #pragma warning restore S2589 - // Log the startup messages - logger.LogMessage(Severity.Info, new string('=', 80)); - logger.LogMessage(Severity.Info, title); + // Log the startup messages + logger.LogMessage(Severity.Info, new string('=', 80)); + logger.LogMessage(Severity.Info, title); - Console.WriteLine(title); - Console.WriteLine($"Output will be logged to {settings.LogFile}"); - Console.WriteLine("Press ESC to stop the simulator"); + Console.WriteLine(title); + Console.WriteLine($"Output will be logged to {settings.LogFile}"); + Console.WriteLine("Press ESC to stop the simulator"); - // Configure the aircraft and message generators - IAircraftGenerator aircraftGenerator = new AircraftGenerator(logger); - var generators = new List + // Configure the aircraft and message generators + IAircraftGenerator aircraftGenerator = new AircraftGenerator(logger); + var generators = new List { new IdentificationMessageGenerator(logger), new SurfacePositionMessageGenerator(logger), @@ -48,24 +59,25 @@ static void Main(string[] args) new AirToAirMessageGenerator(logger), new AllCallReplyMessageGenerator(logger) }; - IMessageGenerator messageGenerator = new MessageGenerator(generators); + IMessageGenerator messageGenerator = new MessageGenerator(generators); - // Configure a timer, aircraft and message generatorand the simulator - ITrackerTimer timer = new TrackerTimer(settings.SendInterval); - using (var simulator = new ReceiverSimulator(logger, timer, aircraftGenerator, messageGenerator, settings.Port, settings.AircraftLifespan, settings.NumberOfAircraft)) - { - // Run the simulator - Task.Run(() => simulator.Start()); - - // Continue until the user hits ESC to stop the simulator - do + // Configure a timer, aircraft and message generatorand the simulator + ITrackerTimer timer = new TrackerTimer(settings.SendInterval); + using (var simulator = new ReceiverSimulator(logger, timer, aircraftGenerator, messageGenerator, settings.Port, settings.AircraftLifespan, settings.NumberOfAircraft)) { - while (!Console.KeyAvailable) + // Run the simulator + Task.Run(() => simulator.Start()); + + // Continue until the user hits ESC to stop the simulator + do { - Thread.Sleep(100); + while (!Console.KeyAvailable) + { + Thread.Sleep(100); + } } + while (Console.ReadKey().Key != ConsoleKey.Escape); } - while (Console.ReadKey().Key != ConsoleKey.Escape); } } } diff --git a/src/BaseStationReader.Terminal/BaseStationReader.Terminal.csproj b/src/BaseStationReader.Terminal/BaseStationReader.Terminal.csproj index 3ec1847..52fd9f8 100644 --- a/src/BaseStationReader.Terminal/BaseStationReader.Terminal.csproj +++ b/src/BaseStationReader.Terminal/BaseStationReader.Terminal.csproj @@ -2,10 +2,10 @@ Exe - net7.0 - 1.31.0.0 - 1.31.0.0 - 1.31.0 + net8.0 + 1.32.0.0 + 1.32.0.0 + 1.32.0 enable enable @@ -23,11 +23,11 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/src/BaseStationReader.Terminal/Logic/HelpTabulator.cs b/src/BaseStationReader.Terminal/Logic/HelpTabulator.cs new file mode 100644 index 0000000..6098fc1 --- /dev/null +++ b/src/BaseStationReader.Terminal/Logic/HelpTabulator.cs @@ -0,0 +1,42 @@ +using BaseStationReader.Entities.Config; +using BaseStationReader.Entities.Interfaces; +using Spectre.Console; + +namespace BaseStationReader.Terminal.Logic +{ + public class HelpTabulator : IHelpGenerator + { + /// + /// Tabulate a collection of available command line options + /// + /// + public void Generate(IEnumerable options) + { + var table = new Table(); + + table.AddColumn("Option"); + table.AddColumn("Short Form"); + table.AddColumn("Min Values"); + table.AddColumn("Max Values"); + table.AddColumn("Description"); + + foreach (var option in options) + { + var rowData = new string[] { + GetCellData(option.Name), + GetCellData(option.ShortName), + GetCellData(option.MinimumNumberOfValues.ToString()), + GetCellData(option.MaximumNumberOfValues.ToString()), + GetCellData(option.Description) + }; + + table.AddRow(rowData); + } + + AnsiConsole.Write(table); + } + + private string GetCellData(string value) + => $"[white]{value}[/]"; + } +} diff --git a/src/BaseStationReader.Terminal/Program.cs b/src/BaseStationReader.Terminal/Program.cs index c610a3e..74470f1 100644 --- a/src/BaseStationReader.Terminal/Program.cs +++ b/src/BaseStationReader.Terminal/Program.cs @@ -25,49 +25,59 @@ public static class Program public static async Task Main(string[] args) { - // Read the application config file - _settings = new TrackerSettingsBuilder().BuildSettings(args, "appsettings.json"); + // Process the command line arguments. If help's been requested, show help and exit + var parser = new TrackerCommandLineParser(new HelpTabulator()); + parser.Parse(args); + if (parser.IsPresent(CommandLineOptionType.Help)) + { + parser.Help(); + } + else + { + // Read the application config file + _settings = new TrackerSettingsBuilder().BuildSettings(parser, "appsettings.json"); - // Configure the log file - _logger = new FileLogger(); - _logger.Initialise(_settings!.LogFile, _settings.MinimumLogLevel); + // Configure the log file + _logger = new FileLogger(); + _logger.Initialise(_settings!.LogFile, _settings.MinimumLogLevel); - // Get the version number and application title - Assembly assembly = Assembly.GetExecutingAssembly(); - FileVersionInfo info = FileVersionInfo.GetVersionInfo(assembly.Location); + // Get the version number and application title + Assembly assembly = Assembly.GetExecutingAssembly(); + FileVersionInfo info = FileVersionInfo.GetVersionInfo(assembly.Location); #pragma warning disable S2589 - var title = $"Aircraft Tracker v{info.FileVersion}: {_settings?.Host}:{_settings?.Port}"; + var title = $"Aircraft Tracker v{info.FileVersion}: {_settings?.Host}:{_settings?.Port}"; #pragma warning restore S2589 - // Log the startup messages - _logger.LogMessage(Severity.Info, new string('=', 80)); - _logger.LogMessage(Severity.Info, title); - - // Initialise the tracker wrapper - _wrapper = new TrackerWrapper(_logger, _settings!); - _wrapper.Initialise(); - _wrapper.AircraftAdded += OnAircraftAdded; - _wrapper.AircraftUpdated += OnAircraftUpdated; - _wrapper.AircraftRemoved += OnAircraftRemoved; - - do - { - // Configure the table - var trackerIndexManager = new TrackerIndexManager(); - _tableManager = new TrackerTableManager(trackerIndexManager, _settings!.Columns, _settings!.MaximumRows); - _tableManager.CreateTable(title); - - // Construct the live view - await AnsiConsole.Live(_tableManager.Table!) - .AutoClear(true) - .Overflow(VerticalOverflow.Ellipsis) - .Cropping(VerticalOverflowCropping.Bottom) - .StartAsync(async ctx => - { - await ShowTrackingTable(ctx); - }); + // Log the startup messages + _logger.LogMessage(Severity.Info, new string('=', 80)); + _logger.LogMessage(Severity.Info, title); + + // Initialise the tracker wrapper + _wrapper = new TrackerWrapper(_logger, _settings!); + _wrapper.Initialise(); + _wrapper.AircraftAdded += OnAircraftAdded; + _wrapper.AircraftUpdated += OnAircraftUpdated; + _wrapper.AircraftRemoved += OnAircraftRemoved; + + do + { + // Configure the table + var trackerIndexManager = new TrackerIndexManager(); + _tableManager = new TrackerTableManager(trackerIndexManager, _settings!.Columns, _settings!.MaximumRows); + _tableManager.CreateTable(title); + + // Construct the live view + await AnsiConsole.Live(_tableManager.Table!) + .AutoClear(true) + .Overflow(VerticalOverflow.Ellipsis) + .Cropping(VerticalOverflowCropping.Bottom) + .StartAsync(async ctx => + { + await ShowTrackingTable(ctx); + }); + } + while (_settings!.RestartOnTimeout); } - while (_settings!.RestartOnTimeout); } /// diff --git a/src/BaseStationReader.Terminal/appsettings.json b/src/BaseStationReader.Terminal/appsettings.json index 188ec35..ddffda3 100644 --- a/src/BaseStationReader.Terminal/appsettings.json +++ b/src/BaseStationReader.Terminal/appsettings.json @@ -87,6 +87,6 @@ ] }, "ConnectionStrings": { - "BaseStationReaderDB": "Data Source=C:\\MyApps\\aircrafttracker.db" + "BaseStationReaderDB": "Data Source=C:\\MyApps\\BaseStationReader\\aircrafttracker.db" } } \ No newline at end of file diff --git a/src/BaseStationReader.Tests/BaseStationReader.Tests.csproj b/src/BaseStationReader.Tests/BaseStationReader.Tests.csproj index 0927081..e8a5eee 100644 --- a/src/BaseStationReader.Tests/BaseStationReader.Tests.csproj +++ b/src/BaseStationReader.Tests/BaseStationReader.Tests.csproj @@ -1,7 +1,7 @@ - net7.0 + net8.0 enable enable @@ -24,14 +24,14 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - - + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/BaseStationReader.Tests/SimulatorSettingsBuilderTest.cs b/src/BaseStationReader.Tests/SimulatorSettingsBuilderTest.cs index 87aaed2..c4ddcf3 100644 --- a/src/BaseStationReader.Tests/SimulatorSettingsBuilderTest.cs +++ b/src/BaseStationReader.Tests/SimulatorSettingsBuilderTest.cs @@ -1,4 +1,5 @@ -using BaseStationReader.Entities.Logging; +using BaseStationReader.Entities.Interfaces; +using BaseStationReader.Entities.Logging; using BaseStationReader.Logic.Configuration; namespace BaseStationReader.Tests @@ -6,10 +7,21 @@ namespace BaseStationReader.Tests [TestClass] public class SimulatorSettingsBuilderTest { + private ISimulatorSettingsBuilder? _builder = null; + private ICommandLineParser? _parser = null; + + [TestInitialize] + public void Initialise() + { + _builder = new SimulatorSettingsBuilder(); + _parser = new SimulatorCommandLineParser(null); + } + [TestMethod] public void DefaultConfigTest() { - var settings = new SimulatorSettingsBuilder().BuildSettings(Array.Empty(), "simulatorsettings.json"); + _parser!.Parse(Array.Empty()); + var settings = _builder!.BuildSettings(_parser, "simulatorsettings.json"); Assert.AreEqual(30003, settings?.Port); Assert.AreEqual(1000, settings?.SendInterval); @@ -23,7 +35,8 @@ public void DefaultConfigTest() public void OverridePortTest() { var args = new string[] { "--port", "12345" }; - var settings = new SimulatorSettingsBuilder().BuildSettings(args, "simulatorsettings.json"); + _parser!.Parse(args); + var settings = _builder!.BuildSettings(_parser, "simulatorsettings.json"); Assert.AreEqual(12345, settings?.Port); } @@ -31,7 +44,8 @@ public void OverridePortTest() public void OverrideSendIntervalTest() { var args = new string[] { "--send-interval", "33456" }; - var settings = new SimulatorSettingsBuilder().BuildSettings(args, "simulatorsettings.json"); + _parser!.Parse(args); + var settings = _builder!.BuildSettings(_parser, "simulatorsettings.json"); Assert.AreEqual(33456, settings?.SendInterval); } @@ -39,7 +53,8 @@ public void OverrideSendIntervalTest() public void OverrideNumberOfAircraftTest() { var args = new string[] { "--number", "126" }; - var settings = new SimulatorSettingsBuilder().BuildSettings(args, "simulatorsettings.json"); + _parser!.Parse(args); + var settings = _builder!.BuildSettings(_parser, "simulatorsettings.json"); Assert.AreEqual(126, settings?.NumberOfAircraft); } @@ -47,7 +62,8 @@ public void OverrideNumberOfAircraftTest() public void OverrideAircraftLifespanTest() { var args = new string[] { "--lifespan", "543" }; - var settings = new SimulatorSettingsBuilder().BuildSettings(args, "simulatorsettings.json"); + _parser!.Parse(args); + var settings = _builder!.BuildSettings(_parser, "simulatorsettings.json"); Assert.AreEqual(543, settings?.AircraftLifespan); } @@ -55,7 +71,8 @@ public void OverrideAircraftLifespanTest() public void OverrideLogFileTest() { var args = new string[] { "--log-file", "MyLog.log" }; - var settings = new SimulatorSettingsBuilder().BuildSettings(args, "simulatorsettings.json"); + _parser!.Parse(args); + var settings = _builder!.BuildSettings(_parser, "simulatorsettings.json"); Assert.AreEqual("MyLog.log", settings?.LogFile); } @@ -63,7 +80,8 @@ public void OverrideLogFileTest() public void OverrideMinimumLogLevelTest() { var args = new string[] { "--log-level", "Debug" }; - var settings = new SimulatorSettingsBuilder().BuildSettings(args, "simulatorsettings.json"); + _parser!.Parse(args); + var settings = _builder!.BuildSettings(_parser, "simulatorsettings.json"); Assert.AreEqual(Severity.Debug, settings?.MinimumLogLevel); } } diff --git a/src/BaseStationReader.Tests/TrackerSettingsBuilderTest.cs b/src/BaseStationReader.Tests/TrackerSettingsBuilderTest.cs index 06d0ae3..2d827d6 100644 --- a/src/BaseStationReader.Tests/TrackerSettingsBuilderTest.cs +++ b/src/BaseStationReader.Tests/TrackerSettingsBuilderTest.cs @@ -1,4 +1,5 @@ -using BaseStationReader.Entities.Logging; +using BaseStationReader.Entities.Interfaces; +using BaseStationReader.Entities.Logging; using BaseStationReader.Logic.Configuration; namespace BaseStationReader.Tests @@ -6,10 +7,21 @@ namespace BaseStationReader.Tests [TestClass] public class TrackerSettingsBuilderTest { + private ITrackerSettingsBuilder? _builder = null; + private ICommandLineParser? _parser = null; + + [TestInitialize] + public void Initialise() + { + _builder = new TrackerSettingsBuilder(); + _parser = new TrackerCommandLineParser(null); + } + [TestMethod] public void DefaultConfigTest() { - var settings = new TrackerSettingsBuilder().BuildSettings(Array.Empty(), "trackersettings.json"); + _parser!.Parse(Array.Empty()); + var settings = _builder!.BuildSettings(_parser, "trackersettings.json"); Assert.AreEqual("192.168.0.98", settings?.Host); Assert.AreEqual(30003, settings?.Port); @@ -41,7 +53,8 @@ public void DefaultConfigTest() public void OverrideHostTest() { var args = new string[] { "--host", "127.0.0.1" }; - var settings = new TrackerSettingsBuilder().BuildSettings(args, "trackersettings.json"); + _parser!.Parse(args); + var settings = _builder!.BuildSettings(_parser, "trackersettings.json"); Assert.AreEqual("127.0.0.1", settings?.Host); } @@ -49,7 +62,8 @@ public void OverrideHostTest() public void OverridePortTest() { var args = new string[] { "--port", "12345" }; - var settings = new TrackerSettingsBuilder().BuildSettings(args, "trackersettings.json"); + _parser!.Parse(args); + var settings = _builder!.BuildSettings(_parser, "trackersettings.json"); Assert.AreEqual(12345, settings?.Port); } @@ -57,7 +71,8 @@ public void OverridePortTest() public void OverrideSocketReadTimeoutTest() { var args = new string[] { "--read-timeout", "33456" }; - var settings = new TrackerSettingsBuilder().BuildSettings(args, "trackersettings.json"); + _parser!.Parse(args); + var settings = _builder!.BuildSettings(_parser, "trackersettings.json"); Assert.AreEqual(33456, settings?.SocketReadTimeout); } @@ -65,7 +80,8 @@ public void OverrideSocketReadTimeoutTest() public void OverrideApplicationTimeoutTest() { var args = new string[] { "--app-timeout", "45198" }; - var settings = new TrackerSettingsBuilder().BuildSettings(args, "trackersettings.json"); + _parser!.Parse(args); + var settings = _builder!.BuildSettings(_parser, "trackersettings.json"); Assert.AreEqual(45198, settings?.ApplicationTimeout); } @@ -73,7 +89,8 @@ public void OverrideApplicationTimeoutTest() public void OverrideRestartOnTimeoutTest() { var args = new string[] { "--auto-restart", "false" }; - var settings = new TrackerSettingsBuilder().BuildSettings(args, "trackersettings.json"); + _parser!.Parse(args); + var settings = _builder!.BuildSettings(_parser, "trackersettings.json"); Assert.IsFalse(settings?.RestartOnTimeout); } @@ -81,7 +98,8 @@ public void OverrideRestartOnTimeoutTest() public void OverrideTimeToRecentTest() { var args = new string[] { "--recent", "25000" }; - var settings = new TrackerSettingsBuilder().BuildSettings(args, "trackersettings.json"); + _parser!.Parse(args); + var settings = _builder!.BuildSettings(_parser, "trackersettings.json"); Assert.AreEqual(25000, settings?.TimeToRecent); } @@ -89,7 +107,8 @@ public void OverrideTimeToRecentTest() public void OverrideTimeToStaleTest() { var args = new string[] { "--stale", "31000" }; - var settings = new TrackerSettingsBuilder().BuildSettings(args, "trackersettings.json"); + _parser!.Parse(args); + var settings = _builder!.BuildSettings(_parser, "trackersettings.json"); Assert.AreEqual(31000, settings?.TimeToStale); } @@ -97,7 +116,8 @@ public void OverrideTimeToStaleTest() public void OverrideTimeToRemovalTest() { var args = new string[] { "--remove", "39000" }; - var settings = new TrackerSettingsBuilder().BuildSettings(args, "trackersettings.json"); + _parser!.Parse(args); + var settings = _builder!.BuildSettings(_parser, "trackersettings.json"); Assert.AreEqual(39000, settings?.TimeToRemoval); } @@ -105,7 +125,8 @@ public void OverrideTimeToRemovalTest() public void OverrideTimeToLockTest() { var args = new string[] { "--lock", "501896" }; - var settings = new TrackerSettingsBuilder().BuildSettings(args, "trackersettings.json"); + _parser!.Parse(args); + var settings = _builder!.BuildSettings(_parser, "trackersettings.json"); Assert.AreEqual(501896, settings?.TimeToLock); } @@ -113,7 +134,8 @@ public void OverrideTimeToLockTest() public void OverrideLogFileTest() { var args = new string[] { "--log-file", "MyLog.log" }; - var settings = new TrackerSettingsBuilder().BuildSettings(args, "trackersettings.json"); + _parser!.Parse(args); + var settings = _builder!.BuildSettings(_parser, "trackersettings.json"); Assert.AreEqual("MyLog.log", settings?.LogFile); } @@ -121,7 +143,8 @@ public void OverrideLogFileTest() public void OverrideMinimumLogLevelTest() { var args = new string[] { "--log-level", "Debug" }; - var settings = new TrackerSettingsBuilder().BuildSettings(args, "trackersettings.json"); + _parser!.Parse(args); + var settings = _builder!.BuildSettings(_parser, "trackersettings.json"); Assert.AreEqual(Severity.Debug, settings?.MinimumLogLevel); } @@ -129,7 +152,8 @@ public void OverrideMinimumLogLevelTest() public void OverrideEnableSqlWriterTest() { var args = new string[] { "--enable-sql-writer", "true" }; - var settings = new TrackerSettingsBuilder().BuildSettings(args, "trackersettings.json"); + _parser!.Parse(args); + var settings = _builder!.BuildSettings(_parser, "trackersettings.json"); Assert.IsTrue(settings?.EnableSqlWriter); } @@ -137,7 +161,8 @@ public void OverrideEnableSqlWriterTest() public void OverrideWriterIntervalTest() { var args = new string[] { "--writer-interval", "15000" }; - var settings = new TrackerSettingsBuilder().BuildSettings(args, "trackersettings.json"); + _parser!.Parse(args); + var settings = _builder!.BuildSettings(_parser, "trackersettings.json"); Assert.AreEqual(15000, settings?.WriterInterval); } @@ -145,7 +170,8 @@ public void OverrideWriterIntervalTest() public void OverrideWriterBatchSizeTest() { var args = new string[] { "--writer-batch-size", "5000" }; - var settings = new TrackerSettingsBuilder().BuildSettings(args, "trackersettings.json"); + _parser!.Parse(args); + var settings = _builder!.BuildSettings(_parser, "trackersettings.json"); Assert.AreEqual(5000, settings?.WriterBatchSize); } @@ -153,7 +179,8 @@ public void OverrideWriterBatchSizeTest() public void OverrideWriterRefreshIntervalTest() { var args = new string[] { "--ui-interval", "45000" }; - var settings = new TrackerSettingsBuilder().BuildSettings(args, "trackersettings.json"); + _parser!.Parse(args); + var settings = _builder!.BuildSettings(_parser, "trackersettings.json"); Assert.AreEqual(45000, settings?.RefreshInterval); } @@ -161,7 +188,8 @@ public void OverrideWriterRefreshIntervalTest() public void OverrideMaximumRowsTest() { var args = new string[] { "--max-rows", "0" }; - var settings = new TrackerSettingsBuilder().BuildSettings(args, "trackersettings.json"); + _parser!.Parse(args); + var settings = _builder!.BuildSettings(_parser, "trackersettings.json"); Assert.AreEqual(0, settings?.MaximumRows); } @@ -169,7 +197,8 @@ public void OverrideMaximumRowsTest() public void OverrideReceiverLatitudeTest() { var args = new string[] { "--latitude", "58.93" }; - var settings = new TrackerSettingsBuilder().BuildSettings(args, "trackersettings.json"); + _parser!.Parse(args); + var settings = _builder!.BuildSettings(_parser, "trackersettings.json"); Assert.AreEqual(58.93, Math.Round((double)settings!.ReceiverLatitude!, 2, MidpointRounding.AwayFromZero)); } @@ -177,7 +206,8 @@ public void OverrideReceiverLatitudeTest() public void OverrideReceiverLongitueTest() { var args = new string[] { "--longitude", "120.56" }; - var settings = new TrackerSettingsBuilder().BuildSettings(args, "trackersettings.json"); + _parser!.Parse(args); + var settings = _builder!.BuildSettings(_parser, "trackersettings.json"); Assert.AreEqual(120.56, Math.Round((double)settings!.ReceiverLongitude!, 2, MidpointRounding.AwayFromZero)); } } diff --git a/src/BaseStationReader.UI/BaseStationReader.UI.csproj b/src/BaseStationReader.UI/BaseStationReader.UI.csproj index 909306b..d491aa5 100644 --- a/src/BaseStationReader.UI/BaseStationReader.UI.csproj +++ b/src/BaseStationReader.UI/BaseStationReader.UI.csproj @@ -1,10 +1,10 @@  WinExe - net7.0 - 1.31.0.0 - 1.31.0.0 - 1.31.0 + net8.0 + 1.32.0.0 + 1.32.0.0 + 1.32.0 enable true app.manifest @@ -31,14 +31,14 @@ - - - - - + + + + + - - + + diff --git a/src/BaseStationReader.UI/appsettings.json b/src/BaseStationReader.UI/appsettings.json index 2dce38b..318fc75 100644 --- a/src/BaseStationReader.UI/appsettings.json +++ b/src/BaseStationReader.UI/appsettings.json @@ -133,6 +133,6 @@ ] }, "ConnectionStrings": { - "BaseStationReaderDB": "Data Source=C:\\MyApps\\aircrafttracker.db" + "BaseStationReaderDB": "Data Source=C:\\MyApps\\BaseStationReader\\aircrafttracker.db" } } \ No newline at end of file From 5675057a672f1073a0896de75ee544b29b4d36c7 Mon Sep 17 00:00:00 2001 From: Dave Walker <56451830+davewalker5@users.noreply.github.com> Date: Fri, 16 Aug 2024 10:44:57 +0100 Subject: [PATCH 2/2] Update dotnet.yml --- .github/workflows/dotnet.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index 0dc3454..a44bf45 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -12,7 +12,7 @@ jobs: - name: Setup .NET Core uses: actions/setup-dotnet@v1 with: - dotnet-version: 7.0.302 + dotnet-version: 8.0.101 - name: Set up JDK 11 uses: actions/setup-java@v1 with: