Example #1
0
        public static decimal Get(Waehrung from, Waehrung to)
        {
            // exchange rate is 1:1 for same currency
            if (from == to)
            {
                return(1);
            }

            var key = string.Format("{0}{1}", from, to); // e.g. EURUSD means "How much is 1 EUR in USD?".

            // if we've already downloaded this exchange rate, use the cached value
            if (s_rates.ContainsKey(key))
            {
                return(s_rates[key]);
            }

            // otherwise create the request URL, ...
            var url = string.Format(@"http://download.finance.yahoo.com/d/quotes.csv?s={0}=X&f=sl1d1t1c1ohgv&e=.csv", key);
            // download the response as string
            var data = new WebClient().DownloadString(url);
            // split the string at ','
            var parts = data.Split(',');
            // convert the exchange rate part to a decimal
            var rate = decimal.Parse(parts[1], CultureInfo.InvariantCulture);

            s_rates[key] = rate;

            return(rate);
        }
Example #2
0
 public void UpdatePrice(decimal newPrice, Waehrung waehrung)
 {
     if (newPrice < 0)
     {
         throw new ArgumentException("Preis muss positiv sein.", nameof(newPrice));
     }
     m_preis = new Preis(newPrice, waehrung);
 }
Example #3
0
 public Preis ConvertTo(Waehrung targetCurrency)
 {
     if (targetCurrency == Unit)
     {
         return(this);
     }
     return(new Preis(Amount * Umrechnung.Get(Unit, targetCurrency), targetCurrency));
 }
 public Geld(int betrag, Waehrung waehrung)
 {
     if (!IsValid(betrag, waehrung))
     {
         throw new InvalidGeldValueException(betrag.ToString());
     }
     this.Value    = betrag;
     this.Waehrung = waehrung;
 }
Example #5
0
        public static decimal Get(Waehrung from, Waehrung to)
        {
            if (from == to)
            {
                return(1);
            }

            var key = string.Format("{0}{1}", from, to);

            if (s_rates.ContainsKey(key))
            {
                return(s_rates[key]);
            }

            var url   = string.Format(@"http://download.finance.yahoo.com/d/quotes.csv?s={0}=X&f=sl1d1t1c1ohgv&e=.csv", key);
            var data  = new WebClient().DownloadString(url);
            var parts = data.Split(',');
            var rate  = decimal.Parse(parts[1], CultureInfo.InvariantCulture);

            s_rates[key] = rate;

            return(rate);
        }
Example #6
0
 public Bremsen(string produzent, string modell, decimal price, Waehrung waehrung)
     : this(produzent, modell, new Preis(price, waehrung))
 {
 }
Example #7
0
 public Reifen(string produzent, string modell, decimal preis, Waehrung waehrung)
     : this(produzent, modell, new Preis(preis, waehrung))
 {
 }
Example #8
0
 public Schaltwerk(string produzent, string modell, decimal price, Waehrung waehrung)
     : this(produzent, modell, new Preis(price, waehrung))
 {
 }
Example #9
0
 public Preis(decimal amount, Waehrung unit)
 {
     Amount = amount;
     Unit   = unit;
 }
Example #10
0
 private bool IsValid(int betrag, Waehrung waehrung)
 => betrag >= 0 && waehrung != Waehrung.Undefined;