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 ShowListOfPrinters(PrinterManager pm) { if (pm == null) { Console.WriteLine($"PrinterManager {nameof(pm)} is null - nothing to show"); } if (pm.Printers == null) { Console.WriteLine($"PrinterManager {nameof(pm)} has empty list of printers - nothing to show"); } if (pm.Printers.Count > 8) { Console.WriteLine($"PrinterManager {nameof(pm)} has more than 8 printers - only 8 will be shown"); } int i = 2; foreach (var printer in pm.Printers) { Console.WriteLine($"{i}: Print on {printer.Name}, model {printer.Model}"); i++; } }
static void Main(string[] args) { PrinterManager manager = new PrinterManager(); Console.WriteLine("Select your choice:"); Console.WriteLine("1:Add new Epson printer"); Console.WriteLine("2:Add new Canon printer"); Console.WriteLine("3:Print on Canon"); Console.WriteLine("4:Print on Epson"); var key = Console.ReadKey(); if (key.Key == ConsoleKey.D1) { CreateEpsonPrinter(manager); } if (key.Key == ConsoleKey.D2) { CreateCanonPrinter(manager); } if (key.Key == ConsoleKey.D3) { } if (key.Key == ConsoleKey.D4) { } }
private static void CreateEpsonPrinter(PrinterManager m) { string name = Console.ReadLine(); string model = Console.ReadLine(); m.Add(new EpsonPrinter(name, model)); }
private static void Print(Printer printer) { ILogger standartLogger = new DefaultLogger(); PrinterManager.Print(printer, standartLogger); standartLogger.Log($"Printed on {printer.Model} {printer.Name}"); }
private static void CreatePrinter() { Printer printer = new Printer(); try { Console.WriteLine("Enter printer name"); printer.Name = Console.ReadLine(); Console.WriteLine("Enter printer model"); printer.Model = Console.ReadLine(); if (PrinterManager.Add(printer)) { Console.WriteLine("Printer added."); } else { Console.WriteLine("Printer already exists."); } } catch (ArgumentNullException) { Console.WriteLine("Name or Model can't be empty!"); } }
public static void Main(string[] args) { LogToFile logToFile = new LogToFile(); PrinterManager pm = PrinterManager.GetPrinterManager(logToFile); AddKnownPrinters(pm); ProcessPrinting(pm); }
private static void CreatePrinter() { Console.WriteLine("Enter name of printer"); string name = Console.ReadLine(); Console.WriteLine("Enter model of printer"); string model = Console.ReadLine(); PrinterManager.Add(new Printer(name, model)); }
static void Main(string[] args) { PrinterManager printerManager = new PrinterManager(); while (true) { ShowMenu(printerManager); Analyzer(printerManager); } }
private static void CreatePrinter() { Console.WriteLine("Enter printer name"); string name = Console.ReadLine(); Console.WriteLine("Enter printer model"); string model = Console.ReadLine(); PrinterManager.Add(new Printer(model, name)); }
static void Main(string[] args) { var printerManager = new PrinterManager(new Logger()); PrinterManager.OnPrinted += PrinterManager_OnPrinted; while (true) { printerManager.Show(); Process(printerManager); } }
private static void CreatePrinter(this PrinterManager manager) { Console.WriteLine("Enter printer name"); string name = Console.ReadLine(); Console.WriteLine("Enter printer model"); string model = Console.ReadLine(); Printer printer = new Printer(name, model); manager.Add(printer); }
private static void Print(Printer printer, PrinterManager manager) { if (manager.OnStartPrinting.Invoke(printer)) { manager.Print(printer); manager.OnEndPrinting(printer); } else { Console.WriteLine("There is no such printer"); } }
private static void Print(Printer printer) { string fileName = ""; if (GetFile(ref fileName)) { PrinterManager.Print(printer, fileName); } else { Console.WriteLine("Wrong FileName."); } }
private static void Print(this PrinterManager manager, Printer printer) { if (manager == null || printer == null) { throw new ArgumentNullException($"{(nameof(manager))} cant be a null"); } if (printer == null) { throw new ArgumentNullException($"{(nameof(printer))} cant be a null"); } Console.WriteLine(printer.GetType()); manager.Print(printer); }
/// <summary> /// Shows the menu. /// </summary> /// <param name="printerManager">The printer manager.</param> public static void ShowMenu(PrinterManager printerManager) { Console.Clear(); Console.WriteLine("Select your choice:"); Console.WriteLine("1:Add new printer"); Console.WriteLine("2:Print on Canon"); Console.WriteLine("3:Print on Epson"); int i = 4; foreach (var item in printerManager.GetPrinters()) { Console.WriteLine($"{i++} Print on {item.Name} {item.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]); } }
public static PrinterManager GetPrinterManager(ILogger logger) { if (_instance == null) { _instance = new PrinterManager(logger) { Printers = new List <Printer>() }; return(_instance); } else { return(_instance); } }
static void Main(string[] args) { Console.WriteLine("Select your choice:"); Console.WriteLine("0:Add new Epson printer"); Console.WriteLine("1:Add new Canon printer"); Console.WriteLine("2:Print on Canon"); Console.WriteLine("3:Print on Epson"); DefaultLogger logger = new DefaultLogger(); PrinterManager printerManager = new PrinterManager(logger, new PrinterRepository()); var epsonPrinter = new EpsonPrinter("123x"); var canonPrinter = new CanonPrinter("123x"); while (true) { var key = Console.ReadKey(); if (key.Key == ConsoleKey.D0) { printerManager.Add(epsonPrinter); } if (key.Key == ConsoleKey.D1) { printerManager.Add(canonPrinter); } if (key.Key == ConsoleKey.D2) { printerManager.Print(canonPrinter, @"D:\1.txt"); } if (key.Key == ConsoleKey.D3) { printerManager.Print(epsonPrinter, @"D:\1.txt"); } if (key.Key == ConsoleKey.E) { break; } } }
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(); } }
static void Main(string[] args) { var canon = new CanonPrinter("Canon", "1454"); var epson = new EpsonPrinter("Epson", "1231"); var manager = new PrinterManager(); canon.Register(manager); epson.Register(manager); manager.SimulateNewPrint("Start"); Console.WriteLine("Select your choice:"); Console.WriteLine("1:Add new printer"); Console.WriteLine("2:Print on Canon"); Console.WriteLine("3:Print on Epson"); var key = Console.ReadKey(); if (key.Key == ConsoleKey.D1) { CreatePrinter(); } if (key.Key == ConsoleKey.D2) { Print(canon); } if (key.Key == ConsoleKey.D3) { Print(epson); } while (true) { // waiting } }
private static void AddKnownPrinters(PrinterManager pm) { pm.Add(new CanonPrinter()); pm.Add(new EpsonPrinter()); }
private void Print(CanonPrinter canonPrinter) { PrinterManager.Print(canonPrinter, logger); logger.Info("Printed on Canon"); }
private void Print(BasePrinter epsonPrinter) { PrinterManager.Print(epsonPrinter, logger); logger.Info("Printed on Epson"); }
public void Unregister(PrinterManager printerManager) { printerManager.Printing -= StartPrinting; }
public void Register(PrinterManager printerManager) { printerManager.Printing += StartPrinting; }
private static void CreatePrinter() { PrinterManager.Add(); }
private static void Print(CanonPrinter canonPrinter) { PrinterManager.Print(canonPrinter); PrinterManager.Log("Printed on Canon"); }
private static void Print(Printer Printer) { PrinterManager.Print(Printer); Logger.Log($"Printed on {Printer.Name}{Printer.Model}"); }
private static void Print(Printer printer) { PrinterManager.Print(printer); PrinterManager.Log($"Printed on :{printer.Name},{printer.Model}"); }