-
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.
Basic database search tab added to the UI
- Loading branch information
1 parent
3c86146
commit c43682e
Showing
7 changed files
with
432 additions
and
83 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
75 changes: 75 additions & 0 deletions
75
src/BaseStationReader.UI/ViewModels/DatabaseSearchViewModel.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,75 @@ | ||
using BaseStationReader.Data; | ||
using BaseStationReader.Entities.Expressions; | ||
using BaseStationReader.Entities.Tracking; | ||
using BaseStationReader.Logic.Database; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.ObjectModel; | ||
using System.Threading.Tasks; | ||
|
||
namespace BaseStationReader.UI.ViewModels | ||
{ | ||
internal class DatabaseSearchViewModel | ||
{ | ||
public ObservableCollection<Aircraft> SearchResults { get; private set; } = new(); | ||
|
||
/// <summary> | ||
/// Search the database for records matching the specified filtering criteria | ||
/// </summary> | ||
/// <param name="address"></param> | ||
/// <param name="callsign"></param> | ||
/// <param name="status"></param> | ||
/// <param name="from"></param> | ||
/// <param name="to"></param> | ||
public void Search(string? address, string? callsign, string? status, DateTime? from, DateTime? to) | ||
{ | ||
// Create an expression builder and add an expression for each non-null/blak filtering criterion | ||
ExpressionBuilder<Aircraft> builder = new ExpressionBuilder<Aircraft>(); | ||
|
||
if (!string.IsNullOrEmpty(address)) | ||
{ | ||
builder.Add("Address", TrackerFilterOperator.Equals, address); | ||
} | ||
|
||
if (!string.IsNullOrEmpty(callsign)) | ||
{ | ||
builder.Add("Callsign", TrackerFilterOperator.Equals, callsign); | ||
} | ||
|
||
if (!string.IsNullOrEmpty(status) && Enum.TryParse<TrackingStatus>(status, out TrackingStatus statusEnumValue)) | ||
{ | ||
builder.Add("Status", TrackerFilterOperator.Equals, statusEnumValue); | ||
} | ||
|
||
if (from != null) | ||
{ | ||
builder.Add("LastSeen", TrackerFilterOperator.GreaterThanOrEqual, from); | ||
} | ||
|
||
if (to != null) | ||
{ | ||
builder.Add("LastSeen", TrackerFilterOperator.LessThanOrEqual, to); | ||
} | ||
|
||
// Create a database context and an instance of the (reader) writer | ||
var context = new BaseStationReaderDbContextFactory().CreateDbContext(Array.Empty<string>()); | ||
var writer = new AircraftWriter(context); | ||
|
||
// Build the filter expression. If there is one, use it to filter the collection of aircraft used | ||
// to refresh the grid. Otherwise, just use all the current tracked aircraft | ||
var filter = builder.Build(); | ||
List<Aircraft> aircraft; | ||
if (filter != null) | ||
{ | ||
aircraft = Task.Run(() => writer.ListAsync(filter)).Result; | ||
} | ||
else | ||
{ | ||
aircraft = Task.Run(() => writer.ListAsync(x => true)).Result; | ||
} | ||
|
||
// Update the observable collection from the filtered aircraft list | ||
SearchResults = new ObservableCollection<Aircraft>(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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
using BaseStationReader.Entities.Config; | ||
using BaseStationReader.Entities.Expressions; | ||
using BaseStationReader.Entities.Interfaces; | ||
using BaseStationReader.Entities.Tracking; | ||
using BaseStationReader.Logic.Database; | ||
using BaseStationReader.Logic.Tracking; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.ObjectModel; | ||
using System.Linq; | ||
|
||
|
||
namespace BaseStationReader.UI.ViewModels | ||
{ | ||
internal class LiveViewViewModel | ||
{ | ||
private ITrackerWrapper? _wrapper = null; | ||
|
||
public ObservableCollection<Aircraft> TrackedAircraft { get; private set; } = new(); | ||
public bool IsTracking { get { return (_wrapper != null) && _wrapper.IsTracking; } } | ||
|
||
/// <summary> | ||
/// Initialise the tracker | ||
/// </summary> | ||
/// <param name="logger"></param> | ||
/// <param name="settings"></param> | ||
public void Initialise(ITrackerLogger logger, ApplicationSettings settings) | ||
{ | ||
_wrapper = new TrackerWrapper(logger, settings); | ||
_wrapper.Initialise(); | ||
} | ||
|
||
/// <summary> | ||
/// Start the tracker | ||
/// </summary> | ||
public void Start() | ||
=> _wrapper!.Start(); | ||
|
||
/// <summary> | ||
/// Stop the tracker | ||
/// </summary> | ||
public void Stop() | ||
=> _wrapper!.Stop(); | ||
|
||
/// <summary> | ||
/// Refresh the tracked aircraft collection | ||
/// </summary> | ||
/// <param name="address"></param> | ||
/// <param name="callsign"></param> | ||
/// <param name="status"></param> | ||
public void Refresh(string? address, string? callsign, string? status) | ||
{ | ||
// Build the filtering expression, if needed | ||
var builder = new ExpressionBuilder<Aircraft>(); | ||
if (!string.IsNullOrEmpty(address)) | ||
{ | ||
builder.Add("Address", TrackerFilterOperator.Equals, address.ToUpper()); | ||
} | ||
|
||
if (!string.IsNullOrEmpty(callsign)) | ||
{ | ||
builder.Add("Callsign", TrackerFilterOperator.Equals, callsign.ToUpper()); | ||
} | ||
|
||
if (!string.IsNullOrEmpty(status) && Enum.TryParse<TrackingStatus>(status, out TrackingStatus statusEnumValue)) | ||
{ | ||
builder.Add("Status", TrackerFilterOperator.Equals, statusEnumValue); | ||
} | ||
|
||
// Build the filter expression. If there is one, use it to filter the collection of aircraft used | ||
// to refresh the grid. Otherwise, just use all the current tracked aircraft | ||
var filter = builder.Build(); | ||
List<Aircraft> aircraft; | ||
if (filter != null) | ||
{ | ||
aircraft = _wrapper!.TrackedAircraft.Values.AsQueryable().Where(filter).ToList(); | ||
} | ||
else | ||
{ | ||
aircraft = _wrapper!.TrackedAircraft.Values.ToList(); | ||
} | ||
|
||
// Update the observable collection from the filtered aircraft list | ||
TrackedAircraft = new ObservableCollection<Aircraft>(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
Oops, something went wrong.