Esempio n. 1
0
        public void Parse(ref string content, USD dollar, RUB rubl, EUR euro)
        {
            var arr = content
                      .Replace("[", "").Replace("]", "")
                      .Replace("{", "")
                      .Replace("}", "")
                      .Replace("\"personal_data\":", "")
                      .Split(new string[] { ",\"" },
                             StringSplitOptions.None);

            if (arr.Count() <= 1)
            {
                throw new ArgumentException("Сервис не вернул данных");
            }

            foreach (string prop in arr)
            {
                string value   = prop.Replace("\"", "").Replace(@"\", "");
                var    propArr = value.Split(':');

                if (propArr[0].Equals("USD_in"))
                {
                    dollar.Rate_in = double.Parse(propArr[1], CultureInfo.InvariantCulture);
                }
                else if (propArr[0].Equals("USD_out"))
                {
                    dollar.Rate_out = double.Parse(propArr[1], CultureInfo.InvariantCulture);
                }
                else if (propArr[0].Equals("RUB_in"))
                {
                    rubl.Rate_in = double.Parse(propArr[1], CultureInfo.InvariantCulture);
                }
                else if (propArr[0].Equals("RUB_out"))
                {
                    rubl.Rate_out = double.Parse(propArr[1], CultureInfo.InvariantCulture);
                }
                else if (propArr[0].Equals("EUR_in"))
                {
                    euro.Rate_in = double.Parse(propArr[1], CultureInfo.InvariantCulture);
                }
                else if (propArr[0].Equals("EUR_out"))
                {
                    euro.Rate_out = double.Parse(propArr[1], CultureInfo.InvariantCulture);
                }

                if (dollar.Rate_in != 0 && dollar.Rate_out != 0 && rubl.Rate_in != 0 && rubl.Rate_out != 0 && euro.Rate_in != 0 && euro.Rate_out != 0)
                {
                    break;
                }
            }
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            WebClient wc     = new WebClient();
            string    answer = wc.DownloadString("https://belarusbank.by/api/kursExchange");
            USD       dollar = new USD();
            RUB       rubl   = new RUB();
            EUR       euro   = new EUR();

            ParseRates babki;
            Parsing    money = new Parsing();

            money.Parse(ref answer, dollar, rubl, euro);
            dollar.ShowInfo();
            rubl.ShowInfo();
            euro.ShowInfo();
        }