-
Notifications
You must be signed in to change notification settings - Fork 2
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 #87 from opensky-to/metar
Metar
- Loading branch information
Showing
6 changed files
with
239 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,176 @@ | ||
// -------------------------------------------------------------------------------------------------------------------- | ||
// <copyright file="Simulator.Metar.cs" company="OpenSky"> | ||
// OpenSky project 2021-2023 | ||
// </copyright> | ||
// -------------------------------------------------------------------------------------------------------------------- | ||
|
||
namespace OpenSky.Agent.Simulator | ||
{ | ||
using System; | ||
using System.Diagnostics; | ||
using System.Net; | ||
using System.Threading; | ||
|
||
/// ------------------------------------------------------------------------------------------------- | ||
/// <content> | ||
/// Simulator interface - Online Metar. | ||
/// </content> | ||
/// ------------------------------------------------------------------------------------------------- | ||
public partial class Simulator | ||
{ | ||
/// ------------------------------------------------------------------------------------------------- | ||
/// <summary> | ||
/// The alternate metar. | ||
/// </summary> | ||
/// ------------------------------------------------------------------------------------------------- | ||
private string alternateMetar = "???"; | ||
|
||
/// ------------------------------------------------------------------------------------------------- | ||
/// <summary> | ||
/// Destination metar. | ||
/// </summary> | ||
/// ------------------------------------------------------------------------------------------------- | ||
private string destinationMetar = "???"; | ||
|
||
/// ------------------------------------------------------------------------------------------------- | ||
/// <summary> | ||
/// The origin metar. | ||
/// </summary> | ||
/// ------------------------------------------------------------------------------------------------- | ||
private string originMetar = "???"; | ||
|
||
/// ------------------------------------------------------------------------------------------------- | ||
/// <summary> | ||
/// Gets or sets the alternate metar. | ||
/// </summary> | ||
/// ------------------------------------------------------------------------------------------------- | ||
public string AlternateMetar | ||
{ | ||
get => this.alternateMetar; | ||
|
||
set | ||
{ | ||
if (Equals(this.alternateMetar, value)) | ||
{ | ||
return; | ||
} | ||
|
||
this.alternateMetar = value; | ||
this.OnPropertyChanged(); | ||
} | ||
} | ||
|
||
/// ------------------------------------------------------------------------------------------------- | ||
/// <summary> | ||
/// Gets or sets destination metar. | ||
/// </summary> | ||
/// ------------------------------------------------------------------------------------------------- | ||
public string DestinationMetar | ||
{ | ||
get => this.destinationMetar; | ||
|
||
set | ||
{ | ||
if (Equals(this.destinationMetar, value)) | ||
{ | ||
return; | ||
} | ||
|
||
this.destinationMetar = value; | ||
this.OnPropertyChanged(); | ||
} | ||
} | ||
|
||
/// ------------------------------------------------------------------------------------------------- | ||
/// <summary> | ||
/// Gets or sets the origin metar. | ||
/// </summary> | ||
/// ------------------------------------------------------------------------------------------------- | ||
public string OriginMetar | ||
{ | ||
get => this.originMetar; | ||
|
||
set | ||
{ | ||
if (Equals(this.originMetar, value)) | ||
{ | ||
return; | ||
} | ||
|
||
this.originMetar = value; | ||
this.OnPropertyChanged(); | ||
} | ||
} | ||
|
||
/// ------------------------------------------------------------------------------------------------- | ||
/// <summary> | ||
/// Refresh metar for flight airports. | ||
/// </summary> | ||
/// <remarks> | ||
/// sushi.at, 12/12/2023. | ||
/// </remarks> | ||
/// ------------------------------------------------------------------------------------------------- | ||
public void RefreshMetar() | ||
{ | ||
new Thread( | ||
() => | ||
{ | ||
using var client = new WebClient(); | ||
try | ||
{ | ||
if (!string.IsNullOrEmpty(this.Flight?.Origin.Icao)) | ||
{ | ||
var url = $"https://aviationweather.gov/api/data/metar?ids={this.Flight.Origin.Icao}"; | ||
this.OriginMetar = client.DownloadString(url); | ||
} | ||
else | ||
{ | ||
this.OriginMetar = "???"; | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
Debug.WriteLine($"Error refreshing origin metar: {ex}"); | ||
this.OriginMetar = "???"; | ||
} | ||
try | ||
{ | ||
if (!string.IsNullOrEmpty(this.Flight?.Destination.Icao)) | ||
{ | ||
var url = $"https://aviationweather.gov/api/data/metar?ids={this.Flight.Destination.Icao}"; | ||
this.DestinationMetar = client.DownloadString(url); | ||
} | ||
else | ||
{ | ||
this.DestinationMetar = "???"; | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
Debug.WriteLine($"Error refreshing destination metar: {ex}"); | ||
this.DestinationMetar = "???"; | ||
} | ||
try | ||
{ | ||
if (!string.IsNullOrEmpty(this.Flight?.Alternate.Icao)) | ||
{ | ||
var url = $"https://aviationweather.gov/api/data/metar?ids={this.Flight.Alternate.Icao}"; | ||
this.AlternateMetar = client.DownloadString(url); | ||
} | ||
else | ||
{ | ||
this.AlternateMetar = "???"; | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
Debug.WriteLine($"Error refreshing destination metar: {ex}"); | ||
this.AlternateMetar = "???"; | ||
} | ||
}) | ||
{ Name = "OpenSky.Simulator.Metar" }.Start(); | ||
} | ||
} | ||
} |
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