public List <CbRateViewModel> GetCbRates() { try { var reader = XmlReader.Create(BuildCbUrl(Currencies.USD, Enums.Days.Week)); var list = new List <CbRateViewModel>(); var items = ((CbRateListModel) new XmlSerializer(typeof(CbRateListModel)).Deserialize(reader)).Items; items.RemoveRange(0, items.Count - 2); var todayValue = DecimalEx.Parse(items.Last().Value); list.Add(new CbRateViewModel { Currency = "$", Value = todayValue, Diff = todayValue - DecimalEx.Parse(items.First().Value) }); reader = XmlReader.Create(BuildCbUrl(Currencies.EUR, Enums.Days.Week)); items = ((CbRateListModel) new XmlSerializer(typeof(CbRateListModel)).Deserialize(reader)).Items; items.RemoveRange(0, items.Count - 2); todayValue = DecimalEx.Parse(items.Last().Value); list.Add(new CbRateViewModel { Currency = "€", Value = todayValue, Diff = todayValue - DecimalEx.Parse(items.First().Value) }); return(list); } catch (Exception ex) { _logger.Trace("[RateService.GetCbRates] " + ex.Message); return(new List <CbRateViewModel>()); } }
/// <summary> /// Промсвязьбанк /// </summary> private void GetPromsvyazbankBankRates() { var htmlWeb = new HtmlWeb(); htmlWeb.OverrideEncoding = Encoding.GetEncoding("utf-8"); try { var reqGet = WebRequest.Create( @"http://www.psbank.ru/psbservices/SearchService.svc/GetCurrencyRatesSpecified?shortNames=%5B%22USD%22%2C%22EUR%22%5D"); var resp = reqGet.GetResponse(); var stream = resp.GetResponseStream(); var sr = new System.IO.StreamReader(stream); var jsonResult = sr.ReadToEnd(); dynamic resObj = JsonConvert.DeserializeObject(jsonResult); var date = DateTime.Parse(DateTime.UtcNow.ToShortDateString()); var usd = new CurrencyModel { ValueName = Currencies.USD, Buy = DecimalEx.Parse(Convert.ToString(resObj[0].PurchasingRate)), Sell = DecimalEx.Parse(Convert.ToString(resObj[0].SellingRate)) }; var eur = new CurrencyModel { ValueName = Currencies.EUR, Buy = DecimalEx.Parse(Convert.ToString(resObj[1].PurchasingRate)), Sell = DecimalEx.Parse(Convert.ToString(resObj[1].SellingRate)) }; _rates.Add(new RateUpdateModel { Bank = Banks.Promsvyazbank, Date = date, CityId = (int)Enums.Cities.Krsk, USD = usd, EUR = eur }); } catch (Exception ex) { _logger.Trace("[RateService.UpdateRates.Promsvyazbank] " + ex.Message); } }