Advertisement
Guest User

Untitled

a guest
Oct 21st, 2014
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.85 KB | None | 0 0
  1. public IEnumerable<IConvertionRate> ListConvertionRates(DateTime? date = null)
  2.         {
  3.             if (date.HasValue)
  4.             {
  5.                 throw new NotSupportedException("only allowed null value");
  6.             }
  7.             var currencyPairs = GetCurrencyPairs().ToArray();
  8.             var convertionRates = new List<IConvertionRate>();
  9.             Parallel.For(0, (int) Math.Ceiling((double) currencyPairs.Length/PartSize), i =>
  10.             {
  11.                 var client = new RestClient("https://query.yahooapis.com/v1/public");
  12.                 var request = new RestRequest(
  13.                     string.Format(RequestFormatString, GetQuery(currencyPairs.Skip(PartSize*i).Take(PartSize))));
  14.                 var response = client.Get(request);
  15.                 var rates = JObject.Parse(response.Content)
  16.                     .SelectToken("query.results.rate")
  17.                     .Select(GetConvertionRate);
  18.                 lock (_lock)
  19.                 {
  20.                     convertionRates.AddRange(rates);
  21.                 }
  22.             });
  23.             return convertionRates;
  24.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement