Exemple #1
0
 public MonetaryValue(CurrencyConversionText originalText, string text)
 {
     this._originalText = originalText;
     _text     = text;
     _value    = decimal.Parse(text.Substring(0, text.IndexOf(" ", StringComparison.Ordinal)));
     _currency = text.Substring(text.IndexOf(" ", StringComparison.Ordinal) + 1);
 }
        public static void Main(string[] args)
        {
            BnbCurrencyData bnbData = new BnbCurrencyData();

            bnbData.Get();

            if (!File.Exists(INPUT_FILE_NAME))
            {
                Console.WriteLine($"Failed to find '{INPUT_FILE_NAME}' file in the execution path. Aborting.");
                return;
            }

            string inputText = File.ReadAllText(INPUT_FILE_NAME);
            CurrencyConversionText conversionText = new CurrencyConversionText(inputText, bnbData.Currencies);

            string outputCurrency = ReadCurrencyParameter(bnbData.Currencies);

            foreach (CurrencyConversionText.MonetaryValue monetaryValue in conversionText)
            {
                decimal newValue = bnbData.Convert(monetaryValue.Currency, outputCurrency, monetaryValue.Value);

                monetaryValue.Set(newValue, outputCurrency);
            }

            File.WriteAllText(OUTPUT_FILE_NAME, conversionText.Text);

            Console.WriteLine("Result has been saved successfully.");
        }