This repository was archived by the owner on Jan 9, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProgram.cs
More file actions
97 lines (91 loc) · 4.11 KB
/
Program.cs
File metadata and controls
97 lines (91 loc) · 4.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
using System;
using System.CodeDom;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace VATBrief
{
class Program
{
public const string Seperator = "-------------------------------------------------------------------------------";
static void Main(string[] args)
{
Console.Title = "VATBrief";
Console.WriteLine("Downloading VATSIM data...");
VATRequestManager.updateStatus();
VATDataAPI.query();
askAirport();
}
private static void askAirport()
{
Console.WriteLine(Seperator);
Console.Write("Enter Airport (or leave it empty to update data): ");
string ap = Console.ReadLine();
ap = ap.ToUpper();
Console.Clear();
Regex r = new Regex("^[a-zA-Z]*$");
if (ap == "")
{
VATDataAPI.query();
askAirport();
}
if (!r.IsMatch(ap) || ap.Length != 4)
{
Console.WriteLine("Invalid airport code");
askAirport();
}
// Provide with info
Console.WriteLine(ap+" INFORMATION");
Console.WriteLine(Seperator);
var clients = new List<VATDataAPI.VATClient>();
clients.AddRange(VATDataAPI.GetClients());
var atis = clients.Find((e) => e.Callsign == ap + "_ATIS");
Console.WriteLine(ap+ (atis != null ? " ATIS: " +parseATIS(atis.ATIS) : " METAR: "+ VATRequestManager.queryURL(VATRequestManager.metar+"?id=" + Uri.EscapeDataString(ap))));
Console.WriteLine(Seperator);
Console.WriteLine("Controller List");
Console.WriteLine("Callsign\tName\t\t\t\tFrequency");
Console.WriteLine("--------\t----\t\t\t\t---------");
var controllers = clients.Where((e) => (e.Callsign.StartsWith(ap+"_") || (ap.StartsWith("K") && e.Callsign.StartsWith(ap.Substring(1)+"_"))) && e.IsController).ToArray();
foreach (VATDataAPI.VATClient client in controllers)
{
Console.WriteLine((client.Callsign.Length < 8 ? "_"+client.Callsign : client.Callsign)+"\t"+shortenName(client.Realname)+"\t\t"+(client.Realname.Length > 15 ? "" : "\t")+ client.Frequency);
}
Console.WriteLine(Seperator);
Console.WriteLine("Departure/Arrival list");
var departures = clients.Where((e) => e.DepartureAirport == ap).ToArray();
var arrivals = clients.Where((e) => e.DestinationAirport == ap).ToArray();
Console.WriteLine("Callsign\tName\t\t\t\tAirport\t\tDep/Arr");
Console.WriteLine("--------\t----\t\t\t\t-------\t\t-------");
foreach (VATDataAPI.VATClient client in departures)
{
Console.WriteLine((client.Callsign.Length > 7 ? client.Callsign.Substring(7) : client.Callsign) +"\t\t"+shortenName(client.Realname)+"\t\t"+ (client.Realname.Length > 15 ? "" : "\t") + client.DestinationAirport+"\t\tDep");
}
foreach (VATDataAPI.VATClient client in arrivals)
{
Console.WriteLine((client.Callsign.Length > 7 ? client.Callsign.Substring(7) : client.Callsign) + "\t\t" + shortenName(client.Realname) + "\t\t" + (client.Realname.Length > 15 ? "" : "\t") + client.DepartureAirport + "\t\tArr");
}
askAirport();
}
private static string shortenName(string name)
{
if (name.Length > 15)
{
name = name.Substring(0, name.Length - (name.Length - 15)) + "...";
}
return name;
}
private static string parseATIS(string toParse)
{
toParse = toParse.Substring(2);
var tps = toParse.Split('^');
StringBuilder builder = new StringBuilder();
for (int i = 1; i < tps.Length; i++)
{
builder.Append(tps[i].Substring(1) + "\n");
}
return builder.ToString();
}
}
}