Пример #1
0
        private static void ExecuteFileMode(IEquationNormalizer normalizer, string file)
        {
            if (!File.Exists(file))
            {
                Console.WriteLine($"File \"{file}\" does not exists.");
                return;
            }

            // ReSharper disable once AssignNullToNotNullAttribute
            var output = Path.Combine(Path.GetDirectoryName(file), Path.GetFileNameWithoutExtension(file) + ".out");

            using (var reader = new StreamReader(file))
                using (var writer = new StreamWriter(File.Open(output, FileMode.Create, FileAccess.Write)))
                {
                    while (!reader.EndOfStream)
                    {
                        var input = reader.ReadLine();
                        try
                        {
                            // ReSharper disable once AssignNullToNotNullAttribute
                            var result = normalizer.Normalize(input);
                            writer.WriteLine($"{input} -> {result}");
                        }
                        catch (Exception ex)
                        {
                            writer.WriteLine(ex.Message);
                        }
                    }
                }
        }
Пример #2
0
 private static void ExecuteConsoleMode(IEquationNormalizer normalizer)
 {
     while (true)
     {
         Console.WriteLine(Invintation);
         var input = Console.ReadLine();
         try
         {
             // ReSharper disable once AssignNullToNotNullAttribute
             Console.WriteLine(normalizer.Normalize(input));
         }
         catch (Exception ex)
         {
             Console.WriteLine(ex.Message);
         }
     }
 }