RouteDatabase.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using Newtonsoft.Json;
  2. using Newtonsoft.Json.Linq;
  3. using System.Collections.Generic;
  4. using System.Collections.ObjectModel;
  5. using System.Diagnostics;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Threading.Tasks;
  9. namespace Breda_Tour.Data
  10. {
  11. class RouteDatabase
  12. {
  13. public List<Route> Routes;
  14. public RouteDatabase()
  15. {
  16. Routes = new List<Route>();
  17. readRoutes();
  18. }
  19. private void readRoutes()
  20. {
  21. string json = File.ReadAllText("Storage/Routes/routes.json");
  22. JObject JsonObject = JObject.Parse(json);
  23. IList<JToken> JsonList = JsonObject["Routes"].ToList();
  24. foreach (JToken route in JsonList)
  25. {
  26. Routes.Add(JsonConvert.DeserializeObject<Route>(route.ToString()));
  27. }
  28. }
  29. public ObservableCollection<Route> GetCurrentRoutes()
  30. {
  31. ObservableCollection<Route> routes = new ObservableCollection<Route>();
  32. foreach (var route in Routes)
  33. {
  34. if (route.Language == App.Language)
  35. routes.Add(route);
  36. }
  37. return routes;
  38. }
  39. }
  40. }