Ejemplo n.º 1
0
 public async void CbrDownload()
 {
     IsDownloadEnabled = false;
     using (new WaitCursor())
     {
         foreach (var model in Rows)
         {
             if (string.IsNullOrEmpty(model.RurUsdStr))
             {
                 double usd2Rur;
                 try
                 {
                     usd2Rur = await CbrRatesDownloader.GetRateForDate(model.Date);
                 }
                 catch (Exception e)
                 {
                     MessageBox.Show("Error: " + e.Message);
                     break;
                 }
                 var rate = _rates.First(r => r.Date == model.Date);
                 rate.CbrRate.Usd = new OneRate()
                 {
                     Unit = 1, Value = usd2Rur
                 };
                 model.RurUsdStr = usd2Rur.ToString("#,#.##", new CultureInfo("ru-RU"));
             }
         }
     }
     IsDownloadEnabled = true;
 }
Ejemplo n.º 2
0
        public async void Download()
        {
            IsDownloadEnabled = false;
            using (new WaitCursor())
            {
                var date   = Rows.Last().Date.AddDays(1);
                var annual = Rows.Last(r => r.Date.Day == 31 && r.Date.Month == 12);
                while (date <= DateTime.Today.Date.AddDays(1))
                {
                    var nbRbRates = await NbRbRatesDownloader.GetRatesForDate(date);

                    if (nbRbRates == null)
                    {
                        break;
                    }
                    var officialRates = new OfficialRates()
                    {
                        Date = date, NbRates = nbRbRates
                    };
                    var usd2Rur = await CbrRatesDownloader.GetRateForDate(date);

                    officialRates.CbrRate.Usd = new OneRate()
                    {
                        Unit = 1, Value = usd2Rur
                    };

                    _rates.Add(officialRates);
                    var line = new OfficialRatesModel(officialRates, Rows.Last(), annual);
                    Rows.Add(line);

                    if (date.Date.Day == 31 && date.Date.Month == 12)
                    {
                        annual = line;
                    }
                    date = date.AddDays(1);
                }
            }
            IsDownloadEnabled = true;
        }