-
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 #24 from davewalker5/BSR-42-AircraftDuplications
Modify the record locking code to avoid unnecessary aircraft record duplications
- Loading branch information
Showing
23 changed files
with
353 additions
and
138 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
PRAGMA journal_mode=WAL; | ||
|
||
SELECT Address, COUNT(1) AS 'Number' | ||
FROM AIRCRAFT | ||
GROUP BY Address | ||
ORDER BY COUNT(1) DESC; |
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.Entities/Interfaces/IAircraftLockManager.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.Tracking; | ||
|
||
namespace BaseStationReader.Logic | ||
{ | ||
public interface IAircraftLockManager | ||
{ | ||
Task<Aircraft?> GetActiveAircraft(string address); | ||
} | ||
} |
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,40 @@ | ||
using BaseStationReader.Entities.Interfaces; | ||
using BaseStationReader.Entities.Tracking; | ||
|
||
namespace BaseStationReader.Logic | ||
{ | ||
public class AircraftLockManager : IAircraftLockManager | ||
{ | ||
private readonly IAircraftWriter _writer; | ||
private readonly int _timeToLock; | ||
|
||
public AircraftLockManager(IAircraftWriter writer, int timeToLockMs) | ||
{ | ||
_writer = writer; | ||
_timeToLock = timeToLockMs; | ||
} | ||
|
||
/// <summary> | ||
/// Get the active aircraft with the specified address | ||
/// </summary> | ||
/// <param name="address"></param> | ||
/// <returns></returns> | ||
public async Task<Aircraft?> GetActiveAircraft(string address) | ||
{ | ||
// Get the aircraft. This method is guaranteed to return the most recent record for a given aircraft | ||
// address | ||
Aircraft? aircraft = await _writer.GetAsync(x => x.Address == address); | ||
|
||
// If the last seen date has exceeded the time to lock timeout, this record should no longer be active | ||
if ((aircraft != null) && ((DateTime.Now - aircraft.LastSeen).TotalMilliseconds >= _timeToLock)) | ||
{ | ||
// Timeout has been exceeded, so lock the record and return null | ||
aircraft.Locked = true; | ||
await _writer.WriteAsync(aircraft); | ||
aircraft = null; | ||
} | ||
|
||
return aircraft; | ||
} | ||
} | ||
} |
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
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
Oops, something went wrong.