private void GetButtonClick(object sender, RoutedEventArgs e) { if (int.TryParse(amountTextBox.Text, out int amount) && amount >= 0) { EarthquakeService earthquakeInfo = GetEarthquakes(amount); List <ShortInfo> information = new List <ShortInfo>(); for (int i = 0; i < amount; i++) { information.Add(new ShortInfo { Depth = earthquakeInfo.Features[i].Information.Depth, Magnitude = earthquakeInfo.Features[i].Information.Magnitude, Place = earthquakeInfo.Features[i].Information.Place, }); if (!(earthquakeInfo.Features[i].Information.Time is null)) { double time = (double)earthquakeInfo.Features[i].Information.Time; information[i].Time = ConvertFromUnixTimestamp(time); } } dataGrid.ItemsSource = information; } }
private EarthquakeService GetEarthquakes(int amount) { WebClient client = new WebClient(); string json = ""; using (Stream stream = client.OpenRead(new Uri(_url + amount.ToString()))) { using (var reader = new StreamReader(stream)) { string line = ""; while ((line = reader.ReadLine()) != null) { json += line; } } } EarthquakeService earthquakeService = JsonConvert.DeserializeObject <EarthquakeService>(json); return(earthquakeService); }
public List <Feature> GetAllFeaturesData() { EarthquakeService StringFromJson = new EarthquakeService(); return(StringFromJson.GetEarthquakesFeatures()); }