Esempio n. 1
0
        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);
                }
            }
        }
Esempio n. 2
0
        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++;
            }
        }
Esempio n. 3
0
        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)
            {
            }
        }
Esempio n. 4
0
        private static void CreateEpsonPrinter(PrinterManager m)
        {
            string name  = Console.ReadLine();
            string model = Console.ReadLine();

            m.Add(new EpsonPrinter(name, model));
        }
Esempio n. 5
0
        private static void Print(Printer printer)
        {
            ILogger standartLogger = new DefaultLogger();

            PrinterManager.Print(printer, standartLogger);
            standartLogger.Log($"Printed on {printer.Model} {printer.Name}");
        }
Esempio n. 6
0
        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!");
            }
        }
Esempio n. 7
0
        public static void Main(string[] args)
        {
            LogToFile      logToFile = new LogToFile();
            PrinterManager pm        = PrinterManager.GetPrinterManager(logToFile);

            AddKnownPrinters(pm);

            ProcessPrinting(pm);
        }
Esempio n. 8
0
        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);
            }
        }
Esempio n. 10
0
        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);
            }
        }
Esempio n. 12
0
        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);
        }
Esempio n. 13
0
 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");
     }
 }
Esempio n. 14
0
        private static void Print(Printer printer)
        {
            string fileName = "";

            if (GetFile(ref fileName))
            {
                PrinterManager.Print(printer, fileName);
            }
            else
            {
                Console.WriteLine("Wrong FileName.");
            }
        }
Esempio n. 15
0
        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]);
            }
        }
Esempio n. 18
0
        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;
                }
            }
        }
Esempio n. 20
0
        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
            }
        }
Esempio n. 22
0
 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");
 }
Esempio n. 25
0
 public void Unregister(PrinterManager printerManager)
 {
     printerManager.Printing -= StartPrinting;
 }
Esempio n. 26
0
 public void Register(PrinterManager printerManager)
 {
     printerManager.Printing += StartPrinting;
 }
Esempio n. 27
0
 private static void CreatePrinter()
 {
     PrinterManager.Add();
 }
Esempio n. 28
0
 private static void Print(CanonPrinter canonPrinter)
 {
     PrinterManager.Print(canonPrinter);
     PrinterManager.Log("Printed on Canon");
 }
Esempio n. 29
0
 private static void Print(Printer Printer)
 {
     PrinterManager.Print(Printer);
     Logger.Log($"Printed on {Printer.Name}{Printer.Model}");
 }
Esempio n. 30
0
 private static void Print(Printer printer)
 {
     PrinterManager.Print(printer);
     PrinterManager.Log($"Printed on :{printer.Name},{printer.Model}");
 }