Beispiel #1
0
        public SudokuFile ParseFile(string[] args)
        {
            List <string> lines = LoadFile(args);
            SudokuFile    file  = new SudokuFile();

            foreach (string l in lines)
            {
                if (!string.IsNullOrWhiteSpace(l))
                {
                    file.AddRow(ParseRow(l));
                }
            }

            return(file);
        }
Beispiel #2
0
        public static void Main(string[] args)
        {
            ServiceProvider serviceProvider = new ServiceCollection()
                                              .AddTransient <IFileParser, FileParser>()
                                              .AddTransient <IFileReader, FileReader>()
                                              .BuildServiceProvider();

            IFileParser parser = serviceProvider.GetService <IFileParser>();

            try
            {
                SudokuFile file = parser.ParseFile(args).Validate();
                Console.WriteLine($"File '{parser.FileName}' passes Suduko validation.");
            }
            catch (Exception e)
            {
                Console.WriteLine($"File '{parser.FileName}' is NOT valid: {e.Message}");
            }
        }