internal async Task <IEnumerable <Fuel> > GetCompanyCityFuelPrice(string company, string city) { ReadCSV cachedCSV = new ReadCSV(); var cachedFuel = cachedCSV.Read(); // cachedFuel.ForEach(x => System.Console.WriteLine(x.City)); if (cachedFuel.Count > 0 && cachedFuel.First().EffectiveDate.AddDays(1) > DateTime.Today) { if (city != null) { return(cachedFuel.Where(f => f.City == city).ToList().OrderBy(o => o.City)); } return(cachedFuel.OrderBy(o => o.City)); } else { using (HttpClient client = new HttpClient()) { client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); var result = await client.PostAsync("https://www.bharatpetroleum.com/AjaxSmartFleetMap.aspx/SetSmartFleetMap", new StringContent("", Encoding.UTF8, "application/json")); var responseString = await result.Content.ReadAsStringAsync(); JObject rss = JObject.Parse(responseString); JArray jArray = (JArray)rss.SelectToken("d"); List <Fuel> fuel = jArray.Select(a => new Fuel { Company = "Bharat Petroleum", City = a.SelectToken("city").Value <string>(), EffectiveDate = DateTime.ParseExact(a.SelectToken("effDate").Value <string>().Replace(" Hrs", ""), "dd-MM-yyyy hh:mm", CultureInfo.InvariantCulture), FuelType = ((JArray)a.SelectToken("productList")).Select(f => new FuelType { Type = f.SelectToken("name").Value <string>(), Price = f.SelectToken("rsp").Value <decimal?>() }).ToList() }) .ToList(); if (city != null) { fuel = fuel.Where(f => f.City == city).ToList(); } WriteCSV csv = new WriteCSV(); csv.Write(fuel); return(fuel.OrderBy(o => o.City)); } } }
private void buttonLuoExcel_Click(object sender, RoutedEventArgs e) { labelFileCreated.Content = ""; if (DatePickerStart.SelectedDate >= DatePickerEnd.SelectedDate) { labelEndDateTooLow.Content = "Loppu pvm pitää olla suurempi kuin alku pvm"; } else if (listBoxPlaces.Items.Count == 0) { labelNoPlacesError.Content = "Vähintään yksi paikka pitää olla annettu"; } else if (labelTotalDays.Content.ToString() != "" || DatePickerStart.SelectedDate == null || DatePickerEnd.SelectedDate == null) { labelNoPlacesError.Content = "Tarkista päivämäärät"; } else { labelEndDateTooLow.Content = ""; labelNoPlacesError.Content = ""; labelFileCreated.Content = "Luodaan tiedostoa..."; string[] places = new string[listBoxPlaces.Items.Count]; for (int i = 0; i < listBoxPlaces.Items.Count; i++) { places[i] = listBoxPlaces.Items.GetItemAt(i).ToString(); } string file = FileDialog.AskFile(places, Convert.ToDateTime(DatePickerStart.SelectedDate), Convert.ToDateTime(DatePickerEnd.SelectedDate)); string[] urls = ParseUrl.GetUrl(textBoxAPIKey.Text, Convert.ToDateTime(DatePickerStart.SelectedDate), Convert.ToDateTime(DatePickerEnd.SelectedDate), places, textBoxTimeStep.Text); List <Temperature> measurements = new List <Temperature>(); //measurements = ReadData.ReadTemperature(measurements, urls); ReadData.ReadTemperature(measurements, urls); WriteCSV.Write(measurements, file); labelFileCreated.Content = "Tiedosto luotu"; } }
public void TestMethodVersion1Dat() { ArrayList exoplanetArray = null; ReadCSV.Read(Constant.UnitTestDATFolder + "Version1.dat"); exoplanetArray = ReadXML.Read(Constant.UnitTestDATFolder + "Version1.xml", true); WriteCSV.Write(Constant.UnitTestDATFolder + "Version1TestResults.dat", exoplanetArray, Constant.Version2); ArrayList exoplanetArray2 = null; ReadCSV.Read(Constant.UnitTestDATFolder + "Version1TestResults.dat"); exoplanetArray2 = ReadXML.Read(Constant.UnitTestDATFolder + "Version1TestResults.xml", true); Assert.IsNotNull(exoplanetArray); Assert.IsNotNull(exoplanetArray2); Assert.AreEqual(exoplanetArray.Count, exoplanetArray2.Count); Assert.AreEqual(Exoplanets.AreEqual(exoplanetArray, exoplanetArray2), true); }