private async void UserControl_Loaded(object sender, RoutedEventArgs e) { try { using (MNBArfolyamServiceSoapClient client2 = new MNBArfolyamServiceSoapClient()) { dloadpanel.Visibility = Visibility.Visible; var response = await client2.GetCurrentExchangeRatesAsync(new GetCurrentExchangeRatesRequestBody()); var xml = response.GetCurrentExchangeRatesResponse1; var doc = XDocument.Parse(xml.GetCurrentExchangeRatesResult); foreach (var item in doc.Elements().Elements().Elements()) { _rates.Add(item.Attribute("curr").Value, Convert.ToDouble(item.Value)); } } } catch (Exception ex) { MainWindow.ErrorDialog(ex.Message); } finally { dloadpanel.Visibility = Visibility.Collapsed; _rates.Add("HUF", 1); CbSource.ItemsSource = _rates.Keys.OrderBy(i => i); CbDestination.ItemsSource = _rates.Keys.OrderBy(i => i); } }
private async void UserControl_Loaded(object sender, RoutedEventArgs e) { try { using (MNBArfolyamServiceSoapClient client2 = new MNBArfolyamServiceSoapClient()) { dloadpanel.Visibility = Visibility.Visible; var response = await client2.GetCurrentExchangeRatesAsync(new GetCurrentExchangeRatesRequestBody()); var xml = response.GetCurrentExchangeRatesResponse1; var doc = XDocument.Parse(xml.GetCurrentExchangeRatesResult); foreach (var item in doc.Elements().Elements().Elements()) { _rates.Add(item.Attribute("curr").Value, Convert.ToDouble(item.Value)); } } } catch (Exception ex) { MainWindow.ErrorDialog(ex.Message); } finally { dloadpanel.Visibility = Visibility.Collapsed; _rates.Add("HUF", 1); var odered = _rates.Keys.OrderBy(i => i); CbSource.ItemsSource = odered; CbDestination.ItemsSource = odered; CbDestination.SelectedIndex = odered.FirstIndexOf(i => i == "HUF"); } }
/// <summary> /// Aktuális árfolyam lekérdezése /// </summary> public static async Task <decimal> GetCurrentExchangeRate(string currency) { MNBArfolyamServiceSoapClient client = new MNBArfolyamServiceSoapClient(); await client.OpenAsync(); GetCurrentExchangeRatesResponse response = await client.GetCurrentExchangeRatesAsync(new GetCurrentExchangeRatesRequestBody()); await client.CloseAsync(); return(GetCurrentExchangeRateFromString(currency, response.GetCurrentExchangeRatesResponse1.GetCurrentExchangeRatesResult)); }
private async Task <IList <CurrencyRate> > UpdateRates() { using (MNBArfolyamServiceSoapClient client = new MNBArfolyamServiceSoapClient(new BasicHttpBinding(), new EndpointAddress("http://www.mnb.hu/arfolyamok.asmx"))) { var respone = await client.GetCurrentExchangeRatesAsync(new GetCurrentExchangeRatesRequestBody()); var current = respone.GetCurrentExchangeRatesResponse1.GetCurrentExchangeRatesResult; XDocument xml = XDocument.Parse(current); List <CurrencyRate> result = new List <CurrencyRate>(); foreach (var rate in xml.Descendants("Rate")) { var parsed = new CurrencyRate { CurrencyCode = rate.Attribute("curr").Value, Unit = Convert.ToDecimal(rate.Attribute("unit").Value, new CultureInfo("hu-HU")), ValueInForint = Convert.ToDecimal(rate.Value, new CultureInfo("hu-HU")), }; result.Add(parsed); } return(result); } }