public void Start() { Console.WriteLine("Entrer le chemin du fichier à utiliser."); var path = GetPath(); //will be used to display detected error to the user. StringBuilder errorMessage = new StringBuilder(); //if the input datas are incorrect, an exception will be thrown describing what we have to correct. //unhandled errors will be displayed on the console. try { GraphManager = new GraphConverterManager(); var result = GraphManager.ConvertCurrenciesFromFile(path, errorMessage); if (result.HasValue) { Console.WriteLine(result.Value); } } catch (Exception e) { errorMessage.Append(e.ToString()); } finally { if (errorMessage.Length > 0) { Console.WriteLine(errorMessage.ToString()); } } WaitCommand(); }
/// <summary> /// Read the conversion file from the path in parameter and calculate the wanted conversion from a currency to another. /// </summary> /// <param name="args">Arguments from the command line /// Should be a path to a file defining the conversion to do.</param> /// <returns></returns> public void ConvertCurrenciesFromDataFile(string[] args) { //will be used to display detected error to the user. StringBuilder errorMessage = new StringBuilder(); //if the input datas are incorrect, an exception will be thrown describing what we have to correct. //unhandled errors will be displayed on the console. try { string fileName = ReadArgs(args, errorMessage); var GraphConverterManager = new GraphConverterManager(); var result = GraphConverterManager.ConvertCurrenciesFromFile(fileName, errorMessage); if (result.HasValue) { Console.WriteLine(result.Value); } } catch (Exception e) { errorMessage.Append(e.ToString()); } finally { if (errorMessage.Length > 0) { Console.WriteLine(errorMessage.ToString()); } } }