Exemplo n.º 1
0
        /// <summary>
        /// Completes the currencies list.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <param name="tagName">Name of the tag.</param>
        /// <param name="currencyName">Name of the currency.</param>
        /// <param name="currencyRate">The currency rate.</param>
        /// <returns></returns>
        private List <CurrencyLoader> CompleteCurrenciesList(string path, string tagName, string currencyName, string currencyRate)
        {
            var xmlStr = DataStringLoader.GetDataString(path);
            var xmlDoc = new XmlDocument();

            xmlDoc.LoadXml(xmlStr);
            var nList = xmlDoc.GetElementsByTagName(tagName);

            if (nList.Count == 0)
            {
                return(_currencyList);
            }
            foreach (XmlNode node in nList)
            {
                var currAttr = node.Attributes.GetNamedItem(currencyName);
                var rateAttr = node.Attributes.GetNamedItem(currencyRate);
                if (currAttr == null || rateAttr == null)
                {
                    continue;
                }
                decimal.TryParse(rateAttr.Value, out var value);
                _currencyList.Add
                (
                    new CurrencyLoader
                {
                    Currency = currAttr.Value,
                    Rate     = value
                }
                );
            }
            return(_currencyList);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Completes the currencies list.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <returns></returns>
        private List <CurrencyLoader> CompleteCurrenciesList(string path)
        {
            var jsonStr = DataStringLoader.GetDataString(path);

            if (jsonStr is null)
            {
                throw new ArgumentNullException(nameof(jsonStr));
            }
            var jsonDictionary = JObject.Parse(jsonStr).ToDictionary();

            if (jsonDictionary.Count > 0)
            {
                foreach (var(nKey, nVal) in jsonDictionary)
                {
                    if (nKey.Equals("base"))
                    {
                        _currencyList.Add(new CurrencyLoader
                        {
                            Currency = nVal.ToString(),
                            Rate     = 1
                        }
                                          );
                    }

                    if (!nKey.Equals("rates"))
                    {
                        continue;
                    }
                    var objRates = nVal.ToDictionary <string>();
                    foreach (var(rKey, rVal) in objRates)
                    {
                        decimal.TryParse(rVal, out var value);
                        _currencyList.Add(new CurrencyLoader
                        {
                            Currency = rKey.ToString(),
                            Rate     = value
                        }
                                          );
                    }
                }
            }
            return(_currencyList);
        }