using System.Globalization; using System.Collections.Generic; using System.Linq; using System.IO; using Newtonsoft.Json.Linq; namespace EliteBGS.EDDB { public class Stations { private JObject root = null; private Dictionary> by_system_id = null; public JObject JSON => root; private Stations() { } private void Initialise() { by_system_id = new Dictionary>(); foreach (var station in root.Properties()) { int id = int.Parse(station.Name); var names = root.Value(id.ToString()).Values().ToArray(); if (!by_system_id.ContainsKey(id)) { by_system_id[id] = new List(); } by_system_id[id].AddRange(names); } } public static Stations FromFile(string filename) { string alltext = File.ReadAllText(filename); Stations stations = new Stations { root = JObject.Parse(alltext), }; stations.Initialise(); return stations; } public string[] StationNamesBySystemId(int systemid, string filter) { if (!by_system_id.ContainsKey(systemid)) { return new string[0]; } return by_system_id[systemid] .Where(x => CultureInfo.InvariantCulture.CompareInfo.IndexOf(x, filter, CompareOptions.IgnoreCase) > -1) .ToArray() ; } } }