Skip to content

Commit

Permalink
Update to flight plan ICAO search
Browse files Browse the repository at this point in the history
  • Loading branch information
sushiat committed Dec 13, 2023
1 parent f8d7943 commit 364df18
Showing 1 changed file with 146 additions and 122 deletions.
268 changes: 146 additions & 122 deletions OpenSky.Client/Pages/Models/FlightPlanViewModel.Airports.cs
Original file line number Diff line number Diff line change
Expand Up @@ -253,59 +253,67 @@ public string AlternateICAO
return;
}

var needsNewSearch = !string.Equals(this.alternateICAO, value, StringComparison.InvariantCultureIgnoreCase);
this.alternateICAO = value;
this.NotifyPropertyChanged();
this.IsDirty = true;

if (!string.IsNullOrEmpty(value))
if (needsNewSearch)
{
// Search for matching airports
this.AlternateAirports.Clear();
var airportPackage = AirportPackageClientHandler.GetPackage();
if (airportPackage != null)
if (!string.IsNullOrEmpty(value))
{
this.AlternateAirports.AddRange(
airportPackage.Airports
.Where(
a => a.ICAO.ToLowerInvariant().Contains(value.ToLowerInvariant()) || a.Name.ToLowerInvariant().Contains(value.ToLowerInvariant()) ||
(a.City != null && a.City.ToLowerInvariant().Contains(value.ToLowerInvariant()))).Select(a => $"{a.ICAO}: {a.Name}{(string.IsNullOrWhiteSpace(a.City) ? string.Empty : $" / {a.City}")}"));
// Search for matching airports
this.AlternateAirports.Clear();
var airportPackage = AirportPackageClientHandler.GetPackage();
if (airportPackage != null)
{
this.AlternateAirports.AddRange(
airportPackage.Airports
.Where(
a => a.ICAO.ToLowerInvariant().Contains(value.ToLowerInvariant())).Select(a => $"{a.ICAO}: {a.Name}{(string.IsNullOrWhiteSpace(a.City) ? string.Empty : $" / {a.City}")}"));
this.AlternateAirports.AddRange(
airportPackage.Airports
.Where(
a => a.Name.ToLowerInvariant().Contains(value.ToLowerInvariant()) ||
(a.City != null && a.City.ToLowerInvariant().Contains(value.ToLowerInvariant()))).Select(a => $"{a.ICAO}: {a.Name}{(string.IsNullOrWhiteSpace(a.City) ? string.Empty : $" / {a.City}")}"));
}
}
}
else
{
// Restore full list of airports
this.AlternateAirports.Clear();
var airportPackage = AirportPackageClientHandler.GetPackage();
if (airportPackage != null)
else
{
this.AlternateAirports.AddRange(airportPackage.Airports.Select(a => $"{a.ICAO}: {a.Name}{(string.IsNullOrWhiteSpace(a.City) ? string.Empty : $" / {a.City}")}"));
// Restore full list of airports
this.AlternateAirports.Clear();
var airportPackage = AirportPackageClientHandler.GetPackage();
if (airportPackage != null)
{
this.AlternateAirports.AddRange(airportPackage.Airports.Select(a => $"{a.ICAO}: {a.Name}{(string.IsNullOrWhiteSpace(a.City) ? string.Empty : $" / {a.City}")}"));
}
}
}

UpdateGUIDelegate updateAirports = () =>
{
if (!this.UpdateAirportsCommand.IsExecuting)
UpdateGUIDelegate updateAirports = () =>
{
this.UpdateAirportsCommand.DoExecute(null);
}
else
{
new Thread(
() =>
{
var waited = 0;
while (this.UpdateAirportsCommand.IsExecuting && waited < 2000)
if (!this.UpdateAirportsCommand.IsExecuting)
{
this.UpdateAirportsCommand.DoExecute(null);
}
else
{
new Thread(
() =>
{
Thread.Sleep(100);
waited += 100;
}
var waited = 0;
while (this.UpdateAirportsCommand.IsExecuting && waited < 2000)
{
Thread.Sleep(100);
waited += 100;
}

UpdateGUIDelegate tryAgain = () => this.UpdateAirportsCommand.DoExecute(null);
Application.Current.Dispatcher.BeginInvoke(tryAgain);
}).Start();
}
};
Application.Current.Dispatcher.BeginInvoke(updateAirports);
UpdateGUIDelegate tryAgain = () => this.UpdateAirportsCommand.DoExecute(null);
Application.Current.Dispatcher.BeginInvoke(tryAgain);
}).Start();
}
};
Application.Current.Dispatcher.BeginInvoke(updateAirports);
}
}
}

Expand Down Expand Up @@ -503,59 +511,67 @@ public string DestinationICAO
return;
}

var needsNewSearch = !string.Equals(this.destinationICAO, value, StringComparison.InvariantCultureIgnoreCase);
this.destinationICAO = value;
this.NotifyPropertyChanged();
this.IsDirty = true;

if (!string.IsNullOrEmpty(value))
if (needsNewSearch)
{
// Search for matching airports
this.DestinationAirports.Clear();
var airportPackage = AirportPackageClientHandler.GetPackage();
if (airportPackage != null)
if (!string.IsNullOrEmpty(value))
{
this.DestinationAirports.AddRange(
airportPackage.Airports
.Where(
a => a.ICAO.ToLowerInvariant().Contains(value.ToLowerInvariant()) || a.Name.ToLowerInvariant().Contains(value.ToLowerInvariant()) ||
(a.City != null && a.City.ToLowerInvariant().Contains(value.ToLowerInvariant()))).Select(a => $"{a.ICAO}: {a.Name}{(string.IsNullOrWhiteSpace(a.City) ? string.Empty : $" / {a.City}")}"));
// Search for matching airports
this.DestinationAirports.Clear();
var airportPackage = AirportPackageClientHandler.GetPackage();
if (airportPackage != null)
{
this.DestinationAirports.AddRange(
airportPackage.Airports
.Where(
a => a.ICAO.ToLowerInvariant().Contains(value.ToLowerInvariant())).Select(a => $"{a.ICAO}: {a.Name}{(string.IsNullOrWhiteSpace(a.City) ? string.Empty : $" / {a.City}")}"));
this.DestinationAirports.AddRange(
airportPackage.Airports
.Where(
a => a.Name.ToLowerInvariant().Contains(value.ToLowerInvariant()) ||
(a.City != null && a.City.ToLowerInvariant().Contains(value.ToLowerInvariant()))).Select(a => $"{a.ICAO}: {a.Name}{(string.IsNullOrWhiteSpace(a.City) ? string.Empty : $" / {a.City}")}"));
}
}
}
else
{
// Restore full list of airports
this.DestinationAirports.Clear();
var airportPackage = AirportPackageClientHandler.GetPackage();
if (airportPackage != null)
else
{
this.DestinationAirports.AddRange(airportPackage.Airports.Select(a => $"{a.ICAO}: {a.Name}{(string.IsNullOrWhiteSpace(a.City) ? string.Empty : $" / {a.City}")}"));
// Restore full list of airports
this.DestinationAirports.Clear();
var airportPackage = AirportPackageClientHandler.GetPackage();
if (airportPackage != null)
{
this.DestinationAirports.AddRange(airportPackage.Airports.Select(a => $"{a.ICAO}: {a.Name}{(string.IsNullOrWhiteSpace(a.City) ? string.Empty : $" / {a.City}")}"));
}
}
}

UpdateGUIDelegate updateAirports = () =>
{
if (!this.UpdateAirportsCommand.IsExecuting)
{
this.UpdateAirportsCommand.DoExecute(null);
}
else
UpdateGUIDelegate updateAirports = () =>
{
new Thread(
() =>
{
var waited = 0;
while (this.UpdateAirportsCommand.IsExecuting && waited < 2000)
if (!this.UpdateAirportsCommand.IsExecuting)
{
this.UpdateAirportsCommand.DoExecute(null);
}
else
{
new Thread(
() =>
{
Thread.Sleep(100);
waited += 100;
}
var waited = 0;
while (this.UpdateAirportsCommand.IsExecuting && waited < 2000)
{
Thread.Sleep(100);
waited += 100;
}

UpdateGUIDelegate tryAgain = () => this.UpdateAirportsCommand.DoExecute(null);
Application.Current.Dispatcher.BeginInvoke(tryAgain);
}).Start();
}
};
Application.Current.Dispatcher.BeginInvoke(updateAirports);
UpdateGUIDelegate tryAgain = () => this.UpdateAirportsCommand.DoExecute(null);
Application.Current.Dispatcher.BeginInvoke(tryAgain);
}).Start();
}
};
Application.Current.Dispatcher.BeginInvoke(updateAirports);
}
}
}

Expand Down Expand Up @@ -658,62 +674,70 @@ public string OriginICAO
return;
}

var needsNewSearch = !string.Equals(this.originICAO, value, StringComparison.InvariantCultureIgnoreCase);
this.originICAO = value;
this.NotifyPropertyChanged();
this.IsDirty = true;

if (!string.IsNullOrEmpty(value))
if (needsNewSearch)
{
// Search for matching airports
this.OriginAirports.Clear();
var airportPackage = AirportPackageClientHandler.GetPackage();
if (airportPackage != null)
if (!string.IsNullOrEmpty(value))
{
this.OriginAirports.AddRange(
airportPackage.Airports
.Where(
a => a.ICAO.ToLowerInvariant().Contains(value.ToLowerInvariant()) || a.Name.ToLowerInvariant().Contains(value.ToLowerInvariant()) ||
(a.City != null && a.City.ToLowerInvariant().Contains(value.ToLowerInvariant()))).Select(a => $"{a.ICAO}: {a.Name}{(string.IsNullOrWhiteSpace(a.City) ? string.Empty : $" / {a.City}")}"));
// Search for matching airports
this.OriginAirports.Clear();
var airportPackage = AirportPackageClientHandler.GetPackage();
if (airportPackage != null)
{
this.OriginAirports.AddRange(
airportPackage.Airports
.Where(
a => a.ICAO.ToLowerInvariant().Contains(value.ToLowerInvariant())).Select(a => $"{a.ICAO}: {a.Name}{(string.IsNullOrWhiteSpace(a.City) ? string.Empty : $" / {a.City}")}"));
this.OriginAirports.AddRange(
airportPackage.Airports
.Where(
a => a.Name.ToLowerInvariant().Contains(value.ToLowerInvariant()) ||
(a.City != null && a.City.ToLowerInvariant().Contains(value.ToLowerInvariant()))).Select(a => $"{a.ICAO}: {a.Name}{(string.IsNullOrWhiteSpace(a.City) ? string.Empty : $" / {a.City}")}"));
}
}
}
else
{
// Restore full list of airports
this.OriginAirports.Clear();
var airportPackage = AirportPackageClientHandler.GetPackage();
if (airportPackage != null)
else
{
this.OriginAirports.AddRange(airportPackage.Airports.Select(a => $"{a.ICAO}: {a.Name}{(string.IsNullOrWhiteSpace(a.City) ? string.Empty : $" / {a.City}")}"));
// Restore full list of airports
this.OriginAirports.Clear();
var airportPackage = AirportPackageClientHandler.GetPackage();
if (airportPackage != null)
{
this.OriginAirports.AddRange(airportPackage.Airports.Select(a => $"{a.ICAO}: {a.Name}{(string.IsNullOrWhiteSpace(a.City) ? string.Empty : $" / {a.City}")}"));
}
}
}

UpdateGUIDelegate updateAirports = () =>
{
if (!this.UpdateAirportsCommand.IsExecuting)
UpdateGUIDelegate updateAirports = () =>
{
this.UpdateAirportsCommand.DoExecute(null);
}
else
{
new Thread(
() =>
{
var waited = 0;
while (this.UpdateAirportsCommand.IsExecuting && waited < 2000)
if (!this.UpdateAirportsCommand.IsExecuting)
{
this.UpdateAirportsCommand.DoExecute(null);
}
else
{
new Thread(
() =>
{
Thread.Sleep(100);
waited += 100;
}
var waited = 0;
while (this.UpdateAirportsCommand.IsExecuting && waited < 2000)
{
Thread.Sleep(100);
waited += 100;
}

UpdateGUIDelegate tryAgain = () => this.UpdateAirportsCommand.DoExecute(null);
Application.Current.Dispatcher.BeginInvoke(tryAgain);
}).Start();
}
UpdateGUIDelegate tryAgain = () => this.UpdateAirportsCommand.DoExecute(null);
Application.Current.Dispatcher.BeginInvoke(tryAgain);
}).Start();
}

this.UpdateAircraftDistances();
this.UpdatePlannablePayloads();
};
Application.Current.Dispatcher.BeginInvoke(updateAirports);
this.UpdateAircraftDistances();
this.UpdatePlannablePayloads();
};
Application.Current.Dispatcher.BeginInvoke(updateAirports);
}
}
}

Expand Down

0 comments on commit 364df18

Please sign in to comment.