Updated Populate Method to get data from DB
Runs extremely quickly ~150ms on my system in debug mode (10,000 records)
This commit is contained in:
parent
f0da93cdae
commit
cd488440b9
@ -23,7 +23,7 @@ namespace EFB.Models
|
||||
Longitude = longitude;
|
||||
}
|
||||
|
||||
public NavdataModel(int id, string name, int frequency, string latitude, string longitude){
|
||||
public NavdataModel(int id, string name, int? frequency, string latitude, string longitude){
|
||||
Id = id;
|
||||
Name = name;
|
||||
Frequency = frequency;
|
||||
@ -31,20 +31,44 @@ namespace EFB.Models
|
||||
Longitude = longitude;
|
||||
}
|
||||
|
||||
public NavdataModel[] Populate(){
|
||||
MySqlConnection con = new MySqlConnection("root:XXXXXXX@XXX.XXX.XXX.XXX:3306/EFB");
|
||||
public static async Task<NavdataModel[]> Populate(){
|
||||
MySqlConnection con = new MySqlConnection("server=server.luke-else.co.uk;userid=root;password=;database=EFB");
|
||||
con.Open();
|
||||
|
||||
|
||||
|
||||
// Console.WriteLine($"MySQL version : {con.ServerVersion}");
|
||||
|
||||
string query = "SELECT * FROM waypoints";
|
||||
MySqlCommand command = new MySqlCommand(query, con);
|
||||
|
||||
MySqlDataReader reader = (MySqlDataReader) await command.ExecuteReaderAsync();
|
||||
|
||||
List<NavdataModel> navdata = new List<NavdataModel>();
|
||||
|
||||
while (reader.Read())
|
||||
{
|
||||
int id = reader.GetInt32(0);
|
||||
string name = reader.GetString(1);
|
||||
string type = reader.GetString(2);
|
||||
string latitude = reader.GetString(4);
|
||||
string longitude = reader.GetString(5);
|
||||
|
||||
if (reader.GetString(2) == "VOR" || reader.GetString(2) == "NDB")
|
||||
{
|
||||
// int? frequency = reader.GetInt32(3);
|
||||
int? frequency = null;
|
||||
navdata.Add(
|
||||
new NavdataModel(id, name, frequency, latitude, longitude)
|
||||
);
|
||||
}else{
|
||||
navdata.Add(
|
||||
new NavdataModel(id, name, latitude, longitude)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return navdata.ToArray<NavdataModel>();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user