static void Main(string[] args) { Console.WriteLine("Select your choice:"); Console.WriteLine("1:Add new printer"); Console.WriteLine("2:Print on Canon"); Console.WriteLine("3:Print on Epson"); string pathToFile = "D:\\Epam\\Epam.ASP.NET\\LabExam\\LabExam\\bin\\Debug\\log.txt"; ILogger logger = new Logger(pathToFile); PrinterManager manager = new PrinterManager(logger); while (true) { var key = Console.ReadKey(); if (key.Key == ConsoleKey.D1) { manager.CreatePrinter(); } if (key.Key == ConsoleKey.D2) { manager.Print(new Printer("1", "Canon")); } if (key.Key == ConsoleKey.D3) { manager.Print(new Printer("2", "Epson")); } for (int i = 0; i < manager.Printers.Count; i++) { Console.WriteLine("Printers " + i + ' ' + " Name: " + manager.Printers[i].Name + " Model: " + manager.Printers[i].Model); } } }
private static void Process(PrinterManager printerManager) { var key = Console.ReadKey(); if (key.Key == ConsoleKey.D1) { printerManager.CreatePrinter(); } else { int choice = Convert.ToInt32(key.KeyChar.ToString()) - 2; printerManager.Print(printerManager.Printers[choice]); } }
private static void ProcessPrinting(PrinterManager pm) { while (true) { Console.WriteLine("Select your choice:"); Console.WriteLine("0: Exit"); Console.WriteLine("1: Add new printer"); ShowListOfPrinters(pm); var key = Console.ReadKey(); if (key.Key == ConsoleKey.D0) { break; } if (key.Key == ConsoleKey.D1) { Console.WriteLine(); try { pm.CreatePrinter(); } catch (DuplicatedPrinterException e) { Console.WriteLine(e.Message); } continue; } if (key.Key >= ConsoleKey.D2 && key.Key <= ConsoleKey.D9) { pm.Print((int)key.Key - 50); } Console.WriteLine(); } }