-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from davewalker5/BSR-36-Row-Limit
Support optional row limit
- Loading branch information
Showing
18 changed files
with
449 additions
and
192 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
src/BaseStationReader.Terminal/Interfaces/ITrackerIndexManager.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace BaseStationReader.Terminal.Interfaces | ||
{ | ||
internal interface ITrackerIndexManager | ||
{ | ||
void AddAircraft(string address, int rowNumber); | ||
int FindAircraft(string address); | ||
int RemoveAircraft(string address); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/BaseStationReader.Terminal/Interfaces/ITrackerSettingsBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using BaseStationReader.Entities.Config; | ||
|
||
namespace BaseStationReader.Terminal.Interfaces | ||
{ | ||
internal interface ITrackerSettingsBuilder | ||
{ | ||
ApplicationSettings? BuildSettings(IEnumerable<string> args, string configJsonPath); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/BaseStationReader.Terminal/Interfaces/ITrackerTableManager.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using BaseStationReader.Entities.Tracking; | ||
using Spectre.Console; | ||
|
||
namespace BaseStationReader.Terminal.Interfaces | ||
{ | ||
internal interface ITrackerTableManager | ||
{ | ||
Table? Table { get; } | ||
|
||
int AddAircraft(Aircraft aircraft); | ||
void CreateTable(string title); | ||
int RemoveAircraft(Aircraft aircraft); | ||
void UpdateAircraft(Aircraft aircraft); | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
src/BaseStationReader.Terminal/Logic/TrackerIndexManager.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
using BaseStationReader.Terminal.Interfaces; | ||
using System.Diagnostics.CodeAnalysis; | ||
|
||
namespace BaseStationReader.Terminal.Logic | ||
{ | ||
[ExcludeFromCodeCoverage] | ||
internal class TrackerIndexManager : ITrackerIndexManager | ||
{ | ||
private readonly Dictionary<string, int> _rowIndex = new(); | ||
|
||
/// <summary> | ||
/// Add an aircraft ICAO address to the index associated with a given row number | ||
/// </summary> | ||
/// <param name="address"></param> | ||
/// <param name="rowNumber"></param> | ||
public void AddAircraft(string address, int rowNumber) | ||
{ | ||
lock (_rowIndex) | ||
{ | ||
Shuffle(rowNumber, 1); | ||
_rowIndex.Add(address, rowNumber); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Find an aircraft ICAO address in the index and return its row number | ||
/// </summary> | ||
/// <param name="address"></param> | ||
/// <returns></returns> | ||
public int FindAircraft(string address) | ||
{ | ||
int rowNumber = -1; | ||
|
||
lock (_rowIndex) | ||
{ | ||
if (_rowIndex.ContainsKey(address)) | ||
{ | ||
rowNumber = _rowIndex[address]; | ||
} | ||
} | ||
|
||
return rowNumber; | ||
} | ||
|
||
/// <summary> | ||
/// Remove the entry for the specified ICAO address and return the row it was at before removal | ||
/// </summary> | ||
/// <param name="address"></param> | ||
/// <returns></returns> | ||
public int RemoveAircraft(string address) | ||
{ | ||
int rowNumber = -1; | ||
|
||
lock (_rowIndex) | ||
{ | ||
if (_rowIndex.ContainsKey(address)) | ||
{ | ||
rowNumber = _rowIndex[address]; | ||
_rowIndex.Remove(address); | ||
Shuffle(rowNumber, -1); | ||
} | ||
} | ||
|
||
return rowNumber; | ||
} | ||
|
||
/// <summary> | ||
/// Shuffle the index for all rows *after* the one specified, either up or down. The assumption is that | ||
/// the caller will take out a lock to prevent concurrent attempts | ||
/// </summary> | ||
/// <param name="fromRow"></param> | ||
private void Shuffle(int fromRow, int increment) | ||
{ | ||
foreach (var entry in _rowIndex) | ||
{ | ||
if (entry.Value >= fromRow) | ||
{ | ||
_rowIndex[entry.Key] += increment; | ||
} | ||
} | ||
} | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
src/BaseStationReader.Terminal/Logic/TrackerSettingsBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
using BaseStationReader.Entities.Config; | ||
using BaseStationReader.Logic; | ||
using BaseStationReader.Terminal.Interfaces; | ||
using System.Diagnostics.CodeAnalysis; | ||
|
||
namespace BaseStationReader.Terminal.Logic | ||
{ | ||
[ExcludeFromCodeCoverage] | ||
internal class TrackerSettingsBuilder : ITrackerSettingsBuilder | ||
{ | ||
/// <summary> | ||
/// Construct the application settings from the configuration file and any command line arguments | ||
/// </summary> | ||
/// <param name="args"></param> | ||
/// <param name="configJsonPath"></param> | ||
/// <returns></returns> | ||
public ApplicationSettings? BuildSettings(IEnumerable<string> args, string configJsonPath) | ||
{ | ||
// Read the config file to provide default settings | ||
var settings = ConfigReader.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.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) removal of stale records", 1, 1); | ||
parser.Add(CommandLineOptionType.LogFile, false, "--log-file", "-l", "Log file path and name", 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.MaximumRows, false, "--max-rows", "-m", "Maximum number of rows displayed", 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]; | ||
|
||
values = parser.GetValues(CommandLineOptionType.Port); | ||
if (values != null) settings!.Port = int.Parse(values[0]); | ||
|
||
values = parser.GetValues(CommandLineOptionType.SocketReadTimeout); | ||
if (values != null) settings!.SocketReadTimeout = int.Parse(values[0]); | ||
|
||
values = parser.GetValues(CommandLineOptionType.ApplicationTimeout); | ||
if (values != null) settings!.ApplicationTimeout = int.Parse(values[0]); | ||
|
||
values = parser.GetValues(CommandLineOptionType.TimeToRecent); | ||
if (values != null) settings!.TimeToRecent = int.Parse(values[0]); | ||
|
||
values = parser.GetValues(CommandLineOptionType.TimeToStale); | ||
if (values != null) settings!.TimeToStale = int.Parse(values[0]); | ||
|
||
values = parser.GetValues(CommandLineOptionType.TimeToRemoval); | ||
if (values != null) settings!.TimeToRemoval = int.Parse(values[0]); | ||
|
||
values = parser.GetValues(CommandLineOptionType.LogFile); | ||
if (values != null) settings!.LogFile = values[0]; | ||
|
||
values = parser.GetValues(CommandLineOptionType.EnableSqlWriter); | ||
if (values != null) settings!.EnableSqlWriter = bool.Parse(values[0]); | ||
|
||
values = parser.GetValues(CommandLineOptionType.WriterInterval); | ||
if (values != null) settings!.WriterInterval = int.Parse(values[0]); | ||
|
||
values = parser.GetValues(CommandLineOptionType.WriterBatchSize); | ||
if (values != null) settings!.WriterBatchSize = int.Parse(values[0]); | ||
|
||
values = parser.GetValues(CommandLineOptionType.MaximumRows); | ||
if (values != null) settings!.MaximumRows = int.Parse(values[0]); | ||
|
||
return settings; | ||
} | ||
} | ||
} |
Oops, something went wrong.