Exemplo n.º 1
0
        /// <summary>
        /// Create a new Chain to be able to change specified currencies
        /// </summary>
        /// <param name="initialCurrency">Initial currency to change</param>
        /// <param name="targetCurrency">Target currency to change</param>
        /// <returns>Chain builded if it exist, else null</returns>
        /// <remarks>Strategy to determine is:<Br/>
        /// First try to get a ExchangeRate without intermediary change<Br/>
        /// If it's not possible, then build all available chain and keep the fastest path<Br/>
        /// If no way null is returned.
        /// </remarks>
        public IExchangeChain Create(string initialCurrency, string targetCurrency)
        {
            if (string.IsNullOrEmpty(initialCurrency))
            {
                throw new ArgumentNullException("initialCurrency");
            }
            if (string.IsNullOrEmpty(targetCurrency))
            {
                throw new ArgumentNullException("targetCurrency");
            }

            var directExchange = GetFirstOrDefaultDirectExchange(initialCurrency, targetCurrency);

            if (directExchange != null)
            {
                return(DirectExchange.Create(directExchange, initialCurrency, targetCurrency));
            }

            return(GetFastestChain(initialCurrency, targetCurrency));
        }