/// <summary> /// Parse Json data from Open Exchange Rates web service /// </summary> /// <param name="jsonString">received json string</param> /// <returns>list of parsed exchange rates history object</returns> public static List<ExchangeRatesHistory> ParseHistoricalJsonString(string jsonString) { List<ExchangeRatesHistory> parsedObjects = new List<ExchangeRatesHistory>(); JObject parsedJObject = JObject.Parse(jsonString); if (parsedJObject.HasValues && parsedJObject.SelectToken("rates") != null && parsedJObject.SelectToken("timestamp") != null) { double timestamp = parsedJObject.SelectToken("timestamp").Value<double>(); //convert from javascript timestamp to DateTime DateTime parsedDate = new DateTime(1970, 1, 1, 0, 0, 0).AddSeconds(timestamp).Date; foreach (var allowedCurrency in Parameters.Instance.Config.AllowedCurrencyCodes) { AllowedCurrencyConfigElement configElement = (AllowedCurrencyConfigElement)allowedCurrency; if (parsedJObject.SelectToken("rates").SelectToken(configElement.Code) != null) { double parsedRate = parsedJObject.SelectToken("rates").SelectToken(configElement.Code).Value<double>(); ExchangeRatesHistory parsedRateHistoryItem = new ExchangeRatesHistory { CurrencyRate = parsedRate, Date = parsedDate, Currency = new Currency { ServiceCode = configElement.Code } }; parsedObjects.Add(parsedRateHistoryItem); } } } return parsedObjects; }
/// <summary> /// Create a new ExchangeRatesHistory object. /// </summary> /// <param name="id">Initial value of the Id property.</param> /// <param name="date">Initial value of the Date property.</param> /// <param name="currencyId">Initial value of the CurrencyId property.</param> /// <param name="currencyRate">Initial value of the CurrencyRate property.</param> public static ExchangeRatesHistory CreateExchangeRatesHistory(global::System.Int32 id, global::System.DateTime date, global::System.Int32 currencyId, global::System.Double currencyRate) { ExchangeRatesHistory exchangeRatesHistory = new ExchangeRatesHistory(); exchangeRatesHistory.Id = id; exchangeRatesHistory.Date = date; exchangeRatesHistory.CurrencyId = currencyId; exchangeRatesHistory.CurrencyRate = currencyRate; return(exchangeRatesHistory); }
/// <summary> /// Create a new ExchangeRatesHistory object. /// </summary> /// <param name="id">Initial value of the Id property.</param> /// <param name="date">Initial value of the Date property.</param> /// <param name="currencyId">Initial value of the CurrencyId property.</param> /// <param name="currencyRate">Initial value of the CurrencyRate property.</param> public static ExchangeRatesHistory CreateExchangeRatesHistory(global::System.Int32 id, global::System.DateTime date, global::System.Int32 currencyId, global::System.Double currencyRate) { ExchangeRatesHistory exchangeRatesHistory = new ExchangeRatesHistory(); exchangeRatesHistory.Id = id; exchangeRatesHistory.Date = date; exchangeRatesHistory.CurrencyId = currencyId; exchangeRatesHistory.CurrencyRate = currencyRate; return exchangeRatesHistory; }
/// <summary> /// Deprecated Method for adding a new object to the ExchangeRatesHistories EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToExchangeRatesHistories(ExchangeRatesHistory exchangeRatesHistory) { base.AddObject("ExchangeRatesHistories", exchangeRatesHistory); }
/// <summary> /// Deprecated Method for adding a new object to the ExchangeRatesHistories EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToExchangeRatesHistories(ExchangeRatesHistory exchangeRatesHistory) { base.AddObject("ExchangeRatesHistories", exchangeRatesHistory); }