Ejemplo n.º 1
0
        public static void InitializeCurrencies()
        {
            currencies          = new List <Currency>();
            currencyInformation = new CurrencyInformation();

            XmlDocument doc = new XmlDocument();

            try
            {
                doc.Load(URLString);
                XmlNodeList elemList = doc.GetElementsByTagName("Rate");
                for (int i = 0; i < elemList.Count; i++)
                {
                    String s = elemList[i].Attributes["currency"].Value.ToString();
                    String v = elemList[i].InnerXml;
                    v = v.Replace('.', ',');
                    Decimal value = Convert.ToDecimal(v);
                    Currency.CurrencyName currencyName = (Currency.CurrencyName)Enum.Parse(typeof(Currency.CurrencyName), s);

                    Decimal multiplier = 1;
                    if (elemList[i].Attributes["multiplier"] != null)
                    {
                        multiplier = Convert.ToDecimal(elemList[i].Attributes["multiplier"].Value.ToString());
                    }
                    currencies.Add(new Currency(currencyName, value, multiplier));
                }
                currencyInformation.SetCurrencies(currencies);
                SerializeCurrencyInformation();
            }
            catch
            {
                DeserializeCurrencyInformation();
                currencies = currencyInformation.GetCurrencies();
            }
        }
Ejemplo n.º 2
0
 private static void DeserializeCurrencyInformation()
 {
     using (Stream fileStream = new FileStream(currenciesFileName, FileMode.Open,
                                               FileAccess.Read, FileShare.Read))
     {
         IFormatter formatter = new BinaryFormatter();
         currencyInformation = (CurrencyInformation)formatter.Deserialize(fileStream);
     }
 }