Exemplo n.º 1
0
 /// <summary>
 /// Converts as value of a currenciy to the ratio value of another currency; both ExchangeRataData have same base currency
 /// </summary>
 /// <param name="value">The value to convert</param>
 /// <param name="currencyOfValue">The base currency</param>
 /// <param name="returnCurrency">The dependent currency</param>
 /// <returns></returns>
 /// <remarks>Returns 0, if the base currency of both is not equal</remarks>
 public static double ConvertCurrency(double value, ExchangeRateData currencyOfValue, ExchangeRateData returnCurrency)
 {
     try
     {
         if (currencyOfValue.CurrencyRelation.BaseCurrency.ID == returnCurrency.CurrencyRelation.BaseCurrency.ID)
         {
             if (currencyOfValue.CurrencyRelation.DepCurrency.ID != returnCurrency.CurrencyRelation.DepCurrency.ID)
             {
                 double fromRatio = currencyOfValue.DependencyValue;
                 double toRatio   = returnCurrency.DependencyValue;
                 if (fromRatio != 0 & toRatio != 0)
                 {
                     return(value / fromRatio * toRatio);
                 }
                 else
                 {
                     return(0);
                 }
             }
             else
             {
                 return(value);
             }
         }
         else
         {
             throw new ArgumentException("The exchange rates have not the same base currency.");
         }
     }
     catch (Exception ex)
     {
         return(0);
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Updates exchange informations
        /// </summary>
        /// <param name="baseCurrency">The currency all other currencies are depending</param>
        /// <param name="currencies">The dependent currencies</param>
        /// <remarks></remarks>
        public void Update(CurrencyInfo baseCurrency, IEnumerable <CurrencyInfo> currencies)
        {
            mDownloader.CancelAsyncAll();
            mDonwloadCounter += 1;
            mExchangeItems    = new ExchangeRateData[] { };
            ExchangeRateResponse resp = mDownloader.Download(this.GetCurrencyList(baseCurrency, currencies));

            if (resp.Connection.State == Base.ConnectionState.Success)
            {
                mExchangeItems = resp.Result.Items;
            }
        }
Exemplo n.º 3
0
 public static double ConvertCurrency(double value, ExchangeRateData exchangeRate, bool reverse = false)
 {
     if (exchangeRate != null && exchangeRate.LastTradePriceOnly != 0)
     {
         if (!reverse)
         {
             return(value * exchangeRate.LastTradePriceOnly);
         }
         else
         {
             return(value / exchangeRate.LastTradePriceOnly);
         }
     }
     else
     {
         throw new ArgumentException("The exchange rate is invalid", "exchangeRate");
     }
 }